Skip to content

Commit cda3e85

Browse files
committed
comments
1 parent 4eae55b commit cda3e85

File tree

1 file changed

+36
-6
lines changed

1 file changed

+36
-6
lines changed

genBoolMap.cpp

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,42 @@
22
* @file genBoolMap.cpp
33
* @brief Generate a 2D grid of how many trials of UESMANN on
44
* every combination of binary boolean functions succeed.
5-
*
5+
* This should (and does) generate approximately the same
6+
* data as in Fig. 5.3a of the thesis (p.100). The variation is
7+
* no greater than 0.001 (i.e. a single network) in each pairing
8+
* tested.
69
*/
710

811
#include "netFactory.hpp"
912

13+
// How many networks to attempt for each pairing
1014
#define NUM_ATTEMPTS 1000
15+
16+
// the learning rate
1117
#define ETA 0.1
1218

19+
// how many epochs to train each network for. At 8 examples per
20+
// epoch, this is 600000 training iterations (single examples)
1321
#define EPOCHS 75000
1422

15-
// possible inputs
23+
// possible inputs: boolean pairs
1624
double ins[][2]={
1725
{0,0},
1826
{0,1},
1927
{1,0},
2028
{1,1}};
2129

30+
/**
31+
* \brief names of functions for the output
32+
*/
2233
const char *simpleNames[] = {
2334
"f","and","x and !y","x","!x and y","y","xor","or","nor","xnor",
2435
"!y","x or !y","!x","!x or y","nand","t"};
2536

26-
// given a function index, perform the appropriate boolean. The index is actually
27-
// the truth table: four bits in order 00,01,10,11.
37+
/**
38+
* \brief given a function index, perform the appropriate boolean.
39+
* The index is actually the truth table: four bits in order 00,01,10,11.
40+
*/
2841

2942
bool boolFunc(int f,bool a,bool b){
3043
// which bit do we want?
@@ -33,6 +46,12 @@ bool boolFunc(int f,bool a,bool b){
3346
return (f&bit)!=0;
3447
}
3548

49+
/**
50+
* \brief Set an example in the example set to the output of a given
51+
* function (as an index into simpleNames), given the inputs and
52+
* the modulator level.
53+
*/
54+
3655
static void setExample(ExampleSet& e,int exampleIdx,
3756
int functionIdx,int xbit,int ybit,double mod){
3857
double *ins = e.getInputs(exampleIdx);
@@ -45,6 +64,11 @@ static void setExample(ExampleSet& e,int exampleIdx,
4564

4665
}
4766

67+
/**
68+
* \brief test if a given network successfully performs a given pair
69+
* of boolean functions, modulating from f1 to f2. The functions are
70+
* indices into the simpleNames array.
71+
*/
4872
bool success(int f1,int f2,Net *n){
4973
double in[2];
5074
double out;
@@ -68,7 +92,13 @@ bool success(int f1,int f2,Net *n){
6892
}
6993

7094

71-
// returns proportion of networks which worked.
95+
/**
96+
* \brief Train a large number of networks to do a particular
97+
* pairing of boolean functions (provided as indices into simpleNames)
98+
* an return what proportion successfully perform that pairing under
99+
* modulation
100+
*/
101+
72102
double doPairing(int f1,int f2){
73103
// first we need to build the examples.
74104
// 8 examples (4 at each mod level), 2 in, 1 out, 2 mod levels
@@ -86,8 +116,8 @@ double doPairing(int f1,int f2){
86116
setExample(e,6,f1,1,1,0);
87117
setExample(e,7,f2,1,1,1);
88118

119+
// training parameters.
89120
Net::SGDParams params(ETA,e,EPOCHS);
90-
printf("Iterations: %d\n",params.iterations);
91121
params.storeBest().setSeed(1).setShuffle(ExampleSet::STRIDE);
92122

93123

0 commit comments

Comments
 (0)