# Path: util.py
# def getopt(opt, field_name, default_value):
#     return opt.get(field_name, default_value)
# 
# def zeros(n=None):
#     if not n:
#         return []
#     else:
#         return [0.0] * int(n)


from util import getopt, zeros
from random import random
        self.out_depth = opt['in_depth']
        self.layer_type = 'dropout'
        self.drop_prob = getopt(opt, 'drop_prob', 0.5)
        self.dropped = zeros(self.out_sx * self.out_sy * self.out_depth)

    def forward(self, V, is_training=False):
        self.in_act = V
        V2 = V.clone()
        N = len(V.w)

        if is_training: 
            # do dropout
            for i in xrange(N):
                if random() < self.drop_prob: # drop
                    V2.w[i] = 0.0 
                    self.dropped[i] = True
                else:
                    self.dropped[i] = False
        else: 
            # scale the activations during prediction
            for i in xrange(N):
                V2.w[i] *= self.drop_prob

        self.out_act = V2
        return self.out_act

    def backward(self):
        V = self.in_act
        chain_grad = self.out_act
        N = len(V.w)

# Path: util.py
# def getopt(opt, field_name, default_value):
#     return opt.get(field_name, default_value)
# 
# def zeros(n=None):
#     if not n:
#         return []
#     else:
#         return [0.0] * int(n)


# Path: layers/dropout.py
from util import getopt, zeros
from random import random

        self.out_depth = opt['in_depth']
        self.layer_type = 'dropout'
        self.drop_prob = getopt(opt, 'drop_prob', 0.5)
        self.dropped = zeros(self.out_sx * self.out_sy * self.out_depth)

    def forward(self, V, is_training=False):
        self.in_act = V
        V2 = V.clone()
        N = len(V.w)

        if is_training: 
            # do dropout
            for i in xrange(N):
                if random() < self.drop_prob: # drop
                    V2.w[i] = 0.0 
                    self.dropped[i] = True
                else:
                    self.dropped[i] = False
        else: 
            # scale the activations during prediction
            for i in xrange(N):
                V2.w[i] *= self.drop_prob

        self.out_act = V2
        return self.out_act

    def backward(self):
        V = self.in_act
        chain_grad = self.out_act
        N = len(V.w)

        V.dw = zeros(N) # zero out gradient wrt data