-1

I have been trying to prepare a sample training file of fann using the code:

 Fann fann = new Fann( "C:\Documents and Settings\user\My Documents\Downloads\fannj-master\src\test\resources\com\googlecode\fannj\xor.data" );
float[] inputs = new float[]{ -1, 1 };
float[] outputs = fann.run( inputs );
fann.close();

the xor.data file has:

4 2 1
-1 -1
-1
-1 1
1
1 -1
1
1 1
-1

The error encountered is:

Exception in thread "main" java.lang.ExceptionInInitializerError
    at project.Project.main(Project.java:23)
Caused by: java.lang.UnsupportedOperationException
    at java.util.AbstractMap.put(AbstractMap.java:203)
    at com.googlecode.fannj.Fann.<clinit>(Fann.java:54)
    ... 1 more
Java Result: 1
  • 1
    It Seems `com.googlecode.fannj.Fann` internally uses JNA, maybe you use a wrong Version of JNA? – hinneLinks Aug 24 '15 at 05:35
  • i have used jna-3.1.0 version – Shreyas Karnick Aug 24 '15 at 06:27
  • 2
    is the path to file in the proper format ? – Shreyas Karnick Aug 24 '15 at 06:29
  • Compare it to the Version that `com.googlecode.fannj.Fann` requires. And no, the Path is not in the proper format, replace the \ with \\ or /. The \ is the Java Escape Character, the \test in your path will be interpreted as est – hinneLinks Aug 24 '15 at 06:36
  • ive used fannj-0.6.jar. Can u suggest the corresponding jna? – Shreyas Karnick Aug 24 '15 at 07:14
  • I agree that path String looks suspicious. Please try with JNA 3.5.2. Are you using JNA 3.1 or 4.1? I've not tested FannJ on JNA 4.1. (I'm FannJ Maintainer) https://github.com/java-native-access/jna/releases/tag/3.5.2 – Kyle Renfro Aug 25 '15 at 17:22
  • i have changed \ with \\. I have also used jna 3.5.2 lib. Im encountring an error saying wrong version of configuration file. Firstly should this code be written in the main class? I am new to Fann and java. So finding it really difficult to figure out. – Shreyas Karnick Aug 26 '15 at 04:28
  • 1
    Ive found out the mistake. The type of file should be a .net file, which is the right configuration – Shreyas Karnick Aug 26 '15 at 06:14

1 Answers1

0

You are giving a wrong file to the constructor, "xor.data" is a data file not a "net" file which has ANN configurations.

You can see the method that the constructor invokes:

struct fann * fann_create_from_file(const char * configuration_file);

If you don't have the "net" file for your ANN, you can create this kind of file by C code using the method:

void fann_save(struct fann * ann, const char * configuration_file);

After that you can load from java a configured network.

Cleber Jorge Amaral
  • 1,316
  • 13
  • 26