16 #define NUM_ATTEMPTS 1000 42 "f",
"and",
"x and !y",
"x",
"!x and y",
"y",
"xor",
"or",
"nor",
"xnor",
43 "!y",
"x or !y",
"!x",
"!x or y",
"nand",
"t"};
52 int bit = 1<<((a?0:2)+(b?0:1));
63 static void setExample(
ExampleSet& e,
int exampleIdx,
64 int functionIdx,
int xbit,
int ybit,
double mod){
67 e.
setH(exampleIdx,mod);
70 bool val =
boolFunc(functionIdx,xbit!=0,ybit!=0);
85 bool shouldBeHigh1 =
boolFunc(f1,a!=0,b!=0);
86 bool shouldBeHigh2 =
boolFunc(f2,a!=0,b!=0);
92 if(out>0.5 != shouldBeHigh1)
return false;
96 if(out>0.5 != shouldBeHigh2)
return false;
115 setExample(e,0,f1,0,0,0);
116 setExample(e,1,f2,0,0,1);
118 setExample(e,2,f1,0,1,0);
119 setExample(e,3,f2,0,1,1);
121 setExample(e,4,f1,1,0,0);
122 setExample(e,5,f2,1,0,1);
124 setExample(e,6,f1,1,1,0);
125 setExample(e,7,f2,1,1,1);
154 return ((
double)successful)/(double)NUM_ATTEMPTS;
160 int main(
int argc,
char *argv[]){
163 printf(
"a,b,correct\n");
165 for(
int f1=0;f1<16;f1++){
166 for(
int f2=0;f2<16;f2++){
167 printf(
"%d,%d,%f\n",f1,f2,
doPairing(f1,f2));
void setH(int example, double h)
Set the h (modulator) for a given example.
const char * simpleNames[]
names of functions performed by boolFunc()
#define EPOCHS
how many epochs to train each genBoolMap network for - at 8 examples per epoch, this is 600000 traini...
Training parameters for trainSGD(). This structure holds the parameters for the trainSGD() method...
double trainSGD(ExampleSet &examples, SGDParams ¶ms)
Train using stochastic gradient descent. Note that cross-validation parameters are slightly different...
virtual void setH(double h)=0
Set the modulator level for subsequent runs and training of this network.
double * getOutputs(int example)
Get a pointer to the outputs for a given example, for reading or writing.
SGDParams & storeBest()
set up a "best net buffer" to store the best network found, to which the network will be set on compl...
double doPairing(int f1, int f2)
Train a large number of networks to do a particular pairing of boolean functions (provided as indices...
#define ETA
the learning rate for genBoolMap
bool boolFunc(int f, bool a, bool b)
given a function index, perform the appropriate boolean. The index is actually the truth table: four ...
Shuffle blocks of numHLevels examples, rather than single examples. This is intended for cases where ...
SGDParams & setSeed(long v)
fluent setter for seed
double * run(double *in)
Run the network on some data.
static Net * makeNet(NetType t, ExampleSet &e, int hnodes)
Construct a single hidden layer network of a given type which conforms to the example set...
bool success(int f1, int f2, Net *n)
test if a given network successfully performs a given pair of boolean functions, modulating from f1 t...
I'm not a fan of factories, but here's one - this makes a network of the appropriate type which confo...
SGDParams & setShuffle(ExampleSet::ShuffleMode m)
fluent setter for preserveHAlternation
#define NUM_ATTEMPTS
How many networks to attempt for each pairing in genBoolMap.
int main(int argc, char *argv[])
The main function for genBoolMap.
The abstract network type upon which all others are based. It's not pure virtual, in that it encapsul...
double ins[][2]
possible inputs to boolean functions
double * getInputs(int example)
Get a pointer to the inputs for a given example, for reading or writing.
A set of example data. Each datum consists of hormone (i.e. modulator value), inputs and outputs...