Пример #1
0
void writeEvalObjects( ostream & stream ) {
    EvalObjectDeque eos = norm.getEvalObjectDeque();
    
    for (EOIT it = eos.begin(); it != eos.end(); it++)
    {
        stream << (*it)->toNodeList().str() << endl;
    }

}
Пример #2
0
bool Normalization::operator!=(const Normalization &param1)
{
	return !(param1.getMaxValue() == this->getMaxValue() &&
			 param1.getMinValue() == this->getMinValue() &&
			 param1.getThreshold() == this->getThreshold() &&
			 param1.getElongation() == this->getElongation() &&
			 param1.getAmplitude() == this->getAmplitude() &&
			 param1.getType() == this->getType() &&
			 param1.getName() == this->getName());
}
Пример #3
0
void readEvalObjects( istream & stream ) {
    // gather all objects
    
    string inputLine;
    while (getline(stream, inputLine)) {
        EvalObject *eo = EvalObjectFactory::Create(inputLine);
        if (eo != NULL) {
            norm.addEvalObject( eo );
        }
    }

}
Пример #4
0
int main(int argc, char** argv) {
    
    
    readEvalObjects(cin);
      
   
    for (int i = 1; i < argc; i++) 
    {    
        string option = string( argv[i] );
        
        // remove invisible lines
        if ( optionIs( option , "--remove-invisible" , "-r"  ) )                
            norm.removeUndrawableLines();
        
    }
    
    
    writeEvalObjects(cout);

    return 0;
}
Пример #5
0
bool TrainingSetFile::flush()
{
	QXmlStreamWriter tsWriteXML;

	int
			nPatterns = ts->getPatternCount(),
			nInputs = ts->getInputsSize(),
			nTargets = ts->getTargetsSize();

	QString strInputs,
			strTargets;

	vector<vector<double> >
			inputs = ts->getInputs(),
			targets = ts->getTargets();

	Normalization
			*inputsNorm = ts->getInputsNormalization(),
			*targetsNorm = ts->getTargetsNormalization();

	QString
			strInputsNorm = inputsNorm->getName(),
			strTargetsNorm = targetsNorm->getName();

	DataRepresentation
			*idr = ts->getInputsDataRepresentation(),
			*tdr = ts->getTargetsDataRepresentation();

	tsWriteXML.setDevice(this);
	tsWriteXML.setAutoFormatting(true);
	tsWriteXML.setAutoFormattingIndent(3);

	tsWriteXML.writeStartDocument();

	tsWriteXML.writeStartElement(STR_TRAININGSET);
	//Indica el numero de patrones a almacenar
	tsWriteXML.writeAttribute(STR_PATTERNSIZE, QString::number(nPatterns));

	//Indica el tamaño de las entradas
	tsWriteXML.writeAttribute(STR_INPUTSSIZE, QString::number(nInputs));

	//Indica el tamaño de las salidas
	tsWriteXML.writeAttribute(STR_TARGETSSIZE, QString::number(nTargets));

	//Indica propiedades particulares del archivo
	tsWriteXML.writeStartElement(STR_PROPERTIES);
	tsWriteXML.writeAttribute(STR_VERSION, "1.0.0");
	tsWriteXML.writeEndElement();

	//Este parametro indica que representacion grafica se usara para visualizar entradas
	tsWriteXML.writeStartElement(STR_INPUTSDATAREPRESENTATION);
	tsWriteXML.writeAttribute(STR_NAME, idr->getName());
	tsWriteXML.writeAttribute(STR_FORMAT, idr->getImageFormatName());
	tsWriteXML.writeAttribute(STR_WIDTH, QString::number(idr->getWidth()));
	tsWriteXML.writeAttribute(STR_HEIGHT, QString::number(idr->getHeight()));
	tsWriteXML.writeEndElement();

	//Este parametro indica que representacion grafica se usara para visualizar las salidas
	tsWriteXML.writeStartElement(STR_TARGETSDATAREPRESENTATION);
	tsWriteXML.writeAttribute(STR_NAME, tdr->getName());
	tsWriteXML.writeAttribute(STR_FORMAT, tdr->getImageFormatName());
	tsWriteXML.writeAttribute(STR_WIDTH, QString::number(tdr->getWidth()));
	tsWriteXML.writeAttribute(STR_HEIGHT, QString::number(tdr->getHeight()));
	tsWriteXML.writeEndElement();

	//Normalizacion de entradas
	tsWriteXML.writeStartElement(STR_INPUTSNORMALIZATION);
	tsWriteXML.writeAttribute(STR_TYPE, strInputsNorm);
	tsWriteXML.writeAttribute(STR_MAXVALUE, QString::number(inputsNorm->getMaxValue(), decimalformat, decimals));
	tsWriteXML.writeAttribute(STR_MINVALUE, QString::number(inputsNorm->getMinValue(), decimalformat, decimals));
	tsWriteXML.writeAttribute(STR_THRESHOLD, QString::number(inputsNorm->getThreshold(), decimalformat, decimals));
	tsWriteXML.writeAttribute(STR_AMPLITUDE, QString::number(inputsNorm->getAmplitude(), decimalformat, decimals));
	tsWriteXML.writeAttribute(STR_ELONGATION, QString::number(inputsNorm->getElongation(), decimalformat, decimals));
	tsWriteXML.writeEndElement();

	//Normalizacion de salidas
	tsWriteXML.writeStartElement(STR_TARGETSNORMALIZATION);
	tsWriteXML.writeAttribute(STR_TYPE, strTargetsNorm);
	tsWriteXML.writeAttribute(STR_MAXVALUE, QString::number(targetsNorm->getMaxValue(), decimalformat, decimals));
	tsWriteXML.writeAttribute(STR_MINVALUE, QString::number(targetsNorm->getMinValue(), decimalformat, decimals));
	tsWriteXML.writeAttribute(STR_THRESHOLD, QString::number(targetsNorm->getThreshold(), decimalformat, decimals));
	tsWriteXML.writeAttribute(STR_AMPLITUDE, QString::number(targetsNorm->getAmplitude(), decimalformat, decimals));
	tsWriteXML.writeAttribute(STR_ELONGATION, QString::number(targetsNorm->getElongation(), decimalformat, decimals));
	tsWriteXML.writeEndElement();

	for(int p = 0; p < nPatterns; p++){
		tsWriteXML.writeStartElement(STR_PATTERN);
		tsWriteXML.writeAttribute(STR_INDEX, QString::number(p));
		//Se escriben las entradas
		tsWriteXML.writeStartElement(STR_INPUTS);
		strInputs = "";
		for(int i = 0; i < nInputs; i++){
			strInputs += QString::number(inputs[p][i], decimalformat, decimals);
			if(i != nInputs - 1){
				strInputs += STR_SEPARATOR;
			}
		}
		tsWriteXML.writeCharacters(strInputs);
		tsWriteXML.writeEndElement();//inputs

		//Se escriben las salidas
		tsWriteXML.writeStartElement(STR_TARGETS);
		strTargets = "";
		for(int t = 0; t < nTargets; t++){
			strTargets += QString::number(targets[p][t], decimalformat, decimals);
			if(t != nTargets - 1){
				strTargets += STR_SEPARATOR;
			}
		}
		//		tsXML.writeTextElement("targets", strTargets);
		tsWriteXML.writeCharacters(strTargets);
		tsWriteXML.writeEndElement();//targets
		tsWriteXML.writeEndElement();//pattern
	}
	tsWriteXML.writeEndElement();//trainingset
	tsWriteXML.writeEndDocument();

	return true;
}
Пример #6
0
TrainingSetFile::TSFResult TrainingSetFile::fromFile(QFile &file)
{
	QString
			version,
			text;

	QStringRef name;

	QXmlStreamReader tsReadXML;

	QXmlStreamReader::TokenType tt;
	QStringList textElements;
	QXmlStreamAttributes attributes;

	TrainingSetFile *retTSF = new TrainingSetFile();
	TSFResult res = {retTSF, true, NoError, "", 0};

	TrainingSet *ts = retTSF->getTrainingSet();

	int
			lastPatternIndex = 0,
			sTextElements,
			pSize = 0,
			iSize = 0,
			tSize = 0;

	Normalization
			*inor = new Normalization(),
			*tnor = new Normalization();

	vector<vector<double> >
			inputs,
			targets;

	DataRepresentation
			*idr = ts->getInputsDataRepresentation(),
			*tdr = ts->getTargetsDataRepresentation();

	if(file.open(QIODevice::ReadOnly)){
		tsReadXML.setDevice(&file);
		while (!tsReadXML.atEnd()) {
			tt = tsReadXML.readNext();

			if(tsReadXML.hasError()){
				file.close();
				return {retTSF, false, toTSFError(tsReadXML.error()), tsReadXML.errorString(), tsReadXML.lineNumber()};
			}

			if(tt == QXmlStreamReader::StartDocument){
				continue;
			}else if(tt == QXmlStreamReader::StartElement){
				name = tsReadXML.name();
				if(name == STR_TRAININGSET){
					attributes = tsReadXML.attributes();
					if(attributes.hasAttribute(STR_PATTERNSIZE) &&
					   attributes.hasAttribute(STR_INPUTSSIZE) &&
					   attributes.hasAttribute(STR_TARGETSSIZE))
					{
						pSize = attributes.value(STR_PATTERNSIZE).toInt();
						iSize = attributes.value(STR_INPUTSSIZE).toInt();
						tSize = attributes.value(STR_TARGETSSIZE).toInt();

						inputs = vector<vector<double> >(pSize, vector<double>(iSize, 0));
						targets = vector<vector<double> >(pSize, vector<double>(tSize, 0));
					}else{
						file.close();
						return {
							retTSF, false, NotWellFormedError, "NotWellFormedError: Missing attributes (" + STR_PATTERNSIZE + ", " + STR_INPUTSSIZE + ", " + STR_TARGETSSIZE + ") on tag " + STR_TRAININGSET, tsReadXML.lineNumber()
						};
					}
				}else if(name == STR_PROPERTIES){
					attributes = tsReadXML.attributes();
					if(attributes.hasAttribute(STR_VERSION)){
						version = attributes.value(STR_VERSION).toString();
					}else{
						file.close();
						return
						{
							retTSF, false, NotWellFormedError, "NotWellFormedError: Missing attributes (" + STR_VERSION + ") on tag " + STR_PROPERTIES, tsReadXML.lineNumber()
						};
					}
				}else if(name == STR_INPUTSDATAREPRESENTATION){
					attributes = tsReadXML.attributes();
					if(attributes.hasAttribute(STR_NAME) &&
					   attributes.hasAttribute(STR_WIDTH) &&
					   attributes.hasAttribute(STR_HEIGHT) &&
					   attributes.hasAttribute(STR_FORMAT))
					{
						idr->setType(drFromStrToInt(attributes.value(STR_NAME).toString()));
						idr->setWidth(attributes.value(STR_WIDTH).toInt());
						idr->setHeight(attributes.value(STR_HEIGHT).toInt());
						idr->setImageFormat(fromStrToImgFormat(attributes.value(STR_FORMAT).toString()));
					}else{
						file.close();
						return
						{
							retTSF, false, NotWellFormedError, "NotWellFormedError: Missing attributes (" + STR_NAME + ", " + STR_WIDTH + ", " + STR_HEIGHT + ", " + STR_FORMAT + ") on tag " + STR_INPUTSDATAREPRESENTATION, tsReadXML.lineNumber()
						};
					}
				}else if(name == STR_TARGETSDATAREPRESENTATION){
					attributes = tsReadXML.attributes();
					if(attributes.hasAttribute(STR_NAME) &&
					   attributes.hasAttribute(STR_WIDTH) &&
					   attributes.hasAttribute(STR_HEIGHT) &&
					   attributes.hasAttribute(STR_FORMAT))
					{
						tdr->setType(drFromStrToInt(attributes.value(STR_NAME).toString()));
						tdr->setWidth(attributes.value(STR_WIDTH).toInt());
						tdr->setHeight(attributes.value(STR_HEIGHT).toInt());
						tdr->setImageFormat(fromStrToImgFormat(attributes.value(STR_FORMAT).toString()));
					}else{
						file.close();
						return
						{
							retTSF, false, NotWellFormedError, "NotWellFormedError: Missing attributes (" + STR_NAME + ", " + STR_WIDTH + ", " + STR_HEIGHT + ", " + STR_FORMAT + ") on tag " + STR_TARGETSDATAREPRESENTATION, tsReadXML.lineNumber()
						};
					}
				}else if(name == STR_INPUTSNORMALIZATION){
					attributes = tsReadXML.attributes();
					if(attributes.hasAttribute(STR_TYPE) &&
					   attributes.hasAttribute(STR_MAXVALUE) &&
					   attributes.hasAttribute(STR_MINVALUE) &&
					   attributes.hasAttribute(STR_THRESHOLD) &&
					   attributes.hasAttribute(STR_AMPLITUDE) &&
					   attributes.hasAttribute(STR_ELONGATION))
					{
						inor->setType(normFromStrToInt(attributes.value(STR_TYPE).toString()));
						inor->setMaxValue(attributes.value(STR_MAXVALUE).toDouble());
						inor->setMinValue(attributes.value(STR_MINVALUE).toDouble());
						inor->setThreshold(attributes.value(STR_THRESHOLD).toDouble());
						inor->setAmplitude(attributes.value(STR_AMPLITUDE).toDouble());
						inor->setElongation(attributes.value(STR_ELONGATION).toDouble());
					}else{
						file.close();
						return
						{
							retTSF, false, NotWellFormedError, "NotWellFormedError: Missing attributes (" + STR_TYPE + ", " + STR_MAXVALUE + ", " + STR_MINVALUE + ", " + STR_THRESHOLD + ", " + STR_ELONGATION + ") on tag " + STR_INPUTSNORMALIZATION, tsReadXML.lineNumber()
						};
					}
				}else if(name == STR_TARGETSNORMALIZATION){
					attributes = tsReadXML.attributes();
					if(attributes.hasAttribute(STR_TYPE) &&
					   attributes.hasAttribute(STR_MAXVALUE) &&
					   attributes.hasAttribute(STR_MINVALUE) &&
					   attributes.hasAttribute(STR_THRESHOLD) &&
					   attributes.hasAttribute(STR_AMPLITUDE) &&
					   attributes.hasAttribute(STR_ELONGATION))
					{
						tnor->setType(normFromStrToInt(attributes.value(STR_TYPE).toString()));
						tnor->setMaxValue(attributes.value(STR_MAXVALUE).toDouble());
						tnor->setMinValue(attributes.value(STR_MINVALUE).toDouble());
						tnor->setThreshold(attributes.value(STR_THRESHOLD).toDouble());
						tnor->setAmplitude(attributes.value(STR_AMPLITUDE).toDouble());
						tnor->setElongation(attributes.value(STR_ELONGATION).toDouble());
					}else{
						file.close();
						return
						{
							retTSF, false, NotWellFormedError, "NotWellFormedError: Missing attributes (" + STR_TYPE + ", " + STR_MAXVALUE + ", " + STR_MINVALUE + ", " + STR_THRESHOLD + ", " + STR_ELONGATION + ") on tag " + STR_TARGETSNORMALIZATION, tsReadXML.lineNumber()
						};
					}
				}else if(name == STR_PATTERN){
					attributes = tsReadXML.attributes();
					if(attributes.hasAttribute(STR_INDEX))
					{
						lastPatternIndex = attributes.value(STR_INDEX).toInt();
					}else{
						file.close();
						return
						{
							retTSF, false, NotWellFormedError, "NotWellFormedError: Missing attributes (" + STR_INDEX + ") on tag " + STR_PATTERN, tsReadXML.lineNumber()
						};
					}
				}else if(name == STR_INPUTS){
					text = tsReadXML.readElementText(QXmlStreamReader::SkipChildElements);
					textElements = text.split(STR_SEPARATOR, QString::KeepEmptyParts, Qt::CaseInsensitive);
					sTextElements = textElements.size();
					if(sTextElements == iSize){
						for(int i = 0; i < sTextElements; i++){
							inputs[lastPatternIndex][i] = textElements[i].toDouble();
						}
					}else{
						file.close();
						return
						{
							retTSF, false, NotWellFormedError, "NotWellFormedError: Incongruence between reported input size with found inputs elements", tsReadXML.lineNumber()
						};
					}
				}else if(name == STR_TARGETS){
					text = tsReadXML.readElementText(QXmlStreamReader::SkipChildElements);
					textElements = text.split(STR_SEPARATOR, QString::KeepEmptyParts, Qt::CaseInsensitive);
					sTextElements = textElements.size();
					if(sTextElements == tSize){
						for(int t = 0; t < sTextElements; t++){
							targets[lastPatternIndex][t] = textElements[t].toDouble();
						}
					}else{
						file.close();
						return
						{
							retTSF, false, NotWellFormedError, "NotWellFormedError: Incongruence between reported target size with found target elements", tsReadXML.lineNumber()
						};
					}
				}
			}
		}

		retTSF->setFileName(file.fileName());
		res.file = retTSF;

		ts->setPatternCount(pSize);
		ts->setInputs(inputs, iSize);
		ts->setTargets(targets, tSize);
		ts->setInputsNormalization(inor);
		ts->setTargetsNormalization(tnor);
		ts->setInputsDataRepresentation(idr);
		ts->setTargetsDataRepresentation(tdr);

		res.sucess = true;
		res.errnum = toTSFError(QXmlStreamReader::NoError);
		res.errormsg = "";
		res.line = -1;

		file.close();
		return res;
	}else{
		file.close();
		return
		{
			retTSF, false, toTSFError(file.error()), file.errorString(), -1
		};
	}
}