Merge /pub/main
[educational.data.git] / AI01 / rbp / rbp.h
blobe3f97ffce9e61933e00743e5e0bc5ea39e99e825
1 /* ***************************************************** */
2 /* file rbp.h: contains definitions for the rbp program */
3 /* that uses 64-bit floating point weights */
4 /* */
5 /* Copyright (c) 1990-1996 by Donald R. Tveter */
6 /* */
7 /* *******************************************************/
9 #include <stdio.h>
10 #include <signal.h>
11 #include <setjmp.h>
12 #include <math.h>
13 #include <string.h>
15 #ifdef DOS16
16 #include <stdlib.h>
17 #include <time.h>
18 #include <conio.h>
19 #define INT32 long
20 #define MAXINT 32767
21 #define HOTKEYS
22 #endif
24 #ifdef DOS32
25 #include <stdlib.h>
26 #include <time.h>
27 #include <conio.h>
28 #define INT32 int
29 #define MAXINT 2147483647
30 #define HOTKEYS
31 #endif
33 #ifdef UNIX
34 #ifdef BSD
35 #include <termios.h>
36 #elif defined NEXT
37 #include <malloc.h>
38 #include <sgtty.h>
39 #else /* SysV */
40 #include <malloc.h>
41 #include <termio.h>
42 #endif
43 #define INT32 int
44 #define MAXINT 2147483647
45 #define SIGINT 2
46 #define CLOCKS_PER_SEC 1000000.0
47 #define HOTKEYS
48 extern long clock();
49 #endif
51 #ifdef FLOAT
52 #define WTTYPE float
53 #define WTSIZE 4
54 #define REAL float
55 #else
56 #define WTTYPE double
57 #define WTSIZE 8
58 #define REAL double
59 #endif
61 #define RXSTRSIZE 257 /* max length of string to store rx files */
62 #define MAXFORMAT 21 /* maximum number of format breaks */
63 #define BUFFSIZE 257 /* maximum input buffer size */
64 #define OUTSTRSIZE 400 /* max length of output string */
65 #define FILENAMESIZE 15 /* maximum length of a file name */
66 #define MAXFILES 10 /* maximum number of files on file stack */
67 #define HCODE -32768 /* code number for a layer h (2) unit */
68 #define ICODE -32767 /* code number for an input layer unit */
69 #define OCODE -32766 /* code number for an output layer unit */
70 #define CAPHCODE -32764 /* code for a string of h layer units */
71 #define CAPXCODE -32763 /* code for a string of unknown values */
72 #define SKIPCODE -32762 /* temporal difference code to skip pattern */
73 #define DIFFCODE -32761 /* temporal difference code to use diff */
74 #define GT 0 /* a symbol meaning > */
75 #define GE 1 /* a symbol meaning >= */
76 #define scale(x) x /* scale not used in real version */
77 #define unscale(x) x /* unscale not used in real version */
78 #define unscaleint(x) x /* unscaleint not used in real version */
79 #define TRAIN 0 /* selects the training patterns */
80 #define TEST 1 /* selects the test patterns */
81 #define TOL 0 /* selects stats based on tolerance */
82 #define MAX 1 /* selects stats based on max value */
84 typedef struct seednode
86 unsigned val; /* a seed value */
87 struct seednode *next; /* pointer to next node */
88 } SEEDNODE;
90 typedef struct patnode
92 WTTYPE *addr; /* address to get the value from */
93 WTTYPE val; /* a normal value */
94 short layer; /* layer of the net to take value from */
95 short unitno; /* unit of the layer to take value from */
96 } PATNODE;
98 typedef struct patlist
100 PATNODE *pats; /* the list of patterns */
101 struct patlist *next; /* pointer to the next pattern */
102 } PATLIST;
104 typedef struct unit
106 int inuse; /* flags unit in use */
107 short layernumber; /* layer number of the unit */
108 short unitnumber; /* position within layer */
109 REAL error; /* to sum error factors */
110 WTTYPE oj; /* state of activation of node */
111 WTTYPE tj; /* a temporary variable */
112 WTTYPE translate; /* the amount to translate an input by */
113 WTTYPE userscale; /* the amount to divide an input by */
114 struct wtnode *wtlist; /* to list of weights to prev layer */
115 struct unit *next; /* link to next unit in this layer */
116 } UNIT;
118 typedef struct wtnode
120 #ifdef SYMMETRIC
121 WTTYPE *weight; /* weight from here to backunit */
122 WTTYPE *olddw; /* delta wji from previous iteration */
123 WTTYPE *total; /* total of changes for batch updates */
124 WTTYPE *eta; /* the eta of the DBD method */
125 WTTYPE *slope; /* previous slope */
126 #else
127 WTTYPE weight; /* weight from here to backunit */
128 WTTYPE olddw; /* delta wji from previous iteration */
129 WTTYPE total; /* total of changes for batch updates */
130 WTTYPE eta; /* the eta of the DBD method */
131 WTTYPE slope; /* previous slope */
132 #endif
133 short inuse; /* 0 if unused, > 0 otherwise */
134 struct wtnode *next; /* link to next node */
135 UNIT *backunit; /* ptr to unit the weight comes from */
136 } WTNODE;
138 typedef struct layer
140 char activation; /* activation function for this layer */
141 WTTYPE D; /* gain for this layer */
142 WTTYPE biasact; /* bias act. value for this layer */
143 int unitcount; /* number of units in this layer now */
144 int initialcount; /* number of units to start with */
145 struct layer *backlayer; /* pointer to previous layer */
146 struct layer *next; /* pointer to next layer */
147 UNIT *units; /* start of list of units in this layer */
148 PATLIST *patstart[2]; /* to the list of patterns */
149 PATLIST *currentpat[2]; /* the current pattern */
150 } LAYER;
152 typedef struct data
154 int uncertain; /* flags values created by continuous */
155 /* updates in the forward pass */
156 int off; /* -1 for off by 1, 0 otherwise */
157 int npats; /* number of patterns */
158 INT32 iterno; /* iteration number when data was found */
159 int right; /* number of patterns right */
160 int wrong; /* number of patterns wrong */
161 float avgerr; /* average abs error per unit */
162 float pctright; /* percentage right */
163 } DATA;