Example #1
0
DataSet::DataSet(bool classAtStart, string file, double ratio)
{
  name = file;
  uniqueClasses=0;
  //int classC=0;
  classes = new vector<string>;
  data = new vector< vector<double>* >;
  ifstream ifs(file.c_str());
  if(!ifs.good())
    return;
  char buf[4096];
  string strBuf;
  string * tmpStr;
  while(!ifs.eof()){
    ifs.getline(buf,sizeof buf);
    strBuf = buf;
    if(strBuf.length()==0)
      break;
    if(classAtStart){
      if(!isIn(classes,*getNext(strBuf)))
	uniqueClasses++;
      classes->push_back(*getNext(strBuf));
      strBuf = getRest(strBuf);
    }else{
      if(!isIn(classes,*getLast(strBuf)))
	uniqueClasses++;
      classes->push_back(*getLast(strBuf));
      strBuf = getRestEnd(strBuf);
    }
    vector<double> * intvector = new vector<double>;
    while((tmpStr = getNext(strBuf)) != 0){
      intvector->push_back(atof(tmpStr->c_str()));
      strBuf = getRest(strBuf);
    }
    data->push_back(intvector);
  }
  ifs.close();
  cerr << "read "<<data->size()<<" datapoints, with "<<data->at(0)->size()<<" paramaters  classes: "<<classes->size()<<" unique:"<<uniqueClasses<<"\n";
  tests = (int)(data->size()*ratio);
  trainings = data->size()-tests;
  Dummy myDummy;
  int ** tmpCoord = myDummy.randomCoords(data->size(),0);
  trainCoords = new int [trainings];
  testCoords = new int [tests];
  int c = 0;
  for(;c<tests;c++)
    testCoords[c] = tmpCoord[c][0];
	
  for(;c<(tests+trainings);c++)
    trainCoords[(c-tests)] = tmpCoord[c][0];

  cerr << "tests: "<<tests<<" trainings: "<<trainings<<endl;
}
Example #2
0
// Get arguments according to specified format
bool LineParser::getArgsFormatted(ParseFormat& format, int optionMask, bool readLine)
{
	Messenger::enter("LineParser::getArgsFormatted");
	bool done = false;
	int result;

	arguments_.clear();

	// Get line from file?
	if (readLine)
	{
		// Returns : 0=ok, 1=error, -1=eof
		result = readNextLine(optionMask);
		
		if (result != 0)
		{
			Messenger::exit("LineParser::getArgsFormatted");
			return result;
		}
	}

	// Loop over chunks in format
	QString arg;
	bool failed = false;
	for (ParseChunk* chunk = format.chunks(); chunk != NULL; chunk = chunk->next)
	{
		switch (chunk->type())
		{
			case (ParseChunk::DelimitedChunk):
				if (getNextArg(optionMask, arg)) arguments_ << arg;
				else failed = true;
				break;
			case (ParseChunk::FormattedChunk):
				if (getNextN(optionMask, chunk->formatLength(), arg)) arguments_ << arg;
				else failed = true;
				break;
			case (ParseChunk::DiscardChunk):
				if (!getNextN(optionMask, chunk->formatLength(), arg)) failed = true;
				break;
			case (ParseChunk::PlainTextChunk):
				if (!getNextN(optionMask, chunk->cFormat().length(), arg)) failed = true;
				break;
			case (ParseChunk::GreedyDelimitedChunk):
				if (getRest(arg)) arguments_ << arg;
				else failed = true;
				break;
      default:
        break;
		}

		if (failed) break;
	}

	Messenger::exit("LineParser::getArgsFormatted");
	return 0;
}