File: t_ARMA_std.py

package info (click to toggle)
openturns 1.7-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 38,588 kB
  • ctags: 26,495
  • sloc: cpp: 144,032; python: 26,855; ansic: 7,868; sh: 419; makefile: 263; yacc: 123; lex: 44
file content (109 lines) | stat: -rwxr-xr-x 3,051 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#! /usr/bin/env python

from __future__ import print_function
from openturns import *

TESTPREAMBLE()
RandomGenerator.SetSeed(0)

try:

    # 2 D case
    RandomGenerator.SetSeed(0)

    # Matrices of the process
    dim = 2
    squareMatrix1 = SquareMatrix(dim)
    squareMatrix1[0, 0] = 0.2
    squareMatrix1[1, 0] = 0.3
    squareMatrix1[0, 1] = 0.7
    squareMatrix1[1, 1] = 0.4

    # Second matrix to add to the ARMACoefficients
    squareMatrix2 = SquareMatrix(dim)
    squareMatrix2[0, 0] = 0.1
    squareMatrix2[1, 0] = 0.
    squareMatrix2[0, 1] = 0.
    squareMatrix2[1, 1] = 0.5

    # ARMA(p, q)
    p = 1
    q = 1

    # AR coefficients
    coefficientsP = ARMACoefficients(p, dim)
    coefficientsP[0] = squareMatrix1

    # MA coefficients
    coefficientsQ = ARMACoefficients(p, dim)
    coefficientsQ[0] = squareMatrix2

    print("coefficientsP = ", repr(coefficientsP))
    print("coefficientsQ = ", repr(coefficientsQ))

    # Time grid creation and White Noise
    Tmin = 0.0
    deltaT = 0.1
    steps = 11

    # Initialization of the TimeGrid timeGrid1
    timeGrid = RegularGrid(Tmin, deltaT, steps)

    # Distributions for the  choice
    dist1 = Distribution(Normal(0.0, 0.01))
    dist2 = Distribution(Normal(0.0, 0.02))

    # Create a collection of distribution
    aCollection = DistributionCollection()
    aCollection.add(dist1)
    aCollection.add(dist2)

    dist = Distribution(ComposedDistribution(aCollection))
    print("dist = ",  dist)

    epsilon = WhiteNoise(dist)

    # Setting the timeGrid
    epsilon.setTimeGrid(timeGrid)

    # Last coefficients values
    lastValues = NumericalSample(p, dim)
    lastNoiseValues = NumericalSample(q, dim)

    #
    for j in range(dim):
        # Fill the AR-part (the last p-coefficients X_{-1}, X{-2},..., X_{-p})
        for i in range(p):
            lastValues[i, j] = RandomGenerator.Generate()

        # Fill the MA-part (the last p-coefficients \epsilon_{-1},
        # \epsilon_{-2},..., \epsilon_{-p})
        for i in range(q):
            lastNoiseValues[i, j] = RandomGenerator.Generate()

    # Print the initial state of the ARMA : coefficients
    print("Last values of the process = ",  lastValues)
    print("Last innovations of the process = ",  lastNoiseValues)

    # ARMAState creation
    # instanciation of timeGrid
    state = ARMAState(lastValues, lastNoiseValues)
    process = Process(ARMA(coefficientsP, coefficientsQ, epsilon))
    process2 = ARMA(coefficientsP, coefficientsQ, epsilon)
    process3 = ARMA(coefficientsP, coefficientsQ, epsilon, state)
    print("process = ",  process)
    print("ARMA process = ",  process2)
    print("ARMA process with ARMAstate = ",  process3)

    # Test realization
    print("One realization=", process2.getRealization())

    # Some steps further
    stepNumber = 4
    print("One future=", process2.getFuture(stepNumber))
    size = 3
    print("Some futures=", process2.getFuture(stepNumber, size))

except:
    import sys
    print("t_ARMA_std.py", sys.exc_info()[0], sys.exc_info()[1])