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 UTILS_H
parkbanks 0:ac93d9db8dbd 2 #define UTILS_H
parkbanks 0:ac93d9db8dbd 3
parkbanks 0:ac93d9db8dbd 4 #include <stdlib.h>
parkbanks 0:ac93d9db8dbd 5 #include <math.h>
parkbanks 0:ac93d9db8dbd 6 #include <vector>
parkbanks 0:ac93d9db8dbd 7
parkbanks 0:ac93d9db8dbd 8 using namespace std;
parkbanks 0:ac93d9db8dbd 9
parkbanks 0:ac93d9db8dbd 10 // Random number functions
parkbanks 0:ac93d9db8dbd 11
parkbanks 0:ac93d9db8dbd 12 //returns a random integer between x and y
parkbanks 0:ac93d9db8dbd 13 inline int RandInt(int x,int y) {return rand()%(y-x+1)+x;}
parkbanks 0:ac93d9db8dbd 14
parkbanks 0:ac93d9db8dbd 15 //returns a random float between zero and 1
parkbanks 0:ac93d9db8dbd 16 inline float RandFloat() {return (rand())/(RAND_MAX+1.0);}
parkbanks 0:ac93d9db8dbd 17
parkbanks 0:ac93d9db8dbd 18 //returns a random float in the range -1 < n < 1
parkbanks 0:ac93d9db8dbd 19 inline float RandomClamped() {return RandFloat() - RandFloat();}
parkbanks 0:ac93d9db8dbd 20
parkbanks 0:ac93d9db8dbd 21 inline void Squash(float &arg, int obj, float min, float max){
parkbanks 0:ac93d9db8dbd 22 arg = arg/obj - 1;
parkbanks 0:ac93d9db8dbd 23 if (arg < min){arg = min;}
parkbanks 0:ac93d9db8dbd 24 if (arg > max){arg = max;}
parkbanks 0:ac93d9db8dbd 25 }
parkbanks 0:ac93d9db8dbd 26
parkbanks 0:ac93d9db8dbd 27 #endif