<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> from theano . compat import OrderedDict <EOL> from theano import function <EOL> from pylearn2 . models . model import Model <EOL> from pylearn2 . model_extensions . norm_constraint import ConstrainFilterMaxNorm <EOL> from pylearn2 . model_extensions . norm_constraint import MaxL2FilterNorm <EOL> from pylearn2 . utils import sharedX <EOL> class ModelWithW ( Model ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , W ) : <EOL> self . W = W <EOL> super ( ModelWithW , self ) . __init__ ( ) <EOL> def test_max_l2_filter_norm ( ) : <EOL> """<STR_LIT>""" <EOL> limit = <NUM_LIT:1.> <EOL> ext = MaxL2FilterNorm ( limit ) <EOL> W = np . zeros ( ( <NUM_LIT:2> , <NUM_LIT:4> ) ) <EOL> W [ <NUM_LIT:0> , <NUM_LIT:1> ] = <NUM_LIT> <EOL> W [ <NUM_LIT:0> , <NUM_LIT:2> ] = <NUM_LIT:1.> <EOL> W [ <NUM_LIT:0> , <NUM_LIT:3> ] = <NUM_LIT> <EOL> W = sharedX ( W / <NUM_LIT> ) <EOL> model = ModelWithW ( W ) <EOL> model . extensions . append ( ext ) <EOL> updates = OrderedDict ( ) <EOL> updates [ W ] = W * <NUM_LIT> <EOL> model . modify_updates ( updates ) <EOL> f = function ( [ ] , updates = updates ) <EOL> f ( ) <EOL> W = W . get_value ( ) <EOL> assert W . shape == ( <NUM_LIT:2> , <NUM_LIT:4> ) <EOL> assert np . abs ( W [ <NUM_LIT:1> , : ] ) . max ( ) == <NUM_LIT:0> <EOL> assert W [ <NUM_LIT:0> , <NUM_LIT:0> ] == <NUM_LIT:0.> <EOL> assert W [ <NUM_LIT:0> , <NUM_LIT:1> ] == <NUM_LIT:0.5> <EOL> assert W [ <NUM_LIT:0> , <NUM_LIT:2> ] == <NUM_LIT:1.> <EOL> assert W [ <NUM_LIT:0> , <NUM_LIT:3> ] == <NUM_LIT:1.> , W [ <NUM_LIT:0> , <NUM_LIT:3> ] <EOL> def test_constrain_filter_max_norm ( ) : <EOL> """<STR_LIT>""" <EOL> limit = <NUM_LIT:1.> <EOL> ext = ConstrainFilterMaxNorm ( limit ) <EOL> W = np . zeros ( ( <NUM_LIT:2> , <NUM_LIT:4> ) ) <EOL> W [ <NUM_LIT:0> , <NUM_LIT:1> ] = <NUM_LIT> <EOL> W [ <NUM_LIT:0> , <NUM_LIT:2> ] = <NUM_LIT:1.> <EOL> W [ <NUM_LIT:0> , <NUM_LIT:3> ] = <NUM_LIT> <EOL> W = sharedX ( W / <NUM_LIT> ) <EOL> model = ModelWithW ( W ) <EOL> model . extensions . append ( ext ) <EOL> updates = OrderedDict ( ) <EOL> updates [ W ] = W * <NUM_LIT> <EOL> model . modify_updates ( updates ) <EOL> f = function ( [ ] , updates = updates ) <EOL> f ( ) <EOL> W = W . get_value ( ) <EOL> assert W . shape == ( <NUM_LIT:2> , <NUM_LIT:4> ) <EOL> assert np . abs ( W [ <NUM_LIT:1> , : ] ) . max ( ) == <NUM_LIT:0> <EOL> assert W [ <NUM_LIT:0> , <NUM_LIT:0> ] == <NUM_LIT:0.> <EOL> assert W [ <NUM_LIT:0> , <NUM_LIT:1> ] == <NUM_LIT:0.5> <EOL> assert W [ <NUM_LIT:0> , <NUM_LIT:2> ] == <NUM_LIT:1.> <EOL> assert W [ <NUM_LIT:0> , <NUM_LIT:3> ] == <NUM_LIT:1.> , W [ <NUM_LIT:0> , <NUM_LIT:3> ] </s>
