<s> import itertools <EOL> import numpy as np <EOL> import deeppy as dp <EOL> import deeppy . expr as ex <EOL> from deeppy . misc . test import ( eps , BPropableSource , approx_fprime , gradclose , <EOL> graph_funs ) <EOL> shapes = [ ( <NUM_LIT:1> , <NUM_LIT:4> ) , ( <NUM_LIT:1> , <NUM_LIT:7> ) , ( <NUM_LIT:2> , <NUM_LIT:6> ) , ( <NUM_LIT:3> , <NUM_LIT:3> ) , ( <NUM_LIT:3> , <NUM_LIT:4> ) , ( <NUM_LIT:5> , <NUM_LIT:1> ) ] <EOL> def test_activations ( ) : <EOL> ops = [ <EOL> ex . nnet . LeakyReLU , ex . nnet . ReLU , ex . nnet . Sigmoid , ex . nnet . Softmax , <EOL> ex . nnet . Softplus , <EOL> ] <EOL> confs = itertools . product ( shapes , ops ) <EOL> for shape , op in confs : <EOL> print ( '<STR_LIT>' % ( op . __name__ . ljust ( <NUM_LIT:20> ) , shape ) ) <EOL> src_array = np . random . normal ( size = shape ) . astype ( dp . float_ ) <EOL> if op is ex . nnet . LeakyReLU : <EOL> src_array [ np . fabs ( src_array ) < eps ] = eps <EOL> if op is ex . nnet . Softmax : <EOL> src_array *= <NUM_LIT:100> <EOL> src = BPropableSource ( src_array ) <EOL> sink = op ( ) ( src ) <EOL> f , f_grad = graph_funs ( src , sink ) <EOL> g_approx = approx_fprime ( src_array , f ) <EOL> g_true = f_grad ( src_array ) <EOL> assert gradclose ( g_true , g_approx ) </s>
