当前位置: 首页>>代码示例>>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;未经允许,请勿转载。