Bobot_nn.h

#ifndef _BOBOT_NN_H
#define _BOBOT_NN_H

// numéro des NN
#define BOBOT_MOVE_BRAIN 1
#define BOBOT_LOOK_BRAIN 2

// -----------------------------------------------------------------------------
// RESEAU DE NEURONES (NN) S'OCCUPANT DES MOUVEMENTS DU BOBOT
// -----------------------------------------------------------------------------
#define BOBOT_MOVE_BRAIN__BRAIN_NAME "moveBrain"

#define BOBOT_MOVE_BRAIN__NUM_SONARS 6
#define BOBOT_MOVE_BRAIN__NUM_INPUTS (BOBOT_MOVE_BRAIN__NUM_SONARS + 5)

// Indices des entrées du NN. Les sonars doivent être impérativement en premiers
#define BOBOT_MOVE_BRAIN__SONAR_CENTER_DOWN 0
#define BOBOT_MOVE_BRAIN__SONAR_RIGHT 1
#define BOBOT_MOVE_BRAIN__SONAR_LEFT 2
#define BOBOT_MOVE_BRAIN__SONAR_CENTER 3
#define BOBOT_MOVE_BRAIN__SONAR_RIGHT_DOWN 4
#define BOBOT_MOVE_BRAIN__SONAR_LEFT_DOWN 5

#define BOBOT_MOVE_BRAIN__LAST_ROTATION 6
#define BOBOT_MOVE_BRAIN__NODE_YAW 7
#define BOBOT_MOVE_BRAIN__NODE_PITCH 8
#define BOBOT_MOVE_BRAIN__DISTANCE_FROM_NEXT_NODE 9
#define BOBOT_MOVE_BRAIN__LAST_VERTICAL_ROTATION 10

#define BOBOT_MOVE_BRAIN__NUM_OUTPUTS 3

// Indices des sorties du NN
#define BOBOT_MOVE_BRAIN__ROTATION 0
#define BOBOT_MOVE_BRAIN__JUMP 1
#define BOBOT_MOVE_BRAIN__VERTICAL_ROTATION 2

#define BOBOT_MOVE_BRAIN__NUM_HIDDEN_LAYERS 1
#define BOBOT_MOVE_BRAIN__NUM_LAYERS (BOBOT_MOVE_BRAIN__NUM_HIDDEN_LAYERS + 1)
#define BOBOT_MOVE_BRAIN__NUM_NEURONS_PER_HIDDEN_LAYER 12
#define BOBOT_MOVE_BRAIN__MAX_NEURONS_PER_LAYER max(BOBOT_MOVE_BRAIN__NUM_NEURONS_PER_HIDDEN_LAYER,BOBOT_MOVE_BRAIN__NUM_INPUTS)
#define BOBOT_MOVE_BRAIN__NUM_WEIGHTS (((BOBOT_MOVE_BRAIN__NUM_INPUTS+1) * (BOBOT_MOVE_BRAIN__NUM_NEURONS_PER_HIDDEN_LAYER) + (BOBOT_MOVE_BRAIN__NUM_NEURONS_PER_HIDDEN_LAYER+1) * BOBOT_MOVE_BRAIN__NUM_OUTPUTS + (BOBOT_MOVE_BRAIN__NUM_HIDDEN_LAYERS - 1) * (BOBOT_MOVE_BRAIN__NUM_NEURONS_PER_HIDDEN_LAYER+1) * (BOBOT_MOVE_BRAIN__NUM_NEURONS_PER_HIDDEN_LAYER)))

// -----------------------------------------------------------------------------
// RESEAU DE NEURONES (NN) S'OCCUPANT DE LA DETECTION D'ENNEMIS DU BOBOT
// uniquement du point de vue de la visée, avec couverture basique des copains
// -----------------------------------------------------------------------------
#define BOBOT_LOOK_BRAIN__BRAIN_NAME "lookBrain"

#define BOBOT_LOOK_BRAIN__NUM_SONARS 3
#define BOBOT_LOOK_BRAIN__NUM_INPUTS (BOBOT_LOOK_BRAIN__NUM_SONARS + 6)

// Indices des entrées du NN. Les sonars doivent être impérativement en premiers
#define BOBOT_LOOK_BRAIN__SONAR_CENTER 0
//#define BOBOT_LOOK_BRAIN__SONAR_CENTER_DOWN 1
#define BOBOT_LOOK_BRAIN__SONAR_RIGHT 1
#define BOBOT_LOOK_BRAIN__SONAR_LEFT 2

#define BOBOT_LOOK_BRAIN__LAST_ROTATION 3
#define BOBOT_LOOK_BRAIN__LAST_VERTICAL_ROTATION 4
#define BOBOT_LOOK_BRAIN__NODE_YAW 5
#define BOBOT_LOOK_BRAIN__NODE_PITCH 6
#define BOBOT_LOOK_BRAIN__TEAMMATES_YAW 7
#define BOBOT_LOOK_BRAIN__TEAMMATES_PITCH 8

#define BOBOT_LOOK_BRAIN__NUM_OUTPUTS 2
// Indices des sorties du NN
#define BOBOT_LOOK_BRAIN__ROTATION 0
#define BOBOT_LOOK_BRAIN__VERTICAL_ROTATION 1


#define BOBOT_LOOK_BRAIN__NUM_HIDDEN_LAYERS 1
#define BOBOT_LOOK_BRAIN__NUM_LAYERS (BOBOT_MOVE_BRAIN__NUM_HIDDEN_LAYERS + 1)
#define BOBOT_LOOK_BRAIN__NUM_NEURONS_PER_HIDDEN_LAYER 12
#define BOBOT_LOOK_BRAIN__MAX_NEURONS_PER_LAYER max(BOBOT_MOVE_BRAIN__NUM_NEURONS_PER_HIDDEN_LAYER,BOBOT_MOVE_BRAIN__NUM_INPUTS)
#define BOBOT_LOOK_BRAIN__NUM_WEIGHTS (((BOBOT_LOOK_BRAIN__NUM_INPUTS+1) * (BOBOT_LOOK_BRAIN__NUM_NEURONS_PER_HIDDEN_LAYER) + (BOBOT_LOOK_BRAIN__NUM_NEURONS_PER_HIDDEN_LAYER+1) * BOBOT_LOOK_BRAIN__NUM_OUTPUTS + (BOBOT_LOOK_BRAIN__NUM_HIDDEN_LAYERS - 1) * (BOBOT_LOOK_BRAIN__NUM_NEURONS_PER_HIDDEN_LAYER+1) * (BOBOT_LOOK_BRAIN__NUM_NEURONS_PER_HIDDEN_LAYER)))

#define BOBOT_LOOK_BRAIN__MAX_TEAMMATES 3
#define BOBOT_LOOK_BRAIN__MAX_TEAMMATE_DIST 400 // distance maximale à laquelle la position des équipiers du bot sont pris en compte


// CONSTANTES COMMUNES A TOUS LES NN
#define BOBOT_COEFF_IMPORTANCE_OF_NEXT_NODE_DISTANCE 0.66//0.1 // plus c'est dur d'atteindre le node (bcp d'obstacles), plus cette valeur doit être grande.
#define BOBOT_COEFF_IMPORTANCE_OF_GOAL_REACHED 100
#define BOBOT_FRAG_IMPORTANCE 200

#define BOBOT_MAX_NUM_LAYERS        max(BOBOT_MOVE_BRAIN__NUM_LAYERS,BOBOT_LOOK_BRAIN__NUM_LAYERS)
#define BOBOT_MAX_NUM_NEURONS_PER_HIDDEN_LAYER max(BOBOT_MOVE_BRAIN__NUM_NEURONS_PER_HIDDEN_LAYER,BOBOT_LOOK_BRAIN__NUM_NEURONS_PER_HIDDEN_LAYER)
#define BOBOT_MAX_NEURONS_PER_LAYER max(BOBOT_MOVE_BRAIN__MAX_NEURONS_PER_LAYER,BOBOT_LOOK_BRAIN__MAX_NEURONS_PER_LAYER)
#define BOBOT_MAX_NUM_WEIGHTS        max(BOBOT_MOVE_BRAIN__NUM_WEIGHTS,BOBOT_LOOK_BRAIN__NUM_WEIGHTS)
#define BOBOT_MAX_NOISE 0.2
#define BOBOT_BIAS (-1)
#define BOBOT_ACTIVATION_RESPONSE 0.1

// définit quels NN vont apprendre
#define BOBOT_MOVE_BRAIN__IS_LEARNING 0
#define BOBOT_LOOK_BRAIN__IS_LEARNING 1



extern double RandomClamped();

//-------------------------------------------------------------------
//    define neuron struct
//-------------------------------------------------------------------
typedef struct SNeuron
{
    //the number of inputs into the neuron
    int                    m_NumInputs;

    //the weights for each input
    double                vecWeight[BOBOT_MAX_NEURONS_PER_LAYER+1];

}SNeuron;


//---------------------------------------------------------------------
//    struct to hold a layer of neurons.
//---------------------------------------------------------------------

typedef struct SNeuronLayer
{
    //the number of neurons in this layer
    int                m_NumNeurons;

    //the layer of neurons
    SNeuron            vecNeurons[BOBOT_MAX_NEURONS_PER_LAYER+1];
}SNeuronLayer;


//----------------------------------------------------------------------
//    neural net class
//----------------------------------------------------------------------

typedef struct CNeuralNet
{
    int                    m_NumInputs;

    int                    m_NumOutputs;

    int                    m_NumHiddenLayers;

    int                    m_NeuronsPerHiddenLyr;

    //storage for each layer of neurons including the output layer
    SNeuronLayer        vecLayers[BOBOT_MAX_NUM_LAYERS];

}CNeuralNet;
               
// constructors
void    CreateSNeuron(SNeuron* neuron,int NumInputs);
void    CreateSNeuronLayer(SNeuronLayer* neuronLayer, int NumNeurons, int NumInputsPerNeuron);
void    CreateNeuralNet(CNeuralNet* neuralNet,int numInputs,int numOutputs,int numHiddenLayers,int neuronsPerHiddenLyr);

void    CreateNet(CNeuralNet* neuralNet);

//gets the weights from the NN
void    GetWeights(CNeuralNet* neuralNet, double* weights)/*const*/;

//returns total number of weights in net
int        GetNumberOfWeights(CNeuralNet* neuralNet)/*const*/;

//replaces the weights with new ones
void    PutWeights(CNeuralNet* neuralNet, double* weights);

//calculates the outputs from a set of inputs
void    UpdateNN(CNeuralNet* neuralNet, double* inputs, double* realOutputs);

//sigmoid response curve
double    Sigmoid(double activation, double response);

void    LoadWeightsNotEvolving(int brainType);

#endif

Créer un site gratuit avec e-monsite - Signaler un contenu illicite sur ce site