Next: Module: Definitions
Up: Source Code
Previous: Source Code
  Contents
Subsections
1
2 /* Implementaion of the Encode/Decoder-Problem */
3
4 #include "defs.h"
5 #include "ind.h"
6 #include "stdnet.h"
7
8 /* Parameter Handling */
9
10 #define DEFNIN AUTO
11 #define DEFNHID AUTO
12
13 #define MAXIN 0x7fff
14 #define MAXHID 15
15
16 char *StdOptStr() {return "N:M:\0";}
17
18 char *StdUsage() {return
19 "Network (N-M-N-ENC/DEC) Parameters:\n"
20 "-N <no. of inputs/outputs>: 4\n"
21 "-M <no. of hidden units>: auto (>= ld M)\n\0";}
22
23 /* set default values */
24
25 int Nin = DEFNIN; /* no. of inputs */
26 int Nhid = DEFNHID; /* no. of hidden units */
27
28 int handleStdOpt(char opt,char* arg)
29 {
30 switch(opt)
31 {
32 case 'N': return (Nin =getint(arg,1,MAXIN))<0;
33 case 'M': return (Nhid =getint(arg,1,MAXHID))<0;
34 default: return 1;
35 };
36 }
37
38 int initStd()
39 {
40 if(Nin==AUTO) Nin=4;
41 Nout=Nin;
42 if(Nhid==AUTO) Nhid=duallog(Nin);
43 if(Nhid<duallog(Nin)) return 1;
44 Ntrain=Nin;
45 sprintf(StdName,"%d-%d-%d ENC/DEC",Nin,Nhid,Nout);
46 return 0;
47 }
48
49 void initTrain()
50 {
51 int p,i;
52
53 for(p=0;p<Ntrain;p++)
54 for(i=0;i<Nin;i++)
55 TrainIn[p][i]=TrainOut[p][i]= p==i ? 1.0 : 0.0;
56 }
1
2 /* Implementation of 1-norm of a binary vector */
3 /* out[]=sum(i,in[i]) mod 2^O */
4
5 #include "defs.h"
6 #include "ind.h"
7 #include "stdnet.h"
8
9 /* Parameter Handling */
10
11 #define DEFNIN 3
12 #define DEFNHID AUTO
13 #define DEFNOUT AUTO
14
15 #define MAXIN 31
16 #define MAXHID 255
17 #define MAXOUT 5
18
19 char *StdOptStr() {return "N:M:O:\0";}
20
21 char *StdUsage() {return
22 "Network (Counter):\n"
23 "-N <no. of input units>: 3\n"
24 "-M <no. of hidden units>: auto (M)\n"
25 "-O <no. of output units>: auto (>= ld M)\n\0";}
26
27 int Nin=DEFNIN;
28 int Nhid=DEFNHID;
29 int Nout=DEFNOUT;
30
31 const int grey2dec[16]={0,1,3,2,7,6,4,5,15,14,12,13,8,9,11,10};
32
33 int handleStdOpt(char opt,char* arg)
34 {
35 switch(opt)
36 {
37 case 'N': return (Nin =getint(arg,1,MAXIN))<0;
38 case 'M': return (Nhid =getint(arg,1,MAXHID))<0;
39 case 'O': return (Nout =getint(arg,1,MAXOUT))<0;
40 };
41 return 1;
42 }
43
44 int initStd()
45 {
46 if(Nhid==AUTO) Nhid=Nin;
47 if(Nout==AUTO) Nout=duallog(Nin+1);
48 Ntrain=1<<Nin;
49 sprintf(StdName,"%d bit Counter (counts 1s in input)",Nin);
50 return 0;
51 }
52
53 void initTrain()
54 {
55 int p,z,i;
56
57 for(p=0;p<Ntrain;p++)
58 {
59 z=0;
60 for(i=0;i<Nin;i++)
61 z+=TrainIn[p][i]=(float) ((p>>i) & 1);
62 for(i=0;i<Nout;i++)
63 TrainOut[p][i]=(float) ((z>>i) & 1);
64 };
65 }
66
1
2 /* Implementation of 2*N-bit Comperator */
3
4 #include "defs.h"
5 #include "ind.h"
6 #include "stdnet.h"
7
8 /* Parameter Handling */
9
10 #define DEFNIN 3
11 #define DEFNHID AUTO
12
13 #define MAXIN 8
14 #define MAXHID 255
15
16 char *StdOptStr() {return "N:M:\0";}
17
18 char *StdUsage() {return
19 "Network (2xN Comperator) Parameters:\n"
20 "-N <no. of input units>: 3\n"
21 "-M <no. of hidden units>: auto (M)\n"
22 "-Q <train for = instead of =< ?> 0\n\0";}
23
24 int Nin=DEFNIN;
25 int Nhid=DEFNHID;
26 int Equality=0;
27
28 const int grey2dec[16]={0,1,3,2,7,6,4,5,15,14,12,13,8,9,11,10};
29 const char EqualityStr[2][40]={"less or equal","equal"};
30 const int stdNhid[17]={0,0,2,0,2,0,3,0,3,0,3,0,4,0,4,0,4};
31
32 int handleStdOpt(char opt,char* arg)
33 {
34 switch(opt)
35 {
36 case 'N': return (Nin =getint(arg,1,MAXIN))<0;
37 case 'M': return (Nhid =getint(arg,1,MAXHID))<0;
38 case 'Q': return (Equality =getint(arg,0,1))<0;
39 };
40 return 1;
41 }
42
43 int initStd()
44 {
45 Nin*=2;
46 if(Nhid==AUTO) Nhid=stdNhid[Nin];
47 Nout=1;
48 Ntrain=1<<Nin;
49 sprintf(StdName,"2x%d bit Comperator (%s)",
50 Nin/2,EqualityStr[Equality]);
51 return 0;
52 }
53
54 void initTrain()
55 {
56 int p,i;
57 unsigned l,a,b,m;
58
59 l=Nin/2; m=(1<<l)-1;
60 for(p=0;p<Ntrain;p++)
61 {
62 a=p&m; b=(p>>l)&m;
63 for(i=0;i<Nin;i++)
64 TrainIn[p][i]=(float) ((p>>i) & 1);
65 TrainOut[p][0]=(float)( Equality ? (a==b) : (a<=b) );
66 };
67 }
68
(c) Bernhard Ömer - oemer@tph.tuwien.ac.at - http://tph.tuwien.ac.at/~oemer/