<s> import pytest <EOL> def test_initializer_sample ( ) : <EOL> from lasagne . init import Initializer <EOL> with pytest . raises ( NotImplementedError ) : <EOL> Initializer ( ) . sample ( ( <NUM_LIT:100> , <NUM_LIT:100> ) ) <EOL> def test_shape ( ) : <EOL> from lasagne . init import Initializer <EOL> for klass in Initializer . __subclasses__ ( ) : <EOL> if len ( klass . __subclasses__ ( ) ) : <EOL> for sub_klass in klass . __subclasses__ ( ) : <EOL> assert sub_klass ( ) . sample ( ( <NUM_LIT:12> , <NUM_LIT> ) ) . shape == ( <NUM_LIT:12> , <NUM_LIT> ) <EOL> else : <EOL> assert klass ( ) . sample ( ( <NUM_LIT:12> , <NUM_LIT> ) ) . shape == ( <NUM_LIT:12> , <NUM_LIT> ) <EOL> def test_specified_rng ( ) : <EOL> from lasagne . random import get_rng , set_rng <EOL> from lasagne . init import ( Normal , Uniform , GlorotNormal , <EOL> GlorotUniform , Sparse , Orthogonal ) <EOL> from numpy . random import RandomState <EOL> from numpy import allclose <EOL> seed = <NUM_LIT> <EOL> rng = get_rng ( ) <EOL> for init_class in [ Normal , Uniform , GlorotNormal , <EOL> GlorotUniform , Sparse , Orthogonal ] : <EOL> set_rng ( RandomState ( seed ) ) <EOL> sample1 = init_class ( ) . sample ( ( <NUM_LIT:100> , <NUM_LIT:100> ) ) <EOL> set_rng ( RandomState ( seed ) ) <EOL> sample2 = init_class ( ) . sample ( ( <NUM_LIT:100> , <NUM_LIT:100> ) ) <EOL> set_rng ( rng ) <EOL> assert allclose ( sample1 , sample2 ) , ( "<STR_LIT>" <EOL> . format ( init_class . __name__ ) ) <EOL> def test_normal ( ) : <EOL> from lasagne . init import Normal <EOL> sample = Normal ( ) . sample ( ( <NUM_LIT:100> , <NUM_LIT:200> ) ) <EOL> assert - <NUM_LIT> < sample . mean ( ) < <NUM_LIT> <EOL> assert <NUM_LIT> < sample . std ( ) < <NUM_LIT> <EOL> def test_uniform_range_as_number ( ) : <EOL> from lasagne . init import Uniform <EOL> sample = Uniform ( <NUM_LIT:1.0> ) . sample ( ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> assert sample . shape == ( <NUM_LIT> , <NUM_LIT> ) <EOL> assert - <NUM_LIT:1.0> <= sample . min ( ) < - <NUM_LIT> <EOL> assert <NUM_LIT> < sample . max ( ) <= <NUM_LIT:1.0> <EOL> def test_uniform_range_as_range ( ) : <EOL> from lasagne . init import Uniform <EOL> sample = Uniform ( ( <NUM_LIT:0.0> , <NUM_LIT:1.0> ) ) . sample ( ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> assert sample . shape == ( <NUM_LIT> , <NUM_LIT> ) <EOL> assert <NUM_LIT:0.0> <= sample . min ( ) < <NUM_LIT:0.1> <EOL> assert <NUM_LIT> < sample . max ( ) <= <NUM_LIT:1.0> <EOL> def test_uniform_mean_std ( ) : <EOL> from lasagne . init import Uniform <EOL> sample = Uniform ( std = <NUM_LIT:1.0> , mean = <NUM_LIT> ) . sample ( ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> assert <NUM_LIT> < sample . mean ( ) < <NUM_LIT> <EOL> assert <NUM_LIT> < sample . std ( ) < <NUM_LIT> <EOL> def test_glorot_normal ( ) : <EOL> from lasagne . init import GlorotNormal <EOL> sample = GlorotNormal ( ) . sample ( ( <NUM_LIT:100> , <NUM_LIT:100> ) ) <EOL> assert - <NUM_LIT> < sample . mean ( ) < <NUM_LIT> <EOL> assert <NUM_LIT> < sample . std ( ) < <NUM_LIT> <EOL> def test_glorot_1d_not_supported ( ) : <EOL> from lasagne . init import GlorotNormal <EOL> with pytest . raises ( RuntimeError ) : <EOL> GlorotNormal ( ) . sample ( ( <NUM_LIT:100> , ) ) <EOL> def test_glorot_normal_receptive_field ( ) : <EOL> from lasagne . init import GlorotNormal <EOL> sample = GlorotNormal ( ) . sample ( ( <NUM_LIT:50> , <NUM_LIT:50> , <NUM_LIT:2> ) ) <EOL> assert - <NUM_LIT> < sample . mean ( ) < <NUM_LIT> <EOL> assert <NUM_LIT> < sample . std ( ) < <NUM_LIT> <EOL> def test_glorot_normal_gain ( ) : <EOL> from lasagne . init import GlorotNormal <EOL> sample = GlorotNormal ( gain = <NUM_LIT> ) . sample ( ( <NUM_LIT:100> , <NUM_LIT:100> ) ) <EOL> assert - <NUM_LIT:0.1> < sample . mean ( ) < <NUM_LIT:0.1> <EOL> assert <NUM_LIT> < sample . std ( ) < <NUM_LIT> <EOL> sample = GlorotNormal ( gain = '<STR_LIT:relu>' ) . sample ( ( <NUM_LIT:100> , <NUM_LIT:100> ) ) <EOL> assert - <NUM_LIT> < sample . mean ( ) < <NUM_LIT> <EOL> assert <NUM_LIT> < sample . std ( ) < <NUM_LIT> <EOL> def test_glorot_normal_c01b ( ) : <EOL> from lasagne . init import GlorotNormal <EOL> sample = GlorotNormal ( c01b = True ) . sample ( ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT> ) ) <EOL> assert - <NUM_LIT> < sample . mean ( ) < <NUM_LIT> <EOL> assert <NUM_LIT> < sample . std ( ) < <NUM_LIT> <EOL> def test_glorot_normal_c01b_4d_only ( ) : <EOL> from lasagne . init import GlorotNormal <EOL> with pytest . raises ( RuntimeError ) : <EOL> GlorotNormal ( c01b = True ) . sample ( ( <NUM_LIT:100> , ) ) <EOL> with pytest . raises ( RuntimeError ) : <EOL> GlorotNormal ( c01b = True ) . sample ( ( <NUM_LIT:100> , <NUM_LIT:100> ) ) <EOL> with pytest . raises ( RuntimeError ) : <EOL> GlorotNormal ( c01b = True ) . sample ( ( <NUM_LIT:100> , <NUM_LIT:100> , <NUM_LIT:100> ) ) <EOL> def test_glorot_uniform ( ) : <EOL> from lasagne . init import GlorotUniform <EOL> sample = GlorotUniform ( ) . sample ( ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> assert - <NUM_LIT:0.1> <= sample . min ( ) < - <NUM_LIT> <EOL> assert <NUM_LIT> < sample . max ( ) <= <NUM_LIT:0.1> <EOL> def test_glorot_uniform_receptive_field ( ) : <EOL> from lasagne . init import GlorotUniform <EOL> sample = GlorotUniform ( ) . sample ( ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:2> ) ) <EOL> assert - <NUM_LIT> <= sample . min ( ) < - <NUM_LIT> <EOL> assert <NUM_LIT> < sample . max ( ) <= <NUM_LIT> <EOL> def test_glorot_uniform_gain ( ) : <EOL> from lasagne . init import GlorotUniform <EOL> sample = GlorotUniform ( gain = <NUM_LIT> ) . sample ( ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> assert - <NUM_LIT:1.0> <= sample . min ( ) < - <NUM_LIT> <EOL> assert <NUM_LIT> < sample . max ( ) <= <NUM_LIT:1.0> <EOL> sample = GlorotUniform ( gain = '<STR_LIT:relu>' ) . sample ( ( <NUM_LIT:100> , <NUM_LIT:100> ) ) <EOL> assert - <NUM_LIT> < sample . mean ( ) < <NUM_LIT> <EOL> assert <NUM_LIT> < sample . std ( ) < <NUM_LIT> <EOL> def test_glorot_uniform_c01b ( ) : <EOL> from lasagne . init import GlorotUniform <EOL> sample = GlorotUniform ( c01b = True ) . sample ( ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT> ) ) <EOL> assert - <NUM_LIT:0.1> <= sample . min ( ) < - <NUM_LIT> <EOL> assert <NUM_LIT> < sample . max ( ) <= <NUM_LIT:0.1> <EOL> def test_glorot_uniform_c01b_4d_only ( ) : <EOL> from lasagne . init import GlorotUniform <EOL> with pytest . raises ( RuntimeError ) : <EOL> GlorotUniform ( c01b = True ) . sample ( ( <NUM_LIT:100> , ) ) <EOL> with pytest . raises ( RuntimeError ) : <EOL> GlorotUniform ( c01b = True ) . sample ( ( <NUM_LIT:100> , <NUM_LIT:100> ) ) <EOL> with pytest . raises ( RuntimeError ) : <EOL> GlorotUniform ( c01b = True ) . sample ( ( <NUM_LIT:100> , <NUM_LIT:100> , <NUM_LIT:100> ) ) <EOL> def test_he_normal ( ) : <EOL> from lasagne . init import HeNormal <EOL> sample = HeNormal ( ) . sample ( ( <NUM_LIT:100> , <NUM_LIT:100> ) ) <EOL> assert - <NUM_LIT> < sample . mean ( ) < <NUM_LIT> <EOL> assert <NUM_LIT> < sample . std ( ) < <NUM_LIT> <EOL> def test_he_1d_not_supported ( ) : <EOL> from lasagne . init import HeNormal <EOL> with pytest . raises ( RuntimeError ) : <EOL> HeNormal ( ) . sample ( ( <NUM_LIT:100> , ) ) <EOL> def test_he_normal_receptive_field ( ) : <EOL> from lasagne . init import HeNormal <EOL> sample = HeNormal ( ) . sample ( ( <NUM_LIT:50> , <NUM_LIT:50> , <NUM_LIT:2> ) ) <EOL> assert - <NUM_LIT> < sample . mean ( ) < <NUM_LIT> <EOL> assert <NUM_LIT> < sample . std ( ) < <NUM_LIT> <EOL> def test_he_normal_gain ( ) : <EOL> from lasagne . init import HeNormal <EOL> sample = HeNormal ( gain = <NUM_LIT> ) . sample ( ( <NUM_LIT:100> , <NUM_LIT:100> ) ) <EOL> assert - <NUM_LIT:0.1> < sample . mean ( ) < <NUM_LIT:0.1> <EOL> assert <NUM_LIT> < sample . std ( ) < <NUM_LIT> <EOL> sample = HeNormal ( gain = '<STR_LIT:relu>' ) . sample ( ( <NUM_LIT:200> , <NUM_LIT:50> ) ) <EOL> assert - <NUM_LIT:0.1> < sample . mean ( ) < <NUM_LIT:0.1> <EOL> assert <NUM_LIT> < sample . std ( ) < <NUM_LIT> <EOL> def test_he_normal_c01b ( ) : <EOL> from lasagne . init import HeNormal <EOL> sample = HeNormal ( c01b = True ) . sample ( ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT> ) ) <EOL> assert - <NUM_LIT> < sample . mean ( ) < <NUM_LIT> <EOL> assert <NUM_LIT> < sample . std ( ) < <NUM_LIT> <EOL> def test_he_normal_c01b_4d_only ( ) : <EOL> from lasagne . init import HeNormal <EOL> with pytest . raises ( RuntimeError ) : <EOL> HeNormal ( c01b = True ) . sample ( ( <NUM_LIT:100> , ) ) <EOL> with pytest . raises ( RuntimeError ) : <EOL> HeNormal ( c01b = True ) . sample ( ( <NUM_LIT:100> , <NUM_LIT:100> ) ) <EOL> with pytest . raises ( RuntimeError ) : <EOL> HeNormal ( c01b = True ) . sample ( ( <NUM_LIT:100> , <NUM_LIT:100> , <NUM_LIT:100> ) ) <EOL> def test_he_uniform ( ) : <EOL> from lasagne . init import HeUniform <EOL> sample = HeUniform ( ) . sample ( ( <NUM_LIT> , <NUM_LIT:200> ) ) <EOL> assert - <NUM_LIT:0.1> <= sample . min ( ) < - <NUM_LIT> <EOL> assert <NUM_LIT> < sample . max ( ) <= <NUM_LIT:0.1> <EOL> def test_he_uniform_receptive_field ( ) : <EOL> from lasagne . init import HeUniform <EOL> sample = HeUniform ( ) . sample ( ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT:2> ) ) <EOL> assert - <NUM_LIT> <= sample . min ( ) < - <NUM_LIT> <EOL> assert <NUM_LIT> < sample . max ( ) <= <NUM_LIT> <EOL> def test_he_uniform_gain ( ) : <EOL> from lasagne . init import HeUniform <EOL> sample = HeUniform ( gain = <NUM_LIT> ) . sample ( ( <NUM_LIT> , <NUM_LIT:200> ) ) <EOL> assert - <NUM_LIT:1.0> <= sample . min ( ) < - <NUM_LIT> <EOL> assert <NUM_LIT> < sample . max ( ) <= <NUM_LIT:1.0> <EOL> sample = HeUniform ( gain = '<STR_LIT:relu>' ) . sample ( ( <NUM_LIT:100> , <NUM_LIT:100> ) ) <EOL> assert - <NUM_LIT:0.1> < sample . mean ( ) < <NUM_LIT:0.1> <EOL> assert <NUM_LIT:0.1> < sample . std ( ) < <NUM_LIT> <EOL> def test_he_uniform_c01b ( ) : <EOL> from lasagne . init import HeUniform <EOL> sample = HeUniform ( c01b = True ) . sample ( ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT> ) ) <EOL> assert - <NUM_LIT:0.1> <= sample . min ( ) < - <NUM_LIT> <EOL> assert <NUM_LIT> < sample . max ( ) <= <NUM_LIT:0.1> <EOL> def test_he_uniform_c01b_4d_only ( ) : <EOL> from lasagne . init import HeUniform <EOL> with pytest . raises ( RuntimeError ) : <EOL> HeUniform ( c01b = True ) . sample ( ( <NUM_LIT:100> , ) ) <EOL> with pytest . raises ( RuntimeError ) : <EOL> HeUniform ( c01b = True ) . sample ( ( <NUM_LIT:100> , <NUM_LIT:100> ) ) <EOL> with pytest . raises ( RuntimeError ) : <EOL> HeUniform ( c01b = True ) . sample ( ( <NUM_LIT:100> , <NUM_LIT:100> , <NUM_LIT:100> ) ) <EOL> def test_constant ( ) : <EOL> from lasagne . init import Constant <EOL> sample = Constant ( <NUM_LIT:1.0> ) . sample ( ( <NUM_LIT:10> , <NUM_LIT:20> ) ) <EOL> assert ( sample == <NUM_LIT:1.0> ) . all ( ) <EOL> def test_sparse ( ) : <EOL> from lasagne . init import Sparse <EOL> sample = Sparse ( sparsity = <NUM_LIT:0.1> ) . sample ( ( <NUM_LIT:10> , <NUM_LIT:20> ) ) <EOL> assert ( sample != <NUM_LIT:0.0> ) . sum ( ) == ( <NUM_LIT:10> * <NUM_LIT:20> ) * <NUM_LIT:0.1> <EOL> def test_sparse_1d_not_supported ( ) : <EOL> from lasagne . init import Sparse <EOL> with pytest . raises ( RuntimeError ) : <EOL> Sparse ( ) . sample ( ( <NUM_LIT:100> , ) ) <EOL> def test_orthogonal ( ) : <EOL> import numpy as np <EOL> from lasagne . init import Orthogonal <EOL> sample = Orthogonal ( ) . sample ( ( <NUM_LIT:100> , <NUM_LIT:200> ) ) <EOL> assert np . allclose ( np . dot ( sample , sample . T ) , np . eye ( <NUM_LIT:100> ) , atol = <NUM_LIT> ) <EOL> sample = Orthogonal ( ) . sample ( ( <NUM_LIT:200> , <NUM_LIT:100> ) ) <EOL> assert np . allclose ( np . dot ( sample . T , sample ) , np . eye ( <NUM_LIT:100> ) , atol = <NUM_LIT> ) <EOL> def test_orthogonal_gain ( ) : <EOL> import numpy as np <EOL> from lasagne . init import Orthogonal <EOL> gain = <NUM_LIT:2> <EOL> sample = Orthogonal ( gain ) . sample ( ( <NUM_LIT:100> , <NUM_LIT:200> ) ) <EOL> assert np . allclose ( np . dot ( sample , sample . T ) , gain * gain * np . eye ( <NUM_LIT:100> ) , <EOL> atol = <NUM_LIT> ) <EOL> gain = np . sqrt ( <NUM_LIT:2> ) <EOL> sample = Orthogonal ( '<STR_LIT:relu>' ) . sample ( ( <NUM_LIT:100> , <NUM_LIT:200> ) ) <EOL> assert np . allclose ( np . dot ( sample , sample . T ) , gain * gain * np . eye ( <NUM_LIT:100> ) , <EOL> atol = <NUM_LIT> ) <EOL> def test_orthogonal_multi ( ) : <EOL> import numpy as np <EOL> from lasagne . init import Orthogonal <EOL> sample = Orthogonal ( ) . sample ( ( <NUM_LIT:100> , <NUM_LIT:50> , <NUM_LIT> ) ) <EOL> sample = sample . reshape ( <NUM_LIT:100> , <NUM_LIT:50> * <NUM_LIT> ) <EOL> assert np . allclose ( np . dot ( sample , sample . T ) , np . eye ( <NUM_LIT:100> ) , atol = <NUM_LIT> ) <EOL> def test_orthogonal_1d_not_supported ( ) : <EOL> from lasagne . init import Orthogonal <EOL> with pytest . raises ( RuntimeError ) : <EOL> Orthogonal ( ) . sample ( ( <NUM_LIT:100> , ) ) </s>
