#NEWLINE# def test_determinism( ) : #NEWLINE# #INDENT# for mode in _iteration_schemes : #NEWLINE# #INDENT# dim = 1 #NEWLINE# batch_size = 3 #NEWLINE# num_batches = 5 #NEWLINE# m = ( num_batches * batch_size ) #NEWLINE# dataset = ArangeDataset ( m ) #NEWLINE# model = SoftmaxModel ( dim ) #NEWLINE# learning_rate = 0.001 #NEWLINE# batch_size = 5 #NEWLINE# visited = [ ( [ ( - 1 ) ] * m ) ] #NEWLINE# def visit( X ) : #NEWLINE# #INDENT# mx = max ( visited [ 0 ] ) #NEWLINE# counter = ( mx + 1 ) #NEWLINE# for i in X [ : , 0 ] : #NEWLINE# #INDENT# i = int ( i ) #NEWLINE# assert ( visited [ 0 ] [ i ] == ( - 1 ) ) #NEWLINE# visited [ 0 ] [ i ] = counter #NEWLINE# counter += 1 #NEWLINE# #UNINDENT# #UNINDENT# data_specs = ( model . get_input_space ( ) , model . get_input_source ( ) ) #NEWLINE# cost = CallbackCost ( visit , data_specs ) #NEWLINE# termination_criterion = EpochCounter ( 5 ) #NEWLINE# def run_algorithm( ) : #NEWLINE# #INDENT# unsupported_modes = [ 'random_slice' , 'random_uniform' , 'even_sequences' ] #NEWLINE# algorithm = SGD ( learning_rate , cost , batch_size = batch_size , train_iteration_mode = mode , monitoring_dataset = None , termination_criterion = termination_criterion , update_callbacks = None , set_batch_size = False ) #NEWLINE# algorithm . setup ( dataset = dataset , model = model ) #NEWLINE# raised = False #NEWLINE# try : #NEWLINE# #INDENT# algorithm . train ( dataset ) #NEWLINE# #UNINDENT# except ValueError : #NEWLINE# #INDENT# assert ( mode in unsupported_modes ) #NEWLINE# raised = True #NEWLINE# #UNINDENT# if ( mode in unsupported_modes ) : #NEWLINE# #INDENT# assert raised #NEWLINE# return True #NEWLINE# #UNINDENT# return False #NEWLINE# #UNINDENT# if run_algorithm ( ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# visited . insert ( 0 , ( [ ( - 1 ) ] * m ) ) #NEWLINE# del model . monitor #NEWLINE# run_algorithm ( ) #NEWLINE# for v in visited : #NEWLINE# #INDENT# assert ( len ( v ) == m ) #NEWLINE# for elem in range ( m ) : #NEWLINE# #INDENT# assert ( elem in v ) #NEWLINE# #UNINDENT# #UNINDENT# assert ( len ( model ) == 2 ) #NEWLINE# print ( visited [ 0 ] ) #NEWLINE# print ( visited [ 1 ] ) #NEWLINE# assert np . all ( ( np . asarray ( visited [ 0 ] ) == np . asarray ( visited [ 1 ] ) ) )