<s> import numpy as np <EOL> import numpy . random as npr <EOL> from . import Differentiable , EPSILON <EOL> class Dropout ( Differentiable ) : <EOL> __slots__ = [ '<STR_LIT:X>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self , X , drop_prob = <NUM_LIT:0.5> , rng = None , batcher = None ) : <EOL> if batcher is not None : <EOL> super ( Dropout , self ) . __init__ ( [ X , batcher ] ) <EOL> batcher . add_dropout_node ( self ) <EOL> else : <EOL> super ( Dropout , self ) . __init__ ( [ X ] ) <EOL> self . X = X <EOL> self . drop_prob = drop_prob <EOL> if rng is None : <EOL> self . _rng = npr . RandomState ( ) <EOL> else : <EOL> self . _rng = rng <EOL> self . _enhancement = ( <NUM_LIT:1.0> + EPSILON ) / ( <NUM_LIT:1.0> - self . drop_prob + EPSILON ) <EOL> self . draw_new_mask ( ) <EOL> def draw_new_mask ( self ) : <EOL> self . _mask = self . _enhancement * ( self . _rng . rand ( * self . X . shape ) <EOL> > self . drop_prob ) <EOL> self . _clear_value_cache ( ) <EOL> def reinstate_units ( self ) : <EOL> self . _mask = np . ones ( self . X . shape ) <EOL> self . _clear_value_cache ( ) <EOL> def _compute_value ( self ) : <EOL> return self . _mask * self . X . value <EOL> def _local_grad ( self , parent , d_out_d_self ) : <EOL> return d_out_d_self * self . _mask </s>
