org.joone.net
Class NeuralNet
- java.lang.Object
-
- org.joone.net.NeuralNet
-
- All Implemented Interfaces:
- java.io.Serializable, java.util.EventListener, NeuralLayer, NeuralNetListener
public class NeuralNet extends java.lang.Object implements NeuralLayer, NeuralNetListener, java.io.Serializable
This object represents a container of a neural network, giving to the developer the possibility to manage a neural network as a whole. Thanks to it, a neural network can be saved and restored using an unique writeObject and readObject command, without be worried about its internal composition. Not only this, because using a NeuralNet object, we can also easily transport a neural network on remote machines and runnit there, writing only few and generalized java code.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field and Description static intHIDDEN_LAYERstatic intINPUT_LAYERstatic intOUTPUT_LAYER
-
Constructor Summary
Constructors Constructor and Description NeuralNet()Creates new NeuralNet
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description booleanaddInputSynapse(InputPatternListener p1)Adds a new input synapse to the layervoidaddLayer(Layer layer)voidaddLayer(Layer layer, int tier)voidaddNeuralNetListener(NeuralNetListener listener)voidaddNoise(double p1)Adds a noise to the biases of the layer and to all the input synapses connectedbooleanaddOutputSynapse(OutputPatternListener p1)Adds a new output synapse to the layerLayer[]calculateOrderedLayers()This method calculates the order of the layers of the network, from the input to the output.java.util.TreeSetcheck()Compiles all layers' check messages.voidcicleTerminated(NeuralNetEvent e)Not implemented.NeuralNetcloneNet()Creates a copy of the contained neural networkNeuralLayercopyInto(NeuralLayer p1)Copies a Layer into another one, to obtain a type-transformation from a kind of Layer to another.voiderrorChanged(NeuralNetEvent e)Not implemented.LayerfindInputLayer()Returns the input layer, by searching for it following the rules written in Layer.isInputLayer.LayerfindOutputLayer()Returns the output layer by searching for it following the rules written in Layer.isOutputLayer.java.util.VectorgetAllInputs()Returns the vector of the input listenersjava.util.VectorgetAllOutputs()Returns the vector of the input listenersMatrixgetBias()Return the bias matrixNeuralNetAttributesgetDescriptor()LayergetInputLayer()Returns the input layer of the network.java.lang.String[]getKeys()Return all the keys of the parameters contained in the net.LayergetLayer(java.lang.String layerName)java.lang.StringgetLayerName()Returns the name of the layerjava.util.VectorgetLayers()java.util.VectorgetListeners()MacroInterfacegetMacroPlugin()Getter for property macroPlugin.MonitorgetMonitor()Returns the monitor objectstatic java.lang.IntegergetNumericVersion()Method to get the numeric version.Layer[]getOrderedLayers()LayergetOutputLayer()Returns the output layer of the network.java.lang.ObjectgetParam(java.lang.String key)Gets a custom parameter from the neural net.intgetRows()Returns the dimension (# of neurons) of the LayerComparingElementgetTeacher()static java.lang.StringgetVersion()Method to get the version.voidgo()Runs the network in async mode (i.e.voidgo(boolean sync)Runs the network.voidgo(boolean singleThreadMode, boolean sync)Runs the network.booleanisRunning()Returns true if the network is runningbooleanisScriptingEnabled()Gets if the scripting engine is enabledvoidjoin()Waits for all the termination of all running ThreadsvoidnetStarted(NeuralNetEvent e)Not implemented.voidnetStopped(NeuralNetEvent e)Not implemented.voidnetStoppedError(NeuralNetEvent e, java.lang.String error)Stops the execution threads and resets all the layers in the event of an crtitical network error.voidrandomize(double amplitude)voidremoveAllInputs()Remove all the input listeners of the netvoidremoveAllListeners()voidremoveAllOutputs()Remove all the output listeners of the netvoidremoveInputSynapse(InputPatternListener p1)Remove an input ListenervoidremoveLayer(Layer layer)voidremoveNeuralNetListener(NeuralNetListener listener)voidremoveOutputSynapse(OutputPatternListener p1)Remove an output listener from the layervoidresetInput()Resets all the StreamInputLayer of the netvoidrestore()Continue the execution of the network after the stop() method is called.voidsetAllInputs(java.util.Vector p1)Sets the vector that contains all the input listeners.voidsetAllOutputs(java.util.Vector p1)Sets the vector that contains all the output listeners.voidsetBias(Matrix p1)Sets the matrix of biasesvoidsetDescriptor(NeuralNetAttributes newdescriptor)voidsetInputLayer(Layer newLayer)voidsetLayerName(java.lang.String p1)Sets the name of the layervoidsetLayers(java.util.Vector newlayers)Permits to initialize a neural network with a Vector containing layers.voidsetLayersList(java.util.ArrayList list)Permits to initialize a neural network with an ArrayList containing layers.voidsetListeners(java.util.Vector listeners)voidsetMacroPlugin(MacroInterface macroPlugin)Setter for property macroPlugin.voidsetMonitor(Monitor p1)Sets the monitor objectvoidsetOrderedLayers(Layer[] orderedLayers)This method permits to set externally a particular order to traverse the Layers.voidsetOutputLayer(Layer newLayer)voidsetParam(java.lang.String key, java.lang.Object obj)Sets a custom parameter of the neural net.voidsetRows(int p1)Sets the dimension (# of neurons) of the LayervoidsetScriptingEnabled(boolean enabled)Enable/disable the scripting engine for the net.voidsetTeacher(ComparingElement ts)Sets the Teacher for this NeuralNet objectvoidstart()Starts all the Layers' threads, in order to prepare the launch of the neural network in multi-thread mode.voidstop()Terminates the execution of this NeuralNet independently from the threading mode activated.voidterminate()Terminates the execution of all the threads of the neural network.voidterminate(boolean notify)Terminates the execution of all the threads of the neural network.
-
-
-
Field Detail
-
INPUT_LAYER
public static final int INPUT_LAYER
- See Also:
- Constant Field Values
-
HIDDEN_LAYER
public static final int HIDDEN_LAYER
- See Also:
- Constant Field Values
-
OUTPUT_LAYER
public static final int OUTPUT_LAYER
- See Also:
- Constant Field Values
-
-
Method Detail
-
start
public void start()
Starts all the Layers' threads, in order to prepare the launch of the neural network in multi-thread mode. DO NOT use for single-thread mode.- Specified by:
startin interfaceNeuralLayer
-
join
public void join()
Waits for all the termination of all running Threads- See Also:
Thread.join()
-
stop
public void stop()
Terminates the execution of this NeuralNet independently from the threading mode activated.
-
terminate
public void terminate(boolean notify)
Terminates the execution of all the threads of the neural network. Used to force a neural network independently from its internal state. Use ONLY in multi-thread mode, and ONLY when the call to the stop() method doesn't give the expected results.- Parameters:
notify- if true, the netStopped event is raised
-
terminate
public void terminate()
Terminates the execution of all the threads of the neural network.- See Also:
this.terminate(boolean notify)
-
getInputLayer
public Layer getInputLayer()
Returns the input layer of the network. If the method setInputLayer has been never invoked, the input layer is found, set and returned.
-
findInputLayer
public Layer findInputLayer()
Returns the input layer, by searching for it following the rules written in Layer.isInputLayer. Ignores any previous call made to setInputLayer.
-
getOutputLayer
public Layer getOutputLayer()
Returns the output layer of the network. If the method setOutputLayer has been never invoked, the output layer is found, set and returned.
-
findOutputLayer
public Layer findOutputLayer()
Returns the output layer by searching for it following the rules written in Layer.isOutputLayer. Ignores any previous call made to setOutputLayer.
-
getRows
public int getRows()
Description copied from interface:NeuralLayerReturns the dimension (# of neurons) of the Layer- Specified by:
getRowsin interfaceNeuralLayer- Returns:
- int
-
setRows
public void setRows(int p1)
Description copied from interface:NeuralLayerSets the dimension (# of neurons) of the Layer- Specified by:
setRowsin interfaceNeuralLayer- Parameters:
p1- The number of the neurons contained in the Layer
-
addNoise
public void addNoise(double p1)
Description copied from interface:NeuralLayerAdds a noise to the biases of the layer and to all the input synapses connected- Specified by:
addNoisein interfaceNeuralLayer- Parameters:
p1- the noise's amplitude in terms of distance from zero; e.g.: a value equal 0.3 means a noise from -0.3 to 0.3
-
randomize
public void randomize(double amplitude)
-
getBias
public Matrix getBias()
Description copied from interface:NeuralLayerReturn the bias matrix- Specified by:
getBiasin interfaceNeuralLayer- Returns:
- neural.engine.Matrix
-
getAllOutputs
public java.util.Vector getAllOutputs()
Description copied from interface:NeuralLayerReturns the vector of the input listeners- Specified by:
getAllOutputsin interfaceNeuralLayer- Returns:
- java.util.Vector
-
getLayerName
public java.lang.String getLayerName()
Description copied from interface:NeuralLayerReturns the name of the layer- Specified by:
getLayerNamein interfaceNeuralLayer- Returns:
- java.lang.String
-
removeOutputSynapse
public void removeOutputSynapse(OutputPatternListener p1)
Description copied from interface:NeuralLayerRemove an output listener from the layer- Specified by:
removeOutputSynapsein interfaceNeuralLayer- Parameters:
p1- the output listener to remove
-
setAllInputs
public void setAllInputs(java.util.Vector p1)
Description copied from interface:NeuralLayerSets the vector that contains all the input listeners. Can be useful to set the input synapses taken from another Layer- Specified by:
setAllInputsin interfaceNeuralLayer- Parameters:
p1- The vector containing the list of input synapses
-
removeAllOutputs
public void removeAllOutputs()
Description copied from interface:NeuralLayerRemove all the output listeners of the net- Specified by:
removeAllOutputsin interfaceNeuralLayer
-
getAllInputs
public java.util.Vector getAllInputs()
Description copied from interface:NeuralLayerReturns the vector of the input listeners- Specified by:
getAllInputsin interfaceNeuralLayer- Returns:
- java.util.Vector
-
addOutputSynapse
public boolean addOutputSynapse(OutputPatternListener p1)
Description copied from interface:NeuralLayerAdds a new output synapse to the layer- Specified by:
addOutputSynapsein interfaceNeuralLayer- Parameters:
p1- The new output synapse- Returns:
- true if the output synapse has been attached sucessfully
-
setBias
public void setBias(Matrix p1)
Description copied from interface:NeuralLayerSets the matrix of biases- Specified by:
setBiasin interfaceNeuralLayer- Parameters:
p1- The Matrix object containing the biases
-
removeInputSynapse
public void removeInputSynapse(InputPatternListener p1)
Description copied from interface:NeuralLayerRemove an input Listener- Specified by:
removeInputSynapsein interfaceNeuralLayer- Parameters:
p1- the input listener to remove
-
setLayerName
public void setLayerName(java.lang.String p1)
Description copied from interface:NeuralLayerSets the name of the layer- Specified by:
setLayerNamein interfaceNeuralLayer- Parameters:
p1- The name
-
addInputSynapse
public boolean addInputSynapse(InputPatternListener p1)
Description copied from interface:NeuralLayerAdds a new input synapse to the layer- Specified by:
addInputSynapsein interfaceNeuralLayer- Parameters:
p1- The new input synapse- Returns:
- true if the input synapse has been attached sucessfully
-
setAllOutputs
public void setAllOutputs(java.util.Vector p1)
Description copied from interface:NeuralLayerSets the vector that contains all the output listeners. Can be useful to set the output synapses taken from another Layer- Specified by:
setAllOutputsin interfaceNeuralLayer- Parameters:
p1- The vector containing the list of output synapses
-
setMonitor
public void setMonitor(Monitor p1)
Description copied from interface:NeuralLayerSets the monitor object- Specified by:
setMonitorin interfaceNeuralLayer- Parameters:
p1- The Monitor to be set
-
getMonitor
public Monitor getMonitor()
Description copied from interface:NeuralLayerReturns the monitor object- Specified by:
getMonitorin interfaceNeuralLayer- Returns:
- java.engine.Monitor
-
removeAllInputs
public void removeAllInputs()
Description copied from interface:NeuralLayerRemove all the input listeners of the net- Specified by:
removeAllInputsin interfaceNeuralLayer
-
copyInto
public NeuralLayer copyInto(NeuralLayer p1)
Description copied from interface:NeuralLayerCopies a Layer into another one, to obtain a type-transformation from a kind of Layer to another. The old Layer is disconnected from the net, while the new Layer takes its place.- Specified by:
copyIntoin interfaceNeuralLayer- Parameters:
p1- neural.engine.Layer- Returns:
- The new layer
-
addLayer
public void addLayer(Layer layer)
-
addLayer
public void addLayer(Layer layer, int tier)
-
removeLayer
public void removeLayer(Layer layer)
-
resetInput
public void resetInput()
Resets all the StreamInputLayer of the net
-
addNeuralNetListener
public void addNeuralNetListener(NeuralNetListener listener)
-
getListeners
public java.util.Vector getListeners()
-
removeNeuralNetListener
public void removeNeuralNetListener(NeuralNetListener listener)
-
getVersion
public static java.lang.String getVersion()
Method to get the version.- Returns:
- A string containing the version of joone's engine in the format xx.yy.zz
-
getNumericVersion
public static java.lang.Integer getNumericVersion()
Method to get the numeric version.- Returns:
- an integer containing the joone's engine version
-
getLayer
public Layer getLayer(java.lang.String layerName)
-
getLayers
public java.util.Vector getLayers()
-
setLayers
public void setLayers(java.util.Vector newlayers)
Permits to initialize a neural network with a Vector containing layers.
-
setLayersList
public void setLayersList(java.util.ArrayList list)
Permits to initialize a neural network with an ArrayList containing layers. Added for Spring.
-
setTeacher
public void setTeacher(ComparingElement ts)
Sets the Teacher for this NeuralNet object- Parameters:
TeachingSynapse- - the new teacher. It can be null to make unsupervised this neural network
-
getTeacher
public ComparingElement getTeacher()
-
setListeners
public void setListeners(java.util.Vector listeners)
-
setInputLayer
public void setInputLayer(Layer newLayer)
-
setOutputLayer
public void setOutputLayer(Layer newLayer)
-
getDescriptor
public NeuralNetAttributes getDescriptor()
-
setDescriptor
public void setDescriptor(NeuralNetAttributes newdescriptor)
-
isRunning
public boolean isRunning()
Returns true if the network is running- Specified by:
isRunningin interfaceNeuralLayer- Returns:
- boolean
-
cloneNet
public NeuralNet cloneNet()
Creates a copy of the contained neural network- Returns:
- the cloned NeuralNet
-
removeAllListeners
public void removeAllListeners()
-
setScriptingEnabled
public void setScriptingEnabled(boolean enabled)
Enable/disable the scripting engine for the net. If disabled, all the event-driven macros will be not run- Parameters:
enabled- true to enable the scripting, otherwise false
-
isScriptingEnabled
public boolean isScriptingEnabled()
Gets if the scripting engine is enabled- Returns:
- true if enabled
-
getMacroPlugin
public MacroInterface getMacroPlugin()
Getter for property macroPlugin.- Returns:
- Value of property macroPlugin.
-
setMacroPlugin
public void setMacroPlugin(MacroInterface macroPlugin)
Setter for property macroPlugin.- Parameters:
macroPlugin- New value of property macroPlugin.
-
getParam
public java.lang.Object getParam(java.lang.String key)
Gets a custom parameter from the neural net. The user is free to use the custom parameters as s/he wants. They are useful to transport a whatever value along with the net.- Parameters:
key- The searched key- Returns:
- The value of the parameter if found, otherwise null
-
setParam
public void setParam(java.lang.String key, java.lang.Object obj)Sets a custom parameter of the neural net. The user is free to use the custom parameters as s/he wants. They are useful to transport a whatever value along with the net.- Parameters:
key- The key of the paramobj- The value of the param
-
getKeys
public java.lang.String[] getKeys()
Return all the keys of the parameters contained in the net.- Returns:
- An array of Strings containing all the keys if found, otherwise null
-
check
public java.util.TreeSet check()
Compiles all layers' check messages.- Specified by:
checkin interfaceNeuralLayer- Returns:
- validation errors.
- See Also:
NeuralLayer
-
netStarted
public void netStarted(NeuralNetEvent e)
Not implemented.- Specified by:
netStartedin interfaceNeuralNetListener- Parameters:
e-
-
cicleTerminated
public void cicleTerminated(NeuralNetEvent e)
Not implemented.- Specified by:
cicleTerminatedin interfaceNeuralNetListener- Parameters:
e-
-
netStopped
public void netStopped(NeuralNetEvent e)
Not implemented.- Specified by:
netStoppedin interfaceNeuralNetListener- Parameters:
e-
-
errorChanged
public void errorChanged(NeuralNetEvent e)
Not implemented.- Specified by:
errorChangedin interfaceNeuralNetListener- Parameters:
e-
-
netStoppedError
public void netStoppedError(NeuralNetEvent e, java.lang.String error)
Stops the execution threads and resets all the layers in the event of an crtitical network error.- Specified by:
netStoppedErrorin interfaceNeuralNetListener- Parameters:
error- The error message.e- The event source of this event.
-
setOrderedLayers
public void setOrderedLayers(Layer[] orderedLayers)
This method permits to set externally a particular order to traverse the Layers. If not used, the order will be calculated automatically. Use this method in cases where the automatic ordering doesn't work (e.g. in case of complex recurrent connections) NOTE: if you set this property, you're responsible to update the array whenever a layer is added/removed.- Parameters:
orderedLayers- an array containing the ordered layers
-
getOrderedLayers
public Layer[] getOrderedLayers()
-
calculateOrderedLayers
public Layer[] calculateOrderedLayers()
This method calculates the order of the layers of the network, from the input to the output. If the setOrderedLayers method has been invoked before, that array will be returned, otherwise the order will be calculated automatically.- Returns:
- An array containing the ordered Layers, from the input to the output (i.e. layers[0]=input layer, layers[n-1]=output layer.
-
go
public void go(boolean singleThreadMode, boolean sync)Runs the network.- Parameters:
singleThreadMode- If true, runs the network in single thread modesync- If true, runs the network in a separated thread and returns immediately.
-
go
public void go(boolean sync)
Runs the network. The running mode is determined by the value of the singleThreadMode property.- Parameters:
sync- If true, runs the network in a separated thread and returns immediately.
-
go
public void go()
Runs the network in async mode (i.e. equivalent to go(false) ). The running mode is determined by the value of the singleThreadMode property.
-
restore
public void restore()
Continue the execution of the network after the stop() method is called.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG