FloatKrigingSurrogate() を使用して、openmdao 1.7.1 でサロゲートをトレーニングしようとしています。エラー メッセージが表示されます。
/applications/Frameworks/Python_Frameworks/OpenMDAO/openmdao-1.7.1/lib/python2.7/site-packages/openmdao/surrogate_models/kriging.py:145: RuntimeWarning: divide by zero encountered in log
reduced_likelihood = -(np.log(np.sum(sigma2)) + logdet / self.n_samples)
/applications/Python_distributions/python2.7_anaconda/lib/python2.7/site-packages/scipy/optimize/slsqp.py:62: RuntimeWarning: invalid value encountered in subtract
jac[i] = (func(*((x0+dx,)+args)) - f0)/epsilon
Traceback (most recent call last):
File "/applications/Frameworks/Python_Frameworks/OpenMDAO/openmdao-1.7.1/lib/python2.7/site-packages/openmdao/drivers/predeterminedruns_driver.py", line 441, in _try_case
root.solve_nonlinear(metadata=metadata)
File "/applications/Frameworks/Python_Frameworks/OpenMDAO/openmdao-1.7.1/lib/python2.7/site-packages/openmdao/core/group.py", line 733, in solve_nonlinear
self.nl_solver.solve(params, unknowns, resids, self, metadata)
File "/applications/Frameworks/Python_Frameworks/OpenMDAO/openmdao-1.7.1/lib/python2.7/site-packages/openmdao/solvers/solver_base.py", line 23, in wrapper
fn(driver, params, unknowns, resids, system, metadata)
File "/applications/Frameworks/Python_Frameworks/OpenMDAO/openmdao-1.7.1/lib/python2.7/site-packages/openmdao/solvers/run_once.py", line 51, in solve
system.children_solve_nonlinear(local_meta)
File "/applications/Frameworks/Python_Frameworks/OpenMDAO/openmdao-1.7.1/lib/python2.7/site-packages/openmdao/core/group.py", line 751, in children_solve_nonlinear
sub._sys_solve_nonlinear(sub.params, sub.unknowns, sub.resids)
File "/applications/Frameworks/Python_Frameworks/OpenMDAO/openmdao-1.7.1/lib/python2.7/site-packages/openmdao/core/component.py", line 617, in _sys_solve_nonlinear
self.solve_nonlinear(params, unknowns, resids)
File "/applications/Frameworks/Python_Frameworks/OpenMDAO/openmdao-1.7.1/lib/python2.7/site-packages/openmdao/components/meta_model.py", line 211, in solve_nonlinear
self._train()
File "/applications/Frameworks/Python_Frameworks/OpenMDAO/openmdao-1.7.1/lib/python2.7/site-packages/openmdao/components/meta_model.py", line 371, in _train
surrogate.train(self._training_input, self._training_output[name])
File "/applications/Frameworks/Python_Frameworks/OpenMDAO/openmdao-1.7.1/lib/python2.7/site-packages/openmdao/surrogate_models/kriging.py", line 96, in train
bounds=bounds)
File "/applications/Python_distributions/python2.7_anaconda/lib/python2.7/site-packages/scipy/optimize/_minimize.py", line 455, in minimize
constraints, callback=callback, **options)
File "/applications/Python_distributions/python2.7_anaconda/lib/python2.7/site-packages/scipy/optimize/slsqp.py", line 363, in _minimize_slsqp
fx = func(x)
File "/applications/Python_distributions/python2.7_anaconda/lib/python2.7/site-packages/scipy/optimize/optimize.py", line 289, in function_wrapper
return function(*(wrapper_args + args))
File "/applications/Frameworks/Python_Frameworks/OpenMDAO/openmdao-1.7.1/lib/python2.7/site-packages/openmdao/surrogate_models/kriging.py", line 89, in _calcll
loglike = self._calculate_reduced_likelihood_params(np.exp(thetas))[0]
File "/applications/Frameworks/Python_Frameworks/OpenMDAO/openmdao-1.7.1/lib/python2.7/site-packages/openmdao/surrogate_models/kriging.py", line 133, in _calculate_reduced_likelihood_params
[U,S,Vh] = linalg.svd(R)
File "/applications/Python_distributions/python2.7_anaconda/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py", line 88, in svd
a1 = _asarray_validated(a, check_finite=check_finite)
File "/applications/Python_distributions/python2.7_anaconda/lib/python2.7/site-packages/scipy/_lib/_util.py", line 187, in _asarray_validated
a = toarray(a)
File "/applications/Python_distributions/python2.7_anaconda/lib/python2.7/site-packages/numpy/lib/function_base.py", line 1033, in asarray_chkfinite
"array must not contain infs or NaNs")
ValueError: array must not contain infs or NaNs
Traceback (most recent call last):
File "C3DMMdriver.py", line 321, in <module>
sample.run()
File "/applications/Frameworks/Python_Frameworks/OpenMDAO/openmdao-1.7.1/lib/python2.7/site-packages/openmdao/core/problem.py", line 1167, in run
self.driver.run(self)
File "/applications/Frameworks/Python_Frameworks/OpenMDAO/openmdao-1.7.1/lib/python2.7/site-packages/openmdao/drivers/predeterminedruns_driver.py", line 409, in run
self._run_serial()
File "/applications/Frameworks/Python_Frameworks/OpenMDAO/openmdao-1.7.1/lib/python2.7/site-packages/openmdao/drivers/predeterminedruns_driver.py", line 473, in _run_serial
exec('raise exc[0], exc[1], exc[2]')
File "/applications/Frameworks/Python_Frameworks/OpenMDAO/openmdao-1.7.1/lib/python2.7/site-packages/openmdao/drivers/predeterminedruns_driver.py", line 441, in _try_case
root.solve_nonlinear(metadata=metadata)
File "/applications/Frameworks/Python_Frameworks/OpenMDAO/openmdao-1.7.1/lib/python2.7/site-packages/openmdao/core/group.py", line 733, in solve_nonlinear
self.nl_solver.solve(params, unknowns, resids, self, metadata)
File "/applications/Frameworks/Python_Frameworks/OpenMDAO/openmdao-1.7.1/lib/python2.7/site-packages/openmdao/solvers/solver_base.py", line 23, in wrapper
fn(driver, params, unknowns, resids, system, metadata)
File "/applications/Frameworks/Python_Frameworks/OpenMDAO/openmdao-1.7.1/lib/python2.7/site-packages/openmdao/solvers/run_once.py", line 51, in solve
system.children_solve_nonlinear(local_meta)
File "/applications/Frameworks/Python_Frameworks/OpenMDAO/openmdao-1.7.1/lib/python2.7/site-packages/openmdao/core/group.py", line 751, in children_solve_nonlinear
sub._sys_solve_nonlinear(sub.params, sub.unknowns, sub.resids)
File "/applications/Frameworks/Python_Frameworks/OpenMDAO/openmdao-1.7.1/lib/python2.7/site-packages/openmdao/core/component.py", line 617, in _sys_solve_nonlinear
self.solve_nonlinear(params, unknowns, resids)
File "/applications/Frameworks/Python_Frameworks/OpenMDAO/openmdao-1.7.1/lib/python2.7/site-packages/openmdao/components/meta_model.py", line 211, in solve_nonlinear
self._train()
File "/applications/Frameworks/Python_Frameworks/OpenMDAO/openmdao-1.7.1/lib/python2.7/site-packages/openmdao/components/meta_model.py", line 371, in _train
surrogate.train(self._training_input, self._training_output[name])
File "/applications/Frameworks/Python_Frameworks/OpenMDAO/openmdao-1.7.1/lib/python2.7/site-packages/openmdao/surrogate_models/kriging.py", line 96, in train
bounds=bounds)
File "/applications/Python_distributions/python2.7_anaconda/lib/python2.7/site-packages/scipy/optimize/_minimize.py", line 455, in minimize
constraints, callback=callback, **options)
File "/applications/Python_distributions/python2.7_anaconda/lib/python2.7/site-packages/scipy/optimize/slsqp.py", line 363, in _minimize_slsqp
fx = func(x)
File "/applications/Python_distributions/python2.7_anaconda/lib/python2.7/site-packages/scipy/optimize/optimize.py", line 289, in function_wrapper
return function(*(wrapper_args + args))
File "/applications/Frameworks/Python_Frameworks/OpenMDAO/openmdao-1.7.1/lib/python2.7/site-packages/openmdao/surrogate_models/kriging.py", line 89, in _calcll
loglike = self._calculate_reduced_likelihood_params(np.exp(thetas))[0]
File "/applications/Frameworks/Python_Frameworks/OpenMDAO/openmdao-1.7.1/lib/python2.7/site-packages/openmdao/surrogate_models/kriging.py", line 133, in _calculate_reduced_likelihood_params
[U,S,Vh] = linalg.svd(R)
File "/applications/Python_distributions/python2.7_anaconda/lib/python2.7/site-packages/scipy/linalg/decomp_svd.py", line 88, in svd
a1 = _asarray_validated(a, check_finite=check_finite)
File "/applications/Python_distributions/python2.7_anaconda/lib/python2.7/site-packages/scipy/_lib/_util.py", line 187, in _asarray_validated
a = toarray(a)
File "/applications/Python_distributions/python2.7_anaconda/lib/python2.7/site-packages/numpy/lib/function_base.py", line 1033, in asarray_chkfinite
"array must not contain infs or NaNs")
ValueError: array must not contain infs or NaNs
モデルを作成しているアプリケーションのデータ ファイルを確認しました。トレーニング データをファイルにコピーして確認しました。すべては数字です。常に混乱するわけではありませんが、サンプリング部分がネストされている大きな問題のこの部分を作成するつもりです。めちゃくちゃになっているものを他にどのように探すことができますか?私のコードの抜粋:
class C3DMM(MetaModel):
def __init__(self):
super(C3DMM, self).__init__()
self.add_param('AOA', val= 0.)
self.add_output('cl', val=0., surrogate=FloatKrigingSurrogate())
self.add_output('cd', val=0., surrogate=FloatKrigingSurrogate())
self.add_output('cm', val=0., surrogate=FloatKrigingSurrogate())
self.add_output('wfy', val=0., surrogate=FloatKrigingSurrogate())
self.add_output('wfx', val=0., surrogate=FloatKrigingSurrogate())
self.add_output('wmz', val=0., surrogate=FloatKrigingSurrogate())
self.add_output('hfy', val=0., surrogate=FloatKrigingSurrogate())
self.add_output('hfx', val=0., surrogate=FloatKrigingSurrogate())
self.add_output('dlcoefs', val=np.zeros(96), surrogate=FloatKrigingSurrogate())
class C3Dsurr(Group):
def __init__(self,):
super(C3Dsurr, self).__init__()
# Create meta_model for C3D with response
self.add('c3dmm', C3DMM())
# Create variable for problem interaction
self.add('mmalp', IndepVarComp('AOA',0.))
self.connect('mmalp.AOA','c3dmm.AOA')
...
train=Problem(root=Group())
train.root.add('train', IndepVarComp('AOA',0.))
train.root.add('c3d',GoC3D())
train.root.connect('train.AOA','c3d.AOA')
train.driver = FullFactorialDriver(num_levels=samples)
train.driver.add_desvar("train.AOA", lower= -4.,\
upper= 32.)
recorder = InMemoryRecorder()
recorder.options['record_params'] = True
recorder.options['record_metadata'] = True
train.driver.add_recorder(recorder)
train.setup()
train.run()
train.cleanup()
...
sample=Problem(root=C3Dsurr())
...
sample.setup()
# train the surrogate
alp_train=[]
cl_train=[]
cm_train=[]
cd_train=[]
wfy_train=[]
wfx_train=[]
wmz_train=[]
hfy_train=[]
hfx_train=[]
knot_train=[]
dlc_train=[]
if debug:
dbfile=open('C3Dsample.dat','w')
dbfile.write('variables=AOA,cl,cm,cd,wfy,wfx,wmz,hfy,hfx,knots,coefs\n')
dbfile.write('variables=AOA,cl,cm,cd,wfy,wfx,wmz,hfy,hfx,coefs\n')
for line in recorder.iters:
alp_train.append(line['params']['c3d.AOA'])
cl_train.append(line['unknowns']['c3d.cl'])
cm_train.append(line['unknowns']['c3d.cm'])
cd_train.append(line['unknowns']['c3d.cd'])
wfy_train.append(line['unknowns']['c3d.wfy'])
wfx_train.append(line['unknowns']['c3d.wfx'])
wmz_train.append(line['unknowns']['c3d.wmz'])
hfy_train.append(line['unknowns']['c3d.hfy'])
hfx_train.append(line['unknowns']['c3d.hfx'])
#knot_train.append(line['unknowns']['c3d.knots'].flatten())
dlc_train.append(line['unknowns']['c3d.dlcoefs'].flatten())
if debug:
dbfile.write('%f '% line['params']['c3d.AOA'])
dbfile.write('%f '% line['unknowns']['c3d.cl'])
dbfile.write('%f '% line['unknowns']['c3d.cm'])
dbfile.write('%f '% line['unknowns']['c3d.cd'])
dbfile.write('%f '% line['unknowns']['c3d.wfy'])
dbfile.write('%f '% line['unknowns']['c3d.wfx'])
dbfile.write('%f '% line['unknowns']['c3d.wmz'])
dbfile.write('%f '% line['unknowns']['c3d.hfy'])
dbfile.write('%f '% line['unknowns']['c3d.hfx'])
#for each in line['unknowns']['c3d.knots'].flatten():
#dbfile.write('%f '%each)
for each in line['unknowns']['c3d.dlcoefs'].flatten():
dbfile.write('%f '%each)
dbfile.write('\n')
...
sample.setup()
# train the surrogate
sample['c3dmm.train:AOA']=alp_train
sample['c3dmm.train:cl']=cl_train
sample['c3dmm.train:cm']= cm_train
sample['c3dmm.train:cd']= cd_train
sample['c3dmm.train:wfy']= wfy_train
sample['c3dmm.train:wfx']= wfx_train
sample['c3dmm.train:wmz']= wmz_train
sample['c3dmm.train:hfy']= hfy_train
sample['c3dmm.train:hfx']= hfx_train
#sample['c3dmm.train:knots']= knot_train
sample['c3dmm.train:dlcoefs']= dlc_train
sample.run()
Kenneth のコメントに基づく 9 月 1 日の改訂: どうやらクリギング サロゲート モデルには課題が必要です。f(x)=constant のように骨の折れる単純な関数は好きではありません。ドキュメントのメタモデルの例の問題を少し修正しました。
from __future__ import print_function
import sys
import numpy as np
from openmdao.api import Group, Component, MetaModel, KrigingSurrogate, FloatKrigingSurrogate
class TrigMM(Group):
''' FloatKriging gives responses as floats '''
def __init__(self):
super(TrigMM, self).__init__()
# Create meta_model for f_x as the response
sin_mm = self.add("sin_mm", MetaModel())
sin_mm.add_param('x', val=0.)
sin_mm.add_output('f_x:float', val=0., surrogate=FloatKrigingSurrogate())
# train a vector or a set of scalars
#sin_mm.add_output('g', val=np.zeros(SURVECSIZ), surrogate=KrigingSurrogate())
for each in range(SURVECSIZ):
sin_mm.add_output('g%d'%each, val=0., surrogate=FloatKrigingSurrogate())
from openmdao.api import Problem
prob = Problem()
prob.root = TrigMM()
prob.setup()
#traning data is just set manually. No connected input needed, since
# we're assuming the data is pre-existing
prob['sin_mm.train:x'] = np.linspace(0,10,20)
prob['sin_mm.train:f_x:float'] = np.sin(prob['sin_mm.train:x'])
for each in range(SURVECSIZ):
prob['sin_mm.train:g%d'%each]=np.sin(prob['sin_mm.train:x'])*(float(each))
try:
samplex=float(sys.argv[1])
except IndexError:
samplex=2.1
prob['sin_mm.x'] = samplex #prediction happens at this value
prob.run()
print('float predicted:', '%3.4f'%prob['sin_mm.f_x:float']) #predicted value
print('float actual :', '%3.4f'%np.sin(samplex))
for each in range(SURVECSIZ):
print('g%d predicted:'%each, '%3.4f,'%prob['sin_mm.g%d'%each]) #predicted value
print('g actual :', '%3.4f'%(np.sin(samplex)*(float(each))))
私は最初、サロゲートの最大数があるかどうか疑問に思っていたので、その変数 SURVECSIZ を作成しました。SURVECSIZ=1 でも死にました。しかし、gi の関数を (float(each)+1.) で乗算するように変更すると、実行されます。+1 を括弧の外側に置いて、値を 0 ではなく定数 = 1 にすることも、それを停止させます。クリギング モデル プロセスは、データの変動範囲によって正規化されると思います。クリギングは単純な問題で時間を無駄にしたくありません。残念ながら、バリエーションがゼロである場合があり、クリギング モデルでそれを許可する必要があります。