<s> from collections import OrderedDict <EOL> import theano <EOL> from numpy . testing import assert_allclose <EOL> from theano import tensor <EOL> from blocks . algorithms import BasicMomentum <EOL> from blocks_extras . algorithms import BasicNesterovMomentum , NesterovMomentum <EOL> from blocks . utils import shared_floatx <EOL> def test_basic_nesterov_momentum ( ) : <EOL> a = shared_floatx ( [ <NUM_LIT:3> , <NUM_LIT:4> ] ) <EOL> cost = ( a ** <NUM_LIT:2> ) . sum ( ) <EOL> steps , updates = BasicNesterovMomentum ( <NUM_LIT:0.5> ) . compute_steps ( <EOL> OrderedDict ( [ ( a , tensor . grad ( cost , a ) ) ] ) ) <EOL> f = theano . function ( [ ] , [ steps [ a ] ] , updates = updates ) <EOL> steps_classic , updates_classic = BasicMomentum ( <NUM_LIT:0.5> ) . compute_steps ( <EOL> OrderedDict ( [ ( a , tensor . grad ( cost , a ) ) ] ) ) <EOL> f_classic = theano . function ( [ ] , [ steps_classic [ a ] ] , <EOL> updates = updates_classic ) <EOL> f_classic ( ) <EOL> assert_allclose ( f ( ) [ <NUM_LIT:0> ] , f_classic ( ) [ <NUM_LIT:0> ] ) <EOL> assert_allclose ( f ( ) [ <NUM_LIT:0> ] , f_classic ( ) [ <NUM_LIT:0> ] ) <EOL> assert_allclose ( f ( ) [ <NUM_LIT:0> ] , f_classic ( ) [ <NUM_LIT:0> ] ) <EOL> def test_nesterov_momentum ( ) : <EOL> a = shared_floatx ( [ <NUM_LIT:3> , <NUM_LIT:4> ] ) <EOL> cost = ( a ** <NUM_LIT:2> ) . sum ( ) <EOL> steps , updates = NesterovMomentum ( <NUM_LIT:0.1> , <NUM_LIT:0.5> ) . compute_steps ( <EOL> OrderedDict ( [ ( a , tensor . grad ( cost , a ) ) ] ) ) <EOL> f = theano . function ( [ ] , [ steps [ a ] ] , updates = updates ) <EOL> assert_allclose ( f ( ) [ <NUM_LIT:0> ] , [ <NUM_LIT> , <NUM_LIT> ] ) <EOL> assert_allclose ( f ( ) [ <NUM_LIT:0> ] , [ <NUM_LIT> , <NUM_LIT> ] ) <EOL> assert_allclose ( f ( ) [ <NUM_LIT:0> ] , [ <NUM_LIT> , <NUM_LIT> ] ) </s>
