Top Description Inners Fields Constructors Methods
org.apache.commons.math3.ml.neuralnet

public Class Neuron

extends Object
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Imports
java.io.Serializable, .ObjectInputStream, java.util.concurrent.atomic.AtomicReference, .AtomicLong, org.apache.commons.math3.exception.DimensionMismatchException, org.apache.commons.math3.util.Precision

Describes a neuron element of a neural network. This class aims to be thread-safe.
Since
3.3

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private final AtomicReference<double[]>
features

Neuron data.

private final long
identifier

Identifier.

private final AtomicLong
numberOfAttemptedUpdates

Number of attempts to update a neuron.

private final AtomicLong
numberOfSuccessfulUpdates

Number of successful updates of a neuron.

private static final long
serialVersionUID

Serializable.

private final int
size

Length of the feature set.

Constructor Summary

AccessConstructor and Description
pack-priv
Neuron(long
Identifier (assigned by the Network).
identifier
,
double[]
Initial values of the feature set.
features
)

Creates a neuron.

Method Summary

Modifier and TypeMethod and Description
public boolean

Returns:

true if the update was successful, false otherwise.
compareAndSetFeatures
(double[]
Current values of the features, as assumed by the caller. Update will never succeed if the contents of this array does not match the values returned by getFeatures().
expect
,
double[]
Features's new values.
update
)

Tries to atomically update the neuron's features.

private boolean

Returns:

true if the arrays contain the same values.
containSameValues
(double[]
Current values.
current
,
double[]
Expected values.
expect
)

Checks whether the contents of both arrays is the same.

public synchronized Neuron

Returns:

a new instance with the same state as this instance.
copy
()

Performs a deep copy of this instance.

public double[]

Returns:

a copy of the neuron's features.
getFeatures
()

Gets the neuron's features.

public long

Returns:

the identifier.
getIdentifier
()

Gets the neuron's identifier.

public long

Returns:

the number of update attempts.
getNumberOfAttemptedUpdates
()

Retrieves the number of calls to the compareAndSetFeatures method.

public long

Returns:

the number of successful updates.
getNumberOfSuccessfulUpdates
()

Retrieves the number of successful calls to the compareAndSetFeatures method.

public int

Returns:

the number of features.
getSize
()

Gets the length of the feature set.

private void
readObject(ObjectInputStream
Input stream.
in
)

Prevents proxy bypass.

private Object

Returns:

the proxy instance that will be actually serialized.
writeReplace
()

Custom serialization.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

featuresback to summary
private final AtomicReference<double[]> features

Neuron data.

identifierback to summary
private final long identifier

Identifier.

numberOfAttemptedUpdatesback to summary
private final AtomicLong numberOfAttemptedUpdates

Number of attempts to update a neuron.

numberOfSuccessfulUpdatesback to summary
private final AtomicLong numberOfSuccessfulUpdates

Number of successful updates of a neuron.

serialVersionUIDback to summary
private static final long serialVersionUID

Serializable.

sizeback to summary
private final int size

Length of the feature set.

Constructor Detail

Neuronback to summary
pack-priv Neuron(long identifier, double[] features)

Creates a neuron. The size of the feature set is fixed to the length of the given argument.
Constructor is package-private: Neurons must be created by the network instance to which they will belong.

Parameters
identifier:long

Identifier (assigned by the Network).

features:double[]

Initial values of the feature set.

Method Detail

compareAndSetFeaturesback to summary
public boolean compareAndSetFeatures(double[] expect, double[] update)

Tries to atomically update the neuron's features. Update will be performed only if the expected values match the current values.
In effect, when concurrent threads call this method, the state could be modified by one, so that it does not correspond to the the state assumed by another. Typically, a caller retrieves the current state, and uses it to compute the new state. During this computation, another thread might have done the same thing, and updated the state: If the current thread were to proceed with its own update, it would overwrite the new state (which might already have been used by yet other threads). To prevent this, the method does not perform the update when a concurrent modification has been detected, and returns false. When this happens, the caller should fetch the new current state, redo its computation, and call this method again.

Parameters
expect:double[]

Current values of the features, as assumed by the caller. Update will never succeed if the contents of this array does not match the values returned by getFeatures().

update:double[]

Features's new values.

Returns:boolean

true if the update was successful, false otherwise.

Exceptions
DimensionMismatchException:
if the length of update is not the same as specified in the constructor.
containSameValuesback to summary
private boolean containSameValues(double[] current, double[] expect)

Checks whether the contents of both arrays is the same.

Parameters
current:double[]

Current values.

expect:double[]

Expected values.

Returns:boolean

true if the arrays contain the same values.

Exceptions
DimensionMismatchException:
if the length of expected is not the same as specified in the constructor.
copyback to summary
public synchronized Neuron copy()

Performs a deep copy of this instance. Upon return, the copied and original instances will be independent: Updating one will not affect the other.

Returns:Neuron

a new instance with the same state as this instance.

Since
3.6
getFeaturesback to summary
public double[] getFeatures()

Gets the neuron's features.

Returns:double[]

a copy of the neuron's features.

getIdentifierback to summary
public long getIdentifier()

Gets the neuron's identifier.

Returns:long

the identifier.

getNumberOfAttemptedUpdatesback to summary
public long getNumberOfAttemptedUpdates()

Retrieves the number of calls to the compareAndSetFeatures method. Note that if the caller wants to use this method in combination with getNumberOfSuccessfulUpdates(), additional synchronization may be required to ensure consistency.

Returns:long

the number of update attempts.

Since
3.6
getNumberOfSuccessfulUpdatesback to summary
public long getNumberOfSuccessfulUpdates()

Retrieves the number of successful calls to the compareAndSetFeatures method. Note that if the caller wants to use this method in combination with getNumberOfAttemptedUpdates(), additional synchronization may be required to ensure consistency.

Returns:long

the number of successful updates.

Since
3.6
getSizeback to summary
public int getSize()

Gets the length of the feature set.

Returns:int

the number of features.

readObjectback to summary
private void readObject(ObjectInputStream in)

Prevents proxy bypass.

Parameters
in:ObjectInputStream

Input stream.

writeReplaceback to summary
private Object writeReplace()

Custom serialization.

Returns:Object

the proxy instance that will be actually serialized.

org.apache.commons.math3.ml.neuralnet back to summary

private Class Neuron.SerializationProxy

extends Object
implements Serializable
Class Inheritance
  • java.lang.Object
  • org.apache.commons.math3.ml.neuralnet.Neuron.SerializationProxy
All Implemented Interfaces
java.io.Serializable

Serialization.

Field Summary

Modifier and TypeField and Description
private final double[]
features

Features.

private final long
identifier

Identifier.

private static final long
serialVersionUID

Serializable.

Constructor Summary

AccessConstructor and Description
pack-priv
SerializationProxy(long
Identifier.
identifier
,
double[]
Features.
features
)

Method Summary

Modifier and TypeMethod and Description
private Object

Returns:

the Neuron for which this instance is the proxy.
readResolve
()

Custom serialization.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

featuresback to summary
private final double[] features

Features.

identifierback to summary
private final long identifier

Identifier.

serialVersionUIDback to summary
private static final long serialVersionUID

Serializable.

Constructor Detail

SerializationProxyback to summary
pack-priv SerializationProxy(long identifier, double[] features)
Parameters
identifier:long

Identifier.

features:double[]

Features.

Method Detail

readResolveback to summary
private Object readResolve()

Custom serialization.

Returns:Object

the Neuron for which this instance is the proxy.