30 #include "neuralNet/Neural Network v2/neuralNetwork.h"
40 NeuroAdapter::NeuroAdapter() :
44 NeuroAdapter::~NeuroAdapter(){};
48 numberOfActions=configdata.getDoubleValue(
"numberOfActions");
49 numberOfStates=configdata.getDoubleValue(
"numberOfStates");
50 numberOfControllers=configdata.getDoubleValue(
"numberOfControllers");
57 currentControllers = this->neuroEvo->nextSetOfControllers();
61 currentControllers = this->neuroEvo->nextSetOfControllers();
62 for(std::size_t i=0;i<currentControllers.size();i++)
65 ss<< neuroEvo->
resourcePath <<
"logs/bestParameters-"<<this->neuroEvo->suffix<<
"-"<<i<<
".nnw";
66 currentControllers[i]->loadFromFile(ss.str().c_str());
69 errorOfFirstController=0.0;
72 vector<vector<double> > NeuroAdapter::step(
double deltaTimeSeconds,vector<double> state)
74 totalTime+=deltaTimeSeconds;
76 vector< vector<double> > actions;
79 double *inputs =
new double[numberOfStates];
83 assert (state.size() == numberOfStates);
84 for (
int i = 0; i < numberOfStates; i++)
86 inputs[i]=state[i] / 2.0 + 0.5;
88 for(std::size_t i=0;i<currentControllers.size();i++)
90 double *output=currentControllers[i]->getNn()->feedForwardPattern(inputs);
91 vector<double> tmpAct;
92 for(
int j=0;j<numberOfActions;j++)
94 tmpAct.push_back(output[j]);
96 actions.push_back(tmpAct);
102 for(std::size_t i=0;i<currentControllers.size();i++)
104 vector<double> tmpAct;
105 for(std::size_t j=0;j<currentControllers[i]->statelessParameters.size();j++)
107 tmpAct.push_back(currentControllers[i]->statelessParameters[j]);
109 actions.push_back(tmpAct);
117 void NeuroAdapter::endEpisode(vector<double> scores)
121 vector< double > tmp(1);
123 neuroEvo->updateScores(tmp);
124 cout<<
"Exploded"<<endl;
128 cout<<
"Dist Moved: "<<scores[0]<<
" energy: "<<scores[1]<<endl;
130 neuroEvo->updateScores(scores);
void initialize(NeuroEvolution *evo, bool isLearning, configuration config)
A class to read a learning configuration from a .ini file.
A series of functions to assist with file input/output.
Defines a class NeuroAdapter to pass parameters from NeuroEvolution to a controller.