def test_multi_surrogate_models_bad_surrogate_dict(self): metamodel = MetaModel() metamodel.name = 'meta' metamodel.sur_d = KrigingSurrogate() try: metamodel.model = Simple() except RuntimeError,err: self.assertEqual("meta: No default surrogate model is defined and the following outputs do not have a surrogate model: ['c']. " "Either specify default_surrogate, or specify a surrogate model for all " "outputs.",str(err))
def test_multi_surrogate_models_bad_surrogate_dict(self): metamodel = MetaModel() metamodel.name = 'meta' metamodel.surrogate = {'d':KrigingSurrogate()} try: metamodel.model = Simple() except ValueError,err: self.assertEqual('meta: No default surrogate model was specified. ' 'Either specify a default, or specify a surrogate model for all ' 'outputs',str(err))
def test_multi_surrogate_models_bad_surrogate_dict(self): metamodel = MetaModel() metamodel.name = 'meta' metamodel.surrogate = {'d': KrigingSurrogate()} try: metamodel.model = Simple() except ValueError, err: self.assertEqual( 'meta: No default surrogate model was specified. ' 'Either specify a default, or specify a surrogate model for all ' 'outputs', str(err))
def test_multi_surrogate_models_bad_surrogate_dict(self): metamodel = MetaModel() metamodel.name = "meta" metamodel.surrogate = {"d": KrigingSurrogate()} try: metamodel.model = Simple() except ValueError, err: self.assertEqual( "meta: No default surrogate model was specified. " "Either specify a default, or specify a surrogate model for all " "outputs", str(err), )
def test_warm_start(self): model = set_as_top(Assembly()) model.add('meta', MetaModel(params=('x1', 'x2'), responses=('y1', 'y2'))) model.driver.workflow.add('meta') model.meta.default_surrogate = ResponseSurface() model.meta.warm_restart = True model.meta.params.x1 = [1.0, 3.0] model.meta.params.x2 = [1.0, 4.0] model.meta.responses.y1 = [3.0, 1.0] model.meta.responses.y2 = [1.0, 7.0] model.meta.default_surrogate = ResponseSurface() model.meta.x1 = 2.0 model.meta.x2 = 3.0 model.meta.run() assert_rel_error(self, model.meta.y1, 1.9085, .001) assert_rel_error(self, model.meta.y2, 3.9203, .001) # Adding the 3rd point moves the estimate for that point # back to where it should be. model.meta.params.x1 = [2.0] model.meta.params.x2 = [3.0] model.meta.responses.y1 = [2.0] model.meta.responses.y2 = [4.0] self.assertTrue(model.meta._train == True) model.meta.run() assert_rel_error(self, model.meta.y1, 2.0, .00001) assert_rel_error(self, model.meta.y2, 4.0, .00001)
def test_basics(self): model = set_as_top(Assembly()) model.add('meta', MetaModel(params=('x1', 'x2'), responses=('y1', 'y2'))) model.driver.workflow.add('meta') model.meta.params.x1 = [1.0, 2.0, 3.0] model.meta.params.x2 = [1.0, 3.0, 4.0] model.meta.responses.y1 = [3.0, 2.0, 1.0] model.meta.responses.y2 = [1.0, 4.0, 7.0] model.meta.default_surrogate = ResponseSurface() model.meta.x1 = 2.0 model.meta.x2 = 3.0 model.meta.run() assert_rel_error(self, model.meta.y1, 2.0, .00001) assert_rel_error(self, model.meta.y2, 4.0, .00001) model.meta.x1 = 2.5 model.meta.x2 = 3.5 model.meta.run() assert_rel_error(self, model.meta.y1, 1.5934, .001) # Slot a new surrogate. model.meta.default_surrogate = FloatKrigingSurrogate() self.assertTrue(model.meta._train == True) model.meta.run() assert_rel_error(self, model.meta.y1, 1.4609, .001)
def test_model_change(self): metamodel = MetaModel() mmins = set(metamodel.list_inputs()) mmouts = set(metamodel.list_outputs()) metamodel.surrogate = {'default':KrigingSurrogate()} metamodel.model = Simple() inputs = set(metamodel.list_inputs()) outputs = set(metamodel.list_outputs()) self.assertEquals(inputs-mmins, set(['a','b'])) self.assertEquals(outputs-mmouts, set(['c','d'])) # now put a different model in metamodel.model = Simple2() inputs = set(metamodel.list_inputs()) outputs = set(metamodel.list_outputs()) self.assertEquals(inputs-mmins, set(['w','x'])) self.assertEquals(outputs-mmouts, set(['y','z']))
def test_model_change(self): metamodel = MetaModel() mmins = set(metamodel.list_inputs()) mmouts = set(metamodel.list_outputs()) metamodel.surrogate = {"default": KrigingSurrogate()} metamodel.model = Simple() inputs = set(metamodel.list_inputs()) outputs = set(metamodel.list_outputs()) self.assertEquals(inputs - mmins, set(["a", "b"])) self.assertEquals(outputs - mmouts, set(["c", "d"])) # now put a different model in metamodel.model = Simple2() inputs = set(metamodel.list_inputs()) outputs = set(metamodel.list_outputs()) self.assertEquals(inputs - mmins, set(["w", "x"])) self.assertEquals(outputs - mmouts, set(["y", "z"]))
def test_proxy(self): meta = MetaModel() meta.default_surrogate = KrigingSurrogate() meta.model = SimpleProxy() for i in range(3): meta.train_next = True meta.run() self.assertEqual(len(meta._training_data['f_x']), 3)
def _get_assembly(self): asm = set_as_top(Assembly()) asm.add('metamodel', MetaModel()) asm.add('comp1', Simple()) asm.add('comp2', Simple()) asm.metamodel.surrogate = {'default': KrigingSurrogate()} asm.metamodel.model = Simple() asm.metamodel.recorder = DumbRecorder() asm.driver.workflow.add(['metamodel', 'comp1', 'comp2']) asm.connect('comp1.c', 'metamodel.a') asm.connect('comp1.d', 'metamodel.b') asm.connect('metamodel.c', 'comp2.a') asm.connect('metamodel.d', 'comp2.b') return asm
def test_comp_error(self): a = Assembly() a.add('m', MetaModel()) a.m.surrogate = {'default': KrigingSurrogate()} a.m.model = DummyError() a.m.train_next = True a.driver.workflow.add('m') try: a.run() except RuntimeError as err: self.assertEqual("m.model: Test Error", str(err)) else: self.fail("RuntimeError expected")
def _trained_asm(self, avals, bvals): asm = set_as_top(Assembly()) asm.add('metamodel', MetaModel()) asm.metamodel.surrogate = {'default': KrigingSurrogate()} asm.metamodel.model = Simple() asm.metamodel.recorder = DumbRecorder() asm.driver.workflow.add(['metamodel']) for a, b in zip(avals, bvals): asm.metamodel.a = a asm.metamodel.b = b asm.metamodel.train_next = 1 asm.metamodel.run() return asm
def test_multi_surrogate_models(self): model = set_as_top(Assembly()) model.add('meta', MetaModel(params=('x1', 'x2'), responses=('y1', 'y2'))) model.driver.workflow.add('meta') model.meta.warm_restart = True model.meta.params.x1 = [1.0, 3.0] model.meta.params.x2 = [1.0, 4.0] model.meta.responses.y1 = [3.0, 1.0] model.meta.responses.y2 = [1.0, 7.0] model.meta.surrogates['y1'] = KrigingSurrogate() model.meta.surrogates['y2'] = LogisticRegression() model.meta.x1 = 2.0 model.meta.x2 = 3.0 model.meta.run() self.assertTrue(isinstance(model.meta.y1, NormalDistribution)) self.assertTrue(isinstance(model.meta.y2, float)) model.meta.surrogates['y1'] = LogisticRegression() model.meta.surrogates['y2'] = KrigingSurrogate() model.meta.run() self.assertTrue(isinstance(model.meta.y1, float)) self.assertTrue(isinstance(model.meta.y2, NormalDistribution)) model.meta.default_surrogate = KrigingSurrogate() model.meta.surrogates['y1'] = None model.meta.surrogates['y2'] = None model.meta.run() self.assertTrue(isinstance(model.meta.y1, NormalDistribution)) self.assertTrue(isinstance(model.meta.y2, NormalDistribution)) model.meta.surrogates['y1'] = LogisticRegression() model.meta.run() self.assertTrue(isinstance(model.meta.y1, float)) self.assertTrue(isinstance(model.meta.y2, NormalDistribution))
def _get_assembly(self, default=True, meta=True): asm = set_as_top(Assembly()) asm.add('comp1', Simple()) asm.add('comp2', Simple()) if meta: asm.add('metamodel', MetaModel()) if default: asm.metamodel.default_surrogate = KrigingSurrogate() asm.metamodel.model = Simple() asm.metamodel.recorder = DumbRecorder() else: asm.add('metamodel', Simple()) # put a real Simple comp in place of metamodel asm.driver.workflow.add(['metamodel','comp1','comp2']) asm.connect('comp1.c','metamodel.a') asm.connect('comp1.d','metamodel.b') asm.connect('metamodel.c','comp2.a') asm.connect('metamodel.d','comp2.b') return asm
def test_assy_promotion(self): class Trig(Component): x = Float(0,iotype="in",units="rad") f_x_sin = Float(0.0,iotype="out") f_x_cos = Float(0.0,iotype="out") def execute(self): self.f_x_sin = .5*sin(self.x) self.f_x_cos = .5*cos(self.x) class TrigAsmb(Assembly): x = Float(0,iotype="in",units="rad") def configure(self): self.add('trig1', Trig()) self.add('trig2', Trig()) self.connect('x', 'trig1.x') self.connect('trig1.f_x_sin', 'trig2.x') self.create_passthrough('trig2.f_x_sin') self.create_passthrough('trig2.f_x_cos') self.driver.workflow.add(['trig1', 'trig2']) top = set_as_top(Assembly()) top.add("trig_meta_model", MetaModel()) top.trig_meta_model.model = TrigAsmb() top.trig_meta_model.surrogates['f_x_sin'] = FloatKrigingSurrogate() top.trig_meta_model.surrogates['f_x_cos'] = FloatKrigingSurrogate() # Will error if vars don't promote correctly top.run()
def test_multi_surrogate_models_bad_surrogate_dict(self): model = set_as_top(Assembly()) model.add('meta', MetaModel(params=('x1', 'x2'), responses=('y1', 'y2'))) model.driver.workflow.add('meta') model.meta.warm_restart = True model.meta.params.x1 = [1.0, 3.0] model.meta.params.x2 = [1.0, 4.0] model.meta.responses.y1 = [3.0, 1.0] model.meta.responses.y2 = [1.0, 7.0] model.meta.surrogates['y1'] = KrigingSurrogate() try: model.meta.run() except RuntimeError as err: self.assertEqual("meta: No default surrogate model is defined and " "the following outputs do not have a surrogate " "model: ['y2']. Either specify default_surrogate, " "or specify a surrogate model for all outputs.", str(err)) else: self.fail('ValueError expected')
def test_warm_start(self): metamodel = MetaModel() metamodel.name = 'meta' metamodel.surrogate = {'default': KrigingSurrogate()} metamodel.model = Simple() metamodel.recorder = DumbRecorder() simple = Simple() cases = [] metamodel.a = 1. metamodel.b = 2. metamodel.train_next = True metamodel.run() inputs = [('meta2.a', metamodel.a), ('meta2.b', metamodel.b)] outputs = [('meta2.c', metamodel.c.mu), ('meta2.d', metamodel.d.mu)] cases.append(Case(inputs=inputs, outputs=outputs)) metamodel.a = 3. metamodel.b = 5. metamodel.train_next = True metamodel.run() inputs = [('meta2.a', metamodel.a), ('meta2.b', metamodel.b)] outputs = [('meta2.c', metamodel.c.mu), ('meta2.d', metamodel.d.mu)] cases.append(Case(inputs=inputs, outputs=outputs)) case_iter = ListCaseIterator(cases) metamodel2 = MetaModel() metamodel2.name = 'meta2' metamodel2.surrogate = {'default': KrigingSurrogate()} metamodel2.model = Simple() metamodel2.recorder = DumbRecorder() metamodel2.warm_start_data = case_iter metamodel2.a = simple.a = 1 metamodel2.b = simple.b = 2 metamodel2.run() simple.run() self.assertEqual(metamodel2.c.getvalue(), 3.) self.assertEqual(metamodel2.d.getvalue(), -1.) self.assertEqual(metamodel2.c.getvalue(), simple.c) self.assertEqual(metamodel2.d.getvalue(), simple.d)
metamodel = MetaModel() metamodel.name = "meta" metamodel.surrogate = {"d": KrigingSurrogate()} try: metamodel.model = Simple() except ValueError, err: self.assertEqual( "meta: No default surrogate model was specified. " "Either specify a default, or specify a surrogate model for all " "outputs", str(err), ) else: self.fail("ValueError expected") metamodel = MetaModel() metamodel.name = "meta" metamodel.surrogate = {"d": KrigingSurrogate()} metamodel.includes = ["a", "b", "d"] try: metamodel.model = Simple() except ValueError, err: if ( 'meta: Dict provided for "surrogates" does not include a value for "c". All outputs must be specified' == str(err) ): self.fail("should not get a value error for variable c. It is not included in the metamodel") def test_multi_surrogate_models(self): metamodel = MetaModel() metamodel.name = "meta"
def test_model_change(self): metamodel = MetaModel() mmins = set(metamodel.list_inputs()) mmouts = set(metamodel.list_outputs()) metamodel.surrogate = {'default': KrigingSurrogate()} metamodel.model = Simple() inputs = set(metamodel.list_inputs()) outputs = set(metamodel.list_outputs()) self.assertEquals(inputs - mmins, set(['a', 'b'])) self.assertEquals(outputs - mmouts, set(['c', 'd'])) # now put a different model in metamodel.model = Simple2() inputs = set(metamodel.list_inputs()) outputs = set(metamodel.list_outputs()) self.assertEquals(inputs - mmins, set(['w', 'x'])) self.assertEquals(outputs - mmouts, set(['y', 'z']))
def test_reset_training_data_event(self): metamodel = MetaModel() metamodel.name = 'meta' metamodel.surrogate = {'default': KrigingSurrogate()} metamodel.model = Simple() metamodel.recorder = DumbRecorder() simple = Simple() metamodel.a = 1. metamodel.b = 2. metamodel.train_next = True metamodel.run() metamodel.a = 2. metamodel.b = 3. metamodel.train_next = True metamodel.run()
def test_multi_surrogate_models(self): metamodel = MetaModel() metamodel.name = 'meta' metamodel.surrogate = { 'd': KrigingSurrogate(), 'c': LogisticRegression() } metamodel.model = Simple() metamodel.recorder = DumbRecorder() simple = Simple() metamodel.a = simple.a = 1. metamodel.b = simple.b = 2. metamodel.train_next = True simple.run() metamodel.run() metamodel.a = simple.a = 3. metamodel.b = simple.b = 4. metamodel.train_next = True simple.run() metamodel.run() self.assertTrue(isinstance(metamodel.d, NormalDistribution)) self.assertTrue(isinstance(metamodel.c, float))
def test_multi_surrogate_models_bad_surrogate_dict(self): metamodel = MetaModel() metamodel.name = 'meta' metamodel.surrogate = {'d': KrigingSurrogate()} try: metamodel.model = Simple() except ValueError, err: self.assertEqual( 'meta: No default surrogate model was specified. ' 'Either specify a default, or specify a surrogate model for all ' 'outputs', str(err)) else: self.fail('ValueError expected') metamodel = MetaModel() metamodel.name = 'meta' metamodel.surrogate = {'d': KrigingSurrogate()} metamodel.includes = ['a', 'b', 'd'] try: metamodel.model = Simple() except ValueError, err: if 'meta: Dict provided for "surrogates" does not include a value for "c". All outputs must be specified' == str( err): self.fail( 'should not get a value error for variable c. It is not included in the metamodel' ) def test_multi_surrogate_models(self): metamodel = MetaModel() metamodel.name = 'meta'
def configure(self): self.add('mm', MetaModel()) self.mm.default_surrogate = KrigingSurrogate() self.mm.model = Dummy()
def test_default_surrogate_change(self): metamodel = MetaModel() mmins = set(metamodel.list_inputs()) mmouts = set(metamodel.list_outputs()) metamodel.default_surrogate = KrigingSurrogate() metamodel.model = Simple() metamodel.default_surrogate = LogisticRegression() attrs = metamodel.get_attributes(io_only=False) for s in attrs['Slots']: self.assertNotEqual(s['name'], 'c') self.assertNotEqual(s['name'], 'd') inputs = set(metamodel.list_inputs()) outputs = set(metamodel.list_outputs()) self.assertEquals(inputs - mmins, set(['a', 'b'])) self.assertEquals(outputs - mmouts, set(['c', 'd'])) for i in range(3): metamodel.train_next = True metamodel.run() self.assertTrue(len(metamodel._training_data['c']) == 3) self.assertTrue(len(metamodel._training_data['d']) == 3) self.assertTrue(len(metamodel._training_input_history) == 3) metamodel.includes = ['a', 'b', 'c', 'd'] self.assertTrue(len(metamodel._training_data['c']) == 3) self.assertTrue(len(metamodel._training_data['d']) == 3) self.assertTrue(len(metamodel._training_input_history) == 3) # removing an output should not clobber the rest of the training data metamodel.includes = ['a', 'b', 'c'] self.assertTrue(len(metamodel._training_data['c']) == 3) self.assertTrue('d' not in metamodel._training_data) self.assertTrue(len(metamodel._training_input_history) == 3) # now put a different model in with the same inputs/outputs metamodel.model = SimpleMatch() metamodel.includes = ['a', 'b', 'c', 'd'] inputs = set(metamodel.list_inputs()) outputs = set(metamodel.list_outputs()) self.assertEquals(inputs - mmins, set(['a', 'b'])) self.assertEquals(outputs - mmouts, set(['c', 'd'])) self.assertTrue(len(metamodel._training_data['c']) == 0) self.assertTrue(len(metamodel._training_data['d']) == 0) self.assertTrue(len(metamodel._training_input_history) == 0) # now put a different model in metamodel.model = Simple2() metamodel.includes = ['w', 'x', 'y', 'z'] inputs = set(metamodel.list_inputs()) outputs = set(metamodel.list_outputs()) self.assertEquals(inputs - mmins, set(['w', 'x'])) self.assertEquals(outputs - mmouts, set(['y', 'z']))
def test_reset_training_data_event(self): metamodel = MetaModel() metamodel.name = 'meta' metamodel.surrogate = {'default':KrigingSurrogate()} metamodel.model = Simple() metamodel.recorder = DumbRecorder() simple = Simple() metamodel.a = 1. metamodel.b = 2. metamodel.train_next = True metamodel.run() metamodel.a = 2. metamodel.b = 3. metamodel.train_next = True metamodel.run()
def __init__(self): super(Sim, self).__init__() self.add('mm', MetaModel()) self.mm.surrogate = {'default': KrigingSurrogate()} self.mm.model = Dummy()
def test_multi_surrogate_models(self): metamodel = MetaModel() metamodel.name = 'meta' metamodel.surrogate = {'d':KrigingSurrogate(), 'c':LogisticRegression()} metamodel.model = Simple() metamodel.recorder = DumbRecorder() simple = Simple() metamodel.a = simple.a = 1. metamodel.b = simple.b = 2. metamodel.train_next = True simple.run() metamodel.run() metamodel.a = simple.a = 3. metamodel.b = simple.b = 4. metamodel.train_next = True simple.run() metamodel.run() self.assertTrue(isinstance(metamodel.d,NormalDistribution)) self.assertTrue(isinstance(metamodel.c,float))
def test_multi_surrogate_models_bad_surrogate_dict(self): metamodel = MetaModel() metamodel.name = 'meta' metamodel.model = Simple() metamodel.surrogates[ 'd' ] = KrigingSurrogate() try: metamodel.run() except RuntimeError,err: self.assertEqual("meta: No default surrogate model is defined and the following outputs do not have a surrogate model: ['c']. " "Either specify default_surrogate, or specify a surrogate model for all " "outputs.",str(err)) else: self.fail('ValueError expected') metamodel = MetaModel() metamodel.name = 'meta' metamodel.surrogates['d'] = KrigingSurrogate() metamodel.includes = ['a','b','d'] try: metamodel.model = Simple() except ValueError,err: if 'meta: No surrogate was provided for "c". All outputs must have a surrogate' == str(err): self.fail('should not get a value error for variable c. It is not included in the metamodel') def test_multi_surrogate_models(self): metamodel = MetaModel() metamodel.name = 'meta' metamodel.model = Simple() metamodel.surrogates['d'] = KrigingSurrogate() metamodel.surrogates['c'] = LogisticRegression()
def test_model_change(self): metamodel = MetaModel() mmins = set(metamodel.list_inputs()) mmouts = set(metamodel.list_outputs()) metamodel.default_surrogate = KrigingSurrogate() metamodel.model = Simple() attrs = metamodel.get_attributes(io_only=False) for s in attrs['Slots']: self.assertNotEqual(s['name'], 'c') self.assertNotEqual(s['name'], 'd') inputs = set(metamodel.list_inputs()) outputs = set(metamodel.list_outputs()) self.assertEquals(inputs-mmins, set(['a','b'])) self.assertEquals(outputs-mmouts, set(['c','d'])) for i in range(3): metamodel.train_next = True metamodel.run() self.assertTrue(len(metamodel._training_data['c']) == 3) self.assertTrue(len(metamodel._training_data['d']) == 3) self.assertTrue(len(metamodel._training_input_history) == 3) metamodel.includes = ['a','b','c','d'] self.assertTrue(len(metamodel._training_data['c']) == 3) self.assertTrue(len(metamodel._training_data['d']) == 3) self.assertTrue(len(metamodel._training_input_history) == 3) # removing an output shouldn't clobber the rest of the training data metamodel.includes = ['a','b','c'] self.assertTrue(len(metamodel._training_data['c']) == 3) self.assertTrue('d' not in metamodel._training_data) self.assertTrue(len(metamodel._training_input_history) == 3) # now put a different model in with the same inputs/outputs metamodel.model = SimpleMatch() metamodel.includes = ['a','b','c','d'] inputs = set(metamodel.list_inputs()) outputs = set(metamodel.list_outputs()) self.assertEquals(inputs-mmins, set(['a','b'])) self.assertEquals(outputs-mmouts, set(['c', 'd'])) self.assertTrue(len(metamodel._training_data['c']) == 0) self.assertTrue(len(metamodel._training_data['d']) == 0) self.assertTrue(len(metamodel._training_input_history) == 0) # now put a different model in metamodel.model = Simple2() metamodel.includes = ['w','x','y','z'] inputs = set(metamodel.list_inputs()) outputs = set(metamodel.list_outputs()) self.assertEquals(inputs-mmins, set(['w','x'])) self.assertEquals(outputs-mmouts, set(['y','z']))
def test_default_execute(self): metamodel = MetaModel() metamodel.name = 'meta' metamodel.surrogate = {'default': KrigingSurrogate()} metamodel.model = Simple() metamodel.recorder = DumbRecorder() simple = Simple() metamodel.a = simple.a = 1. metamodel.b = simple.b = 2. metamodel.train_next = True simple.run() metamodel.run() metamodel.a = simple.a = 1. metamodel.b = simple.b = 2. metamodel.train_next = True simple.run() metamodel.run() self.assertEqual(metamodel.c.getvalue(), 3.) self.assertEqual(metamodel.d.getvalue(), -1.) self.assertEqual(metamodel.c.getvalue(), simple.c) self.assertEqual(metamodel.d.getvalue(), simple.d)
def configure(self): mm = MetaModel() self.add('mm', mm) self.mm.default_surrogate = FloatKrigingSurrogate() self.driver.workflow.add('mm')
def test_warm_start(self): metamodel = MetaModel() metamodel.name = 'meta' metamodel.surrogate = {'default':KrigingSurrogate()} metamodel.model = Simple() metamodel.recorder = DumbRecorder() simple = Simple() cases = [] metamodel.a = 1. metamodel.b = 2. metamodel.train_next = True metamodel.run() inputs = [('meta2.a',metamodel.a),('meta2.b',metamodel.b)] outputs = [('meta2.c',metamodel.c.mu),('meta2.d',metamodel.d.mu)] cases.append(Case(inputs=inputs,outputs=outputs)) metamodel.a = 3. metamodel.b = 5. metamodel.train_next = True metamodel.run() inputs = [('meta2.a',metamodel.a),('meta2.b',metamodel.b)] outputs = [('meta2.c',metamodel.c.mu),('meta2.d',metamodel.d.mu)] cases.append(Case(inputs=inputs,outputs=outputs)) case_iter = ListCaseIterator(cases) metamodel2 = MetaModel() metamodel2.name = 'meta2' metamodel2.surrogate = {'default':KrigingSurrogate()} metamodel2.model = Simple() metamodel2.recorder = DumbRecorder() metamodel2.warm_start_data = case_iter metamodel2.a = simple.a = 1 metamodel2.b = simple.b = 2 metamodel2.run() simple.run() self.assertEqual(metamodel2.c.getvalue(), 3.) self.assertEqual(metamodel2.d.getvalue(), -1.) self.assertEqual(metamodel2.c.getvalue(), simple.c) self.assertEqual(metamodel2.d.getvalue(), simple.d)
self.assertEqual(metamodel.d.getvalue(), simple.d) def test_multi_surrogate_models_bad_surrogate_dict(self): metamodel = MetaModel() metamodel.name = 'meta' metamodel.surrogate = {'d':KrigingSurrogate()} try: metamodel.model = Simple() except ValueError,err: self.assertEqual('meta: No default surrogate model was specified. ' 'Either specify a default, or specify a surrogate model for all ' 'outputs',str(err)) else: self.fail('ValueError expected') metamodel = MetaModel() metamodel.name = 'meta' metamodel.surrogate = {'d':KrigingSurrogate()} metamodel.includes = ['a','b','d'] try: metamodel.model = Simple() except ValueError,err: if 'meta: Dict provided for "surrogates" does not include a value for "c". All outputs must be specified'==str(err): self.fail('should not get a value error for variable c. It is not included in the metamodel') def test_multi_surrogate_models(self): metamodel = MetaModel() metamodel.name = 'meta' metamodel.surrogate = {'d':KrigingSurrogate(), 'c':LogisticRegression()}
def configure(self): self.add('mm', MetaModel()) self.mm.surrogate = {'default': KrigingSurrogate()} self.mm.model = Dummy()
def test_default_execute(self): metamodel = MetaModel() metamodel.name = 'meta' metamodel.surrogate = {'default':KrigingSurrogate()} metamodel.model = Simple() metamodel.recorder = DumbRecorder() simple = Simple() metamodel.a = simple.a = 1. metamodel.b = simple.b = 2. metamodel.train_next = True simple.run() metamodel.run() metamodel.a = simple.a = 1. metamodel.b = simple.b = 2. metamodel.train_next = True simple.run() metamodel.run() self.assertEqual(metamodel.c.getvalue(), 3.) self.assertEqual(metamodel.d.getvalue(), -1.) self.assertEqual(metamodel.c.getvalue(), simple.c) self.assertEqual(metamodel.d.getvalue(), simple.d)