BioinstSim  2
 All Classes Functions Variables
ctrnninrobotagent.h
1 #ifndef CTRNNINROBOTAGENT_H
2 #define CTRNNINROBOTAGENT_H
3 
4 /******************************************************************************/
5 /******************************************************************************/
6 #include <assert.h>
7 #include <limits.h>
8 #include <math.h>
9 #include "arguments.h"
10 #include "featurevector.h"
11 #include "random.h"
12 #include "robotagent.h"
13 
14 /******************************************************************************/
15 /******************************************************************************/
16 enum NNLAYER
17 {
18  HiddenLayer,
19  OutputLayer
20 };
21 
22 /******************************************************************************/
23 /******************************************************************************/
24 
25 #define HIDDENNEURONACTIVATIONLOWERBOUND 1.0e-6 //todo: set as percentage instead of absolute value
26 
27 /******************************************************************************/
28 /******************************************************************************/
29 
30 class CTRNNinRobotAgent;
31 
32 /******************************************************************************/
33 /******************************************************************************/
34 
35 class CRobotAgent;
36 
37 /******************************************************************************/
38 /******************************************************************************/
39 
41 {
42 public:
43  CTRNNinRobotAgent(CRobotAgent* ptr_robotAgent, CArguments* m_ctrnnArguments);
44 
45  virtual ~CTRNNinRobotAgent();
46 
47  virtual double GetHN(unsigned hnindex);
48  virtual void SetHN(unsigned hnindex, double f_hn);
49 
50  virtual double GetON(unsigned hnindex);
51  virtual double GetInputsToON(unsigned hnindex);
52 
53  virtual double GetAPC(unsigned apctype);
54 
55  virtual double GetFVtoApcScaling();
56 
57  virtual bool GetConvergenceFlag(NNLAYER layer);
58  virtual double GetConvergenceError(NNLAYER layer);
59  virtual double GetConvergenceError_Perc(NNLAYER layer);
60 
61  virtual void PrintCTRNNDetails(unsigned id);
62 
63  virtual void SimulationStepUpdatePosition();
64 
65  static unsigned int GetNumberOfSetBits(unsigned int x);
66  static double Sigmoid(double f_currActv, double f_Saturation);
67 
68  virtual double GetSigmoidSaturation();
69 
70 protected:
71 
72  CRobotAgent* robotAgent;
73 
74  static double NormalizedAffinity(unsigned int v1, unsigned int v2);
75  static double NegExpDistAffinity(unsigned int v1, unsigned int v2, double k);
76  double GetAf(unsigned int v1, unsigned int v2);
77 
78 
79  virtual void Derivative(double *hn, double *deltaHN, NNLAYER layer);
80  virtual void NumericalIntegration(double totalintegration_t, double* neurons, double* neurons_prev, double* convg_error, double* percconvg_error, bool* convg_flag, NNLAYER layer);
81 
82  virtual void UpdateState();
83 
84  virtual void Sense();
85 
86  virtual double GetWeight();
87 
88 
89 
90  double step_h; // internal step count of the CTRNN instance
91 
92  // For communication of hidden neuron activation levels between robots
93  double m_fTryExchangeProbability; // Probability of trying to exchange cells with other robots
94  //double m_fExchangeRange;
95 
96  // hidden neurons
97  double m_fCOMPETITION_FACTOR;
98  double m_fACTIVATION_FACTOR;
99 
100  // output neurons
101  double m_fOUTPUTGAIN_FACTOR;
102  // PLASTIC BIAS
103  double m_fINHIBTIONSCALINGFACTOR;
104  double m_fBIASWEIGHT;
105  double m_fEXTERNALBIASWEIGHT;
106  double m_fSIGMOIDSATURATION;
107 
108  // or FIXED (NONPLASTIC) BIAS
109  double m_fOUTPUTNEURONBIAS;
110 
111 
112  double* m_pfOutputNeurons;
113  double* m_pfOutputNeurons_prev;
114  double* m_pfInputToOutputNeurons;
115 
116  double* m_pfHiddenNeurons;
117  double* m_pfHiddenNeurons_prev;
118  double m_pfNeuronTimeConstant;
119 
120 
121  // predicted activation level of neurons at time t+step with Euler method
122  double* m_pfNeurons_Eu;
123  // predicted activation level of neurons at time t+step with Heun method
124  double* m_pfNeurons_Hu;
125  // the slopes at time = t and time = t+step
126  double* m_pfDeltaNeurons_k0;
127  double* m_pfDeltaNeurons_k1;
128 
129 
130  double* m_pfAPCs;
131  //double** m_pfAffinities;
132  unsigned int m_unNumberOfReceptors;
133 
134 
135  //double m_fAttackProbability;
136  double m_fcross_affinity; /* the level of cross affinity*/
137  double m_fWeight;
138  double m_fFVtoApcscaling;
139 
140  bool m_bhlconvergence_flag;
141  double m_fhlconvergence_error;
142  double m_fhlpercconvergence_error;
143 
144  bool m_bolconvergence_flag;
145  double m_folconvergence_error;
146  double m_folpercconvergence_error;
147 };
148 
149 /******************************************************************************/
150 /******************************************************************************/
151 
152 #endif // CTRNNINROBOTAGENT_H