ViElement ViNeuralNetwork::exportData() { ViElement element("neuralnetwork"); ViElement neuronLayers("neuronlayers"); neuronLayers.addAttribute("count", mLayers.size()); for(int i = 0; i < mLayers.size(); ++i) { neuronLayers.addChild(mLayers[i]->exportData()); } element.addChild(neuronLayers); ViElement synapseLayers("synapselayers"); synapseLayers.addAttribute("count", mLayers.size() - 1); for(int i = 1; i < mLayers.size(); ++i) { ViElement synapseLayer("synapselayer"); synapseLayer.addAttribute("count", mLayers[i]->inputSize()); for(int j = 0; j < mLayers[i]->size(); ++j) { for(int k = 0; k < mLayers[i]->at(j)->inputSize(); ++k) { synapseLayer.addChild(mLayers[i]->at(j)->inputAt(k)->exportData()); } } synapseLayers.addChild(synapseLayer); } element.addChild(synapseLayers); return element; }
int main(int argc, char const *argv[]) { std::srand ( unsigned ( std::time(0) ) ); DataRetrieval dr(argv[1]); particles = dr.getParticles(); std::random_shuffle ( particles.begin(), particles.end() ); numHiddenLayers =atoi(argv[2]); numHiddenNodes = atoi(argv[3]); int generations = atoi(argv[4]); double trainPercent =0.8; cout << "==========================================================================================" << endl; cout << "Starting Neural Network" << endl; cout << "Number of Inputs: " << numInputs << endl; cout << "Number of Hidden Layers: " << numHiddenLayers << endl; cout << "Number of Hidden Nodes: " << numHiddenNodes << endl; cout << "Number of Outputs: " << numOutputs << endl; cout << "Number of Generations: " << generations << endl; cout << "-------------------------------------------------------------------------------------------" << endl; int numTrainedParticles = particles.size()*trainPercent; cout << "Number of Trained Particles: " << numTrainedParticles << endl; NeuronLayers neuronLayers(numInputs, numHiddenLayers, numHiddenNodes, numOutputs); for(int i=0;i<generations;i++) { //std::random_shuffle ( particles.begin(), particles.begin()+numTrainedParticles ); clog << "Generation No: "<< i<< " out of " << generations; for(int u=0;u<numTrainedParticles;u++) { ParticleInformation particle = particles[u]; fillInputs(particle, neuronLayers); fillTargets(particle, neuronLayers); neuronLayers.forwardPass(); neuronLayers.backwardPass(); } float error = fillNeuralNetworkPIDs(neuronLayers, 0, numTrainedParticles); float efficiency = makeNeuralNetworkHistogram(0,numTrainedParticles, false); clog << "\t"<< efficiency << " " << error << endl; //clog << endl; } //Trained Results cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl; cout << "Trained Results" << endl; float error = fillNeuralNetworkPIDs(neuronLayers, 0, numTrainedParticles); float efficiency = makeNeuralNetworkHistogram( 0,numTrainedParticles, true); cout << "Error: " << error << endl; cout << "Pion Efficiency: " << efficiency << endl; cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl; //Untrained Results cout << "Untrained Results" << endl; error = fillNeuralNetworkPIDs(neuronLayers, numTrainedParticles, particles.size()); efficiency =makeNeuralNetworkHistogram( numTrainedParticles,particles.size(), true); cout << "Error: " << error << endl; cout << "Pion Efficiency: " << efficiency << endl; cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl; //Combined Results cout << "Combined Results" << endl; error = fillNeuralNetworkPIDs(neuronLayers, 0, particles.size()); efficiency = makeNeuralNetworkHistogram( 0,particles.size(), true); cout << "Error: " << error << endl; cout << "Pion Efficiency: " << efficiency << endl; cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl; return 0; }