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)
ot.GeneralizedExponential() ] coll += [ ot.MaternModel(), ot.SphericalModel(), ot.ExponentiallyDampedCosineModel() ] for model in coll: test_scalar_model(model) # 13) Isotropic covariance model scale = 3.5 amplitude = 1.5 myOneDimensionalKernel = ot.SquaredExponential([scale], [amplitude]) myIsotropicKernel = ot.IsotropicCovarianceModel(myOneDimensionalKernel, inputDimension) # Test consistency of isotropic model with underlying 1D kernel ott.assert_almost_equal(myIsotropicKernel.getAmplitude()[0], amplitude, 1e-12, 0.0) ott.assert_almost_equal(myIsotropicKernel.getScale()[0], scale, 1e-12, 0.0) ott.assert_almost_equal(myIsotropicKernel.getKernel().getAmplitude()[0], amplitude, 1e-12, 0.0) ott.assert_almost_equal(myIsotropicKernel.getKernel().getScale()[0], scale, 1e-12, 0.0) # Standard tests applied test_model(myIsotropicKernel) # Test consistency of isotropic kernel's discretization inputVector = ot.Point([0.3, 1.7])
import openturns.testing as ott ot.TESTPREAMBLE() def fitKriging(covarianceModel): ''' Fit the parameters of a kriging metamodel. ''' coordinates = ot.Sample([[1.0,1.0],[5.0,1.0],[9.0,1.0], \ [1.0,3.5],[5.0,3.5],[9.0,3.5], \ [1.0,6.0],[5.0,6.0],[9.0,6.0]]) observations = ot.Sample([[25.0], [25.0], [10.0], [20.0], [25.0], [20.0], [15.0], [25.0], [25.0]]) basis = ot.ConstantBasisFactory(2).build() algo = ot.KrigingAlgorithm(coordinates, observations, covarianceModel, basis) algo.run() krigingResult = algo.getResult() return krigingResult # Isotropic covariance model myIsotropicKernel = ot.IsotropicCovarianceModel(ot.SquaredExponential(), 2) krigingFittedCovarianceModel = fitKriging( myIsotropicKernel).getCovarianceModel() ott.assert_almost_equal(krigingFittedCovarianceModel.getScale()[0], 2.86427, 0.0, 1e-4) ott.assert_almost_equal(krigingFittedCovarianceModel.getAmplitude()[0], 6.65231, 0.0, 1e-4)
# The value of :math:`\hat{\theta}_1` is actually equal to the lower bound: print(lower) # %% # This means that temperatures are likely to vary a lot along the X axis # and much slower accross the Y axis based on the observation data. # %% # Predict with an isotropic covariance kernel # --------------------------------------------------- # If we know that variations of the temperature are isotropic # (i.e. with no priviledged direction), # we can embed this information within the covariance kernel. isotropic = ot.IsotropicCovarianceModel(ot.SquaredExponential(), inputDimension) # %% # The :class:`~openturns.IsotropicCovarianceModel` class creates an isotropic # version with a given input dimension of a :class:`~openturns.CovarianceModel`. # Because is is isotropic, it only needs one scale parameter :math:`\theta_{iso}` # and it will make sure :math:`\theta_1 = \theta_2 = \theta_{iso}` at all times # during the optimization. krigingResult, krigingMetamodel = fitKriging(coordinates, observations, isotropic, basis) print(krigingResult.getCovarianceModel().getScale()) # %% # Prediction with the isotropic covariance kernel is much more satisfactory.