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

Code/utils.h

Committer:
parkbanks
Date:
2015-04-23
Revision:
0:ac93d9db8dbd

File content as of revision 0:ac93d9db8dbd:

#ifndef UTILS_H
#define UTILS_H

#include <stdlib.h>
#include <math.h>
#include <vector>

using namespace std;

// Random number functions

//returns a random integer between x and y
inline int RandInt(int x,int y) {return rand()%(y-x+1)+x;}

//returns a random float between zero and 1
inline float RandFloat() {return (rand())/(RAND_MAX+1.0);}

//returns a random float in the range -1 < n < 1
inline float RandomClamped() {return RandFloat() - RandFloat();}

inline void Squash(float &arg, int obj, float min, float max){
    arg = arg/obj - 1;
    if (arg < min){arg = min;}
    if (arg > max){arg = max;}
}

#endif