void NeuralNetwork::read(TextFileReader const& _file) throw()
{
	TextFileReader file = _file;
	
	Text text;
	int line = 0;
	int numLayers = -1;
	float learnRate, actFuncOffset;
	
	IntArray nodes;
	
	while(file.isEof() == false)
	{
		text = file.readLine();
		
		if(line == 0)
		{
			// should be the format/version string
			if(text.contains("NeuralNetworkSimple:v1") == false)
			{
				printf("NeuralNetwork::read wrong version type\n");
				return;
			}
		}
		else if(line == 1)
		{
			// should be learn rate and act func offset			
			sscanf(text.getArray(), "learnRate: %f actFuncOffset: %f", &learnRate, &actFuncOffset);
		}
		else if(line == 2)
		{
			// should be the number of layers			
			sscanf(text.getArray(), "Layers:%d", &numLayers);
			
			if(numLayers < 2) 
			{
				printf("NeuralNetwork::read invalid number of layers\n");
				return;
			}
			
			nodes = IntArray::withSize(numLayers, false);
		}
		else if(numLayers > 0)
		{
			int layer, numNodes;
			sscanf(text.getArray(), "Layer %d:%d", &layer, &numNodes);
			numLayers--;
			
			nodes[layer] = numNodes;
			
			if(numLayers == 0)
			{				
				if(nodes == getStructure())
				{
					setLearnRate(learnRate);
					setActFuncOffset(actFuncOffset);
				}
				else
				{
					setInternal(new NeuralNetworkSimpleInternal(nodes, learnRate, actFuncOffset));
				}
			}
		}
		else
		{
			// it's a weight or a threshold
			int layer, node, index;
			float value;
			sscanf(text.getArray(), "%d %d %d %f", &layer, &node, &index, &value);
			
			if(index < 0)
				setThreshold(layer, node, value);
			else
				setWeight(layer, node, index, value);
		}
		
		line++;
	}		
}
Beispiel #2
0
size_t messagePart::getPartCount() const
{
	return getStructure()->getPartCount();
}
Beispiel #3
0
// ------------------ getFacets ---------------------
StructuralComponent * Cell::getFacets() {

    StructuralComponent * facets = new StructuralComponent(getPhysicalModel());
    Cell * face;
    switch (getProperties()->getType())
    {
    case StructureProperties::HEXAHEDRON :
        face = new Cell(getPhysicalModel(), StructureProperties::QUAD);
        face->addStructure(getStructure(0));
        face->addStructure(getStructure(3));
        face->addStructure(getStructure(2));
        face->addStructure(getStructure(1));
        facets->addStructure(face);
        face = new Cell(getPhysicalModel(), StructureProperties::QUAD);
        face->addStructure(getStructure(0));
        face->addStructure(getStructure(4));
        face->addStructure(getStructure(7));
        face->addStructure(getStructure(3));
        facets->addStructure(face);
        face = new Cell(getPhysicalModel(), StructureProperties::QUAD);
        face->addStructure(getStructure(0));
        face->addStructure(getStructure(1));
        face->addStructure(getStructure(5));
        face->addStructure(getStructure(4));
        facets->addStructure(face);
        face = new Cell(getPhysicalModel(), StructureProperties::QUAD);
        face->addStructure(getStructure(3));
        face->addStructure(getStructure(7));
        face->addStructure(getStructure(6));
        face->addStructure(getStructure(2));
        facets->addStructure(face);
        face = new Cell(getPhysicalModel(), StructureProperties::QUAD);
        face->addStructure(getStructure(1));
        face->addStructure(getStructure(2));
        face->addStructure(getStructure(6));
        face->addStructure(getStructure(5));
        facets->addStructure(face);
        face = new Cell(getPhysicalModel(), StructureProperties::QUAD);
        face->addStructure(getStructure(4));
        face->addStructure(getStructure(5));
        face->addStructure(getStructure(6));
        face->addStructure(getStructure(7));
        facets->addStructure(face);
        return facets;
    case StructureProperties::TETRAHEDRON :
        face = new Cell(getPhysicalModel(), StructureProperties::TRIANGLE);
        face->addStructure(getStructure(0));
        face->addStructure(getStructure(1));
        face->addStructure(getStructure(2));
        facets->addStructure(face);
        face = new Cell(getPhysicalModel(), StructureProperties::TRIANGLE);
        face->addStructure(getStructure(0));
        face->addStructure(getStructure(2));
        face->addStructure(getStructure(3));
        facets->addStructure(face);
        face = new Cell(getPhysicalModel(), StructureProperties::TRIANGLE);
        face->addStructure(getStructure(0));
        face->addStructure(getStructure(3));
        face->addStructure(getStructure(1));
        facets->addStructure(face);
        face = new Cell(getPhysicalModel(), StructureProperties::TRIANGLE);
        face->addStructure(getStructure(2));
        face->addStructure(getStructure(1));
        face->addStructure(getStructure(3));
        facets->addStructure(face);
        return facets;
    case StructureProperties::WEDGE :
        face = new Cell(getPhysicalModel(), StructureProperties::QUAD);
        face->addStructure(getStructure(2));
        face->addStructure(getStructure(5));
        face->addStructure(getStructure(4));
        face->addStructure(getStructure(1));
        facets->addStructure(face);
        face = new Cell(getPhysicalModel(), StructureProperties::QUAD);
        face->addStructure(getStructure(0));
        face->addStructure(getStructure(1));
        face->addStructure(getStructure(4));
        face->addStructure(getStructure(3));
        facets->addStructure(face);
        face = new Cell(getPhysicalModel(), StructureProperties::QUAD);
        face->addStructure(getStructure(2));
        face->addStructure(getStructure(0));
        face->addStructure(getStructure(3));
        face->addStructure(getStructure(5));
        facets->addStructure(face);
        return facets;
    case StructureProperties::QUAD :
    case StructureProperties::TRIANGLE :
        facets->addStructure(this);
        return facets;
    default :
        return NULL;
    }

}
Beispiel #4
0
ref <messagePart> messagePart::getPartAt(const size_t pos)
{
	return getStructure()->getPartAt(pos);
}