def _exec(self, X): f = ot.Function( ot.PiecewiseLinearEvaluation( [x[0] for x in self.getInputMesh().getVertices()], X)) outputValues = ot.Sample(0, 1) for t in self.getOutputMesh().getVertices(): kernel = ot.Normal(t[0], 0.05) def pdf(X): return [kernel.computePDF(X)] weight = ot.Function(ot.PythonFunction(1, 1, pdf)) outputValues.add( self.algo_.integrate(weight * f, kernel.getRange())) return outputValues N = 5 X = ot.GaussianProcess(ot.GeneralizedExponential([0.1], 1.0), mesh) f = ot.FieldFunction(GaussianConvolution()) Y = ot.CompositeProcess(f, X) x_graph = X.getSample(N).drawMarginal(0) y_graph = Y.getSample(N).drawMarginal(0) fig = plt.figure(figsize=(10, 4)) plt.suptitle("Composite process") x_axis = fig.add_subplot(121) y_axis = fig.add_subplot(122) View(x_graph, figure=fig, axes=[x_axis], add_legend=False) View(y_graph, figure=fig, axes=[y_axis], add_legend=False)
return True 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.FieldFunction(F) # Copy constructor newFunc = ot.FieldFunction(myFunc) print(('myFunc input dimension= ' + str(myFunc.getInputDimension()))) print(('myFunc output dimension= ' + str(myFunc.getOutputDimension()))) print(myFunc(X.getValues())) print(myFunc(Xsample)) print('point-wise?', myFunc.isActingPointwise()) vertices = [] vertices.append([0.0, 0.0, 0.0])
for j in range(size): self.mat_W_[i, j] = values_w[j, 0] G = mesh.computeP1Gram() self.mat_W_ = self.mat_W_ * G def _exec(self, X): point_X = [val[0] for val in X] values_Y = self.mat_W_ * point_X return [[v] for v in values_Y] # %% # Dynamical model: convolution wrt kernel p print("Create the convolution function") p = ot.SymbolicFunction("x", "exp(-(x/" + str(h) + ")^2)") myConvolution = ot.FieldFunction(ConvolutionP1(p, mesh)) # %% # Output database generation print("Sample the output process") sample_Y = myConvolution(sample_X) # %% # Karhunen-Loeve decomposition of the output process print("Compute the decomposition of the output process") algo_Y = ot.KarhunenLoeveSVDAlgorithm(sample_Y, threshold) algo_Y.run() result_Y = algo_Y.getResult() phi_Y = result_Y.getScaledModesAsProcessSample() lambda_Y = result_Y.getEigenvalues() graph_modes_Y, graph_ev_Y = drawKL(phi_Y, lambda_Y, mesh, "Y")
deltaT = 0.1 steps = 11 # Initialization of the TimeGrid timeGrid timeGrid = ot.RegularGrid(Tmin, deltaT, steps) # Creation of the Antecedent myARMAProcess = ot.ARMA() myARMAProcess.setTimeGrid(timeGrid) print('myAntecedentProcess = ', myARMAProcess) # Creation of a function f = ot.SymbolicFunction(['x'], ['2 * x + 5.0']) # We build a dynamical function myFieldFunction = ot.FieldFunction(ot.ValueFunction(f)) # finally we get the compsite process myCompositeProcess = ot.CompositeProcess(myFieldFunction, myARMAProcess) print('myCompositeProcess = ', repr(myCompositeProcess)) # Test realization print('One realization= ') print(myCompositeProcess.getRealization()) # # Create a spatial dynamical function # Create the function g : R^2 --> R^2 # (x1,x2) --> (x1^2, x1+x2) g = ot.SymbolicFunction(['x1', 'x2'], ['x1^2', 'x1+x2'])
deltaT = 0.1 steps = 11 # Initialization of the TimeGrid timeGrid timeGrid = ot.RegularGrid(Tmin, deltaT, steps) # Creation of the Antecedent myARMAProcess = ot.ARMA() myARMAProcess.setTimeGrid(timeGrid) print('myAntecedentProcess = ', myARMAProcess) # Creation of a function f = ot.SymbolicFunction(['t', 'x'], ['t+0.1*x^2']) # We build a dynamical function myFieldFunction = ot.FieldFunction(ot.VertexValueFunction(f, timeGrid)) # finally we get the compsite process myCompositeProcess = ot.CompositeProcess(myFieldFunction, myARMAProcess) print('myCompositeProcess = ', repr(myCompositeProcess)) # Test realization print('One realization= ') print(myCompositeProcess.getRealization()) # future print('future=', myCompositeProcess.getFuture(5)) # # Create a spatial dynamical function # Create the function g : R^2 --> R^2
#! /usr/bin/env python from __future__ import print_function import openturns as ot # Create an intance myFunc = ot.FieldFunction() print('myFunc=', myFunc) # Get the input and output description print('myFunc input description=', myFunc.getInputDescription()) print('myFunc output description=', myFunc.getOutputDescription()) # Get the input and output dimension, based on description print('myFunc input dimension=', myFunc.getInputDimension()) print('myFunc output dimension=', myFunc.getOutputDimension()) print('myFunc input dimension=', myFunc.getInputMesh().getDimension()) # Get the number of calls print('called ', myFunc.getCallsNumber(), ' times')
import openturns as ot class OpenTURNSPythonFieldFunction(object): def __init__(self): self.__mesh = ot.Mesh(42) def getInputMesh(self): return self.__mesh obj = OpenTURNSPythonFieldFunction() f = ot.FieldFunction(obj) print('OK')