當前位置: 首頁>>代碼示例>>Python>>正文


Python api.CaseSet類代碼示例

本文整理匯總了Python中openmdao.lib.casehandlers.api.CaseSet的典型用法代碼示例。如果您正苦於以下問題:Python CaseSet類的具體用法?Python CaseSet怎麽用?Python CaseSet使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了CaseSet類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: ParetoFilterBase

class ParetoFilterBase(Component):
    """
    Base functionality for a pareto filter.
    Not to be instantiated directly. Should be subclassed.
    """

    def _is_dominated(self, y1, y2):
        """Tests to see if the point y1 is dominated by the point y2.
        True if y1 is dominated by y2, False otherwise.
        """
        if y1 == y2:
            return False
        for a, b in zip(y1, y2):
            if a < b:
                return False

        return True

    def execute(self):
        """Finds and removes pareto optimal points in the given case set.
        Returns a list of pareto optimal points. Smaller is better for all
        criteria.
        """
        #convert stuff to caseSets if they are not
        case_sets = []
        for ci in self.case_sets:
            if not isinstance(ci, CaseSet):
                case_sets.append(caseiter_to_caseset(ci))
            else:
                case_sets.append(ci)

        y_list = []
        if len(case_sets) > 1:
            case_set = case_sets[0].union(*case_sets[1:])
        else:
            case_set = case_sets[0]
        criteria_count = len(self.criteria)

        try:
            # need to transpose the list of outputs
            y_list = zip(*[case_set[crit] for crit in self.criteria])
        except KeyError:
            self.raise_exception('no cases provided had all of the outputs '
                 'matching the provided criteria, %s' % self.criteria, ValueError)

        y_temp = list(y_list)

        self.dominated_set = CaseSet()
        self.pareto_set = CaseSet()  # TODO: need a way to copy casesets

        for point1, case in zip(y_list, iter(case_set)):
            dominated = False
            for point2 in y_temp:
                if self._is_dominated(point1, point2):
                    self.dominated_set.record(case)
                    y_temp.remove(point1)
                    dominated = True
                    break
            if not dominated:
                self.pareto_set.record(case)
開發者ID:Daiyu506,項目名稱:OpenMDAO-Framework,代碼行數:60,代碼來源:pareto_filter.py

示例2: test_from_case

 def test_from_case(self):
     cs = CaseSet(self.case1)
     self.assertEqual(1, len(cs))
     self.assertEqual(cs[0]._inputs, self.case1_dup._inputs)
     self.assertEqual(cs[0]._outputs, self.case1_dup._outputs)
     cs.record(self.case2)
     cs.record(self.case1_dup)
     self.assertEqual(2, len(cs))
開發者ID:JustinSGray,項目名稱:OpenMDAO-Framework,代碼行數:8,代碼來源:test_caseset.py

示例3: test_iteration

 def test_iteration(self):
     cs = CaseSet()
     cs.record(self.case1)
     cs.record(self.case2)
     cs.record(self.case1_dup)
     expected = [self.case1, self.case2, self.case1_dup]
     for i,case in enumerate(cs):
         self.assertEqual(case._inputs, expected[i]._inputs)
         self.assertEqual(case._outputs, expected[i]._outputs)
開發者ID:JustinSGray,項目名稱:OpenMDAO-Framework,代碼行數:9,代碼來源:test_caseset.py

示例4: test_start_empty

 def test_start_empty(self):
     cs = CaseSet()
     cs.record(self.case1)
     cs.record(self.case2)
     cs.record(self.case1_dup)
     self.assertEqual(2, len(cs))
     self.assertEqual(cs[0]._inputs, self.case1_dup._inputs)
     self.assertEqual(cs[0]._outputs, self.case1_dup._outputs)
     self.assertEqual(cs[1]._inputs, self.case2._inputs)
     self.assertEqual(cs[1]._outputs, self.case2._outputs)
開發者ID:JustinSGray,項目名稱:OpenMDAO-Framework,代碼行數:10,代碼來源:test_caseset.py

示例5: test_ei_2obj

 def test_ei_2obj(self):
     ei = MultiObjExpectedImprovement()
     bests = CaseSet()
     list_of_cases = [Case(outputs=[("y1", 1), ("y2", 10)]), Case(outputs=[("y1", 1), ("y2", -10)])]
     for case in list_of_cases:
         bests.record(case)
     ei.best_cases = bests
     ei.criteria = ["y1", "y2"]
     ei.predicted_values = [NormalDistribution(mu=1, sigma=1), NormalDistribution(mu=0, sigma=1)]
     ei.calc_switch = "EI"
     ei.execute()
     self.assertAlmostEqual([5.0], ei.EI, 1)
     self.assertEqual(0.5, ei.PI, 6)
