10 #define BOOST_TEST_MAIN 11 #define BOOST_TEST_DYN_LINK 12 #include <boost/test/unit_test.hpp> 49 BOOST_AUTO_TEST_SUITE(basic)
64 BOOST_REQUIRE(d[j]== i*10+j);
67 BOOST_REQUIRE(d[j]== i*20+j);
68 BOOST_REQUIRE(e.
getH(i)==i*1000);
80 BOOST_REQUIRE_THROW(
ExampleSet bad(parent,5,6),std::out_of_range);
81 BOOST_REQUIRE_THROW(
ExampleSet bad(parent,-1,6),std::out_of_range);
82 BOOST_REQUIRE_THROW(
ExampleSet bad(parent,5,6),std::out_of_range);
83 BOOST_REQUIRE_THROW(
ExampleSet bad(parent,11,6),std::out_of_range);
88 int parentIndex = i+5;
91 BOOST_REQUIRE(d[j]== parentIndex*10+j);
94 BOOST_REQUIRE(d[j]== parentIndex*20+j);
95 BOOST_REQUIRE(e.
getH(i)==parentIndex*1000);
106 for(
int i=ct-1;i>=1;i--){
108 int j = rand()%(i+1);
122 static const int NUMEXAMPLES = 100;
123 static const int CYCLE=5;
127 int arr[NUMEXAMPLES];
128 for(
int i=0;i<NUMEXAMPLES;i++){
131 sshuffle<int>(arr,NUMEXAMPLES);
134 alternate<int>(arr,NUMEXAMPLES,CYCLE,[](
int v){
return v;});
140 bool seen[NUMEXAMPLES];
141 for(
int i=0;i<NUMEXAMPLES;i++)seen[i]=
false;
142 for(
int i=0;i<NUMEXAMPLES;i++){
144 BOOST_REQUIRE(!seen[n]);
146 BOOST_REQUIRE((n%CYCLE) == (i%CYCLE));
164 BOOST_REQUIRE((e.
getH(i)<0.5 ? 0 : 1) == i%2);
173 static const int NUMBEREXAMPLES=32;
180 for(
int i=0;i<NUMBEREXAMPLES/4;i++){
182 for(
int j=0;j<4;j++){
203 bool monotonic_increasing=
true;
204 for(
int i=0;i<NUMBEREXAMPLES;i++){
209 int h = (int)e.
getH(i);
210 if(o<lasto)monotonic_increasing=
false;
212 BOOST_REQUIRE(i0 == i%4);
213 BOOST_REQUIRE(o/4 == h);
215 BOOST_REQUIRE(!monotonic_increasing);
223 static const int NUMBEREXAMPLES=32;
237 for(
int i=0;i<NUMBEREXAMPLES/4;i++){
239 for(
int j=0;j<4;j++){
261 bool monotonic_increasing=
true;
262 for(
int i=0;i<NUMBEREXAMPLES;i++){
267 int h = (int)e.
getH(i);
268 if(o<lasto)monotonic_increasing=
false;
270 BOOST_REQUIRE(i%4==h);
271 BOOST_REQUIRE(o%4==i0);
273 BOOST_REQUIRE(!monotonic_increasing);
284 double *buf =
new double[ct];
285 for(
int i=0;i<ct;i++)buf[i]=0;
307 double t = n->
test(e);
312 BOOST_REQUIRE(t==11400.25);
323 MNIST m(
"../testdata/t10k-labels-idx1-ubyte",
"../testdata/t10k-images-idx3-ubyte");
329 for(
int y=0;y<28;y++){
330 for(
int x=0;x<28;x++){
331 uint8_t qq = *in++ * 10;
332 if(qq>9)putchar(
'?');
333 else putchar(qq?qq+
'0':
'.');
339 for(
int i=0;i<10;i++){
341 BOOST_REQUIRE(out[i]==1.0);
343 BOOST_REQUIRE(out[i]==0.0);
352 BOOST_AUTO_TEST_SUITE_END()
int getCount() const
get the number of examples
void setH(int example, double h)
Set the h (modulator) for a given example.
This class encapsulates and loads data in the standard MNIST format. The data resides in two files...
Useful stuff for testing.
Shuffle single examples, but follow up by running a pass over the examples to ensure that they altern...
ExampleSet & setHRange(double mn, double mx)
double * getOutputs(int example)
Get a pointer to the outputs for a given example, for reading or writing.
Utility test class. Constructs a standard set: 10 examples, 5 ins, 2 outs:
void shuffle(drand48_data *rd, ShuffleMode mode, int nExamples=0)
Shuffle the example using a PRNG and a Fisher-Yates shuffle.
int getInputCount() const
get the number of inputs in all examples
Shuffle blocks of numHLevels examples, rather than single examples. This is intended for cases where ...
void zero(Net *n)
set all parameters (weights and biases) in a network to zero
void sshuffle(T *x, int ct)
simple shuffle for testing - performs a Fisher-Yates shuffle on an array of items of class T...
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...
int getOutputCount() const
get the number of outputs in all examples
BOOST_AUTO_TEST_CASE(example)
Test the basic example.
virtual int getDataSize() const =0
Get the length of the serialised data block for this network.
virtual void load(double *buf)=0
Given that the pointer points to a data block of the correct size for the current network...
double getH(int example) const
Get the h (modulator) for a given example.
double test(ExampleSet &examples, int start=0, int num=-1)
Test a network. Runs the network over a set of examples and returns the mean MSE for all outputs whe...
The abstract network type upon which all others are based. It's not pure virtual, in that it encapsul...
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...