Thread: Modifying FANN library

  1. #1
    Registered User
    Join Date
    Apr 2017
    Location
    Iran
    Posts
    138

    Modifying FANN library

    Hi,

    I want to use Fast Artificial Neural Network Library (fann). This is a performance critical work. I want to use:

    Code:
    typedef int16_t fann_type;
    In a header file.

    Also I want to implement relu function for neurons as activation function.

    Should I just modify the FANN library code and compile it as a static library ? Anything else ?

  2. #2
    Registered User
    Join Date
    Apr 2017
    Location
    Iran
    Posts
    138
    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:


    1. How to use a single copy of input that right now is in both files?
    2. 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".

  3. #3
    Registered User
    Join Date
    Apr 2017
    Location
    Iran
    Posts
    138
    This compilation passes and gives no error:

    Code:
    gcc -Wall -Wextra -pedantic example_train.c -lfann -fopenmp -static -lm
    gcc -Wall -Wextra -pedantic example_run.c -lfixedfann -fopenmp -static -lm

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 9
    Last Post: 02-08-2012, 10:23 PM
  2. Modifying a file.
    By RoRo in forum C Programming
    Replies: 2
    Last Post: 11-24-2010, 10:00 PM
  3. modifying help plz ( int to float )
    By sh4k3 in forum C Programming
    Replies: 11
    Last Post: 06-29-2007, 06:46 AM
  4. Replies: 19
    Last Post: 01-12-2006, 11:04 AM
  5. Help with Modifying Program
    By omalleys in forum C Programming
    Replies: 0
    Last Post: 06-19-2002, 09:45 AM

Tags for this Thread