<s> import os . path <EOL> from openmdao . main . problem_formulation import ArchitectureAssembly <EOL> from openmdao . lib . architectures . api import EGO <EOL> from openmdao . lib . optproblems . branin import BraninComponent <EOL> class Analysis ( ArchitectureAssembly ) : <EOL> def __init__ ( self ) : <EOL> super ( Analysis , self ) . __init__ ( ) <EOL> self . add ( '<STR_LIT>' , BraninComponent ( ) ) <EOL> self . add_parameter ( '<STR_LIT>' , low = - <NUM_LIT> , high = <NUM_LIT> ) <EOL> self . add_parameter ( '<STR_LIT>' , low = <NUM_LIT:0.> , high = <NUM_LIT> ) <EOL> self . add_objective ( '<STR_LIT>' ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> import sys <EOL> from openmdao . lib . casehandlers . api import case_db_to_dict <EOL> seed = None <EOL> backend = None <EOL> figname = None <EOL> for arg in sys . argv [ <NUM_LIT:1> : ] : <EOL> if arg . startswith ( '<STR_LIT>' ) : <EOL> import random <EOL> seed = int ( arg . split ( '<STR_LIT:=>' ) [ <NUM_LIT:1> ] ) <EOL> random . seed ( seed ) <EOL> if arg . startswith ( '<STR_LIT>' ) : <EOL> backend = arg . split ( '<STR_LIT:=>' ) [ <NUM_LIT:1> ] <EOL> if arg . startswith ( '<STR_LIT>' ) : <EOL> figname = arg . split ( '<STR_LIT:=>' ) [ <NUM_LIT:1> ] <EOL> import matplotlib <EOL> if backend is not None : <EOL> matplotlib . use ( backend ) <EOL> elif sys . platform == '<STR_LIT:win32>' : <EOL> matplotlib . use ( '<STR_LIT>' ) <EOL> from matplotlib import pyplot as plt , cm <EOL> from matplotlib . pylab import get_cmap <EOL> from numpy import meshgrid , array , pi , arange , cos <EOL> analysis = Analysis ( ) <EOL> analysis . architecture = EGO ( ) <EOL> analysis . architecture . initial_DOE_size = <NUM_LIT:20> <EOL> analysis . architecture . sample_iterations = <NUM_LIT:20> <EOL> analysis . architecture . EI_PI = "<STR_LIT>" <EOL> analysis . architecture . min_ei_pi = <NUM_LIT> <EOL> analysis . run ( ) <EOL> points = [ ( - pi , <NUM_LIT> , <NUM_LIT> ) , ( pi , <NUM_LIT> , <NUM_LIT> ) , ( <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ) ] <EOL> for x , y , z in points : <EOL> print "<STR_LIT>" , x , "<STR_LIT>" , y <EOL> analysis . branin . x = x <EOL> analysis . branin . y = y <EOL> analysis . branin . execute ( ) <EOL> print "<STR_LIT>" , analysis . branin . f_xy , "<STR_LIT>" , ( analysis . branin . f_xy . mu - z ) / z * <NUM_LIT:100> <EOL> def branin ( x , y ) : <EOL> return ( y - ( <NUM_LIT> / ( <NUM_LIT> * pi ** <NUM_LIT> ) ) * x ** <NUM_LIT> + <NUM_LIT> * x / pi - <NUM_LIT> ) ** <NUM_LIT> + <NUM_LIT> * ( <NUM_LIT:1.> - <NUM_LIT:1.> / ( <NUM_LIT> * pi ) ) * cos ( x ) + <NUM_LIT> <EOL> X_range = arange ( - <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT> ) <EOL> Y_range = arange ( <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ) <EOL> X , Y = meshgrid ( X_range , Y_range ) <EOL> Z = branin ( X , Y ) <EOL> plt . contour ( X , Y , Z , arange ( <NUM_LIT:1> , <NUM_LIT:200> , <NUM_LIT:2> ) , zorder = <NUM_LIT:1> ) <EOL> cb = plt . colorbar ( shrink = <NUM_LIT> ) <EOL> data_train = case_db_to_dict ( os . path . join ( analysis . architecture . _tdir , '<STR_LIT>' ) , <EOL> [ '<STR_LIT>' , <EOL> '<STR_LIT>' , ] ) <EOL> plt . scatter ( data_train [ '<STR_LIT>' ] , <EOL> data_train [ '<STR_LIT>' ] , s = <NUM_LIT:30> , c = '<STR_LIT>' , zorder = <NUM_LIT:10> ) <EOL> data_EI = { } <EOL> data_EI [ '<STR_LIT>' ] = data_train [ '<STR_LIT>' ] [ analysis . architecture . initial_DOE_size : ] <EOL> data_EI [ '<STR_LIT>' ] = data_train [ '<STR_LIT>' ] [ analysis . architecture . initial_DOE_size : ] <EOL> count = len ( data_EI [ '<STR_LIT>' ] ) <EOL> print "<STR_LIT>" % count <EOL> colors = arange ( <NUM_LIT:0> , count ) / float ( count ) <EOL> color_map = get_cmap ( '<STR_LIT>' ) <EOL> plt . scatter ( data_EI [ '<STR_LIT>' ] , data_EI [ '<STR_LIT>' ] , <EOL> s = <NUM_LIT:30> , <EOL> c = colors , <EOL> zorder = <NUM_LIT:11> , <EOL> cmap = color_map ) <EOL> plt . axis ( [ - <NUM_LIT:5> , <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:15> ] ) <EOL> plt . xlabel ( "<STR_LIT:x>" ) <EOL> plt . ylabel ( "<STR_LIT:y>" ) <EOL> plt . title ( "<STR_LIT>" ) <EOL> plt . text ( <NUM_LIT> , <NUM_LIT:11> , "<STR_LIT>" ) <EOL> if figname is not None : <EOL> matplotlib . pylab . savefig ( figname ) <EOL> plt . figure ( ) <EOL> Z2 = [ ] <EOL> for x_row , y_row in zip ( X , Y ) : <EOL> row = [ ] <EOL> for x , y in zip ( x_row , y_row ) : <EOL> analysis . branin . x = x <EOL> analysis . branin . y = y <EOL> analysis . branin . execute ( ) <EOL> row . append ( analysis . branin . f_xy . mu ) <EOL> Z2 . append ( row ) <EOL> Z2 = array ( Z2 ) <EOL> plt . contour ( X , Y , Z2 , arange ( <NUM_LIT:1> , <NUM_LIT:200> , <NUM_LIT:2> ) , zorder = <NUM_LIT:1> ) <EOL> cb = plt . colorbar ( shrink = <NUM_LIT> ) <EOL> plt . axis ( [ - <NUM_LIT:5> , <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:15> ] ) <EOL> plt . xlabel ( "<STR_LIT:x>" ) <EOL> plt . ylabel ( "<STR_LIT:y>" ) <EOL> plt . title ( "<STR_LIT>" ) <EOL> plt . text ( <NUM_LIT> , <NUM_LIT:11> , "<STR_LIT>" ) <EOL> plt . show ( ) <EOL> analysis . architecture . cleanup ( ) </s>
