-
Notifications
You must be signed in to change notification settings - Fork 4
/
experiments.h
120 lines (93 loc) · 3.52 KB
/
experiments.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#ifndef EXPERIMENTS_H
#define EXPERIMENTS_H
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <list>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include "noveltyset.h"
#include "neat.h"
#include "network.h"
#include "population.h"
#include "organism.h"
#include "genome.h"
#include "species.h"
#include "datarec.h"
#include "maze.h"
using namespace std;
using namespace NEAT;
//Walker novelty steady-state
int maze_novelty_realtime_loop(Population *pop);
Population *maze_novelty_realtime(char* output_dir=NULL,const char* mazefile="maze.txt",int param=-1);
noveltyitem* maze_novelty_map(Organism *org,data_record* record=NULL);
Population *maze_fitness_realtime(char* output_dir=NULL,const char* mazefile="maze.txt",int param=-1);
int maze_fitness_realtime_loop(Population *pop);
double mazesimStep(Environment* newenv,Network *net,vector< vector<float> > &dc);
Environment* mazesimIni(Environment* tocopy,Network *net, vector< vector<float> > &dc);
//Single pole balancing evolution routines ***************************
Population *pole1_test(int gens);
bool pole1_evaluate(Organism *org);
int pole1_epoch(Population *pop,int generation,char *filename);
int go_cart(Network *net,int max_steps,int thresh); //Run input
//Move the cart and pole
void cart_pole(int action, float *x,float *x_dot, float *theta, float *theta_dot);
//Double pole balacing evolution routines ***************************
class CartPole;
Population *pole2_test(int gens,int velocity);
bool pole2_evaluate(Organism *org,bool velocity,CartPole *thecart);
int pole2_epoch(Population *pop,int generation,char *filename,bool velocity, CartPole *thecart,int &champgenes,int &champnodes, int &winnernum, ofstream &oFile);
//rtNEAT validation with pole balancing *****************************
Population *pole2_test_realtime();
int pole2_realtime_loop(Population *pop, CartPole *thecart);
class CartPole {
public:
CartPole(bool randomize,bool velocity);
virtual void simplifyTask();
virtual void nextTask();
virtual double evalNet(Network *net,int thresh);
double maxFitness;
bool MARKOV;
bool last_hundred;
bool nmarkov_long; //Flag that we are looking at the champ
bool generalization_test; //Flag we are testing champ's generalization
double state[6];
double jigglestep[1000];
protected:
virtual void init(bool randomize);
private:
void performAction(double output,int stepnum);
void step(double action, double *state, double *derivs);
void rk4(double f, double y[], double dydx[], double yout[]);
bool outsideBounds();
const static int NUM_INPUTS=7;
const static double MUP = 0.000002;
const static double MUC = 0.0005;
const static double GRAVITY= -9.8;
const static double MASSCART= 1.0;
const static double MASSPOLE_1= 0.1;
const static double LENGTH_1= 0.5; /* actually half the pole's length */
const static double FORCE_MAG= 10.0;
const static double TAU= 0.01; //seconds between state updates
const static double one_degree= 0.0174532; /* 2pi/360 */
const static double six_degrees= 0.1047192;
const static double twelve_degrees= 0.2094384;
const static double fifteen_degrees= 0.2617993;
const static double thirty_six_degrees= 0.628329;
const static double fifty_degrees= 0.87266;
double LENGTH_2;
double MASSPOLE_2;
double MIN_INC;
double POLE_INC;
double MASS_INC;
//Queues used for Gruau's fitness which damps oscillations
int balanced_sum;
double cartpos_sum;
double cartv_sum;
double polepos_sum;
double polev_sum;
};
#endif