Reputation: 1151
In general, I have a model g which has observed inputs X, parameters θ and observed outputs Y. However, there are some situations where I have no observed inputs X. In this case, using OpenTURNS seems to be impossible, because the constructor of e.g. the LinearLeastSquaresCalibration
class requires an input sample.
In order to provide a basic use case, let me consider the following example, adapted from the documentation of the LinearLeastSquaresCalibration
class.
We first define the model g to be calibrated.
import numpy as np
import openturns as ot
# We define the model g which has 3 inputs and one output H.
def functionFlooding(X) :
L = 5.0e3
B = 300.0
Q, K_s, DeltaZ = X
alpha = DeltaZ/L
if alpha < 0.0 or K_s <= 0.0:
H = np.inf
else:
H = (Q/(K_s*B*np.sqrt(alpha)))**(3.0/5.0)
return [H]
g = ot.PythonFunction(3, 1, functionFlooding)
g = ot.MemoizeFunction(g)
g.setOutputDescription(["H (m)"])
Then we define the input random vector.
This is a set of 3 Dirac
distributions.
# Set the parameters to be calibrated.
Q = ot.Dirac(1013.0)
K_s = ot.Dirac(30.0)
DeltaZ = ot.Dirac(5.0)
# Create the joint input distribution.
inputRandomVector = ot.ComposedDistribution([Q, K_s, DeltaZ])
Then we create a Monte-Carlo sample of the output H. In this case, this is a sample which contains a constant value.
nbobs = 100
inputSample = inputRandomVector.getSample(nbobs)
outputH = g(inputSample)
Then we generate the observation noise and add it to the output of the model.
sigmaObservationNoiseH = 0.1 # (m)
noiseH = ot.Normal(0.0, sigmaObservationNoiseH)
sampleNoiseH = noiseH.getSample(nbobs)
Hobs = outputH + sampleNoiseH
Finally, we define the value of the reference values of the theta parameter.
QInitial = 1000.0
KsInitial = 20.0
DeltaZInitial = 2.0
thetaPrior = ot.Point([QInitial,KsInitial,DeltaZInitial])
Then we come to the core of the example. The following statement create the calibrated function from the model.
calibratedIndices = [0,1,2]
mycf = ot.ParametricFunction(g, calibratedIndices, thetaPrior)
Therefore, the calibrated function has no input and this is why we set an empty list as input argument to check it works.
>>> print(mycf([]))
[3.56855]
The constructor of the class requires a sample inputObservations
:
LinearLeastSquaresCalibration(
model, inputObservations,
outputObservations, candidate, methodName)
However, in this case, we do not have such an input sample. How may I use the calibration tool?
Upvotes: 1
Views: 124
Reputation: 1151
Since we have no input observation, we create an empty Sample
as input.
emptyInputObservations = [[]]*len(Hobs)
algo = ot.LinearLeastSquaresCalibration(
mycf, emptyInputObservations, Hobs, thetaPrior, "SVD")
The other classes NonLinearLeastSquaresCalibration
, GaussianLinearCalibration
and GaussianNonLinearCalibration
work the same way.
Upvotes: 1