public class Neuron
extends java.lang.Object
implements java.io.Serializable
| Modifier and Type | Class and Description |
|---|---|
private static class |
Neuron.SerializationProxy
Serialization.
|
| Modifier and Type | Field and Description |
|---|---|
private java.util.concurrent.atomic.AtomicReference<double[]> |
features
Neuron data.
|
private long |
identifier
Identifier.
|
private java.util.concurrent.atomic.AtomicLong |
numberOfAttemptedUpdates
Number of attempts to update a neuron.
|
private java.util.concurrent.atomic.AtomicLong |
numberOfSuccessfulUpdates
Number of successful updates of a neuron.
|
private static long |
serialVersionUID
Serializable.
|
private int |
size
Length of the feature set.
|
| Constructor and Description |
|---|
Neuron(long identifier,
double[] features)
Creates a neuron.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
compareAndSetFeatures(double[] expect,
double[] update)
Tries to atomically update the neuron's features.
|
private boolean |
containSameValues(double[] current,
double[] expect)
Checks whether the contents of both arrays is the same.
|
Neuron |
copy()
Performs a deep copy of this instance.
|
double[] |
getFeatures()
Gets the neuron's features.
|
long |
getIdentifier()
Gets the neuron's identifier.
|
long |
getNumberOfAttemptedUpdates()
Retrieves the number of calls to the
compareAndSetFeatures
method. |
long |
getNumberOfSuccessfulUpdates()
Retrieves the number of successful calls to the
compareAndSetFeatures
method. |
int |
getSize()
Gets the length of the feature set.
|
private void |
readObject(java.io.ObjectInputStream in)
Prevents proxy bypass.
|
private java.lang.Object |
writeReplace()
Custom serialization.
|
private static final long serialVersionUID
private final long identifier
private final int size
private final java.util.concurrent.atomic.AtomicReference<double[]> features
private final java.util.concurrent.atomic.AtomicLong numberOfAttemptedUpdates
private final java.util.concurrent.atomic.AtomicLong numberOfSuccessfulUpdates
Neuron(long identifier,
double[] features)
created by the network
instance to which they will belong.identifier - Identifier (assigned by the Network).features - Initial values of the feature set.public Neuron copy()
public long getIdentifier()
public int getSize()
public double[] getFeatures()
public boolean compareAndSetFeatures(double[] expect,
double[] update)
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.expect - 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 - Features's new values.true if the update was successful, false
otherwise.DimensionMismatchException - if the length of update is
not the same as specified in the constructor.public long getNumberOfAttemptedUpdates()
compareAndSetFeatures
method.
Note that if the caller wants to use this method in combination with
getNumberOfSuccessfulUpdates(), additional synchronization
may be required to ensure consistency.public long getNumberOfSuccessfulUpdates()
compareAndSetFeatures
method.
Note that if the caller wants to use this method in combination with
getNumberOfAttemptedUpdates(), additional synchronization
may be required to ensure consistency.private boolean containSameValues(double[] current,
double[] expect)
current - Current values.expect - Expected values.true if the arrays contain the same values.DimensionMismatchException - if the length of expected
is not the same as specified in the constructor.private void readObject(java.io.ObjectInputStream in)
in - Input stream.private java.lang.Object writeReplace()
Copyright (c) 2003-2017 Apache Software Foundation