<s> import pytest <EOL> import numpy as np <EOL> from keras import initializations <EOL> from keras import backend as K <EOL> SHAPE = ( <NUM_LIT:100> , <NUM_LIT:100> ) <EOL> def _runner ( init , shape , target_mean = None , target_std = None , <EOL> target_max = None , target_min = None ) : <EOL> variable = init ( shape ) <EOL> output = K . get_value ( variable ) <EOL> lim = <NUM_LIT> <EOL> if target_std is not None : <EOL> assert abs ( output . std ( ) - target_std ) < lim <EOL> if target_mean is not None : <EOL> assert abs ( output . mean ( ) - target_mean ) < lim <EOL> if target_max is not None : <EOL> assert abs ( output . max ( ) - target_max ) < lim <EOL> if target_min is not None : <EOL> assert abs ( output . min ( ) - target_min ) < lim <EOL> def test_uniform ( ) : <EOL> _runner ( initializations . uniform , SHAPE , target_mean = <NUM_LIT:0.> , <EOL> target_max = <NUM_LIT> , target_min = - <NUM_LIT> ) <EOL> def test_normal ( ) : <EOL> _runner ( initializations . normal , SHAPE , target_mean = <NUM_LIT:0.> , target_std = <NUM_LIT> ) <EOL> def test_lecun_uniform ( ) : <EOL> scale = np . sqrt ( <NUM_LIT> / SHAPE [ <NUM_LIT:0> ] ) <EOL> _runner ( initializations . lecun_uniform , SHAPE , <EOL> target_mean = <NUM_LIT:0.> , target_max = scale , target_min = - scale ) <EOL> def test_glorot_uniform ( ) : <EOL> scale = np . sqrt ( <NUM_LIT> / ( SHAPE [ <NUM_LIT:0> ] + SHAPE [ <NUM_LIT:1> ] ) ) <EOL> _runner ( initializations . glorot_uniform , SHAPE , target_mean = <NUM_LIT:0.> , <EOL> target_max = scale , target_min = - scale ) <EOL> def test_glorot_normal ( ) : <EOL> scale = np . sqrt ( <NUM_LIT> / ( SHAPE [ <NUM_LIT:0> ] + SHAPE [ <NUM_LIT:1> ] ) ) <EOL> _runner ( initializations . glorot_normal , SHAPE , <EOL> target_mean = <NUM_LIT:0.> , target_std = scale ) <EOL> def test_he_uniform ( ) : <EOL> scale = np . sqrt ( <NUM_LIT> / SHAPE [ <NUM_LIT:0> ] ) <EOL> _runner ( initializations . he_uniform , SHAPE , target_mean = <NUM_LIT:0.> , <EOL> target_max = scale , target_min = - scale ) <EOL> def test_he_normal ( ) : <EOL> scale = np . sqrt ( <NUM_LIT> / SHAPE [ <NUM_LIT:0> ] ) <EOL> _runner ( initializations . he_normal , SHAPE , <EOL> target_mean = <NUM_LIT:0.> , target_std = scale ) <EOL> def test_orthogonal ( ) : <EOL> _runner ( initializations . orthogonal , SHAPE , <EOL> target_mean = <NUM_LIT:0.> ) <EOL> def test_identity ( ) : <EOL> _runner ( initializations . identity , SHAPE , <EOL> target_mean = <NUM_LIT:1.> / SHAPE [ <NUM_LIT:0> ] , target_max = <NUM_LIT:1.> ) <EOL> def test_zero ( ) : <EOL> _runner ( initializations . zero , SHAPE , <EOL> target_mean = <NUM_LIT:0.> , target_max = <NUM_LIT:0.> ) <EOL> def test_one ( ) : <EOL> _runner ( initializations . one , SHAPE , <EOL> target_mean = <NUM_LIT:1.> , target_max = <NUM_LIT:1.> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> pytest . main ( [ __file__ ] ) </s>
