<s> """<STR_LIT>""" <EOL> import copy <EOL> import numpy <EOL> import theano <EOL> from blocks . initialization import NdarrayInitialization , Orthogonal <EOL> class GlorotBengio ( NdarrayInitialization ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , scale = <NUM_LIT:1> , normal = False ) : <EOL> self . _scale = float ( scale ) <EOL> self . _normal = normal <EOL> def generate ( self , rng , shape ) : <EOL> w = numpy . sqrt ( self . _scale / shape [ - <NUM_LIT:1> ] ) <EOL> if self . _normal : <EOL> m = rng . normal ( <NUM_LIT:0.> , w , size = shape ) <EOL> else : <EOL> m = rng . uniform ( - w , w , size = shape ) <EOL> return m . astype ( theano . config . floatX ) <EOL> class OrthogonalGlorot ( GlorotBengio ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( OrthogonalGlorot , self ) . __init__ ( * args , ** kwargs ) <EOL> self . orth = Orthogonal ( ) <EOL> def generate ( self , rng , shape ) : <EOL> if len ( shape ) == <NUM_LIT:1> : <EOL> return super ( OrthogonalGlorot , self ) . generate ( rng , shape ) <EOL> N = shape [ <NUM_LIT:0> ] <EOL> M = shape [ <NUM_LIT:1> ] // N <EOL> if M > <NUM_LIT:1> and len ( shape ) == <NUM_LIT:2> and shape [ <NUM_LIT:1> ] == M * N : <EOL> res = [ self . orth . generate ( rng , ( N , N ) ) for i in range ( M ) ] <EOL> return numpy . concatenate ( res , axis = - <NUM_LIT:1> ) <EOL> return self . orth . generate ( rng , shape ) </s>
