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() ])
import openturns as ot from matplotlib import pyplot as plt from openturns.viewer import View if ot.ExponentiallyDampedCosineModel( ).__class__.__name__ == 'ExponentialModel': covarianceModel = ot.ExponentialModel([0.5], [5.0]) elif ot.ExponentiallyDampedCosineModel( ).__class__.__name__ == 'GeneralizedExponential': covarianceModel = ot.GeneralizedExponential([2.0], [3.0], 1.5) elif ot.ExponentiallyDampedCosineModel( ).__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.ExponentiallyDampedCosineModel( ).__class__.__name__ == 'RankMCovarianceModel': variance = [1.0, 2.0] basis = ot.LinearBasisFactory().build() covarianceModel = ot.RankMCovarianceModel(variance, basis) else: covarianceModel = ot.ExponentiallyDampedCosineModel() title = str(covarianceModel)[:100] if covarianceModel.getInputDimension() == 1: scale = covarianceModel.getScale()[0] if covarianceModel.isStationary(): def f(x): return [covarianceModel(x)[0, 0]]
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) test_model(myDefautModel) myModel = ot.SphericalModel([2.0] * inputDimension, [3.0], 4.5) test_model(myModel) myDefautModel = ot.FractionalBrownianMotionModel(2.0, 3.0, 0.25) print('myDefautModel = ', myDefautModel)
# 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) ott.assert_almost_equal(myModel.getFrequency(), 1, 0, 0) test_model(myModel) myModel.setFrequency(3) ott.assert_almost_equal(myModel.getFrequency(), 3, 0, 0) myModel = ot.ExponentiallyDampedCosineModel([2.0] * inputDimension, [3.0], 1) ott.assert_almost_equal(myModel.getScale(), [2, 2], 0, 0) ott.assert_almost_equal(myModel.getAmplitude(), [3], 0, 0) ott.assert_almost_equal(myModel.getFrequency(), 1, 0, 0) test_model(myModel) # 6) SphericalModel myModel = ot.SphericalModel([2.0], [3.0], 4.5)
import openturns as ot from matplotlib import pyplot as plt from openturns.viewer import View covarianceModel = ot.ExponentiallyDampedCosineModel() 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) 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,