org.apache.commons.math3.ml.neuralnet

## Class Neuron

- java.lang.Object
- - org.apache.commons.math3.ml.neuralnet.Neuron

- All Implemented Interfaces:
    Serializable

      public class Neuron
      extends Object
      implements Serializable

  Describes a neuron element of a neural network. This class aims to be thread-safe.
  Since:
    3.3
  Version:
    $Id: Neuron.java 1566092 2014-02-08 18:48:29Z tn $
  See Also:
    Serialized Form

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `compareAndSetFeatures(double[] expect, double[] update)` Tries to atomically update the neuron's features.
    `double[]` | `getFeatures()` Gets the neuron's features.
    `long` | `getIdentifier()` Gets the neuron's identifier.
    `int` | `getSize()` Gets the length of the feature set.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### getIdentifier

          public long getIdentifier()

      Gets the neuron's identifier.
      Returns:
        the identifier.

    - #### getSize

          public int getSize()

      Gets the length of the feature set.
      Returns:
        the number of features.

    - #### getFeatures

          public double[] getFeatures()

      Gets the neuron's features.
      Returns:
        a copy of the neuron's features.

    - #### compareAndSetFeatures

          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` - 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.
      Returns:
        `true` if the update was successful, `false` otherwise.
      Throws:
        `DimensionMismatchException` - if the length of `update` is not the same as specified in the `constructor`.

Copyright © 2003–2014 The Apache Software Foundation. All rights reserved.