void NeuralNetwork::train(BlockSparseMatrix& input, BlockSparseMatrix& reference) { //create a backpropagate-data class //given the neural network, inputs & reference outputs util::log("NeuralNetwork") << "Running back propagation on input matrix (" << input.rows() << ") rows, (" << input.columns() << ") columns. Using reference output of (" << reference.rows() << ") rows, (" << reference.columns() << ") columns. \n"; auto backPropagation = createBackPropagation(); backPropagation->setNeuralNetwork(this); backPropagation->setInput(&input); backPropagation->setReferenceOutput(&reference); auto solver = NeuralNetworkSolver::create(backPropagation); try { solver->solve(); } catch(...) { delete solver; delete backPropagation; throw; } delete solver; delete backPropagation; }
BackPropagation* NeuralNetwork::createBackPropagation() const { std::string backPropagationType; if(_useSparseCostFunction) { backPropagationType = "SparseBackPropagation"; } else { backPropagationType = "DenseBackPropagation"; } backPropagationType = util::KnobDatabase::getKnobValue( "BackPropagation::ForceType", backPropagationType); auto backPropagation = BackPropagationFactory::create(backPropagationType); if(backPropagation == nullptr) { throw std::runtime_error("Failed to create back propagation " "structure with type: " + backPropagationType); } backPropagation->setNeuralNetwork(const_cast<NeuralNetwork*>(this)); return backPropagation; }
Creature::Creature(int body_parts, int constraints, const NeuralNetwork & neural_network) : _name(""), _number_of_body_parts(body_parts), _number_of_constraints(constraints), _body_parts(new BodyPart*[body_parts]), _constraints(new Constraint*[constraints]), _neural_network(NULL), _initial_position(btVector3(0.0, 0.0, 0.0)), _final_position(btVector3(0.0, 0.0, 0.0)), _fitness(0.0) { for (int i = 0; i < getNumberOfBodyParts(); ++i) { setBodyPart(i, new BodyPart()); getBodyPart(i).setName("Body Part #" + TO_STRING(i)); } for (int i = 0; i < getNumberOfConstraints(); ++i) { setConstraint(i, new Constraint()); getConstraint(i).setName("Constraint #" + TO_STRING(i)); } setNeuralNetwork(neural_network.clone()); }