File: t_ARMA_std.py

package info (click to toggle)
openturns 1.24-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 66,204 kB
  • sloc: cpp: 256,662; python: 63,381; ansic: 4,414; javascript: 406; sh: 180; xml: 164; yacc: 123; makefile: 98; lex: 55
file content (97 lines) | stat: -rwxr-xr-x 2,469 bytes parent folder | download | duplicates (2)
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
#! /usr/bin/env python

import openturns as ot

ot.TESTPREAMBLE()

# 2 D case

# Matrices of the process
dim = 2
squareMatrix1 = ot.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 = ot.SquareMatrix(dim)
squareMatrix2[0, 0] = 0.1
squareMatrix2[1, 0] = 0.0
squareMatrix2[0, 1] = 0.0
squareMatrix2[1, 1] = 0.5

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

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

# MA coefficients
coefficientsQ = ot.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 = ot.RegularGrid(Tmin, deltaT, steps)

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

# Create a collection of distribution
aCollection = [dist1, dist2]

dist = ot.JointDistribution(aCollection)
print("dist = ", dist)

epsilon = ot.WhiteNoise(dist)

# Setting the timeGrid
epsilon.setTimeGrid(timeGrid)

# Last coefficients values
lastValues = ot.Sample(p, dim)
lastNoiseValues = ot.Sample(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] = ot.RandomGenerator.Generate()

    # Fill the MA-part (the last p-coefficients \epsilon_{-1},
    # \epsilon_{-2},..., \epsilon_{-p})
    for i in range(q):
        lastNoiseValues[i, j] = ot.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
state = ot.ARMAState(lastValues, lastNoiseValues)
process = ot.Process(ot.ARMA(coefficientsP, coefficientsQ, epsilon))
process2 = ot.ARMA(coefficientsP, coefficientsQ, epsilon)
process3 = ot.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))