Generates neural net instances through genetic algorithm for use in task learning by m3pi. Reward determined by detection of black areas on arena floor, or by amount of area explored in limited time. Due to memory size, limited # of nets.

Dependencies:   Ping m3pimaze mbed

Committer:
parkbanks
Date:
Thu Apr 23 20:16:51 2015 +0000
Revision:
0:ac93d9db8dbd
Initial commit, bot fully working.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
parkbanks 0:ac93d9db8dbd 1 #ifndef CNEURALNET_H
parkbanks 0:ac93d9db8dbd 2 #define CNEURALNET_H
parkbanks 0:ac93d9db8dbd 3
parkbanks 0:ac93d9db8dbd 4 #include <vector>
parkbanks 0:ac93d9db8dbd 5 #include <fstream>
parkbanks 0:ac93d9db8dbd 6 #include <math.h>
parkbanks 0:ac93d9db8dbd 7 #include "utils.h"
parkbanks 0:ac93d9db8dbd 8
parkbanks 0:ac93d9db8dbd 9 using namespace std;
parkbanks 0:ac93d9db8dbd 10
parkbanks 0:ac93d9db8dbd 11 // Neuron Struct
parkbanks 0:ac93d9db8dbd 12 struct SNeuron
parkbanks 0:ac93d9db8dbd 13 {
parkbanks 0:ac93d9db8dbd 14 int m_NumInputs; //the number of inputs into the neuron
parkbanks 0:ac93d9db8dbd 15 vector<float> m_vecWeight; //the weights for each input
parkbanks 0:ac93d9db8dbd 16 SNeuron(int NumInputs); //ctor
parkbanks 0:ac93d9db8dbd 17 };
parkbanks 0:ac93d9db8dbd 18
parkbanks 0:ac93d9db8dbd 19
parkbanks 0:ac93d9db8dbd 20 // Neuron Layer Struct
parkbanks 0:ac93d9db8dbd 21 struct SNeuronLayer
parkbanks 0:ac93d9db8dbd 22 {
parkbanks 0:ac93d9db8dbd 23 int m_NumNeurons; //number of neurons in layer
parkbanks 0:ac93d9db8dbd 24 vector<SNeuron> m_vecNeurons; //the layer of neurons
parkbanks 0:ac93d9db8dbd 25 SNeuronLayer(int NumNeurons, int NumInputsPerNeuron);
parkbanks 0:ac93d9db8dbd 26 };
parkbanks 0:ac93d9db8dbd 27
parkbanks 0:ac93d9db8dbd 28
parkbanks 0:ac93d9db8dbd 29 // Neural Net
parkbanks 0:ac93d9db8dbd 30 class CNeuralNet
parkbanks 0:ac93d9db8dbd 31 {
parkbanks 0:ac93d9db8dbd 32 private:
parkbanks 0:ac93d9db8dbd 33 int m_NumInputs;
parkbanks 0:ac93d9db8dbd 34 int m_NumOutputs;
parkbanks 0:ac93d9db8dbd 35 int m_NumHiddenLayers;
parkbanks 0:ac93d9db8dbd 36 int m_NeuronsPerHiddenLyr;
parkbanks 0:ac93d9db8dbd 37 vector<SNeuronLayer> m_vecLayers;//storage for each neuron layer
parkbanks 0:ac93d9db8dbd 38
parkbanks 0:ac93d9db8dbd 39 public:
parkbanks 0:ac93d9db8dbd 40 CNeuralNet();
parkbanks 0:ac93d9db8dbd 41 void CreateNet();
parkbanks 0:ac93d9db8dbd 42 vector<float> GetWeights()const; //weights from ANN
parkbanks 0:ac93d9db8dbd 43 int GetNumberOfWeights()const; //returns number of weights in net
parkbanks 0:ac93d9db8dbd 44 void PutWeights(vector<float> &weights); //replaces weights
parkbanks 0:ac93d9db8dbd 45 vector<float> Update(vector<float> &inputs); //gets outputs from net
parkbanks 0:ac93d9db8dbd 46 inline float Sigmoid(float activation, float response); //sigmoid function
parkbanks 0:ac93d9db8dbd 47 };
parkbanks 0:ac93d9db8dbd 48
parkbanks 0:ac93d9db8dbd 49 #endif