UESMANN CPP  1.0
Reference implementation of UESMANN
/home/travis/build/jimfinnis/uesmanncpp/test.hpp
Go to the documentation of this file.
1 
7 #ifndef __TEST_HPP
8 #define __TEST_HPP
9 
10 #include "netFactory.hpp"
11 
14 namespace utf = boost::unit_test;
15 
22 static int getHighest(double *o,int n){
23  int h=0;
24  double maxval=-10;
25  for(int i=0;i<n;i++,o++){
26  if(*o > maxval){
27  maxval= *o;
28  h=i;
29  }
30  }
31  return h;
32 }
33 
34 
41 class BooleanExampleSet : public ExampleSet {
42 
51  void setExample(int i,double h,double in0,double in1,double out){
52  double *ins = getInputs(i);
53  ins[0]=in0;
54  ins[1]=in1;
55  *getOutputs(i) = out;
56  setH(i,h);
57  }
58 public:
59 
60  BooleanExampleSet() : ExampleSet(16,2,1,2) {}
61 
69  void add0(double o00,double o01,double o10,double o11){
70  setExample(0,0, 0,0, o00);
71  setExample(2,0, 0,1, o01);
72  setExample(4,0, 1,0, o10);
73  setExample(6,0, 1,1, o11);
74  setExample(8,0, 0,0, o00);
75  setExample(10,0, 0,1, o01);
76  setExample(12,0, 1,0, o10);
77  setExample(14,0, 1,1, o11);
78  }
86  void add1(double o00,double o01,double o10,double o11){
87  setExample(1,1, 0,0, o00);
88  setExample(3,1, 0,1, o01);
89  setExample(5,1, 1,0, o10);
90  setExample(7,1, 1,1, o11);
91  setExample(9,1, 0,0, o00);
92  setExample(11,1, 0,1, o01);
93  setExample(13,1, 1,0, o10);
94  setExample(15,1, 1,1, o11);
95  }
96 };
97 
102 static double booleanTest(Net *net,double h,int a,int b,double v){
103  double in[2];
104  in[0] = a;
105  in[1] = b;
106  net->setH(h);
107  double out = *net->run(in);
108  BOOST_TEST_MESSAGE(" At " << h << ", " << a << " " << b <<
109  " gives " << out << ", should be " << v);
110  return (v-out)*(v-out);
111 }
112 
113 
114 
115 
116 
117 
118 #endif /* __TEST_HPP */
void setH(int example, double h)
Set the h (modulator) for a given example.
Definition: data.hpp:378
boolean example set: 16 examples, 2 inputs, 1 output, 2 mod levels. There are 4 examples for each fun...
Definition: test.hpp:41
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.
Definition: data.hpp:349
void add1(double o00, double o01, double o10, double o11)
set the 4 examples at modulator=1
Definition: test.hpp:86
void add0(double o00, double o01, double o10, double o11)
set the 4 examples at modulator=0
Definition: test.hpp:69
double * run(double *in)
Run the network on some data.
Definition: net.hpp:107
I&#39;m not a fan of factories, but here&#39;s one - this makes a network of the appropriate type which confo...
The abstract network type upon which all others are based. It&#39;s not pure virtual, in that it encapsul...
Definition: net.hpp:39
double ins[][2]
possible inputs to boolean functions
Definition: genBoolMap.cpp:32
double * getInputs(int example)
Get a pointer to the inputs for a given example, for reading or writing.
Definition: data.hpp:338
A set of example data. Each datum consists of hormone (i.e. modulator value), inputs and outputs...
Definition: data.hpp:57