Class Competitive

  • All Implemented Interfaces:
    java.io.Serializable

    public class Competitive
    extends UnsupervisedLearning
    Competitive Learning is an unsupervised network where "the winner takes all". A pattern is presented to each neuron, the closest neuron wins the right to be updated. The update makes this neuron fittest for that pattern in the future. Finally, the network learns a set of descriptive patterns or centroids (if is compared with a clustering algorithm). In general, the output for that network will be a binary codified class, when only one bit on (the winner). One of the problems with the competitive learning is the unable to know beforehand, the order of the output. For example, suppose we have 3 possible outputs (100, 010, 001). For the first random initialization, the winner for the first pattern is the neuron 0, so the output is 100. But, if retrain with a new random initialization, the winner for the same pattern will be the neuron 2, so the output is 001. That is not necessary incorrect because the relative order could be maintained between the inputs. Therefore, before calculate any error metric we need to label the patterns with the respective answers, in a similar way as Kohonen does.
    See Also:
    Serialized Form
    • Field Detail

      • ins

        protected int ins
      • outs

        protected int outs
    • Constructor Detail

      • Competitive

        public Competitive​(int in,
                           int out)
        Constructor. Creates a network with the specified number of inputs and outputs.
        Parameters:
        in - Number of inputs.
        out - Number of outputs.
      • Competitive

        public Competitive​(int in,
                           int out,
                           java.util.Random rand)
        Constructor. Creates a network with the specified number of inputs and outputs.
        Parameters:
        in - Number of inputs.
        out - Number of outputs.
        rand - Random generator used for creating matrices
    • Method Detail

      • train

        public void train​(Column[] patterns,
                          double alpha,
                          int epochs,
                          int offset,
                          int length)
        Train the network using "the winner takes all". For each neuron the Euclidean distance between the pattern and the neuron is calculated. The position with the lowest distance is updated with the rule:
        Ww = Ww + alpha.(pattern - Ww)
        Specified by:
        train in class UnsupervisedLearning
        Parameters:
        patterns - The patterns to be learned.
        alpha - The learning rate.
        epochs - The maximum number of iterations
        offset - The first pattern position
        length - How many patterns will be used.
      • simulate

        public Column simulate​(Column pattern)
        Description copied from class: NeuralNetwork
        Calculates the output for the pattern.
        Specified by:
        simulate in class NeuralNetwork
        Parameters:
        pattern - Pattern to use as input.
        Returns:
        The output for the neural network.
      • simulate

        public void simulate​(Column pattern,
                             Column result)
        Calculate the output for the pattern and left the result in result. The result will be a row matrix fill with 0 except for the winner position.
        Specified by:
        simulate in class NeuralNetwork
        Parameters:
        pattern - Pattern to use as input.
        result - The output for the input.
      • simulateNoChange

        protected int simulateNoChange​(Matrix pattern)
      • error

        public double error​(Column[] patterns,
                            Column[] answers,
                            int offset,
                            int length)
        Calculate the error using the average distance between the closest neuron. Less distance means less error and vice versa.
        Overrides:
        error in class NeuralNetwork
        Parameters:
        patterns - The array with the patterns to test
        answers - The array with the expected answers for the patterns.
        offset - The initial position inside the array.
        length - How many patterns must be taken from the offset.
        Returns:
        The average distance between the pattern and the winner for that pattern.