本文整理汇总了Python中openmdao.lib.casehandlers.api.CaseSet.record方法的典型用法代码示例。如果您正苦于以下问题:Python CaseSet.record方法的具体用法?Python CaseSet.record怎么用?Python CaseSet.record使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openmdao.lib.casehandlers.api.CaseSet
的用法示例。
在下文中一共展示了CaseSet.record方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ParetoFilterBase
# 需要导入模块: from openmdao.lib.casehandlers.api import CaseSet [as 别名]
# 或者: from openmdao.lib.casehandlers.api.CaseSet import record [as 别名]
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)
示例2: test_from_case
# 需要导入模块: from openmdao.lib.casehandlers.api import CaseSet [as 别名]
# 或者: from openmdao.lib.casehandlers.api.CaseSet import record [as 别名]
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))
示例3: test_copy
# 需要导入模块: from openmdao.lib.casehandlers.api import CaseSet [as 别名]
# 或者: from openmdao.lib.casehandlers.api.CaseSet import record [as 别名]
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)
示例4: test_iteration
# 需要导入模块: from openmdao.lib.casehandlers.api import CaseSet [as 别名]
# 或者: from openmdao.lib.casehandlers.api.CaseSet import record [as 别名]
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)
示例5: test_start_empty
# 需要导入模块: from openmdao.lib.casehandlers.api import CaseSet [as 别名]
# 或者: from openmdao.lib.casehandlers.api.CaseSet import record [as 别名]
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)
示例6: test_ei_2obj
# 需要导入模块: from openmdao.lib.casehandlers.api import CaseSet [as 别名]
# 或者: from openmdao.lib.casehandlers.api.CaseSet import record [as 别名]
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)
示例7: test_ei_nobj
# 需要导入模块: from openmdao.lib.casehandlers.api import CaseSet [as 别名]
# 或者: from openmdao.lib.casehandlers.api.CaseSet import record [as 别名]
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)
示例8: test_update_empty
# 需要导入模块: from openmdao.lib.casehandlers.api import CaseSet [as 别名]
# 或者: from openmdao.lib.casehandlers.api.CaseSet import record [as 别名]
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)
示例9: test_start_empty_subset
# 需要导入模块: from openmdao.lib.casehandlers.api import CaseSet [as 别名]
# 或者: from openmdao.lib.casehandlers.api.CaseSet import record [as 别名]
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')))
示例10: test_bad_criteria
# 需要导入模块: from openmdao.lib.casehandlers.api import CaseSet [as 别名]
# 或者: from openmdao.lib.casehandlers.api.CaseSet import record [as 别名]
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']")
示例11: test_start_empty_subset
# 需要导入模块: from openmdao.lib.casehandlers.api import CaseSet [as 别名]
# 或者: from openmdao.lib.casehandlers.api.CaseSet import record [as 别名]
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")))
示例12: test_ei_calc_switch
# 需要导入模块: from openmdao.lib.casehandlers.api import CaseSet [as 别名]
# 或者: from openmdao.lib.casehandlers.api.CaseSet import record [as 别名]
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')
示例13: test_reset_y_star_event
# 需要导入模块: from openmdao.lib.casehandlers.api import CaseSet [as 别名]
# 或者: from openmdao.lib.casehandlers.api.CaseSet import record [as 别名]
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())
示例14: test_set_ops
# 需要导入模块: from openmdao.lib.casehandlers.api import CaseSet [as 别名]
# 或者: from openmdao.lib.casehandlers.api.CaseSet import record [as 别名]
def test_set_ops(self):
cs = CaseSet()
cs2 = CaseSet()
for case in self.caselist:
cs.record(case)
cs2.record(case)
self.assertEqual(len(cs), len(self.caselist)-2)
self.assertTrue(cs == cs2)
case = cs2.pop(1)
self.assertFalse(cs == cs2)
self.assertTrue(cs2 < cs)
self.assertFalse(cs < cs)
self.assertTrue(cs <= cs)
self.assertTrue(cs >= cs)
self.assertFalse(cs2 > cs)
self.assertFalse(cs2 > cs2)
self.assertTrue(case in cs)
self.assertFalse(case in cs2)
self.assertTrue(case not in cs2)
self.assertFalse(case not in cs)
diffset = cs - cs2
self.assertEqual(len(diffset), 1)
self.assertTrue(case in diffset)
cs3 = CaseSet()
cs4 = CaseSet()
cs3.record(self.case1)
cs3.record(self.case2)
try:
self.assertTrue(cs3.isdisjoint(cs4))
except ValueError, err:
self.assertEqual(str(err), "case containers have different sets of variables")
示例15: ParetoFilter
# 需要导入模块: from openmdao.lib.casehandlers.api import CaseSet [as 别名]
# 或者: from openmdao.lib.casehandlers.api.CaseSet import record [as 别名]
from matplotlib import pyplot as py
from mpl_toolkits.mplot3d import Axes3D
from numpy import random
random.seed(10)
from openmdao.main.case import Case
pf = ParetoFilter()
# 2D PARETO FILTERING EXAMPLE
n = 1000
x = random.uniform(-1, 0, n)
y = -(1-x**2)**0.5*random.random(n)
cases = CaseSet()
for x_0, y_0 in zip(x, y):
cases.record(Case(inputs=[("x", x_0), ("y", y_0)]))
pf.case_sets = [cases]
pf.criteria = ['x', 'y']
pf.execute()
x_p, y_p = pf.pareto_set['x'],pf.pareto_set['y']
x_dom, y_dom = pf.dominated_set['x'],pf.dominated_set['y']
py.figure()
py.scatter(x, y, s=5)
py.scatter(x_dom, y_dom, c='', edgecolor='b', s=80)
py.scatter(x_p, y_p, c='', edgecolors='r', s=80)
#3D PARETO FILTERING EXAMPLE
n = 1000