Skip to content

Commit

Permalink
Fixed and added Inverted Dropout #2
Browse files Browse the repository at this point in the history
  • Loading branch information
rrmina committed Apr 9, 2019
1 parent f954294 commit d75b299
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions eureka/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def backward(self, dh):

# Dropout Layer
class Dropout(BaseLayer):
def __init__(self, drop_prob):
def __init__(self, drop_prob, inverted = True):
super(Dropout, self).__init__()
# Initialize layer type
self.layer_type = "nn.Dropout"
Expand All @@ -84,15 +84,24 @@ def __init__(self, drop_prob):
# Initialize mask
self.mask = None

# Inverted
self.inverted = inverted

def forward(self, x):
# Generate mask
self.mask = np.random.binomial(1, self.keep_prob, size=x.shape)

# Apply mask
return x * self.mask
if (self.inverted):
return x * self.mask / self.keep_prob
else:
return x * self.mask

def backward(self, da):
return da * self.mask
if (self.inverted):
return da * self.mask / self.keep_prob
else:
return da * self.mask

# Normalization Layers
class BatchNorm1d(BaseLayer):
Expand Down

0 comments on commit d75b299

Please sign in to comment.