def configure(self): driver = self.add('driver', FixedPointIterator()) adapt = self.add('adapt', AdaptiveSampleDriver()) ei_opt = self.add('ei_opt', Genetic()) branin = self.add('branin', BraninComponent()) kwargs = {'params': ("x", "y"), 'responses': ('f_xy', )} meta = self.add('meta', MetaModel(**kwargs)) meta.default_surrogate = KrigingSurrogate() pareto = self.add('pareto', ParetoFilter(**kwargs)) ei = self.add('ei', ExpectedImprovement()) #initial training DOE adapt.DOEgenerator = OptLatinHypercube(num_samples=15) #adapt.DOEgenerator = Uniform(100) adapt.add_parameter('branin.x', low=-5, high=10) adapt.add_parameter('branin.y', low=0, high=15) adapt.add_response('branin.f_xy') #pass training data from sampler to metamodel and pareto filter self.connect('adapt.all_case_inputs.branin.x', ['meta.params.x', 'pareto.params.x']) self.connect('adapt.all_case_inputs.branin.y', ['meta.params.y', 'pareto.params.y']) self.connect('adapt.all_case_outputs.branin.f_xy', ['meta.responses.f_xy', 'pareto.responses.f_xy']) #connect meta and pareto to ei self.connect('meta.f_xy', 'ei.current') #this passes a normal distribution variable self.connect( 'pareto.pareto_outputs[0, 0]', 'ei.target' ) #for single objective, frontier is just a scalar value that is the minimum of the set #EI optimization to find next point ei_opt.opt_type = "maximize" ei_opt.population_size = 100 ei_opt.generations = 10 ei_opt.add_parameter('meta.x', low=-5, high=10) ei_opt.add_parameter('meta.y', low=0, high=15) ei_opt.add_objective('ei.PI') #could use ei.EI too #Iterative sampling process driver.add_parameter('adapt.adaptive_inputs.branin.x[0]') driver.add_parameter('adapt.adaptive_inputs.branin.y[0]') driver.add_constraint('adapt.adaptive_inputs.branin.x[0] = meta.x') driver.add_constraint('adapt.adaptive_inputs.branin.y[0] = meta.y') driver.max_iterations = 30 #Iteration Heirarchy driver.workflow.add(['adapt', 'pareto', 'ei_opt']) adapt.workflow.add(['branin']) ei_opt.workflow.add(['meta', 'ei']) #FPI now support stop conditions driver.add_stop_condition('ei.EI <= .0001')
def configure(self): driver = self.add('driver', FixedPointIterator()) adapt = self.add('adapt', AdaptiveSampleDriver()) MOEI_opt = self.add('MOEI_opt', Genetic()) self.add('spiral', SpiralComponent()) kwargs = {'params': ("x", "y"), 'responses': ('f1_xy', 'f2_xy')} meta = self.add('meta', MetaModel(**kwargs)) meta.default_surrogate = KrigingSurrogate() self.add('pareto', ParetoFilter(**kwargs)) self.add('MOEI', MultiObjExpectedImprovement()) # initial training DOE adapt.DOEgenerator = OptLatinHypercube(num_samples=25) adapt.add_parameter('spiral.x') adapt.add_parameter('spiral.y') adapt.add_response('spiral.f1_xy') adapt.add_response('spiral.f2_xy') # pass training data from sampler to metamodel and pareto filter self.connect('adapt.all_case_inputs.spiral.x', ['meta.params.x', 'pareto.params.x']) self.connect('adapt.all_case_inputs.spiral.y', ['meta.params.y', 'pareto.params.y']) self.connect('adapt.all_case_outputs.spiral.f1_xy', ['meta.responses.f1_xy', 'pareto.responses.f1_xy']) self.connect('adapt.all_case_outputs.spiral.f2_xy', ['meta.responses.f2_xy', 'pareto.responses.f2_xy']) # connect meta and pareto to ei self.connect('[meta.f1_xy, meta.f2_xy]', 'MOEI.current') self.connect('pareto.pareto_outputs', 'MOEI.target') # MOEI optimization to find next point MOEI_opt.opt_type = "maximize" MOEI_opt.population_size = 100 MOEI_opt.generations = 10 # MOEI_opt.selection_method = "tournament" MOEI_opt.add_parameter("meta.x", low=0.75, high=5. * pi) MOEI_opt.add_parameter("meta.y", low=0.75, high=5. * pi) MOEI_opt.add_objective("MOEI.PI") # Iterative sampling process driver.add_parameter('adapt.adaptive_inputs.spiral.x[0]') driver.add_parameter('adapt.adaptive_inputs.spiral.y[0]') driver.add_constraint('adapt.adaptive_inputs.spiral.x[0] = meta.x') driver.add_constraint('adapt.adaptive_inputs.spiral.y[0] = meta.y') driver.max_iterations = 30 # Iteration Heirarchy driver.workflow.add(['adapt', 'pareto', 'MOEI_opt']) adapt.workflow.add(['spiral']) MOEI_opt.workflow.add(['meta', 'MOEI']) # FPI now support stop conditions driver.add_stop_condition('MOEI.PI <= .0001')
def configure(self): """ Creates counter new Assembly containing counter Paraboloid and an optimizer""" # Create Paraboloid component instances self.add('comp', ParaboloidDerivative()) # Create Optimizer instance self.add('driver', Genetic()) # Driver process definition self.driver.workflow.add('comp') # Objective self.driver.add_objective('comp.f_xy') # Design Variables self.driver.add_parameter('comp.x', low=-50., high=50.) self.driver.add_parameter('comp.y', low=-50., high=50.) # Inequality Constraints #self.driver.add_constraint('comp.x - comp.y >= 15.0') # Equality Constraints #self.driver.add_constraint('comp.x - comp.y = 15.0') # General flag - suppress output self.driver.iprint = 3 # CONMIN-specific Settings #self.driver.itmax = 30 #self.driver.fdch = 0.00001 #self.driver.fdchm = 0.000001 #self.driver.ctlmin = 0.01 #self.driver.delfun = 0.001 #self.driver.conmin_diff = False # NEWSUMT-specific Settings #self.driver.itmax = 50 # COBYLA-specific Settings #self.driver.rhobeg = 1.0 #self.driver.rhoend = 1.0e-5 #self.driver.maxfun = 1000 # SLSQP-specific Settings #self.driver.accuracy = 1.0e-6 #self.driver.maxiter = 50 # Genetic-specific Settings self.driver.population_size = 90 self.driver.crossover_rate = 0.9 self.driver.mutation_rate = 0.02 self.selection_method = 'rank'
def configure(self): self._tdir = mkdtemp() #Components self.add("branin_meta_model", MetaModel()) self.branin_meta_model.default_surrogate = KrigingSurrogate() self.branin_meta_model.model = BraninComponent() self.branin_meta_model.recorder = DBCaseRecorder(':memory:') self.branin_meta_model.force_execute = True self.add("EI", ExpectedImprovement()) self.EI.criteria = "branin_meta_model.f_xy" self.add("filter", ParetoFilter()) self.filter.criteria = ['branin_meta_model.f_xy'] self.filter.case_sets = [ self.branin_meta_model.recorder.get_iterator(), ] self.filter.force_execute = True #Driver Configuration self.add("DOE_trainer", DOEdriver()) self.DOE_trainer.sequential = True self.DOE_trainer.DOEgenerator = OptLatinHypercube(num_samples=15) #self.DOE_trainer.DOEgenerator = FullFactorial(num_levels=5) self.DOE_trainer.add_parameter("branin_meta_model.x", low=-5., high=10.) self.DOE_trainer.add_parameter("branin_meta_model.y", low=0., high=15.) self.DOE_trainer.add_event("branin_meta_model.train_next") self.DOE_trainer.case_outputs = ["branin_meta_model.f_xy"] self.DOE_trainer.recorders = [ DBCaseRecorder(os.path.join(self._tdir, 'trainer.db')) ] self.add("EI_opt", Genetic()) self.EI_opt.opt_type = "maximize" self.EI_opt.population_size = 100 self.EI_opt.generations = 10 #self.EI_opt.selection_method = "tournament" self.EI_opt.add_parameter("branin_meta_model.x", low=-5., high=10.) self.EI_opt.add_parameter("branin_meta_model.y", low=0., high=15.) self.EI_opt.add_objective("EI.PI") self.add("retrain", MyDriver()) self.retrain.add_event("branin_meta_model.train_next") self.retrain.recorders = [ DBCaseRecorder(os.path.join(self._tdir, 'retrain.db')) ] self.add("iter", IterateUntil()) self.iter.max_iterations = 30 self.iter.add_stop_condition('EI.EI <= .0001') #Iteration Heirarchy self.driver.workflow.add(['DOE_trainer', 'iter']) self.DOE_trainer.workflow.add('branin_meta_model') self.iter.workflow = SequentialWorkflow() self.iter.workflow.add(['filter', 'EI_opt', 'retrain']) self.EI_opt.workflow.add(['branin_meta_model', 'EI']) self.retrain.workflow.add('branin_meta_model') #Data Connections self.connect("filter.pareto_set", "EI.best_case") self.connect("branin_meta_model.f_xy", "EI.predicted_value")
def configure(self): self._tdir = mkdtemp() self.comp_name = None #check to make sure no more than one component is being referenced compnames = set() for param in self.parent.get_parameters().values(): compnames.update(param.get_referenced_compnames()) if len(compnames) > 1: self.parent.raise_exception('The EGO architecture can only be used on one' 'component at a time, but parameters from %s ' 'were added to the problem formulation.' %compnames, ValueError) self.comp_name = compnames.pop() #change name of component to add '_model' to it. # lets me name the metamodel as the old name self.comp= getattr(self.parent,self.comp_name) self.comp.name = "%s_model"%self.comp_name #add in the metamodel meta_model = self.parent.add(self.comp_name,MetaModel()) #metamodel now replaces old component with same name meta_model.default_surrogate = KrigingSurrogate() meta_model.model = self.comp meta_model_recorder = DBCaseRecorder(os.path.join(self._tdir,'trainer.db')) meta_model.recorder = meta_model_recorder EI = self.parent.add("EI",ExpectedImprovement()) self.objective = self.parent.get_objectives().keys()[0] EI.criteria = self.objective pfilter = self.parent.add("filter",ParetoFilter()) pfilter.criteria = [self.objective] pfilter.case_sets = [meta_model_recorder.get_iterator(),] #Driver Configuration DOE_trainer = self.parent.add("DOE_trainer",DOEdriver()) DOE_trainer.sequential = True DOE_trainer.DOEgenerator = OptLatinHypercube(num_samples=self.initial_DOE_size) for name,param in self.parent.get_parameters().iteritems(): DOE_trainer.add_parameter(param) DOE_trainer.add_event("%s.train_next"%self.comp_name) DOE_trainer.case_outputs = [self.objective] DOE_trainer.recorders = [DBCaseRecorder(':memory:')] EI_opt = self.parent.add("EI_opt",Genetic()) EI_opt.opt_type = "maximize" EI_opt.population_size = 100 EI_opt.generations = 10 #EI_opt.selection_method = "tournament" for name,param in self.parent.get_parameters().iteritems(): EI_opt.add_parameter(param) EI_opt.add_objective("EI.%s"%self.EI_PI) retrain = self.parent.add("retrain",Driver()) retrain.recorders = self.data_recorders retrain.add_event("%s.train_next"%self.comp_name) iter = self.parent.add("iter",IterateUntil()) iter.max_iterations = self.sample_iterations iter.add_stop_condition('EI.PI <= %s'%self.min_ei_pi) #Data Connections self.parent.connect("filter.pareto_set","EI.best_case") self.parent.connect(self.objective,"EI.predicted_value") #Iteration Heirarchy self.parent.driver.workflow.add(['DOE_trainer', 'iter']) #DOE_trainer.workflow.add(self.comp_name) iter.workflow = SequentialWorkflow() iter.workflow.add(['filter', 'EI_opt', 'retrain']) #EI_opt.workflow.add([self.comp_name,'EI']) retrain.workflow.add(self.comp_name)
def configure(self): self._tdir = mkdtemp() #Components self.add("spiral_meta_model", MetaModel()) self.spiral_meta_model.surrogate = {'default': KrigingSurrogate()} self.spiral_meta_model.model = SpiralComponent() self.spiral_meta_model.recorder = DBCaseRecorder(':memory:') self.spiral_meta_model.force_execute = True self.add("MOEI", MultiObjExpectedImprovement()) self.MOEI.criteria = [ 'spiral_meta_model.f1_xy', 'spiral_meta_model.f2_xy' ] self.add("filter", ParetoFilter()) self.filter.criteria = [ 'spiral_meta_model.f1_xy', 'spiral_meta_model.f2_xy' ] self.filter.case_sets = [ self.spiral_meta_model.recorder.get_iterator() ] self.filter.force_execute = True #Driver Configuration self.add("DOE_trainer", DOEdriver()) self.DOE_trainer.sequential = True self.DOE_trainer.DOEgenerator = OptLatinHypercube(num_samples=25) self.DOE_trainer.add_parameter("spiral_meta_model.x") self.DOE_trainer.add_parameter("spiral_meta_model.y") self.DOE_trainer.add_event("spiral_meta_model.train_next") self.DOE_trainer.case_outputs = [ 'spiral_meta_model.f1_xy', 'spiral_meta_model.f2_xy' ] self.DOE_trainer.recorders = [ DBCaseRecorder(os.path.join(self._tdir, 'trainer.db')) ] self.add("MOEI_opt", Genetic()) self.MOEI_opt.opt_type = "maximize" self.MOEI_opt.population_size = 100 self.MOEI_opt.generations = 10 #self.MOEI_opt.selection_method = "tournament" self.MOEI_opt.add_parameter("spiral_meta_model.x") self.MOEI_opt.add_parameter("spiral_meta_model.y") self.MOEI_opt.add_objective("MOEI.PI") self.add("retrain", MyDriver()) self.retrain.add_event("spiral_meta_model.train_next") self.retrain.recorders = [ DBCaseRecorder(os.path.join(self._tdir, 'retrain.db')) ] self.add("iter", IterateUntil()) self.iter.iterations = 30 self.iter.add_stop_condition('MOEI.PI <= .0001') #Iteration Heirarchy self.driver.workflow.add(['DOE_trainer', 'iter']) self.DOE_trainer.workflow.add('spiral_meta_model') self.iter.workflow = SequentialWorkflow() self.iter.workflow.add(['filter', 'MOEI_opt', 'retrain']) self.MOEI_opt.workflow.add(['spiral_meta_model', 'MOEI']) self.retrain.workflow.add('spiral_meta_model') #Data Connections self.connect("filter.pareto_set", "MOEI.best_cases") self.connect("spiral_meta_model.f1_xy", "MOEI.predicted_values[0]") self.connect("spiral_meta_model.f2_xy", "MOEI.predicted_values[1]")