package org.deeplearning4j.util;

import org.deeplearning4j.nn.api.Layer;
import org.nd4j.linalg.api.ndarray.INDArray;
import org.nd4j.linalg.api.ops.impl.transforms.DropOutInverted;
import org.nd4j.linalg.factory.Nd4j;


/**
 * @author Adam Gibson
 */
public class Dropout {

    private Dropout() {
    }

    /**
     * Apply drop connect to the given variable
     * @param layer the layer with the variables
     * @param variable the variable to apply
     * @return the post applied drop connect
     */
    public static INDArray applyDropConnect(Layer layer,String variable) {
        return layer.getParam(variable).mul(Nd4j.getDistributions().createBinomial(1,layer.conf().getLayer().getDropOut()).sample(layer.getParam(variable).shape()));
    }

    /**
     * Apply dropout to the given input
     * and return the drop out mask used
     * @param input the input to do drop out on
     * @param dropout the drop out probability
     */
    public static void applyDropout(INDArray input,double dropout) {
        Nd4j.getExecutioner().exec(new DropOutInverted(input, dropout));
    }


}

@@ -112,16 +112,72 @@
 DArray;%0A
+import org.nd4j.linalg.api.ops.impl.transforms.DropOut;%0A
 import o
@@ -643,22 +643,33 @@
         
-return
+INDArray result =
  layer.g
@@ -690,20 +690,31 @@
 le).
-mul(
+dup();%0A        
 Nd4j.get
 Dist
@@ -713,41 +713,55 @@
 .get
-Distrib
+Exec
 ution
-s().createBinomial(1,
+er().exec(new DropOut(result, result, 
 laye
@@ -797,50 +797,32 @@
 t())
-.sample(layer.getParam(variable).shape()))
+);%0A        return result
 ;%0A  

Switch dropconnect to native op