72 for (
int x = 0; x <
outputs; x++)
76 for (
int y = 0; y <=
inputs; y++)
77 weight[x][y] = ((
double)2*random()/RAND_MAX-1)/(double)
inputs;
98 f = fopen(fname,
"r");
101 fprintf(stderr,
"PERP Error: could not open file '%s' for loading; trying once more.\n", fname);
103 f = fopen(fname,
"r");
106 fprintf(stderr,
"PERP Error: could not open file '%s' for loading.\n", fname);
117 int inputs1, outputs1;
119 int res = fscanf(f,
"PERP %f %d %d\n", &version, &inputs1, &outputs1);
122 printf(
"Error: unrecognized perceptron file. Expected header 'PERP <version> <inputs> <outputs>'.");
127 printf(
"Error: loaded network is %1.2f, but code can only handle %1.2f.",
139 for (
int y = 0; y <
outputs; y++)
141 for (
int x = 0; x <=
inputs; x++)
143 fscanf(f,
"%le ", &
weight[y][x]);
159 for (
int y = 0; y <
outputs; y++)
161 for (
int x = 0; x <=
inputs; x++)
171 f = fopen(fname,
"r");
178 int res = fscanf(f,
"PERP %f %d %d\n", &version, &finput, &foutput);
194 f = fopen(fname,
"w+");
197 fprintf(stderr,
"Error: could not open file for saving.\n");
208 for (
int y = 0; y <
outputs; y++)
210 for (
int x = 0; x <=
inputs; x++)
212 fprintf(f,
"%le ",
weight[y][x]);
232 double err = (out[which]-expected[which]);
241 for (
int x = 0; x <
outputs; x++)
245 for (
int y = 0; y <
inputs; y++)
258 for (
int x = 0; x <
outputs; x++)
262 double rateTimesError =
rate*err;
263 for (
unsigned int y = 0; y < input.size(); y++)
265 weight[x][input[y]] -= rateTimesError;
274 for (
int y = 0; y <
outputs; y++)
277 for (
int x = 0; x <
inputs; x++)
295 for (
int y = 0; y <
outputs; y++)
298 for (
unsigned int x = 0; x < input.size(); x++)
308 for (
int y = 0; y <
outputs; y++)
309 for (
int x = 0; x <=
inputs; x++)
311 printf(
"%1.3f ",
weight[y][x]);