File: t_WhittleFactory_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 (70 lines) | stat: -rwxr-xr-x 2,346 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
#! /usr/bin/env python

from __future__ import print_function
from openturns import *

TESTPREAMBLE()
RandomGenerator.SetSeed(0)

try:

    # Reduce the precision output as the estimation is based on a lazy
    # optimizer
    PlatformInfo.SetNumericalPrecision(4)

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

    # ARMACoefficients intializing
    arCoefficients = NumericalPoint(p, 0.80)
    maCoefficients = NumericalPoint(q, 0.50)

    # ARMA creation
    myARMA = ARMA(ARMACoefficients(arCoefficients),
                  ARMACoefficients(maCoefficients), WhiteNoise(Normal(0.0, 0.05)))
    myARMA.setTimeGrid(RegularGrid(0.0, 0.1, 256))
    print("myARMA process=", myARMA)

    # Create a realization
    timeSeries = myARMA.getRealization()

    # Create a sample
    sample = myARMA.getSample(100)

    # First, build an ARMA based on a given order using the WhittleFactory
    factory = WhittleFactory(p, q)
    # factory.setVerbose(False)
    print("factory=", factory)
    print("factory as an ARMA factory=", ARMAFactory(factory))
    informationCriteria = NumericalPoint()
    result = factory.build(TimeSeries(timeSeries), informationCriteria)
    # print "Estimated ARMA=", result
    # print "Information criteria=", informationCriteria
    result2 = factory.build(sample, informationCriteria)
    # print "Estimated ARMA=", result2
    # print "Information criteria=", informationCriteria

    # Second, build the best ARMA based on a given range of order using the
    # WhittleFactory
    pIndices = Indices(p + 1)
    pIndices.fill()
    qIndices = Indices(q + 1)
    qIndices.fill()
    factory = WhittleFactory(pIndices, qIndices)
    print("factory=", factory)
    informationCriteria = NumericalPoint()
    result = factory.build(TimeSeries(timeSeries), informationCriteria)
    # print "Estimated ARMA=", result
    # print "Information criteria=", informationCriteria
    # print "History=", factory.getHistory()
    result2 = factory.build(sample, informationCriteria)
    # print "Estimated ARMA=", result2
    # print "Information criteria=", informationCriteria
    history = WhittleFactoryStateCollection(factory.getHistory())
    firstTestes = WhittleFactoryState(history[0])
    # print "History=", factory.getHistory()

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