Merge /pub/main
[educational.data.git] / AI01 / rbp / ibp.h
blob6dddb39fc0c19d44ca3e831baf4ee3a5d1f2eb89
1 /* ****************************************************** */
2 /* file ibp.h: contains definitions for programs that use */
3 /* 16-bit integer weights */
4 /* */
5 /* Copyright (c) 1993 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 WRITEBIN "wb"
22 #define READBIN "rb"
23 #define HOTKEYS
24 #endif
26 #ifdef DOS32
27 #include <stdlib.h>
28 #include <time.h>
29 #include <conio.h>
30 #define INT32 int
31 #define MAXINT 2147483647
32 #define HOTKEYS
33 #endif
35 #ifdef UNIX
36 #ifdef BSD
37 #include <termios.h>
38 #elif defined NEXT
39 #include <malloc.h>
40 #include <sgtty.h>
41 #else /* SysV */
42 #include <malloc.h>
43 #include <termio.h>
44 #endif
45 #define INT32 int
46 #define SIGINT 2
47 #define MAXINT 2147483647
48 #define CLOCKS_PER_SEC 1000000.0
49 #define HOTKEYS
50 extern long clock();
51 #endif
53 #define RXSTRSIZE 257 /* max length of string to store rx files */
54 #define FILENAMESIZE 15 /* maximum length of a file name */
55 #define MAXFILES 10 /* maximum number of files on file stack */
56 #define MAXFORMAT 21 /* maximum number of format breaks */
57 #define BUFFSIZE 257 /* maximum size of an input line */
58 #define OUTSTRSIZE 400 /* max size of output string */
59 #define WTTYPE short /* a 16-bit integer */
60 #define WTSIZE 2 /* shorts are two bytes */
61 #define MAXSHORT 32767 /* largest short */
62 #define MINSHORT -32768 /* smallest short */
63 #define HCODE -32768 /* code number for a layer h (2) unit */
64 #define ICODE -32767 /* code number for a layer i (3) unit */
65 #define OCODE -32766 /* code number for a layer j (4) unit */
66 #define CAPHCODE -32764 /* code for a string of h layer units */
67 #define CAPXCODE -32763 /* code for a string of unknown values */
68 #define SKIPCODE -32762 /* temporal difference code to skip pattern */
69 #define DIFFCODE -32761 /* temporal difference code to use diff */
70 #define GT 0 /* a symbol meaning > */
71 #define GE 1 /* a symbol meaning >= */
72 #define TRAIN 0 /* selects training patterns */
73 #define TEST 1 /* selects testing patterns */
74 #define TOL 0 /* selects stats based on tolerance */
75 #define MAX 1 /* selects stats based on max value */
76 #define LOOKUP 1 /* produces lookup table for s function */
78 #ifdef FLOAT
79 #define REAL float
80 #else
81 #define REAL double
82 #endif
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 INT32 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 scale an input by */
114 struct wtnode *wtlist; /* the list of weights */
115 struct unit *next; /* link to next unit in this layer */
116 } UNIT;
118 typedef struct wtnode
120 #ifdef SYMMETRIC
121 WTTYPE *weight; /* ptr to weight */
122 WTTYPE *olddw; /* ptr to delta wji */
123 WTTYPE *eta; /* ptr to eta for the DBD method */
124 INT32 *total; /* ptr to total of weight changes */
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 eta; /* the eta for the DBD method */
130 INT32 total; /* total weight changes for batch mode */
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;