1

I'm using the FANN Library with the given code.

#include <stdio.h>
#include "doublefann.h"
int main()
{
    const NUM_ITERATIONS = 10000;
    struct fann *ann;
    int topology[] = { 1, 4, 1 };
    fann_type d1[1] = { 0.5 };
    fann_type d2[1] = { 0.0 };
    fann_type *pres;
    int i;

    /* Create network */
    ann = fann_create_standard_array(3, topology);

    /* 
     * Train network 
     * input: 0.0 => output: 0.5
     * input: 0.5 => output: 0.0
     */
    i = NUM_ITERATIONS;
    while (--i)
    {
        fann_train(ann, d1, d2);
        fann_train(ann, d2, d1);
    }

    /* Should return 0.5 */
    pres = fann_run(ann, d2);
    printf("%f\n", pres[0]);

    /* Should return 0.0 */
    pres = fann_run(ann, d1);
    printf("%f\n", pres[0]);

    /* Destroy network */
    fann_destroy(ann);

    return 0;
}

I expected the result of the first run to be 0.5, since according to the training the output value to an input value of 0.0 shall be 0.5. Accordingly I expected the output of the second run to be 0.0.

But the result is constant 0.0 for every of these two runs.

What am I missing here?

Deanie
  • 2,316
  • 2
  • 19
  • 35
ltb68167
  • 37
  • 5

1 Answers1

0

From this site: Try to replace doublefann.h by fann.h.

Stefan Falk
  • 23,898
  • 50
  • 191
  • 378
  • Thanks a lot, that resolved the problem! Now the result is as it should 0.0 and 0.5. But when I split the training loop into two separate loops, the result will be 0.25 and 0.5. Is this normal? – ltb68167 May 04 '15 at 10:38
  • Once you trained, the weights are optimized for a certain dataset, in your case, for `d2 = 0.0`. You then take this *trained* network and optimize it's weights for `d1=0.5`, but in this process you "*overwrite*" the previous training. You should only train once, these networks are **not** able to incorporate new information later on. – Luis Jun 17 '16 at 15:42