<s> """<STR_LIT>""" <EOL> import numpy as np <EOL> import matplotlib . pyplot as plt <EOL> from pystruct . models import GridCRF <EOL> import pystruct . learners as ssvm <EOL> from pystruct . datasets import generate_crosses_explicit <EOL> from pystruct . utils import expand_sym <EOL> X , Y = generate_crosses_explicit ( n_samples = <NUM_LIT:50> , noise = <NUM_LIT:10> ) <EOL> crf = GridCRF ( neighborhood = <NUM_LIT:4> ) <EOL> clf = ssvm . OneSlackSSVM ( model = crf , C = <NUM_LIT:100> , inference_cache = <NUM_LIT:100> , <EOL> tol = <NUM_LIT> ) <EOL> clf . fit ( X , Y ) <EOL> Y_pred = np . array ( clf . predict ( X ) ) <EOL> print ( "<STR_LIT>" % clf . score ( X , Y ) ) <EOL> x , y , y_pred = X [ <NUM_LIT:0> ] , Y [ <NUM_LIT:0> ] , Y_pred [ <NUM_LIT:0> ] <EOL> y_pred = y_pred . reshape ( x . shape [ : <NUM_LIT:2> ] ) <EOL> fig , plots = plt . subplots ( <NUM_LIT:1> , <NUM_LIT:4> , figsize = ( <NUM_LIT:12> , <NUM_LIT:4> ) ) <EOL> plots [ <NUM_LIT:0> ] . matshow ( y ) <EOL> plots [ <NUM_LIT:0> ] . set_title ( "<STR_LIT>" ) <EOL> plots [ <NUM_LIT:1> ] . matshow ( np . argmax ( x , axis = - <NUM_LIT:1> ) ) <EOL> plots [ <NUM_LIT:1> ] . set_title ( "<STR_LIT:input>" ) <EOL> plots [ <NUM_LIT:2> ] . matshow ( y_pred ) <EOL> plots [ <NUM_LIT:2> ] . set_title ( "<STR_LIT>" ) <EOL> loss_augmented = clf . model . loss_augmented_inference ( x , y , clf . w ) <EOL> loss_augmented = loss_augmented . reshape ( y . shape ) <EOL> plots [ <NUM_LIT:3> ] . matshow ( loss_augmented ) <EOL> plots [ <NUM_LIT:3> ] . set_title ( "<STR_LIT>" ) <EOL> for p in plots : <EOL> p . set_xticks ( ( ) ) <EOL> p . set_yticks ( ( ) ) <EOL> w_un = clf . w [ : <NUM_LIT:3> * <NUM_LIT:3> ] . reshape ( <NUM_LIT:3> , <NUM_LIT:3> ) <EOL> w_pw = expand_sym ( clf . w [ <NUM_LIT:3> * <NUM_LIT:3> : ] ) <EOL> fig , plots = plt . subplots ( <NUM_LIT:1> , <NUM_LIT:2> , figsize = ( <NUM_LIT:8> , <NUM_LIT:4> ) ) <EOL> plots [ <NUM_LIT:0> ] . matshow ( w_un , cmap = '<STR_LIT>' , vmin = - <NUM_LIT:5> , vmax = <NUM_LIT:5> ) <EOL> plots [ <NUM_LIT:0> ] . set_title ( "<STR_LIT>" ) <EOL> plots [ <NUM_LIT:1> ] . matshow ( w_pw , cmap = '<STR_LIT>' , vmin = - <NUM_LIT:5> , vmax = <NUM_LIT:5> ) <EOL> plots [ <NUM_LIT:1> ] . set_title ( "<STR_LIT>" ) <EOL> for p in plots : <EOL> p . set_xticks ( ( ) ) <EOL> p . set_yticks ( ( ) ) <EOL> plt . show ( ) </s>
