#NEWLINE# def test_latent_node_boxes_standard_latent( ) : #NEWLINE# #INDENT# ( X , Y ) = make_simple_2x2 ( seed = 1 , n_samples = 40 ) #NEWLINE# latent_crf = LatentNodeCRF ( n_labels = 2 , n_hidden_states = 2 , n_features = 1 ) #NEWLINE# one_slack = OneSlackSSVM ( latent_crf ) #NEWLINE# n_slack = NSlackSSVM ( latent_crf ) #NEWLINE# subgradient = SubgradientSSVM ( latent_crf , max_iter = 100 ) #NEWLINE# for base_svm in [ one_slack , n_slack , subgradient ] : #NEWLINE# #INDENT# base_svm . C = 10 #NEWLINE# latent_svm = LatentSSVM ( base_svm , latent_iter = 10 ) #NEWLINE# G = [ make_grid_edges ( x ) for x in X ] #NEWLINE# edges = make_edges_2x2 ( ) #NEWLINE# G = [ np . vstack ( [ make_grid_edges ( x ) , edges ] ) for x in X ] #NEWLINE# X_flat = [ x . reshape ( ( - 1 ) , 1 ) for x in X ] #NEWLINE# Y_flat = [ y . ravel ( ) for y in Y ] #NEWLINE# X_ = list ( zip ( X_flat , G , [ ( 2 * 2 ) for x in X_flat ] ) ) #NEWLINE# latent_svm . fit ( X_ [ : 20 ] , Y_flat [ : 20 ] ) #NEWLINE# assert_array_equal ( latent_svm . predict ( X_ [ : 20 ] ) , Y_flat [ : 20 ] ) #NEWLINE# assert_equal ( latent_svm . score ( X_ [ : 20 ] , Y_flat [ : 20 ] ) , 1 ) #NEWLINE# assert_true ( ( 0.98 < latent_svm . score ( X_ [ 20 : ] , Y_flat [ 20 : ] ) < 1 ) )