コード例 #1
0
    def test_default_execute(self):
        metamodel = MetaModel()
        metamodel.name = 'meta'
        metamodel.default_surrogate = KrigingSurrogate()
        metamodel.model = Simple()
        metamodel.recorder = DumbRecorder()
        simple = Simple()

        #import pdb; pdb.set_trace()

        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)
コード例 #2
0
    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))
コード例 #3
0
ファイル: test_metamodel.py プロジェクト: hitej/meta-core
    def test_default_execute(self):
        metamodel = MetaModel()
        metamodel.name = 'meta'
        metamodel.default_surrogate = KrigingSurrogate()
        metamodel.model = Simple()
        metamodel.recorder = DumbRecorder()
        simple = Simple()


        #import pdb; pdb.set_trace()

        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)
コード例 #4
0
    def test_warm_start(self):
        metamodel = MetaModel()
        metamodel.name = 'meta'
        metamodel.default_surrogate = 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.default_surrogate = KrigingSurrogate()
        metamodel2.model = Simple()
        metamodel2.recorder = DumbRecorder()
        metamodel2.warm_start_data = case_iter

        metamodel2.a = simple.a = 1
        metamodel2.b = simple.b = 2
        metamodel.train_next = True
        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)
コード例 #5
0
 def test_warm_start(self): 
     metamodel = MetaModel()
     metamodel.name = 'meta'
     metamodel.default_surrogate = 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.default_surrogate = KrigingSurrogate()
     metamodel2.model = Simple()
     metamodel2.recorder = DumbRecorder()
     metamodel2.warm_start_data = case_iter
     
     metamodel2.a = simple.a = 1
     metamodel2.b = simple.b = 2
     metamodel.train_next = True
     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)        
コード例 #6
0
 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()
コード例 #7
0
    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()
コード例 #8
0
    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.0
        metamodel.b = simple.b = 2.0
        metamodel.train_next = True
        simple.run()
        metamodel.run()

        metamodel.a = simple.a = 3.0
        metamodel.b = simple.b = 4.0
        metamodel.train_next = True
        simple.run()
        metamodel.run()

        self.assertTrue(isinstance(metamodel.d, NormalDistribution))
        self.assertTrue(isinstance(metamodel.c, float))
コード例 #9
0
    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.0
        metamodel.b = simple.b = 2.0
        metamodel.train_next = True
        simple.run()
        metamodel.run()

        metamodel.a = simple.a = 1.0
        metamodel.b = simple.b = 2.0
        metamodel.train_next = True
        simple.run()
        metamodel.run()

        self.assertEqual(metamodel.c.getvalue(), 3.0)
        self.assertEqual(metamodel.d.getvalue(), -1.0)
        self.assertEqual(metamodel.c.getvalue(), simple.c)
        self.assertEqual(metamodel.d.getvalue(), simple.d)