UESMANN CPP  1.0
Reference implementation of UESMANN
/home/travis/build/jimfinnis/uesmanncpp/testTrainBooleans.cpp
Go to the documentation of this file.
1 
7 #include <iostream>
8 #include <boost/test/unit_test.hpp>
9 
10 #include "test.hpp"
11 
12 BOOST_AUTO_TEST_SUITE(booleans)
13 
14 
28 static void dotest(NetType tp){
29  static const double threshold=0.4;
31  // xor examples
32  e.add0(0,1,1,0);
33  // and examples
34  e.add1(0,0,0,1);
35 
36  // make a net with 2 hidden nodes of the right type
37  Net *net;
38  try {
39  net = NetFactory::makeNet(tp,e,2);
40  } catch(std::runtime_error *e) {
41  BOOST_FAIL(e->what());
42  }
43  // train it
44  Net::SGDParams params(0.1,1000000);
45  params.storeBest().crossValidation(e,0.5,10000,1,false).setSeed(1);
46 
47  double mse = net->trainSGD(e,params);
48  printf("%f\n",mse);
49  BOOST_REQUIRE(mse<0.002);
50 
51  // now test
52  BOOST_REQUIRE(booleanTest(net,0, 0,0,0)<threshold);
53  BOOST_REQUIRE(booleanTest(net,0, 0,1,1)<threshold);
54  BOOST_REQUIRE(booleanTest(net,0, 1,0,1)<threshold);
55  BOOST_REQUIRE(booleanTest(net,0, 1,1,0)<threshold);
56  BOOST_REQUIRE(booleanTest(net,1, 0,0,0)<threshold);
57  BOOST_REQUIRE(booleanTest(net,1, 0,1,0)<threshold);
58  BOOST_REQUIRE(booleanTest(net,1, 1,0,0)<threshold);
59  BOOST_REQUIRE(booleanTest(net,1, 1,1,1)<threshold);
60  delete net;
61 }
62 
68 }
73  dotest(NetType::HINPUT);
74 }
79  dotest(NetType::UESMANN);
80 }
81 
86 BOOST_AUTO_TEST_SUITE_END()
NetType
The different types of network - each has an associated integer for saving/loading file data...
Definition: netType.hpp:15
output blending
Training parameters for trainSGD(). This structure holds the parameters for the trainSGD() method...
Definition: net.hpp:173
boolean example set: 16 examples, 2 inputs, 1 output, 2 mod levels. There are 4 examples for each fun...
Definition: test.hpp:41
Useful stuff for testing.
double trainSGD(ExampleSet &examples, SGDParams &params)
Train using stochastic gradient descent. Note that cross-validation parameters are slightly different...
Definition: net.hpp:428
plain back-propagation
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
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...
Definition: netFactory.hpp:32
h-as-input
BOOST_AUTO_TEST_CASE(obxorand)
Test of output blending on XOR->AND modulation.
The abstract network type upon which all others are based. It&#39;s not pure virtual, in that it encapsul...
Definition: net.hpp:39