Ejemplo n.º 1
0
 def test_NonZeroMean(self):
     # Create the KL result
     numberOfVertices = 10
     interval = ot.Interval(-1.0, 1.0)
     mesh = ot.IntervalMesher([numberOfVertices - 1]).build(interval)
     covariance = ot.SquaredExponential()
     zeroProcess = ot.GaussianProcess(covariance, mesh)
     # Define a trend function
     f = ot.SymbolicFunction(["t"], ["30 * t"])
     fTrend = ot.TrendTransform(f, mesh)
     # Add it to the process
     process = ot.CompositeProcess(fTrend, zeroProcess)
     # Sample
     sampleSize = 100
     processSample = process.getSample(sampleSize)
     threshold = 0.0
     algo = ot.KarhunenLoeveSVDAlgorithm(processSample, threshold)
     algo.run()
     klresult = algo.getResult()
     # Create the KL reduction
     meanField = processSample.computeMean()
     klreduce = ot.KarhunenLoeveReduction(klresult)
     # Generate a trajectory and reduce it
     field = process.getRealization()
     values = field.getValues()
     reducedValues = klreduce(values)
     ott.assert_almost_equal(values, reducedValues)
Ejemplo n.º 2
0
# Define a scalar temporal Gaussian process on the mesh
# this process is stationary
# myXproc R^2 --> R
amplitude = [1.0]
scale = [0.2, 0.2]
myCovModel = ot.ExponentialModel(scale, amplitude)
myXproc = ot.GaussianProcess(myCovModel, myMesh)

# Transform myXproc to make its variance depend on the vertex (s,t)
# and to get a positive process
# thanks to the spatial function g
# myXtProcess R --> R
g = ot.SymbolicFunction(['x1'], ['exp(x1)'])
myDynTransform = ot.ValueFunction(g, 2)
myXtProcess = ot.CompositeProcess(myDynTransform, myXproc)

myField = myXtProcess.getRealization()
graphMarginal1 = ot.KernelSmoothing().build(myField.getValues()).drawPDF()
graphMarginal1.setTitle("")
graphMarginal1.setXTitle("X")
graphMarginal1.setLegendPosition("")

# Initiate a BoxCoxFactory
myBoxCoxFactory = ot.BoxCoxFactory()

graph = ot.Graph()
shift = [0.0]

# We estimate the lambda parameter from the field myField
# All values of the field are positive
Ejemplo n.º 3
0
# Define a scalar temporal normal process on the mesh
# this process is stationary
amplitude = [1.0]
scale = [0.01]*2
myCovModel = ot.ExponentialModel(scale, amplitude)
myXProcess = ot.GaussianProcess(myCovModel, myMesh)

# Create a trend function
# fTrend : R^2 --> R
#          (t,s) --> 1+2t+2s
fTrend = ot.SymbolicFunction(['t', 's'], ['1+2*t+2*s'])
fTemp = ot.TrendTransform(fTrend, myMesh)

# Add the trend to the initial process
myYProcess = ot.CompositeProcess(fTemp, myXProcess)

# Get a field from myYtProcess
myYField = myYProcess.getRealization()

# %%
# CASE 1 : we estimate the trend from the field

# Define the regression stategy using the LAR method
myBasisSequenceFactory = ot.LARS()

# Define the fitting algorithm using the
# Corrected Leave One Out or KFold algorithms
myFittingAlgorithm = ot.CorrectedLeaveOneOut()
myFittingAlgorithm_2 = ot.KFold()
Ejemplo n.º 4
0
    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)
Ejemplo n.º 5
0
# 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'])

# Convert g : R --> R into a spatial fucntion
# n is the dimension of the mesh
# of the field on wich g will be applied
Ejemplo n.º 6
0
grid = ot.RegularGrid(0.0, 0.1, 10)
amplitude = [5.0]
scale = [0.2]
covModel = ot.ExponentialModel(scale, amplitude)
X = ot.GaussianProcess(covModel, grid)

# %%
# Draw a sample
sample = X.getSample(6)
sample.setName('X')
graph = sample.drawMarginal(0)
view = viewer.View(graph)

# %%
# Define a trend function
f = ot.SymbolicFunction(['t'], ['30*t'])
fTrend = ot.TrendTransform(f, grid)

# %%
# Add it to the process
Y = ot.CompositeProcess(fTrend, X)
Y.setName('Y')

# %%
# Draw a sample
sample = Y.getSample(6)
sample.setName('Y')
graph = sample.drawMarginal(0)
view = viewer.View(graph)
plt.show()