Package tv.floe.metronome.deeplearning.neuralnetwork.activation

Examples of tv.floe.metronome.deeplearning.neuralnetwork.activation.ActivationFunction


     */
    private void computeDeltas(List<Pair<Matrix,Matrix>> deltaRet) {

        Matrix[] gradients = new Matrix[ this.numberLayers + 2 ];
        Matrix[] deltas = new Matrix[ this.numberLayers + 2 ];
        ActivationFunction derivative = this.hiddenLayers[ 0 ].activationFunction;

        ActivationFunction softMaxDerivative = Activations.softmax();

        //- y - h
        Matrix delta = null;

        List<Matrix> activations = this.feedForward();

    /*
     * Precompute activations and z's (pre activation network outputs)
     */
        List<Matrix> weights = new ArrayList<Matrix>();

        for (int j = 0; j < this.preTrainingLayers.length; j++) {

            weights.add( this.preTrainingLayers[j].getConnectionWeights() );

        }

        weights.add( this.logisticRegressionLayer.connectionWeights );

/*   
    List<Matrix> zs = new ArrayList<Matrix>();
   
    zs.add( this.inputTrainingData );
   
    for (int i = 0; i < this.preTrainingLayers.length; i++) {
     
      if (this.preTrainingLayers[i].getInput() == null && i == 0) {
       
        this.preTrainingLayers[i].setInput( this.inputTrainingData );
       
      } else if (this.preTrainingLayers[i].getInput() == null) {
       
        this.feedForward();
       
      }

      zs.add(MatrixUtils.sigmoid( MatrixUtils.addRowVector( this.preTrainingLayers[ i ].getInput().times( weights.get( i ) ),  this.preTrainingLayers[i].getHiddenBias().viewRow(0) )));
     
    }
   
    zs.add( MatrixUtils.addRowVector( this.logisticRegressionLayer.input.times( this.logisticRegressionLayer.connectionWeights ), this.logisticRegressionLayer.biasTerms.viewRow(0) ) );
*/

        Matrix labels = this.outputTrainingLabels;

        //errors
        for (int i = this.numberLayers + 1; i >= 0; i--) {

            // output layer
            if (i >= this.numberLayers + 1) {
        /*
        Matrix z = activations.get(i);
       
        //- y - h
        delta = MatrixUtils.neg( labels.minus( z ) );

        //(- y - h) .* f'(z^l) where l is the output layer
        Matrix initialDelta = MatrixUtils.elementWiseMultiplication( delta, derivative.applyDerivative( z ) );
        deltas[ i ] = initialDelta;
*/

                //-( y - h) .* f'(z^l) where l is the output layer
                //delta = labels.sub(activations.get(i)).neg().mul(softMaxDerivative.applyDerivative(activations.get(i)));
                Matrix tmpDelta = MatrixUtils.neg( labels.minus( activations.get( i ) ) );

                delta = MatrixUtils.elementWiseMultiplication( tmpDelta, softMaxDerivative.applyDerivative(activations.get(i)) );

                deltas[i] = delta;


            } else {
View Full Code Here

TOP

Related Classes of tv.floe.metronome.deeplearning.neuralnetwork.activation.ActivationFunction

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.