開發者ID:JustinSGray,項目名稱:OpenMDAO-Framework,代碼行數:13,代碼來源:test_expected_improvement_multiobj.py

示例6: test_ei_nobj

 def test_ei_nobj(self):
     ei = MultiObjExpectedImprovement(3)
     bests = CaseSet()
     list_of_cases = [Case(outputs=[("y1",1),("y2",1),("y3",1)])]
     for case in list_of_cases:
         bests.record(case)
     ei.best_cases = bests
     ei.criteria = ['y1','y2','y3']
     ei.predicted_values = [NormalDistribution(mu=1,sigma=1),
                            NormalDistribution(mu=1,sigma=1),
                            NormalDistribution(mu=1,sigma=1)]
     ei.execute()
     self.assertAlmostEqual(0.875,ei.PI,1)
開發者ID:Kenneth-T-Moore,項目名稱:OpenMDAO-Framework,代碼行數:13,代碼來源:test_expected_improvement_multiobj.py

示例7: test_bad_criteria

 def test_bad_criteria(self):
     ei = MultiObjExpectedImprovement(2)
     bests = CaseSet()
     list_of_cases = [Case(outputs=[("y1",1),("y2",1)])]
     for case in list_of_cases:
         bests.record(case)
     ei.best_cases = bests
     ei.criteria = ['y1','y3']
     ei.predicted_values = [NormalDistribution(mu=1,sigma=1),
                                                 NormalDistribution(mu=1,sigma=1)]
     try:
         ei.execute()
     except ValueError,err:
         self.assertEqual(str(err),": no cases in the provided case_set"
                             " had output matching the provided criteria, ['y1' 'y3']")
開發者ID:Kenneth-T-Moore,項目名稱:OpenMDAO-Framework,代碼行數:15,代碼來源:test_expected_improvement_multiobj.py

示例8: test_start_empty_subset

 def test_start_empty_subset(self):
     names=['comp1.a','comp2.c+comp2.d','comp1.b']
     ins = [names[0], names[2]]
     outs = [names[1]]
     cs = CaseSet(names=names)
     cs.record(self.case1)
     cs.record(self.case2)
     cs.record(self.case1_dup)
     self.assertEqual(2, len(cs))
     self.assertEqual(3, len(cs[0].items()))
     self.assertEqual(2, len(cs[0].items('in')))
     self.assertEqual(1, len(cs[0].items('out')))
     self.assertEqual(set(names), set(cs[0].keys()))
     self.assertEqual(set(ins), set(cs[0].keys('in')))
     self.assertEqual(set(outs), set(cs[0].keys('out')))
開發者ID:JustinSGray,項目名稱:OpenMDAO-Framework,代碼行數:15,代碼來源:test_caseset.py

示例9: test_start_empty_subset

 def test_start_empty_subset(self):
     names = ["comp1.a", "comp2.c+comp2.d", "comp1.b"]
     ins = [names[0], names[2]]
     outs = [names[1]]
     cs = CaseSet(names=names)
     cs.record(self.case1)
     cs.record(self.case2)
     cs.record(self.case1_dup)
     self.assertEqual(2, len(cs))
     self.assertEqual(3, len(cs[0].items()))
     self.assertEqual(2, len(cs[0].items("in")))
     self.assertEqual(1, len(cs[0].items("out")))
     self.assertEqual(set(names), set(cs[0].keys()))
     self.assertEqual(set(ins), set(cs[0].keys("in")))
     self.assertEqual(set(outs), set(cs[0].keys("out")))
開發者ID:hitej,項目名稱:meta-core,代碼行數:15,代碼來源:test_caseset.py

示例10: test_ei_calc_switch

 def test_ei_calc_switch(self):
     ei = MultiObjExpectedImprovement(3)
     bests = CaseSet()
     list_of_cases = [Case(outputs=[("y1",1),("y2",1),("y3",1)])]
     for case in list_of_cases:
         bests.record(case)
     ei.best_cases = bests
     ei.criteria = ['y1','y2','y3']
     ei.predicted_values = [NormalDistribution(mu=1,sigma=1),
                            NormalDistribution(mu=1,sigma=1),
                            NormalDistribution(mu=1,sigma=1)]
     ei.calc_switch = 'EI'
     try:
         ei.execute()
     except ValueError,err:
         self.assertEqual(str(err),': EI calculations not supported'
                                         ' for more than 2 objectives')
