-1

Hi can somebody help me with the error, I used Fannj for create Neural Network. Fannj is Java bindings to FANN (the Fast Artificial Neural Network C library.)

My code:

Layer l1 = new Layer();
l1.create(1, ActivationFunction.FANN_SIGMOID_SYMMETRIC);
Layer l2 = new Layer();
l2.create(1, ActivationFunction.FANN_SIGMOID_SYMMETRIC);
Layer l3 = new Layer();
l3.create(1, ActivationFunction.FANN_SIGMOID_SYMMETRIC);
List<Layer> list = new ArrayList<Layer>();
list.add(l1);
list.add(l2);
list.add(l3);
Fann fannT = new Fann( list);

And Error:

Exception in thread "main" java.lang.Error: Invalid memory access
at com.googlecode.fannj.Fann.fann_create_standard_array(Native Method)
at com.googlecode.fannj.Fann.<init>(Fann.java:92)
at m.nieco.suns.zadanie01.Main.main(Main.java:34)

I used https://github.com/krenfro/fannj

Matus
  • 172
  • 1
  • 1
  • 13
  • 2
    Do not post images of text, copy/paste the text into your post and format as fixed-width (use the `{}` button in the editor). This looks like one of: (a) a bug in the library you are using; or (b) an error in how you set up the list argument to the `Fann()` constructor. – Jim Garrison Oct 07 '16 at 19:02
  • thanks, i fixed it. is it better ? – Matus Oct 07 '16 at 19:20
  • I think the question is now clear. The point is that your program is crashing when it reachs the instruction "Fann fannT = new Fann( list);" and the error message is "java.lang.Error: Invalid memory access" – Cleber Jorge Amaral Sep 05 '17 at 13:16
  • I hope this topic can be reopened because I had the same problem. If it happens, I'd like to post the solution I've used. The problem with this code is because "Layer" is static and should be treated as it. The final code could be rewrite like this: List layers = new ArrayList(); layers.add(Layer.create(2)); layers.add(Layer.create(3, ActivationFunction.FANN_SIGMOID_SYMMETRIC)); layers.add(Layer.create(1, ActivationFunction.FANN_SIGMOID_SYMMETRIC)); Fann fann = new Fann(layers); – Cleber Jorge Amaral Sep 05 '17 at 13:21

1 Answers1

1

Here's the code for the constructor you are invoking (from GitHub):

public Fann(List<Layer> layers) {
    if (layers == null)
        throw new IllegalArgumentException("layers == null");
    if (layers.isEmpty())
        throw new IllegalArgumentException("layers is empty");

    int[] neurons = new int[layers.size()];
    for (int x = 0; x < neurons.length; x++)
        neurons[x] = layers.get(x).size();

    ann = fann_create_standard_array(neurons.length, neurons);
    addLayers(layers);
}

The error is occurring in the invocation of the native method at

ann = fann_create_standard_array(neurons.length, neurons);

Since there does not appear to be a problem with the argument list, and at this point the only thing it uses is the size of the list and each list element's getSize() value, my bet is on a bug in the library.

You are much more likely to get help if you post a bug report at the GitHub issue tracker for Fann.

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190