Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
otb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Julien Cabieces
otb
Commits
390c3be1
Commit
390c3be1
authored
12 years ago
by
Mickael Savinaud
Browse files
Options
Downloads
Patches
Plain Diff
STYLE
parent
356dcbf3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Testing/Code/Learning/otbTrainMachineLearningModel.cxx
+40
-44
40 additions, 44 deletions
Testing/Code/Learning/otbTrainMachineLearningModel.cxx
with
40 additions
and
44 deletions
Testing/Code/Learning/otbTrainMachineLearningModel.cxx
+
40
−
44
View file @
390c3be1
...
...
@@ -51,63 +51,59 @@ bool ReadDataFile(const std::string & infname, InputListSampleType * samples, Ta
unsigned
int
nbfeatures
=
0
;
while
(
!
ifs
.
eof
())
{
std
::
string
line
;
std
::
getline
(
ifs
,
line
);
if
(
nbfeatures
==
0
)
{
nbfeatures
=
std
::
count
(
line
.
begin
(),
line
.
end
(),
' '
)
-
1
;
//std::cout<<"Found "<<nbfeatures<<" features per samples"<<std::endl;
}
while
(
!
ifs
.
eof
())
{
std
::
string
line
;
std
::
getline
(
ifs
,
line
);
if
(
line
.
size
()
>
1
)
{
if
(
nbfeatures
==
0
)
{
nbfeatures
=
std
::
count
(
line
.
begin
(),
line
.
end
(),
' '
)
-
1
;
//std::cout<<"Found "<<nbfeatures<<" features per samples"<<std::endl;
}
InputSampleType
sample
(
nbfeatures
);
sample
.
Fill
(
0
);
if
(
line
.
size
()
>
1
)
{
InputSampleType
sample
(
nbfeatures
);
sample
.
Fill
(
0
);
std
::
string
::
size_type
pos
=
line
.
find_first_of
(
" "
,
0
);
std
::
string
::
size_type
pos
=
line
.
find_first_of
(
" "
,
0
);
// Parse label
TargetSampleType
label
;
label
[
0
]
=
atoi
(
line
.
substr
(
0
,
pos
).
c_str
());
//std::cout << "label = " << label[0] << std::endl;
// Parse label
TargetSampleType
label
;
label
[
0
]
=
atoi
(
line
.
substr
(
0
,
pos
).
c_str
());
//std::cout << "label = " << label[0] << std::endl;
bool
endOfLine
=
false
;
bool
endOfLine
=
false
;
unsigned
int
id
=
0
;
unsigned
int
id
=
0
;
while
(
!
endOfLine
)
{
std
::
string
::
size_type
nextpos
=
line
.
find_first_of
(
" "
,
pos
+
1
);
while
(
!
endOfLine
)
if
(
nextpos
==
std
::
string
::
npos
)
{
endOfLine
=
true
;
nextpos
=
line
.
size
()
-
1
;
}
else
{
std
::
string
::
size_type
nextpos
=
line
.
find_first_of
(
" "
,
pos
+
1
);
if
(
nextpos
==
std
::
string
::
npos
)
{
endOfLine
=
true
;
nextpos
=
line
.
size
()
-
1
;
}
else
{
std
::
string
feature
=
line
.
substr
(
pos
,
nextpos
-
pos
);
std
::
string
::
size_type
semicolonpos
=
feature
.
find_first_of
(
":"
);
id
=
atoi
(
feature
.
substr
(
0
,
semicolonpos
).
c_str
());
//std::cout << "id = " << id << std::endl;
sample
[
id
-
1
]
=
atof
(
feature
.
substr
(
semicolonpos
+
1
,
feature
.
size
()
-
semicolonpos
).
c_str
());
//std::cout << "sample[" << id << "] = " << sample[id] << std::endl;
pos
=
nextpos
;
}
std
::
string
feature
=
line
.
substr
(
pos
,
nextpos
-
pos
);
std
::
string
::
size_type
semicolonpos
=
feature
.
find_first_of
(
":"
);
id
=
atoi
(
feature
.
substr
(
0
,
semicolonpos
).
c_str
());
//std::cout << "id = " << id << std::endl;
sample
[
id
-
1
]
=
atof
(
feature
.
substr
(
semicolonpos
+
1
,
feature
.
size
()
-
semicolonpos
).
c_str
());
//std::cout << "sample[" << id << "] = " << sample[id] << std::endl;
pos
=
nextpos
;
}
samples
->
PushBack
(
sample
);
labels
->
PushBack
(
label
);
}
samples
->
PushBack
(
sample
);
labels
->
PushBack
(
label
);
}
}
//std::cout<<"Retrieved "<<samples->Size()<<" samples"<<std::endl;
//std::cout<<"Retrieved "<<samples->Size()<<" samples"<<std::endl;
ifs
.
close
();
return
true
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment