1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
#! /usr/bin/env python
import openturns as ot
ot.TESTPREAMBLE()
# Default dimension parameter to evaluate the model
defaultDimension = 1
inputDimension = 1
# Amplitude values
amplitude = ot.Point(defaultDimension, 2.0)
# Scale values
scale = ot.Point(inputDimension, 1.0)
# Default constructor
myDefaultModel = ot.ExponentialModel()
print("myDefaultModel = ", myDefaultModel)
# Second order model with parameters
myModel = ot.ExponentialModel(scale, amplitude)
print("myModel = ", myModel)
timeValueOne = 1.0
print("covariance matrix at t = ", timeValueOne, " : ", myModel(timeValueOne))
print(
"covariance matrix at t = ",
-1.0 * timeValueOne,
" : ",
myModel(-1.0 * timeValueOne),
)
# Evaluation at time higher to check the decrease of the exponential values
timeValueHigh = 15.0
print(
"covariance matrix at t = ", timeValueHigh, " : ", myModel(timeValueHigh).__str__()
)
timeGrid = ot.RegularGrid(0.0, 1.0 / 3.0, 4)
print(
"discretized covariance over the time grid=",
timeGrid,
"is=",
myModel.discretize(timeGrid),
)
# Default dimension parameter to evaluate the model
highDimension = 3
# Reallocation of adequate sizes
amplitude.resize(highDimension)
spatialCorrelation = ot.CorrelationMatrix(highDimension)
for index in range(highDimension):
amplitude[index] = (index + 1) / (defaultDimension * defaultDimension)
if index > 0:
spatialCorrelation[index, index - 1] = 1.0 / (index * index)
# Second order model - dimension 10
myHighModel = ot.ExponentialModel(scale, amplitude, spatialCorrelation)
print("myHighModel = ", myHighModel)
print("covariance matrix at t = ", timeValueOne, " : ", myHighModel(timeValueOne))
print(
"covariance matrix at t = ",
-1.0 * timeValueOne,
" : ",
myHighModel(-1.0 * timeValueOne),
)
print("covariance matrix at t = ", timeValueHigh, " : ", myHighModel(timeValueHigh))
print(
"discretized covariance over the time grid=",
timeGrid,
"is=",
myHighModel.discretize(timeGrid),
)
marginal = myHighModel.getMarginal([0, 2])
print("parameters=", myHighModel.getParameter(), myHighModel.getParameterDescription())
print(
"marginal=",
marginal,
"marginal.parameter=",
marginal.getParameter(),
marginal.getParameterDescription(),
)
# parameter bug
model = ot.ExponentialModel([1.0] * 3, [2.0] * 2)
model.setActiveParameter(range(6))
p = model.getParameter()
print(p)
p[-1] = 0.5
model.setParameter(p)
p = model.getParameter()
print(p)
# draw bug
graph = ot.ExponentialModel().draw()
print("ok")
|