Package com.googlecode.fannj
Class Fann
- java.lang.Object
-
- com.googlecode.fannj.Fann
-
- Direct Known Subclasses:
FannShortcut
,FannSparse
public class Fann extends java.lang.Object
A standard fully connected back-propagation neural network.
Not thread safe.
A Java binding to the Fast Artificial Neural Network (FANN) native library.This class invokes native code. You must call close() to prevent memory leakage.
- See Also:
- Fast Artificial Neural Network, JNA Direct Maping
-
-
Field Summary
Fields Modifier and Type Field Description protected com.sun.jna.Pointer
ann
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addLayers(java.util.List<Layer> layers)
void
close()
Frees allocated memory.protected static com.sun.jna.Pointer
fann_create_from_file(java.lang.String configuration_file)
protected static com.sun.jna.Pointer
fann_create_shortcut_array(int numLayers, int[] layers)
protected static com.sun.jna.Pointer
fann_create_sparse_array(float connection_rate, int numLayers, int[] layers)
protected static com.sun.jna.Pointer
fann_create_standard_array(int numLayers, int[] layers)
protected static void
fann_destroy(com.sun.jna.Pointer ann)
protected static float
fann_get_MSE(com.sun.jna.Pointer ann)
protected static com.sun.jna.Pointer
fann_get_neuron(com.sun.jna.Pointer ann, int layer, int neuron)
protected static int
fann_get_num_input(com.sun.jna.Pointer ann)
protected static int
fann_get_num_output(com.sun.jna.Pointer ann)
protected static int
fann_get_total_neurons(com.sun.jna.Pointer ann)
protected static com.sun.jna.Pointer
fann_run(com.sun.jna.Pointer ann, float[] input)
protected static int
fann_save(com.sun.jna.Pointer ann, java.lang.String file)
protected static void
fann_set_activation_function(com.sun.jna.Pointer ann, int activation_function, int layer, int neuron)
protected static void
fann_set_activation_steepness(com.sun.jna.Pointer ann, float steepness, int layer, int neuron)
void
finalize()
Callclose()
on garbage collection to catch memory leaks.int
getNumInputNeurons()
int
getNumOutputNeurons()
int
getTotalNumNeurons()
float[]
run(float[] input)
Run the ANN on a set of inputs.boolean
save(java.lang.String file)
Save this FANN to a file.
-
-
-
Constructor Detail
-
Fann
protected Fann()
-
Fann
public Fann(java.lang.String file)
Load an existing FANN definition from a file- Parameters:
file
-
-
Fann
public Fann(java.util.List<Layer> layers)
Create a new ANN with the provided layers.- Parameters:
layers
-
-
-
Method Detail
-
addLayers
protected void addLayers(java.util.List<Layer> layers)
-
getNumInputNeurons
public int getNumInputNeurons()
-
getNumOutputNeurons
public int getNumOutputNeurons()
-
getTotalNumNeurons
public int getTotalNumNeurons()
-
save
public boolean save(java.lang.String file)
Save this FANN to a file.- Parameters:
file
-- Returns:
- true on success
-
run
public float[] run(float[] input)
Run the ANN on a set of inputs.- Parameters:
input
- length == numInputNeurons- Returns:
- the output of the ANN. (length = numOutputNeurons)
-
close
public void close()
Frees allocated memory.
You must call this method when you are finished to prevent memory leaks.
-
finalize
public void finalize() throws java.lang.Throwable
Callclose()
on garbage collection to catch memory leaks.- Overrides:
finalize
in classjava.lang.Object
- Throws:
java.lang.Throwable
-
fann_create_standard_array
protected static com.sun.jna.Pointer fann_create_standard_array(int numLayers, int[] layers)
-
fann_create_sparse_array
protected static com.sun.jna.Pointer fann_create_sparse_array(float connection_rate, int numLayers, int[] layers)
-
fann_create_shortcut_array
protected static com.sun.jna.Pointer fann_create_shortcut_array(int numLayers, int[] layers)
-
fann_get_MSE
protected static float fann_get_MSE(com.sun.jna.Pointer ann)
-
fann_run
protected static com.sun.jna.Pointer fann_run(com.sun.jna.Pointer ann, float[] input)
-
fann_destroy
protected static void fann_destroy(com.sun.jna.Pointer ann)
-
fann_get_num_input
protected static int fann_get_num_input(com.sun.jna.Pointer ann)
-
fann_get_num_output
protected static int fann_get_num_output(com.sun.jna.Pointer ann)
-
fann_get_total_neurons
protected static int fann_get_total_neurons(com.sun.jna.Pointer ann)
-
fann_set_activation_function
protected static void fann_set_activation_function(com.sun.jna.Pointer ann, int activation_function, int layer, int neuron)
-
fann_set_activation_steepness
protected static void fann_set_activation_steepness(com.sun.jna.Pointer ann, float steepness, int layer, int neuron)
-
fann_get_neuron
protected static com.sun.jna.Pointer fann_get_neuron(com.sun.jna.Pointer ann, int layer, int neuron)
-
fann_create_from_file
protected static com.sun.jna.Pointer fann_create_from_file(java.lang.String configuration_file)
-
fann_save
protected static int fann_save(com.sun.jna.Pointer ann, java.lang.String file)
-
-