Experimenting on this , I changed the file "fixedfann.h" to :
Code:
typedef int16_t fann_type;//int fann_type;
I have two demonstrating source files:
example_train.c
Code:
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "floatfann.h"
#define TRAIN_TIMES 5000
float input[4][2] = {{0, 0}, {0, 1}, {1, 0}, {1, 1}};
float output[4] = {0, 1, 1, 0};
int main(void)
{
printf("FANN example_train\n");
srand(time(NULL));
int i;
struct fann *ann = fann_create_standard(3, 2, 2, 1);
for (i = 0; i < TRAIN_TIMES; ++i) {
fann_train(ann, input[0], output+0 );
fann_train(ann, input[1], output+1 );
fann_train(ann, input[2], output+2 );
fann_train(ann, input[3], output+3 );
}
//fann_save(ann, "example_float.net");
fann_save_to_fixed(ann, "example_fixed.net");
fann_destroy(ann);
return 0;
}
And
example_run.c
Code:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "fixedfann.h"
int16_t input[4][2] = {{0, 0}, {0, 1}, {1, 0}, {1, 1}};
int main(void)
{
//struct fann *ann_saved = fann_create_from_file("example_float.net");
struct fann *ann_saved = fann_create_from_file("example_fixed.net");
printf("Output for [%d, %d] is %d.\n", input[0][0], input[0][1], *fann_run(ann_saved, input[0]));
printf("Output for [%d, %d] is %d.\n", input[1][0], input[1][1], *fann_run(ann_saved, input[1]));
printf("Output for [%d, %d] is %d.\n", input[2][0], input[2][1], *fann_run(ann_saved, input[2]));
printf("Output for [%d, %d] is %d.\n", input[3][0], input[3][1], *fann_run(ann_saved, input[3]));
fann_destroy(ann_saved);
return 0;
}
Now I have two questions:
- How to use a single copy of input that right now is in both files?
- How to get proper output since I receive this error :
Code:
FANN Error 3: Wrong version of configuration file, aborting read of configuration file "example_fixed.net".