<s> import numpy as np <EOL> import numpy . random as npr <EOL> import kayak <EOL> from . import * <EOL> def test_logsoftmax_values_1 ( ) : <EOL> npr . seed ( <NUM_LIT:1> ) <EOL> for ii in xrange ( NUM_TRIALS ) : <EOL> np_X = npr . randn ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> X = kayak . Parameter ( np_X ) <EOL> Y = kayak . LogSoftMax ( X ) <EOL> np_Y = np . exp ( np_X ) <EOL> np_Y = np_Y / np . sum ( np_Y , axis = <NUM_LIT:1> ) [ : , np . newaxis ] <EOL> np_Y = np . log ( np_Y ) <EOL> assert Y . shape == np_X . shape <EOL> assert np . all ( close_float ( Y . value , np_Y ) ) <EOL> def test_logsoftmax_values_2 ( ) : <EOL> npr . seed ( <NUM_LIT:2> ) <EOL> for ii in xrange ( NUM_TRIALS ) : <EOL> np_X = npr . randn ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> X = kayak . Parameter ( np_X ) <EOL> Y = kayak . LogSoftMax ( X , axis = <NUM_LIT:0> ) <EOL> np_Y = np . exp ( np_X ) <EOL> np_Y = np_Y / np . sum ( np_Y , axis = <NUM_LIT:0> ) [ np . newaxis , : ] <EOL> np_Y = np . log ( np_Y ) <EOL> assert Y . shape == np_X . shape <EOL> assert np . all ( close_float ( Y . value , np_Y ) ) <EOL> def test_logsoftmax_grad_1 ( ) : <EOL> npr . seed ( <NUM_LIT:3> ) <EOL> for ii in xrange ( NUM_TRIALS ) : <EOL> np_X = npr . randn ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> X = kayak . Parameter ( np_X ) <EOL> Y = kayak . LogSoftMax ( X ) <EOL> Z = kayak . MatSum ( Y ) <EOL> assert kayak . util . checkgrad ( X , Z ) < MAX_GRAD_DIFF <EOL> def test_logsoftmax_grad_2 ( ) : <EOL> npr . seed ( <NUM_LIT:4> ) <EOL> for ii in xrange ( NUM_TRIALS ) : <EOL> np_X = npr . randn ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> X = kayak . Parameter ( np_X ) <EOL> Y = kayak . LogSoftMax ( X , axis = <NUM_LIT:0> ) <EOL> Z = kayak . MatSum ( Y ) <EOL> assert kayak . util . checkgrad ( X , Z ) < MAX_GRAD_DIFF <EOL> def test_logsoftmax_grad_3 ( ) : <EOL> npr . seed ( <NUM_LIT:5> ) <EOL> for ii in xrange ( NUM_TRIALS ) : <EOL> np_X = npr . randn ( <NUM_LIT:5> , <NUM_LIT:6> ) <EOL> np_T = npr . randint ( <NUM_LIT:0> , <NUM_LIT:10> , np_X . shape ) <EOL> X = kayak . Parameter ( np_X ) <EOL> T = kayak . Targets ( np_T ) <EOL> Y = kayak . LogSoftMax ( X ) <EOL> Z = kayak . MatSum ( kayak . LogMultinomialLoss ( Y , T ) ) <EOL> assert kayak . util . checkgrad ( X , Z ) < MAX_GRAD_DIFF </s>
