def test_active_parameter(): # Define product of matern 1d cov_model_1d = ot.MaternModel([0.5], 2.5) print("1D Full parameter : ", cov_model_1d.getFullParameter()) print("1D active cov. param.: ", [cov_model_1d.getFullParameterDescription()[ i] for i in cov_model_1d.getActiveParameter()]) print("Activate nu parameter") cov_model_1d.setActiveParameter([0, 1, 2]) print("active cov. param.: ", [cov_model_1d.getFullParameterDescription()[ i] for i in cov_model_1d.getActiveParameter()]) print("Matern d-dimensional covariance as product") d = 3 cov_model = ot.ProductCovarianceModel([cov_model_1d]*d) marginal0 = cov_model.getMarginal(0) assert marginal0.getInputDimension() == d, "wrong marginal input dim" assert marginal0.getOutputDimension() == 1, "wrong marginal output dim" print("Full parameter : ", cov_model.getFullParameter()) print("active cov. param.: ", [cov_model.getFullParameterDescription()[ i] for i in cov_model.getActiveParameter()]) print("Disable nu for marginals 0 & 1 parameter : ", cov_model.getFullParameter()) cov_model.setActiveParameter([0, 1, 2, 3, 6]) print("active cov. param.: ", [cov_model.getFullParameterDescription()[ i] for i in cov_model.getActiveParameter()]) print("Check that active parameter is correctly propagated") for k in range(3): print("Model ", k, " : active cov. param.: ", [cov_model.getCollection()[ k].getFullParameterDescription()[i] for i in cov_model.getCollection()[k].getActiveParameter()])
def test_active_amplitude_parameter(): # Define product of matern 1d model1 = ot.MaternModel([1.0], 2.5) print("Model 1 : ", model1.getFullParameterDescription()) print("Activate nu parameter and disable sigma2") model1.setActiveParameter([0, 2]) print("model1 active parameter: ", [ model1.getFullParameterDescription()[i] for i in model1.getActiveParameter() ]) model2 = ot.ExponentiallyDampedCosineModel() print("Model 2 : ", model2.getFullParameterDescription()) print("Activate freq parameter") model2.setActiveParameter([0, 1, 2]) print("model2 active parameter: ", [ model2.getFullParameterDescription()[i] for i in model2.getActiveParameter() ]) print("Product covariance model") d = 3 cov_model = ot.ProductCovarianceModel([model1, model2]) print("Full parameter : ", cov_model.getFullParameter()) print("active cov. param.: ", [ cov_model.getFullParameterDescription()[i] for i in cov_model.getActiveParameter() ])
def get_kernel_function(self, kernel, name): ''' kernel : dictionary of parameters name : name of the kernel ''' if self.input_dim == 1: if name == 'Matern': return (ot.MaternModel([float(kernel[name]['lengthscale'])], [kernel[name]['scale']], float(kernel[name]['order']))) elif name == 'RBF': return (ot.SquaredExponential( [float(kernel[name]['lengthscale'])], [kernel[name]['scale']])) elif name == 'White': return ( 'Not sure whether this library supports the specified kernel type' ) elif name == 'Const': return ( 'Not sure whether this library supports the specified kernel type' ) elif name == 'RatQd': return ( 'Not sure whether this library supports the specified kernel type' ) else: if name == 'Matern': return (ot.MaternModel(kernel[name]['lengthscale'], [kernel[name]['scale']], float(kernel[name]['order']))) elif name == 'RBF': return (ot.SquaredExponential(kernel[name]['lengthscale'], [kernel[name]['scale']])) elif name == 'White': return ( 'Not sure whether this library supports the specified kernel type' ) elif name == 'Const': return ( 'Not sure whether this library supports the specified kernel type' ) elif name == 'RatQd': return ( 'Not sure whether this library supports the specified kernel type' )
def createMyBasicKriging(X, Y): ''' Create a kriging from a pair of X and Y samples. We use a 3/2 Matérn covariance model and a constant trend. ''' basis = ot.ConstantBasisFactory(dimension).build() covarianceModel = ot.MaternModel([1.0], 1.5) algo = ot.KrigingAlgorithm(X, Y, covarianceModel, basis) algo.run() krigResult = algo.getResult() return krigResult
def get_process_kl_decomposition(mean, coef_var=None, amplitude=None, scale=0, nu=1, mesh=None, dimension=1, name='', threshold= 1e-3): # for matern model only if amplitude is None and coef_var is not None: amplitude = [float(mean*coef_var)]*dimension else : amplitude = [float(amplitude)]*dimension scale = [float(scale)]*dimension model = ot.MaternModel(scale, amplitude, float(nu)) # Karhunen Loeve decomposition of process algorithm = ot.KarhunenLoeveP1Algorithm(mesh, model, threshold) algorithm.run() results = algorithm.getResult() results.setName(name) return results
ott.assert_almost_equal(myModel.getP(), 1.5, 0, 0) test_model(myModel) # 3) AbsoluteExponential myModel = ot.AbsoluteExponential([2.0], [3.0]) ott.assert_almost_equal(myModel.getScale(), [2], 0, 0) ott.assert_almost_equal(myModel.getAmplitude(), [3], 0, 0) test_model(myModel) myModel = ot.AbsoluteExponential([2.0] * inputDimension, [3.0]) ott.assert_almost_equal(myModel.getScale(), [2, 2], 0, 0) ott.assert_almost_equal(myModel.getAmplitude(), [3], 0, 0) test_model(myModel) # 4) MaternModel myModel = ot.MaternModel([2.0], [3.0], 1.5) ott.assert_almost_equal(myModel.getScale(), [2], 0, 0) ott.assert_almost_equal(myModel.getAmplitude(), [3], 0, 0) ott.assert_almost_equal(myModel.getNu(), 1.5, 0, 0) test_model(myModel) myModel = ot.MaternModel([2.0] * inputDimension, [3.0], 1.5) ott.assert_almost_equal(myModel.getScale(), [2, 2], 0, 0) ott.assert_almost_equal(myModel.getAmplitude(), [3], 0, 0) ott.assert_almost_equal(myModel.getNu(), 1.5, 0, 0) test_model(myModel) # 5) ExponentiallyDampedCosineModel myModel = ot.ExponentiallyDampedCosineModel([2.0], [3.0], 1) ott.assert_almost_equal(myModel.getScale(), [2], 0, 0) ott.assert_almost_equal(myModel.getAmplitude(), [3], 0, 0)
z = np.array( [77.88, 71.03, 27.97, 63.41, 57.76, 64.63, 33.54, 65.64, 92.53, 67.06]) x = np.column_stack((x1, x2)) X = ot.Sample(x) z = ot.Sample(np.reshape(z, (len(z), 1))) dimension = len(x[0]) #basis = ot.ConstantBasisFactory(dimension).build() # basis = ot.LinearBasisFactory(dimension).build() basis = ot.QuadraticBasisFactory(dimension).build() # covarianceModel = ot.SquaredExponential([38.44], [1.895]) covarianceModel = ot.MaternModel() #[38.44], [1.895]) algo = ot.KrigingAlgorithm(X, z, covarianceModel, basis) #algo.setNoise([0.7]*len(z)) # nugget algo.run() result = algo.getResult() metamodel = result.getMetaModel() a = np.linspace(13, 16, 100) b = np.linspace(17, 19, 100) A, B = np.meshgrid(a, b) aa = np.reshape(A, (10000, 1)) bb = np.reshape(B, (10000, 1)) c = np.column_stack((aa, bb)) C = np.array(metamodel(c))
# Defining a 1D process. # first define mesh dimension = 1 NElem = [100] mesher = ot.IntervalMesher(NElem) lowerBound = [0] upperBound = [1000] interval = ot.Interval(lowerBound, upperBound) mesh = mesher.build(interval) # then define covariance model amplitude0 = [100] * dimension scale0 = [300] * dimension nu0 = 4.5 model0 = ot.MaternModel(scale0, amplitude0, nu0) # then define the stochastic process process = ot.GaussianProcess(model0, mesh) # get some realizations and a sample ot.RandomGenerator_SetSeed(11111) field1D = process.getRealization() #FIELD BASE ot.RandomGenerator_SetSeed(11111) sample1D = process.getSample(10) #SAMPLE BASE # get the Karhunen Loeve decomposition of the mesh algorithm = ot.KarhunenLoeveP1Algorithm(mesh, model0, 1e-3) algorithm.run() results = algorithm.getResult() #### This is the object we will need !
graph.setLegendPosition("topleft") graph.setTitle("Sample size = %d" % (n_pt)) view = viewer.View(graph) # %% # Create the kriging algorithm # ---------------------------- # 1. basis ot.ResourceMap.SetAsBool( 'GeneralLinearModelAlgorithm-UseAnalyticalAmplitudeEstimate', True) basis = ot.ConstantBasisFactory(dim).build() print(basis) # 2. covariance model cov = ot.MaternModel([1.], [2.5], 1.5) print(cov) # 3. kriging algorithm algokriging = ot.KrigingAlgorithm(x, y, cov, basis) ## error measure #algokriging.setNoise([5*1e-1]*n_pt) # 4. Optimization # algokriging.setOptimizationAlgorithm(ot.NLopt('GN_DIRECT')) lhsExperiment = ot.LHSExperiment(ot.Uniform(1e-1, 1e2), 50) algokriging.setOptimizationAlgorithm( ot.MultiStart(ot.TNC(), lhsExperiment.generate())) algokriging.setOptimizationBounds(ot.Interval([0.1], [1e2]))
ott.assert_almost_equal(myModel.getP(), 1.5, 0, 0) test_model(myModel) # 3) AbsoluteExponential myModel = ot.AbsoluteExponential([2.0], [3.0]) ott.assert_almost_equal(myModel.getScale(), [2], 0, 0) ott.assert_almost_equal(myModel.getAmplitude(), [3], 0, 0) test_model(myModel) myModel = ot.AbsoluteExponential([2.0] * inputDimension, [3.0]) ott.assert_almost_equal(myModel.getScale(), [2, 2], 0, 0) ott.assert_almost_equal(myModel.getAmplitude(), [3], 0, 0) test_model(myModel) # 4) MaternModel myModel = ot.MaternModel([2.0], [3.0], 1.5) ott.assert_almost_equal(myModel.getScale(), [2], 0, 0) ott.assert_almost_equal(myModel.getAmplitude(), [3], 0, 0) ott.assert_almost_equal(myModel.getNu(), 1.5, 0, 0) test_model(myModel) myModel = ot.MaternModel([2.0] * inputDimension, [3.0], 1.5) ott.assert_almost_equal(myModel.getScale(), [2, 2], 0, 0) ott.assert_almost_equal(myModel.getAmplitude(), [3], 0, 0) ott.assert_almost_equal(myModel.getNu(), 1.5, 0, 0) test_model(myModel) # Retrieve a copy of the actual implementation from the interface class myModelInterface = ot.CovarianceModel(myModel) myModelImplementation = myModelInterface.getImplementation()
# application to Point covariancePoint = ot.Point(var.getImplementation()) theoricalVariance = ot.Point(sampleSize * sampleSize) assert_almost_equal(covariancePoint, theoricalVariance, 8.95e-7, 8.95e-7) # Tests with MaternModel scale = [1.0] amplitude = [4.123456] nu = 0.5 # Test A : prior = REFERENCE, parametrization = STANDARD print("Test A : prior = REFERENCE, parametrization = STANDARD") prior = otgu.GeneralLinearModelAlgorithm.REFERENCE #parametrization = ot.CovarianceModelImplementation.STANDARD covarianceModel = ot.MaternModel(scale, amplitude, nu) #covarianceModel.setScaleParametrization(parametrization) algo = otgu.KrigingAlgorithm(X, Y, covarianceModel, basis, False) algo.setScalePrior(prior) algo.run() result = algo.getResult() scaleOTGU = result.getCovarianceModel().getParameter() assert_almost_equal(scaleOTGU[0], 0.8296342228649921, 1.e-1) # Not accurate rllfunction = algo.getReducedLogLikelihoodFunction() objective_value = rllfunction(scaleOTGU) assert_almost_equal(objective_value[0], -11.164598619012276, 1.e-3) # Test B : prior = REFERENCE, parametrization = INVERSE #print("Test B : prior = REFERENCE, parametrization = INVERSE") #prior = otgu.GeneralLinearModelAlgorithm.REFERENCE #parametrization = ot.CovarianceModelImplementation.INVERSE
# Design of Experiment ## aDesign = persalys.FixedDesignOfExperiment('design', model) validationInputSample = ot.LHSExperiment(model.getDistribution(), 10).generate() inputSample = ot.Sample(validationInputSample) inputSample.stack(ot.Sample(10, [0.5])) aDesign.setOriginalInputSample(inputSample) myStudy.add(aDesign) aDesign.run() # Kriging ## analysis = persalys.KrigingAnalysis('kriging_0', aDesign) analysis.setBasis(ot.LinearBasisFactory(2).build()) analysis.setCovarianceModel(ot.MaternModel(2)) myStudy.add(analysis) print(analysis) analysis.run() metaModel = analysis.getResult().getResultForVariable('y0').getMetaModel() openturns.testing.assert_almost_equal( aDesign.getResult().getDesignOfExperiment().getOutputSample(), metaModel(validationInputSample), 3.0e-5, 3.0e-5) # Design of Experiment ## model.addOutput(persalys.Output('y1')) model.setFormula('y1', formula_y0 + ' + xi3') aDesign.setInterestVariables(['y0', 'y1']) aDesign.run()
['x_0', 'x_2', 'x_3'], ['x_1']) myStudy.add(model3) # Design of Experiment ## probaDesign = persalys.ProbabilisticDesignOfExperiment('probaDesign', model1, 20, "MONTE_CARLO") probaDesign.run() myStudy.add(probaDesign) # 1- meta model1 ## # 1-a Kriging ## kriging = persalys.KrigingAnalysis('kriging', probaDesign) kriging.setBasis(ot.LinearBasisFactory(2).build()) kriging.setCovarianceModel(ot.MaternModel(2)) kriging.setTestSampleValidation(True) kriging.setKFoldValidation(True) kriging.setInterestVariables(['y0', 'y1']) myStudy.add(kriging) # 1-b Chaos ## chaos1 = persalys.FunctionalChaosAnalysis('chaos_1', probaDesign) chaos1.setChaosDegree(7) chaos1.setSparseChaos(True) chaos1.setTestSampleValidation(True) chaos1.setKFoldValidation(True) chaos1.setInterestVariables(['y1']) myStudy.add(chaos1) # 2- central tendancy ##
# The :class:`~openturns.MaternModel` class implements the Matern model of parameter :math:`\nu`. # This parameter controls the smoothness of the process : for any :math:`\nu = n + \frac{1}{2}` the # process is :math:`n` times continuously differentiable. # %% # Influence of the regularity # ^^^^^^^^^^^^^^^^^^^^^^^^^^^ # # In this paragraph we represent three models with different regularity and generate the # corresponding random trajectories. We shall use :math:`\nu = 0.5`, :math:`\nu = 1.5` and # :math:`\nu = 2.5` and observe the regularity. # # %% # We define the :math:`\nu = 0.5` Matern model : covarianceModel = ot.MaternModel([1.0], 0.5) # %% # We define the :math:`\nu = 1.5` Matern model : covarianceModel2 = ot.MaternModel([1.0], 1.5) # %% # We define the :math:`\nu = 2.5` Matern model : covarianceModel3 = ot.MaternModel([1.0], 2.5) # %% # We draw the covariance models : graphModel = covarianceModel.draw() graphModel.add(covarianceModel2.draw()) graphModel.add(covarianceModel3.draw()) graphModel.setColors(["green", "orange", "blue"])
# # %% from __future__ import print_function import openturns as ot import openturns.viewer as viewer from matplotlib import pylab as plt import math as m ot.Log.Show(ot.Log.NONE) # %% # Scale vector (input dimension 1) theta = [4.0] # Create the rho function rho = ot.MaternModel(theta, 1.5) # Create the amplitude vector (output dimension 2) sigma = [1.0, 2.0] # output correlation R = ot.CorrelationMatrix(2) R[1, 0] = 0.01 # output covariance C = ot.CovarianceMatrix(2) C[0, 0] = 4.0 C[1, 1] = 5.0 C[1, 0] = 0.5 # %%
myDefautModel = ot.GeneralizedExponential([2.0], [3.0], 1.5) print('myDefautModel = ', myDefautModel) test_model(myDefautModel) myModel = ot.GeneralizedExponential([2.0] * spatialDimension, [3.0], 1.5) test_model(myModel) myDefautModel = ot.AbsoluteExponential([2.0], [3.0]) print('myDefautModel = ', myDefautModel) test_model(myDefautModel) myModel = ot.AbsoluteExponential([2.0] * spatialDimension, [3.0]) test_model(myModel) myDefautModel = ot.MaternModel([2.0], [3.0], 1.5) print('myDefautModel = ', myDefautModel) test_model(myDefautModel) myModel = ot.MaternModel([2.0] * spatialDimension, [3.0], 1.5) test_model(myModel) myDefautModel = ot.ExponentiallyDampedCosineModel([2.0], [3.0], 1.5) print('myDefautModel = ', myDefautModel) test_model(myDefautModel) myModel = ot.ExponentiallyDampedCosineModel([2.0] * spatialDimension, [3.0], 1.5) test_model(myModel) myDefautModel = ot.SphericalModel([2.0], [3.0], 4.5)
graph = ot.Graph() graph.add(plot_data_test(x_test, y_test)) graph.add(plot_data_train(x_train, y_train)) graph.setAxes(True) graph.setXTitle("X") graph.setYTitle("Y") graph.setLegendPosition("topright") view = viewer.View(graph) # %% # We use the `ConstantBasisFactory` class to define the trend and the `MaternModel` class to define the covariance model. This Matérn model is based on the regularity parameter :math:`\nu=3/2`. # %% dimension = 1 basis = ot.ConstantBasisFactory(dimension).build() covarianceModel = ot.MaternModel([1.0] * dimension, 1.5) algo = ot.KrigingAlgorithm(x_train, y_train, covarianceModel, basis) algo.run() krigingResult = algo.getResult() krigingResult # %% # We observe that the `scale` and `amplitude` hyper-parameters have been optimized by the `run` method. Then we get the metamodel with `getMetaModel` and evaluate the outputs of the metamodel on the test design of experiments. # %% krigeageMM = krigingResult.getMetaModel() y_test_MM = krigeageMM(x_test) # %% # The following function plots the kriging data.
# ----------------------- # # There are other covariance models. The models which are used more often are the following. # * `SquaredExponential`. The generated processes can be derivated in mean square at all orders. # * `MaternModel`. When :math:`\nu\rightarrow+\infty`, it converges to the squared exponential model. This model can be derivated :math:`k` times only if :math:`k<\nu`. In other words, when :math:`\nu` increases, then the trajectories are more and more regular. The particular case :math:`\nu=1/2` is the exponential model. The most commonly used values are :math:`\nu=3/2` and :math:`\nu=5/2`, which produce trajectories that are, in terms of regularity, in between the squared exponential and the exponential models. # * `ExponentialModel`. The associated process is continus, but not differentiable. # %% # The Matérn and exponential models # --------------------------------- # %% amplitude = [1.0] scale = [1.0] nu1, nu2, nu3 = 2.5, 1.5, 0.5 myModel1 = ot.MaternModel(scale, amplitude, nu1) myModel2 = ot.MaternModel(scale, amplitude, nu2) myModel3 = ot.MaternModel(scale, amplitude, nu3) # %% nbTrajectories = 10 graph1 = plotCovarianceModel(myModel1, myTimeGrid, nbTrajectories) graph2 = plotCovarianceModel(myModel2, myTimeGrid, nbTrajectories) graph3 = plotCovarianceModel(myModel3, myTimeGrid, nbTrajectories) # %% fig = pl.figure(figsize=(20, 6)) ax1 = fig.add_subplot(1, 3, 1) _ = View(graph1, figure=fig, axes=[ax1]) _ = ax1.set_title("Matern 5/2") ax2 = fig.add_subplot(1, 3, 2)
myDefautModel = ot.GeneralizedExponential([2.0], [3.0], 1.5) print('myDefautModel = ', myDefautModel) test_model(myDefautModel) myModel = ot.GeneralizedExponential([2.0] * inputDimension, [3.0], 1.5) test_model(myModel) myDefautModel = ot.AbsoluteExponential([2.0], [3.0]) print('myDefautModel = ', myDefautModel) test_model(myDefautModel) myModel = ot.AbsoluteExponential([2.0] * inputDimension, [3.0]) test_model(myModel) myDefautModel = ot.MaternModel([2.0], [3.0], 1.5) print('myDefautModel = ', myDefautModel) test_model(myDefautModel) myModel = ot.MaternModel([2.0] * inputDimension, [3.0], 1.5) test_model(myModel) myDefautModel = ot.ExponentiallyDampedCosineModel([2.0], [3.0], 1.5) print('myDefautModel = ', myDefautModel) test_model(myDefautModel) myModel = ot.ExponentiallyDampedCosineModel([2.0] * inputDimension, [3.0], 1.5) test_model(myModel) myDefautModel = ot.SphericalModel([2.0], [3.0], 4.5) print('myDefautModel = ', myDefautModel)
sampleSize = 4 dimension = 1 f = ot.Function(['x'], ['y'], ['0.5*x^2 + sin(2.5*x)']) # Database xMin = -0.9 xMax = 1.9 X = ot.LHSExperiment(ot.Uniform(xMin, xMax), sampleSize, False, False).generate() Y = f(X) # create algorithm basis = ot.ConstantBasisFactory(dimension).build() covarianceModel = ot.MaternModel([1.0], 1.5) ot.Log.Show(ot.Log.INFO) algo = ot.KrigingAlgorithm(X, Y, covarianceModel, basis) algo.run() # perform an evaluation result = algo.getResult() meta = result.getMetaModel() graph_meta = meta.draw(xMin, xMax) data = graph_meta.getDrawable(0).getData() xGrid = data.getMarginal(0) covGrid = result.getConditionalCovariance(xGrid) a = ot.DistFunc.qNormal(0.975) c = ot.Cloud([data[2]]) c.setPointStyle("square")
def test_parameters_iso(): scale = [] amplitude = 1.0 extraParameter = [] # model 1 atom_ex = ot.IsotropicCovarianceModel(ot.MaternModel(), 2) atom_ex.setScale([5]) atom_ex.setAmplitude([1.5]) scale.append(5) amplitude *= 1.5 extraParameter.append(atom_ex.getKernel().getFullParameter()[-1]) # model2 m = ot.MaternModel() m.setNu(2.5) m.setScale([3]) m.setAmplitude([3]) scale.append(3) amplitude *= 3 extraParameter.append(m.getNu()) # model 3 atom = ot.IsotropicCovarianceModel(ot.AbsoluteExponential(), 2) atom.setScale([2]) atom.setAmplitude([2.5]) scale.append(2) amplitude *= 2.5 model = ot.ProductCovarianceModel([atom_ex, m, atom]) ott.assert_almost_equal(model.getScale(), scale, 1e-16, 1e-16) ott.assert_almost_equal(model.getAmplitude(), [amplitude], 1e-16, 1e-16) ott.assert_almost_equal(model.getFullParameter(), scale + [amplitude] + extraParameter, 1e-16, 1e-16) # active parameter should be scale + amplitude ott.assert_almost_equal(model.getActiveParameter(), [0, 1, 2, 3], 1e-16, 1e-16) # setting new parameters extraParameter = [2.5, 0.5] model.setFullParameter([6, 7, 8, 2] + extraParameter) ott.assert_almost_equal(model.getCollection()[ 0].getScale()[0], 6, 1e-16, 1e-16) ott.assert_almost_equal(model.getCollection()[ 1].getScale()[0], 7, 1e-16, 1e-16) ott.assert_almost_equal(model.getCollection()[ 2].getScale()[0], 8, 1e-16, 1e-16) ott.assert_almost_equal(model.getAmplitude()[0], 2, 1e-16, 1e-16) ott.assert_almost_equal(model.getCollection( )[0].getFullParameter()[-1], extraParameter[0], 1e-16, 1e-16) ott.assert_almost_equal(model.getCollection( )[1].getFullParameter()[-1], extraParameter[1], 1e-16, 1e-16) # checking active par setting model.setActiveParameter([0, 1, 2, 3, 5]) ott.assert_almost_equal(model.getParameter(), [ 6, 7, 8, 2, extraParameter[-1]], 1e-16, 1e-16)
import openturns as ot from matplotlib import pyplot as plt from openturns.viewer import View covarianceModel = ot.MaternModel() if covarianceModel.getSpatialDimension() == 1: scale = covarianceModel.getScale()[0] if covarianceModel.isStationary(): def f(x): return [covarianceModel(x)[0, 0]] func = ot.PythonFunction(1, 1, f) func.setDescription(['$tau$', '$cov$']) cov_graph = func.draw(-3.0 * scale, 3.0 * scale, 129) fig = plt.figure(figsize=(10, 4)) plt.suptitle(str(covarianceModel)) cov_axis = fig.add_subplot(111) View(cov_graph, figure=fig, axes=[cov_axis], add_legend=False) else: def f(x): return [covarianceModel([x[0]], [x[1]])[0, 0]] func = ot.PythonFunction(2, 1, f) func.setDescription(['$s$', '$t$', '$cov$']) cov_graph = func.draw([-3.0 * scale] * 2, [3.0 * scale] * 2, [129] * 2) fig = plt.figure(figsize=(10, 4)) plt.suptitle(str(covarianceModel)) cov_axis = fig.add_subplot(111) View(cov_graph, figure=fig, axes=[cov_axis], add_legend=False)
import openturns as ot from matplotlib import pyplot as plt from openturns.viewer import View if ot.MaternModel().__class__.__name__ == 'ExponentialModel': covarianceModel = ot.ExponentialModel([0.5], [5.0]) elif ot.MaternModel().__class__.__name__ == 'GeneralizedExponential': covarianceModel = ot.GeneralizedExponential([2.0], [3.0], 1.5) elif ot.MaternModel().__class__.__name__ == 'ProductCovarianceModel': amplitude = [1.0] scale1 = [4.0] scale2 = [4.0] cov1 = ot.ExponentialModel(scale1, amplitude) cov2 = ot.ExponentialModel(scale2, amplitude) covarianceModel = ot.ProductCovarianceModel([cov1, cov2]) elif ot.MaternModel().__class__.__name__ == 'RankMCovarianceModel': variance = [1.0, 2.0] basis = ot.LinearBasisFactory().build() covarianceModel = ot.RankMCovarianceModel(variance, basis) else: covarianceModel = ot.MaternModel() title = str(covarianceModel)[:100] if covarianceModel.getInputDimension() == 1: scale = covarianceModel.getScale()[0] if covarianceModel.isStationary(): def f(x): return [covarianceModel(x)[0, 0]] func = ot.PythonFunction(1, 1, f) func.setDescription(['$tau$', '$cov$']) cov_graph = func.draw(-3.0 * scale, 3.0 * scale, 129)
myDefautModel = ot.GeneralizedExponential() print("myDefautModel = ", myDefautModel) myModel = ot.GeneralizedExponential(spatialDimension, 10.0, 1.5) test_model(myModel) myDefautModel = ot.AbsoluteExponential() print("myDefautModel = ", myDefautModel) myModel = ot.AbsoluteExponential(spatialDimension) test_model(myModel) myDefautModel = ot.MaternModel() print("myDefautModel = ", myDefautModel) myModel = ot.MaternModel(spatialDimension, 8.0, 2.0) test_model(myModel) myDefautModel = ot.ProductCovarianceModel() print("myDefautModel = ", myDefautModel) coll = ot.CovarianceModelCollection() coll.add(ot.AbsoluteExponential(1, 3.0)) coll.add(ot.SquaredExponential(1, 2.0)) myModel = ot.ProductCovarianceModel(coll) test_model(myModel)