#NEWLINE# def test_epoch_counter( ) : #NEWLINE# #INDENT# '\n    Test epoch counter with max_epochs={True,False}\n    ' #NEWLINE# def produce_train_obj( new_epochs , max_epochs , model = None ) : #NEWLINE# #INDENT# if ( model is None ) : #NEWLINE# #INDENT# model = MLP ( layers = [ Softmax ( layer_name = 'y' , n_classes = 2 , irange = 0.0 ) ] , nvis = 3 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# model = push_monitor ( model , 'old_monitor' , transfer_experience = True ) #NEWLINE# #UNINDENT# dataset = DenseDesignMatrix ( X = np . random . normal ( size = ( 6 , 3 ) ) , y = np . random . normal ( size = ( 6 , 2 ) ) ) #NEWLINE# epoch_counter = EpochCounter ( max_epochs = max_epochs , new_epochs = new_epochs ) #NEWLINE# algorithm = SGD ( batch_size = 2 , learning_rate = 0.1 , termination_criterion = epoch_counter ) #NEWLINE# return Train ( dataset = dataset , model = model , algorithm = algorithm ) #NEWLINE# #UNINDENT# def test_epochs( epochs_seen , n ) : #NEWLINE# #INDENT# assert ( epochs_seen == n ) , ( '%d epochs seen and should be %d' % ( epochs_seen , n ) ) #NEWLINE# #UNINDENT# train_obj = produce_train_obj ( new_epochs = True , max_epochs = 5 ) #NEWLINE# train_obj . main_loop ( ) #NEWLINE# test_epochs ( train_obj . model . monitor . get_epochs_seen ( ) , 5 ) #NEWLINE# train_obj = produce_train_obj ( new_epochs = True , max_epochs = 5 , model = train_obj . model ) #NEWLINE# train_obj . main_loop ( ) #NEWLINE# test_epochs ( train_obj . model . monitor . get_epochs_seen ( ) , ( 2 * 5 ) ) #NEWLINE# train_obj = produce_train_obj ( new_epochs = False , max_epochs = 5 ) #NEWLINE# train_obj . main_loop ( ) #NEWLINE# test_epochs ( train_obj . model . monitor . get_epochs_seen ( ) , 5 ) #NEWLINE# train_obj = produce_train_obj ( new_epochs = False , max_epochs = 5 , model = train_obj . model ) #NEWLINE# train_obj . main_loop ( ) #NEWLINE# test_epochs ( train_obj . model . monitor . get_epochs_seen ( ) , 5 ) #NEWLINE# train_obj = produce_train_obj ( new_epochs = True , max_epochs = 0 ) #NEWLINE# before_train = train_obj . model . get_weights ( ) #NEWLINE# train_obj . main_loop ( ) #NEWLINE# after_train = train_obj . model . get_weights ( ) #NEWLINE# test_epochs ( train_obj . model . monitor . get_epochs_seen ( ) , 0 ) #NEWLINE# assert np . all ( ( before_train == after_train ) ) #NEWLINE# train_obj = produce_train_obj ( new_epochs = True , max_epochs = 0 , model = train_obj . model ) #NEWLINE# before_train = train_obj . model . get_weights ( ) #NEWLINE# train_obj . main_loop ( ) #NEWLINE# after_train = train_obj . model . get_weights ( ) #NEWLINE# test_epochs ( train_obj . model . monitor . get_epochs_seen ( ) , 0 ) #NEWLINE# assert np . all ( ( before_train == after_train ) ) #NEWLINE# train_obj = produce_train_obj ( new_epochs = False , max_epochs = 0 , model = train_obj . model ) #NEWLINE# before_train = train_obj . model . get_weights ( ) #NEWLINE# train_obj . main_loop ( ) #NEWLINE# after_train = train_obj . model . get_weights ( ) #NEWLINE# test_epochs ( train_obj . model . monitor . get_epochs_seen ( ) , 0 ) #NEWLINE# assert np . all ( ( before_train == before_train ) )