def test_stationary_fun():
    # fix https://github.com/openturns/openturns/issues/1861
    ot.RandomGenerator.SetSeed(0)
    rho = ot.SymbolicFunction("tau", "exp(-abs(tau))*cos(2*pi_*abs(tau))")
    model = ot.StationaryFunctionalCovarianceModel([1], [1], rho)
    x = ot.Normal().getSample(20)
    y = x + ot.Normal(0, 0.1).getSample(20)

    algo = ot.KrigingAlgorithm(x, y, model, ot.LinearBasisFactory().build())
    algo.run()
    result = algo.getResult()
    variance = result.getConditionalMarginalVariance(x)
    ott.assert_almost_equal(variance, ot.Sample(len(x), 1), 1e-16, 1e-16)
#!/usr/bin/env python

from __future__ import print_function
import openturns as ot
import openturns.testing as ott
import math as m


f = ot.SymbolicFunction(
    ['tau', 'alpha'], ['cos(4*tau)*cosh((tau-pi_)/alpha)/cosh(pi_/alpha)'])
alpha = 1.36
rho = ot.ParametricFunction(f, [1], [alpha])

cov = ot.StationaryFunctionalCovarianceModel([1.0], [1.0], rho)
print(cov)

tau = 0.1
c = cov([tau])[0, 0]
print("tau=", tau)
print("c=", c)
c_ref = m.cos(4*tau)*m.cosh((tau-m.pi)/alpha)/m.cosh(m.pi/alpha)
ott.assert_almost_equal(c, c_ref)

assert len(cov.getFullParameter()) == 3, "wrong full parameter"
assert len(cov.getFullParameterDescription()
           ) == 3, "wrong full parameter description"

print(cov.getFullParameter())
print(cov.getFullParameterDescription())

assert len(cov.getActiveParameter()) == 2, "wrong active parameter"
예제 #3
0
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)
test_model(myDefautModel)

myModel = ot.SphericalModel([2.0] * inputDimension, [3.0], 4.5)
test_model(myModel)

myDefautModel = ot.DiracCovarianceModel()
print('myDefautModel = ', myDefautModel)
test_model(myDefautModel)

rho = ot.SymbolicFunction(['tau'], ['exp(-tau)*cos(2*pi_*tau)'])
myDefautModel = ot.StationaryFunctionalCovarianceModel([1.0], [1.0], rho)
print('myDefautModel = ', myDefautModel)
test_model(myDefautModel)

amplitude = [1.5 + 2.0 * k for k in range(2)]
dimension = 2
spatialCorrelation = ot.CorrelationMatrix(dimension)
for j in range(dimension):
    for i in range(j + 1, dimension):
        spatialCorrelation[i,
                           j] = (i + 1.0) / dimension - (j + 1.0) / dimension
myModel = ot.DiracCovarianceModel(inputDimension, amplitude,
                                  spatialCorrelation)
test_model(myModel, x1=[0.5, 0.0], x2=[0.5, 0.0])

myDefautModel = ot.ProductCovarianceModel()
예제 #4
0
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(1.0, 9.0)]).getSample(sampleSize)
outputValidSample = model(inputValidSample)

# Reimplement the squared exponential covariance model
rho = ot.SymbolicFunction(
    ['x', 'y'], ['exp(-0.5* (x * x + y * y))'])
covarianceModel = ot.StationaryFunctionalCovarianceModel([6.0, 2.0], [
                                                         1.5], rho)

# Basis definition
basis = ot.LinearBasisFactory(inputDimension).build()

# Kriging algorithm
algo = ot.KrigingAlgorithm(inputSample, outputSample, covarianceModel, basis)
start = [50.0] * inputDimension
loglikelihood = algo.getReducedLogLikelihoodFunction()(start)
algo.setOptimizeParameters(False)
algo.run()
result = algo.getResult()
metaModel = result.getMetaModel()
variance = result.getConditionalMarginalVariance(inputSample)
ott.assert_almost_equal(variance, ot.Sample(
    inputSample.getSize(), 1), 1e-14, 1e-14)
#!/usr/bin/env python

from __future__ import print_function
import openturns as ot
import openturns.testing as ott
import math as m

f = ot.SymbolicFunction(['tau', 'alpha'],
                        ['cos(4*tau)*cosh((tau-pi_)/alpha)/cosh(pi_/alpha)'])
alpha = 1.36
rho = ot.ParametricFunction(f, [1], [alpha])

cov = ot.StationaryFunctionalCovarianceModel([1.0], [1.0], rho)
print(cov)

tau = 0.1
c = cov([tau])[0, 0]
print("tau=", tau)
print("c=", c)
c_ref = m.cos(4 * tau) * m.cosh((tau - m.pi) / alpha) / m.cosh(m.pi / alpha)
ott.assert_almost_equal(c, c_ref)

assert len(cov.getFullParameter()) == 3, "wrong full parameter"
assert len(
    cov.getFullParameterDescription()) == 3, "wrong full parameter description"

print(cov.getFullParameter())
print(cov.getFullParameterDescription())

assert len(cov.getActiveParameter()) == 2, "wrong active parameter"
cov.setActiveParameter(range(3))