Last active
February 8, 2021 14:17
-
-
Save sofianehaddad/d7579d0bbe87ab7ea10644fc06d85cf0 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 | |
Box in [0,10]x[0,10] | |
""" | |
levels = [6, 3] | |
box = ot.Box(levels) | |
inputSample = box.generate() | |
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() | |
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-6, 1e-6], [20, 20])) | |
startingPoints = ot.LHSExperiment(ot.ComposedDistribution(2 * [ot.Uniform(0, 20.0)]), 10).generate() | |
#algo.setOptimizationAlgorithm(ot.MultiStart(ot.NLopt("GN_DIRECT"), startingPoints)) | |
algo.setOptimizationAlgorithm(ot.MultiStart(ot.Cobyla(), startingPoints)) | |
algo.run() | |
result = algo.getResult() | |
# Get meta model | |
metaModel = result.getMetaModel() | |
# Until we fix 1759, we disable TBB | |
ot.TBB.Disable() | |
val = ot.MetaModelValidation(inputValidSample, outputValidSample, metaModel) | |
print(val.computePredictivityFactor()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment