#NEWLINE# def test_momentum_epoch_xfer( ) : #NEWLINE# #INDENT# dim = 3 #NEWLINE# m = 10 #NEWLINE# rng = np . random . RandomState ( [ 25 , 9 , 2012 ] ) #NEWLINE# X = rng . randn ( m , dim ) #NEWLINE# dataset = DenseDesignMatrix ( X = X ) #NEWLINE# m = 15 #NEWLINE# X = rng . randn ( m , dim ) #NEWLINE# monitoring_dataset = DenseDesignMatrix ( X = X ) #NEWLINE# model = SoftmaxModel ( dim ) #NEWLINE# learning_rate = 0.1 #NEWLINE# batch_size = 5 #NEWLINE# epoch_num = 6 #NEWLINE# termination_criterion = EpochCounter ( epoch_num ) #NEWLINE# cost = DummyCost ( ) #NEWLINE# algorithm = SGD ( learning_rate , cost , batch_size = batch_size , monitoring_batches = 3 , monitoring_dataset = monitoring_dataset , termination_criterion = termination_criterion , update_callbacks = None , set_batch_size = False , learning_rule = Momentum ( 0.4 ) ) #NEWLINE# start = 1 #NEWLINE# saturate = 11 #NEWLINE# final_momentum = 0.9 #NEWLINE# momentum_adjustor = MomentumAdjustor ( final_momentum = final_momentum , start = start , saturate = saturate ) #NEWLINE# train = Train ( dataset , model , algorithm , save_path = None , save_freq = 0 , extensions = [ momentum_adjustor ] ) #NEWLINE# train . main_loop ( ) #NEWLINE# mm = model . monitor . channels [ 'momentum' ] #NEWLINE# final_momentum_init = epoch_num . val_record [ ( - 1 ) ] #NEWLINE# algorithm2 = SGD ( learning_rate , cost , batch_size = batch_size , monitoring_batches = 3 , monitoring_dataset = monitoring_dataset , termination_criterion = EpochCounter ( ( epoch_num + 1 ) , new_epochs = False ) , update_callbacks = None , set_batch_size = False , learning_rule = Momentum ( 0.4 ) ) #NEWLINE# model_xfer = push_monitor ( name = 'old_monitor' , transfer_experience = True , model = model ) #NEWLINE# momentum_adjustor2 = MomentumAdjustor ( final_momentum = final_momentum , start = start , saturate = saturate ) #NEWLINE# train2 = Train ( dataset , model_xfer , algorithm2 , save_path = None , save_freq = 0 , extensions = [ momentum_adjustor2 ] ) #NEWLINE# train2 . main_loop ( ) #NEWLINE# assert np . allclose ( model . monitor . channels [ 'momentum' ] . val_record [ 0 ] , final_momentum_init )