Created
November 25, 2020 07:53
-
-
Save sofianehaddad/300e8e5a3218450544e5da776477cf5c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import openturns as ot | |
inputDimension = 2 | |
# Learning data | |
levels = [8, 5] | |
levels = [6, 3] | |
box = ot.Box(levels) | |
inputSample = box.generate() | |
# Scale each direction | |
inputSample *= 10.0 | |
model = ot.SymbolicFunction(['x', 'y'], ['cos(0.5*x) + sin(y)']) | |
outputSample = model(inputSample) | |
# Validation | |
sampleSize = 10 | |
inputValidSample = ot.ComposedDistribution( | |
2 * [ot.Uniform(0, 10.0)]).getSample(sampleSize) | |
outputValidSample = model(inputValidSample) | |
# Basis definition | |
basis = ot.LinearBasisFactory(inputDimension).build() | |
# Ref model (estimated using SquaredCovModel) | |
referenceModel = ot.SquaredExponential( | |
[6.2201668395757395, 3.6347426450644695], [4.288043776733477]) | |
rho = ot.SymbolicFunction(['x', 'y'], ['exp(-0.5* (x * x + y * y))']) | |
covarianceModel = ot.StationaryFunctionalCovarianceModel([5, 2], [1], rho) | |
# Kriging algorithm | |
algo = ot.KrigingAlgorithm(inputSample, outputSample, | |
covarianceModel, basis) | |
algo.setOptimizationBounds(ot.Interval([1e-1, 1e-1], [20, 20])) | |
startingPoints = ot.LHSExperiment(ot.ComposedDistribution(2 * [ot.Uniform(0, 20.0)]), 5).generate() | |
algo.setOptimizationAlgorithm(ot.MultiStart(ot.TNC(), startingPoints)) | |
ot.TBB.Disable() | |
algo.run() | |
result = algo.getResult() | |
# Get meta model | |
metaModel = result.getMetaModel() | |
# | |
#outData = metaModel(inputValidSample) | |
val = ot.MetaModelValidation(inputValidSample, outputValidSample, metaModel) | |
#print(outData - outputValidSample) | |
print(result.getCovarianceModel()) | |
print(val.computePredictivityFactor())# -> reference value is 0.898269 | |
""" | |
# If TBB Enabled, c1 differ from c2 | |
param = result.getCovarianceModel().getParameter() | |
referenceModel.setParameter(param) | |
c1 = referenceModel.discretize(inputSample) | |
c2 = result.getCovarianceModel().discretize(inputSample) | |
""" | |
# Man valid | |
# We do manually the discretize | |
# We intentionally use square matrix | |
size = len(inputSample) | |
delta = ot.SquareMatrix(size) | |
delta_scal = ot.SquareMatrix(size) | |
delta_rho = ot.SquareMatrix(size) | |
for i in range(size): | |
xi = inputSample[i] | |
for j in range(size): | |
xj = inputSample[j] | |
delta[i, j] = referenceModel(xi, xj)[0,0] - result.getCovarianceModel()(xi, xj)[0,0] | |
delta_scal[i, j] = referenceModel.computeAsScalar(xi, xj) - result.getCovarianceModel().computeAsScalar(xi, xj) | |
delta_rho[i, j] = referenceModel.computeStandardRepresentative(xi, xj) - result.getCovarianceModel().computeStandardRepresentative(xi, xj) | |
#print(delta) | |
#print(delta_rho) | |
#print(delta_scal) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment