1#! /usr/bin/env python
2
3from __future__ import print_function
4from openturns import *
5
6TESTPREAMBLE()
7RandomGenerator.SetSeed(0)
8
9try:
10
11    # Default constructor
12    myDefautModel = UserDefinedStationaryCovarianceModel()
13    print("myDefautModel = ", myDefautModel)
14
15    # Default dimension parameter to evaluate the model
16    dimension = 1
17    inputDimension = 1
18
19    # Amplitude values
20    amplitude = Point(dimension)
21    # Scale values
22    scale = Point(dimension)
23    # Spatial correclation
24    spatialCorrelation = CorrelationMatrix(dimension)
25    for index in range(dimension):
26        # constant amplitude
27        amplitude[index] = 2.0
28        scale[index] = (index + 1.0) / dimension
29
30    # Sample a ExponentialModel
31    referenceModel = ExponentialModel(
32        scale, amplitude, spatialCorrelation)
33
34    print("reference model=", referenceModel)
35    size = 100
36    timeGrid = RegularGrid(0.0, 0.1, size)
37    covarianceCollection = SquareMatrixCollection(size)
38
39    for i in range(timeGrid.getN()):
40        t = timeGrid.getValue(i)
41        covarianceCollection[i] = referenceModel(t)
42    # Create a UserDefinedStationaryCovarianceModel
43    myModel = UserDefinedStationaryCovarianceModel(
44        timeGrid, covarianceCollection)
45    print("myModel=", myModel)
46
47    for i in range(timeGrid.getN()):
48        t = timeGrid.getValue(i)
49        # We look for cov(s,t) ==> when adding to the collection, we compute cov(t,s)
50        # Because of symmetry, we check the right index computation
51        print("t= %.6g" % t, "myModel =  %.6g" %
52              myModel(t)[0, 0], ", referenceModel=  %.6g" % referenceModel(t)[0, 0])
53
54    # Test the drawing method as a nonstationary model, in the covariance range
55    graph = myModel.draw(0, 0, -2.0, 2.0, 21, True, False)
56    print(graph)
57    # Test the drawing method as a nonstationary model, in the correlation
58    # range
59    graph = myModel.draw(0, 0, -2.0, 2.0, 21, True, True)
60    print(graph)
61
62except:
63    import sys
64    print("t_UserDefinedStationaryCovarianceModel_std.py",
65          sys.exc_info()[0], sys.exc_info()[1])
66