<s> import numpy as np <EOL> import matplotlib . pyplot as plt <EOL> from matplotlib . widgets import Slider , Button <EOL> from shape_learning . shape_modeler import ShapeModeler <EOL> import argparse <EOL> parser = argparse . ArgumentParser ( description = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = "<STR_LIT:store>" , nargs = '<STR_LIT:?>' , default = "<STR_LIT>" , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = "<STR_LIT:store>" , nargs = '<STR_LIT:?>' , <EOL> help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = "<STR_LIT:store>" , nargs = '<STR_LIT:?>' , <EOL> help = '<STR_LIT>' ) <EOL> axcolor = '<STR_LIT>' <EOL> sliders = None <EOL> mainPlot = None <EOL> fig = None <EOL> def prepareShapesModel ( datasetDirectory , regexp = "<STR_LIT>" ) : <EOL> import glob <EOL> import os . path <EOL> import re <EOL> shapes = { } <EOL> nameFilter = re . compile ( regexp ) <EOL> datasets = glob . glob ( datasetDirectory + '<STR_LIT>' ) <EOL> for dataset in datasets : <EOL> if "<STR_LIT>" not in dataset : <EOL> name = os . path . splitext ( os . path . basename ( dataset ) ) [ <NUM_LIT:0> ] <EOL> if nameFilter . match ( name ) : <EOL> shapeModeler = ShapeModeler ( init_filename = dataset , num_principle_components = <NUM_LIT:5> ) <EOL> shapes [ name ] = shapeModeler <EOL> return shapes <EOL> def parse_parameters ( filename ) : <EOL> params = { } <EOL> with open ( filename ) as f : <EOL> key = None <EOL> for l in f . readlines ( ) : <EOL> if l . startswith ( "<STR_LIT:#>" ) or l . rstrip ( ) == "<STR_LIT>" : continue <EOL> if l . startswith ( "<STR_LIT:[>" ) : key = l [ <NUM_LIT:1> : - <NUM_LIT:2> ] <EOL> else : params [ key ] = np . array ( [ [ float ( p ) ] for p in l . split ( '<STR_LIT:U+002C>' ) ] ) <EOL> return params <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> args = parser . parse_args ( ) <EOL> datasetDirectory = args . dataset_directory <EOL> regexp = args . shapes <EOL> initial_params = { } <EOL> if args . parameters : <EOL> initial_params = parse_parameters ( args . parameters ) <EOL> print ( "<STR_LIT>" % initial_params . keys ( ) ) <EOL> if ( not datasetDirectory ) : <EOL> import inspect <EOL> fileName = inspect . getsourcefile ( ShapeModeler ) <EOL> installDirectory = fileName . split ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> datasetDirectory = installDirectory + '<STR_LIT>' <EOL> shapes = prepareShapesModel ( datasetDirectory , regexp ) <EOL> print ( "<STR_LIT>" % "<STR_LIT:U+0020>" . join ( shapes . keys ( ) ) ) <EOL> for n , k in enumerate ( sorted ( shapes . keys ( ) ) ) : <EOL> shape = shapes [ k ] . meanShape <EOL> plt . subplot ( <NUM_LIT:5> , len ( shapes ) / <NUM_LIT:5> + <NUM_LIT:1> , n + <NUM_LIT:1> ) <EOL> numPointsInShape = len ( shape ) / <NUM_LIT:2> <EOL> x_shape = shape [ <NUM_LIT:0> : numPointsInShape ] <EOL> y_shape = shape [ numPointsInShape : ] <EOL> plt . plot ( x_shape , - y_shape , c = '<STR_LIT:k>' ) <EOL> if k in initial_params : <EOL> shape = shapes [ k ] . makeShape ( initial_params [ k ] ) <EOL> x_shape = shape [ <NUM_LIT:0> : numPointsInShape ] <EOL> y_shape = shape [ numPointsInShape : ] <EOL> plt . plot ( x_shape , - y_shape , c = '<STR_LIT:r>' ) <EOL> plt . title ( "<STR_LIT>" % ( k , shapes [ k ] . numShapesInDataset ) ) <EOL> frame1 = plt . gca ( ) <EOL> frame1 . axes . get_xaxis ( ) . set_visible ( False ) <EOL> frame1 . axes . get_yaxis ( ) . set_visible ( False ) <EOL> plt . show ( ) </s>
