Ejemplo n.º 1
0
        return Y


F = FUNC()
print('in_dim=' + str(F.getInputDimension()) + ' out_dim=' +
      str(F.getOutputDimension()) + ' spatial_dim=' +
      str(F.getInputMesh().getDimension()))

X = ot.Field(mesh, ot.Normal(2).getSample(11))
print(F(X.getValues()))

Xsample = ot.ProcessSample(5, X)
print(F(Xsample))

# Instance creation
myFunc = ot.FieldToPointFunction(F)

# Copy constructor
newFunc = ot.FieldToPointFunction(myFunc)

print('myFunc input dimension= ' + str(myFunc.getInputDimension()))
print('myFunc output dimension= ' + str(myFunc.getOutputDimension()))

print(myFunc(X.getValues()))

print(myFunc(Xsample))

vertices = []
vertices.append([0.0, 0.0, 0.0])
vertices.append([0.0, 0.0, 1.0])
vertices.append([0.0, 1.0, 0.0])
Ejemplo n.º 2
0
# %%
# Generate input realizations and the corresponding output from a Field->Point function
class pyf2p(ot.OpenTURNSPythonFieldToPointFunction):
    def __init__(self, mesh):
        super(pyf2p, self).__init__(mesh, 4, 1)
        self.setInputDescription(["x1", "x2", "x3", "x4"])
        self.setOutputDescription(['y'])

    def _exec(self, X):
        Xs = ot.Sample(X)
        x1, x2, x3, x4 = Xs.computeMean()
        y = x1 + x2 + x3 - x4 + x1 * x2 - x3 * x4 - 0.1 * x1 * x2 * x3
        return [y]


f = ot.FieldToPointFunction(pyf2p(tg))
N = 1000
x = X.getSample(N)
y = f(x)

# %%
# Run the field-vector algorithm that performs KL-decomposition of the inputs
# and chaos learning between the KL coefficients and the ouput vectors
algo = ot.FieldToPointFunctionalChaosAlgorithm(x, y)
# 1. KL parameters
algo.setCenteredSample(False)  # our input sample is not centered (default)
algo.setThreshold(4e-2)  # we expect to explain 96% of variance
algo.setRecompress(
    False
)  # whether to re-truncate modes according to a global eigen value threshold across inputs (default)
algo.setNbModes(10)  # max KL modes (default=unlimited)