graph.add(curve)
graph.setLegendPosition('topright')
view = viewer.View(graph)

# %%
# Here is the decomposition at the second order:
#
# .. math::\underline{y} \, \approx \, \widehat{h}(\underline{x}) \, = \,                                                                                                                                                                                    
#         h(\underline{x}_0) \, + \, \sum_{i=1}^{n_{X}} \;                                                                                                                                                                                            
#       \frac{\partial h}{\partial x_i}(\underline{x}_0).\left(x_i - x_{0,i} \right) \, +                                                                                                                                                          
#      \, \frac{1}{2} \; \sum_{i,j=1}^{n_X} \;                                                                                                                                                                                                
#       \frac{\partial^2 h}{\partial x_i \partial x_j}(\underline{x}_0).\left(x_i - x_{0,i} \right).\left(x_j - x_{0,j} \right):math:``

# %%
# create a quadratic (2nd order) Taylor approximation
algo = ot.QuadraticTaylor(x0, model)
algo.run()
responseSurface = algo.getMetaModel()

# %%
# plot 2nd output of our model with x1=x0_1
graph = ot.ParametricFunction(responseSurface, [0], [x0[1]]).getMarginal(1).draw(a, b)
graph.setLegends(['taylor'])
curve = ot.ParametricFunction(model, [0], [x0[1]]).getMarginal(1).draw(a, b).getDrawable(0)
curve.setColor('red')
curve.setLegend('model')
graph.add(curve)
graph.setLegendPosition('topright')
view = viewer.View(graph)
plt.show()
示例#2
0
#! /usr/bin/env python

from __future__ import print_function
import openturns as ot

eps = 0.4
# Instance creation
myFunc = ot.Function(['x1', 'x2'], ['f1', 'f2', 'f3'],
                     ['x1*sin(x2)', 'cos(x1+x2)', '(x2+1)*exp(x1-2*x2)'])
center = ot.Point(myFunc.getInputDimension())
for i in range(center.getDimension()):
    center[i] = 1.0 + i
myTaylor = ot.QuadraticTaylor(center, myFunc)
myTaylor.run()
responseSurface = ot.Function(myTaylor.getResponseSurface())
print("myTaylor=", repr(myTaylor))
print("responseSurface=", repr(responseSurface))
print("myFunc(", repr(center), ")=", repr(myFunc(center)))
print("responseSurface(", repr(center), ")=", repr(responseSurface(center)))
inPoint = ot.Point(center)
inPoint[0] += eps
inPoint[1] -= eps / 2
print("myFunc(", repr(inPoint), ")=", repr(myFunc(inPoint)))
print("responseSurface(", repr(inPoint), ")=", repr(responseSurface(inPoint)))