Skip to content
Snippets Groups Projects
Commit 390c3be1 authored by Mickael Savinaud's avatar Mickael Savinaud
Browse files

STYLE

parent 356dcbf3
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment