void NeuralPatternArray::write(TextFileWriter const& _file) const throw()
{	
	TextFileWriter file = _file;
	
	const NeuralPattern* array = getArray();
	
	if(array != 0)
	{
		file.write("NeuralPatternArray:v1");
		
		const int numPatterns = size();
		for(int i = 0; i < numPatterns; i++)
		{
			array[i].write(file);
		}
	}
}
void NeuralPatternSimpleInternal::write(TextFileWriter const& _file) const throw()
{
	const int size = 128;
	char buf[size];
	
	TextFileWriter file = _file;
	
	file.write("\nNeuralPatternSimple:v1\n");
	
	const int numInputs = inputVector.size();
	snprintf(buf, size, "Inputs:%3d\n", numInputs);
	file.write(buf);
	
	const float *inputVectorArray = inputVector.getArray();
	for(int i = 0; i < numInputs; i++)
	{
		snprintf(buf, size, "%3d %.16f\n", i, inputVectorArray[i]);
		file.write(buf);
	}
	
	const int numOutputs = outputVector.size();
	snprintf(buf, size, "Outputs:%3d", numOutputs);
	file.write(buf);
	
	const float *outputVectorArray = outputVector.getArray();
	for(int i = 0; i < numOutputs; i++)
	{
		file.write("\n");
		snprintf(buf, size, "%3d %.16f", i, outputVectorArray[i]);
		file.write(buf);
	}
}
Esempio n. 3
0
void NeuralNetworkSimpleInternal::write(TextFileWriter const& _file) const throw()
{
	const int intFieldWidth = 4;
	const int size = 128;
	char buf[size];
	
	TextFileWriter file = _file;
	
	file.write("NeuralNetworkSimple:v1\n");
	
	snprintf(buf, size, "learnRate: %f actFuncOffset: %f\n", getLearnRate(), getActFuncOffset());
	file.write(buf);
	
	snprintf(buf, size, "Layers:%*d\n", intFieldWidth, getNumLayersIncludingInput());
	file.write(buf);
	
	snprintf(buf, size, "Layer %*d:%*d\n", intFieldWidth, 0, 
										   intFieldWidth, numInputs);
	file.write(buf);
	
	for(int layer = 0; layer < getNumLayersExcludingInput(); layer++)
	{
		snprintf(buf, size, "Layer %*d:%*d\n", intFieldWidth, layer+1, 
											   intFieldWidth, getNumNodesOnLayer(layer));
		file.write(buf);
	}
		
	for(int layer = 0; layer < getNumLayersExcludingInput(); layer++)
	{
		const int numNodes = getNumNodesOnLayer(layer);
		for(int node = 0; node < numNodes; node++)
		{
			NumericalArray<float> weights;
			float threshold;
			get(layer, node, &weights, threshold);
				
			snprintf(buf, size, "%*d %*d %*d   %.16f\n", intFieldWidth, layer, 
														 intFieldWidth, node, 
														 intFieldWidth, -1, 
														 threshold);
			file.write(buf);
			
			const int numWeights = weights.size();
			for(int weight = 0; weight < numWeights; weight++)
			{
				snprintf(buf, size, "%*d %*d %*d   %.16f\n", intFieldWidth, layer, 
															 intFieldWidth, node, 
															 intFieldWidth, weight, 
															 weights[weight]);
				file.write(buf);
			}
		}
	}
	
}
Esempio n. 4
0
void TextFileWriterTest::testmethod_WriteFile()
{
	TextFileWriter writer;
	map<string, string> params;
	std::string name = "test.file.text";
	params["a"] = "b";
	params["b"] = "c";
	params["c"] = "d";
	writer.WriteFile(name, params);

	const int linelen=32;
	char line[linelen];
	std::ifstream instr(name.c_str());
	instr.getline(line, linelen);
	CPPUNIT_ASSERT( strncmp(line, "a=b", 3) == 0 );
	instr.getline(line, linelen);
	CPPUNIT_ASSERT( strncmp(line, "b=c", 3) == 0 );
	instr.getline(line, linelen);
	CPPUNIT_ASSERT( strncmp(line, "c=d", 3) == 0 );
}