<s> from __future__ import absolute_import <EOL> from . import backend as K <EOL> class Constraint ( object ) : <EOL> def __call__ ( self , p ) : <EOL> return p <EOL> def get_config ( self ) : <EOL> return { '<STR_LIT:name>' : self . __class__ . __name__ } <EOL> class MaxNorm ( Constraint ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , m = <NUM_LIT:2> , axis = <NUM_LIT:0> ) : <EOL> self . m = m <EOL> self . axis = axis <EOL> def __call__ ( self , p ) : <EOL> norms = K . sqrt ( K . sum ( K . square ( p ) , axis = self . axis , keepdims = True ) ) <EOL> desired = K . clip ( norms , <NUM_LIT:0> , self . m ) <EOL> p = p * ( desired / ( K . epsilon ( ) + norms ) ) <EOL> return p <EOL> def get_config ( self ) : <EOL> return { '<STR_LIT:name>' : self . __class__ . __name__ , <EOL> '<STR_LIT:m>' : self . m , <EOL> '<STR_LIT>' : self . axis } <EOL> class NonNeg ( Constraint ) : <EOL> '''<STR_LIT>''' <EOL> def __call__ ( self , p ) : <EOL> p *= K . cast ( p >= <NUM_LIT:0.> , K . floatx ( ) ) <EOL> return p <EOL> class UnitNorm ( Constraint ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , axis = <NUM_LIT:0> ) : <EOL> self . axis = axis <EOL> def __call__ ( self , p ) : <EOL> return p / ( K . epsilon ( ) + K . sqrt ( K . sum ( K . square ( p ) , axis = self . axis , keepdims = True ) ) ) <EOL> def get_config ( self ) : <EOL> return { '<STR_LIT:name>' : self . __class__ . __name__ , <EOL> '<STR_LIT>' : self . axis } <EOL> maxnorm = MaxNorm <EOL> nonneg = NonNeg <EOL> unitnorm = UnitNorm <EOL> from . utils . generic_utils import get_from_module <EOL> def get ( identifier , kwargs = None ) : <EOL> return get_from_module ( identifier , globals ( ) , '<STR_LIT>' , <EOL> instantiate = True , kwargs = kwargs ) </s>