開發者ID:Kenneth-T-Moore,項目名稱:OpenMDAO-Framework,代碼行數:17,代碼來源:test_expected_improvement_multiobj.py

示例11: execute

    def execute(self):
        """Finds and removes pareto optimal points in the given case set.
        Returns a list of pareto optimal points. Smaller is better for all
        criteria.
        """
        #convert stuff to caseSets if they are not 
        case_sets = []
        for ci in self.case_sets: 
            if not isinstance(ci,CaseSet): 
                case_sets.append(caseiter_to_caseset(ci))
            else: 
                case_sets.append(ci)
        
        y_list = []
        if len(case_sets) > 1: 
            case_set = case_sets[0].union(*case_sets[1:])
        else: 
            case_set = case_sets[0]
        criteria_count = len(self.criteria)
        
        try: 
            # need to transpose the list of outputs
            y_list = zip(*[case_set[crit] for crit in self.criteria]) 
        except KeyError: 
            self.raise_exception('no cases provided had all of the outputs '
                 'matching the provided criteria, %s'%self.criteria, ValueError)
            
        y_temp = list(y_list)
        
        self.dominated_set = CaseSet()
        self.pareto_set = CaseSet() #TODO: need a way to copy casesets

        for point1, case in zip(y_list, iter(case_set)):
            dominated = False
            for point2 in y_temp:
                if self._is_dominated(point1, point2):
                    self.dominated_set.record(case)
                    y_temp.remove(point1)
                    dominated = True
                    break
            if not dominated: 
                self.pareto_set.record(case)
開發者ID:JustinSGray,項目名稱:OpenMDAO-Framework,代碼行數:42,代碼來源:pareto_filter.py

示例12: test_copy

 def test_copy(self):
     cs = CaseSet()
     cs.record(self.case1)
     cs.record(self.case2)
     cs.record(self.case1_dup)
     cscopy = cs.copy()
     for c1, c2 in zip(cs, cscopy):
         self.assertEqual(c1, c2)
開發者ID:JustinSGray,項目名稱:OpenMDAO-Framework,代碼行數:8,代碼來源:test_caseset.py

示例13: test_update_empty

 def test_update_empty(self):
     c1 = Case(inputs=[('x',10),], outputs=[('y',10)])
     c2 = Case(inputs=[('x',1),], outputs=[('y',1)])
     
     cs1 = CaseSet()
     cs1.record(c1)
     cs1.record(c2)
     
     cs2 = CaseSet()
     cs2.update(cs1)
     
     for c1,c2 in zip(cs1, cs2):
         self.assertEqual(c1, c2)
開發者ID:JustinSGray,項目名稱:OpenMDAO-Framework,代碼行數:13,代碼來源:test_caseset.py

示例14: test_reset_y_star_event

 def test_reset_y_star_event(self):
     ei = MultiObjExpectedImprovement(3)
     bests = CaseSet()
     list_of_cases = [Case(outputs=[("y1",1),("y2",1),("y3",1)])]
     for case in list_of_cases:
         bests.record(case)
     ei.best_cases = bests
     ei.criteria = ['y1','y2','y3']
     ei.predicted_values = [NormalDistribution(mu=1,sigma=1),
                                                 NormalDistribution(mu=1,sigma=1),
                                                 NormalDistribution(mu=1,sigma=1)]
     ei.execute()
     bests = CaseSet()
     list_of_cases = [Case(outputs=[("y1",2),("y2",2),("y3",2)])]
     for case in list_of_cases:
         bests.record(case)
     ei.best_cases = bests        
     ei.reset_y_star = True
     ei.execute()
     self.assertEqual(ei.y_star.all(),array([2,2,2]).all())
開發者ID:Kenneth-T-Moore,項目名稱:OpenMDAO-Framework,代碼行數:20,代碼來源:test_expected_improvement_multiobj.py

示例15: test_close

 def test_close(self):
     c1 = Case(inputs=[('x', 10)], outputs=[('y', 10)])
     cs1 = CaseSet()
     cs1.record_case(c1)
     cs1.close()
開發者ID:mghijs,項目名稱:OpenMDAO-Framework,代碼行數:5,代碼來源:test_caseset.py


注:本文中的openmdao.lib.casehandlers.api.CaseSet類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。