Class MultilayerPerceptronCostFunction

  • All Implemented Interfaces:
    CostFunction

    public final class MultilayerPerceptronCostFunction
    extends AbstractMiniBatchCostFunction
    Neural network costfunction for a multilayer perceptron.
    Author:
    thomas.jungblut
    • Constructor Detail

      • MultilayerPerceptronCostFunction

        public MultilayerPerceptronCostFunction​(MultilayerPerceptron network,
                                                de.jungblut.math.DoubleVector[] features,
                                                de.jungblut.math.DoubleVector[] outcome)
    • Method Detail

      • computeNextStep

        public static CostGradientTuple computeNextStep​(de.jungblut.math.DoubleVector input,
                                                        de.jungblut.math.DoubleMatrix x,
                                                        de.jungblut.math.DoubleMatrix y,
                                                        MultilayerPerceptronCostFunction.NetworkConfiguration conf)
        Do a full forward pass and backpropagate the error.
        Parameters:
        input - the input parameters (theta).
        x - the features.
        y - the outcome.
        Returns:
        a tuple of cost and gradient.
      • backwardPropagate

        public static de.jungblut.math.DoubleMatrix[] backwardPropagate​(de.jungblut.math.DoubleMatrix y,
                                                                        de.jungblut.math.DoubleMatrix[] thetas,
                                                                        de.jungblut.math.DoubleMatrix[] ax,
                                                                        de.jungblut.math.DoubleMatrix[] zx,
                                                                        MultilayerPerceptronCostFunction.NetworkConfiguration conf)
      • calculateGradients

        public static void calculateGradients​(de.jungblut.math.DoubleMatrix[] thetas,
                                              de.jungblut.math.DoubleMatrix[] thetaGradients,
                                              de.jungblut.math.DoubleMatrix[] ax,
                                              de.jungblut.math.DoubleMatrix[] deltaX,
                                              int m,
                                              MultilayerPerceptronCostFunction.NetworkConfiguration conf)
      • computeUnfoldParameters

        public static int[][] computeUnfoldParameters​(int[] layerSizes)
        Calculates the unfold parameters to unroll a learned theta vector in their matrix.
        Parameters:
        layerSizes - the layer size that the MultilayerPerceptron got instantiated with.
        Returns:
        the unfold parameters to feed DenseMatrixFolder with.
      • dropout

        public static void dropout​(java.util.Random rnd,
                                   de.jungblut.math.DoubleMatrix activations,
                                   double p)
        Computes dropout for the activations matrix. Each element for each row has the similar probability p to be "dropped out" (set to 0) of the computation. This way, the network does learn to not rely on other units thus learning to detect more general features than drastically overfitting the dataset.
        Parameters:
        rnd - the random number generator to consult.
        activations - activations of units per record on each column.
        p - dropout probability.