import matplotlib.pyplot as plt ot.RandomGenerator.SetSeed(0) ot.Log.Show(ot.Log.NONE) # %% # Create an arma process tMin = 0.0 n = 1000 timeStep = 0.1 myTimeGrid = ot.RegularGrid(tMin, timeStep, n) myWhiteNoise = ot.WhiteNoise(ot.Triangular(-1.0, 0.0, 1.0), myTimeGrid) myARCoef = ot.ARMACoefficients([0.4, 0.3, 0.2, 0.1]) myMACoef = ot.ARMACoefficients([0.4, 0.3]) arma = ot.ARMA(myARCoef, myMACoef, myWhiteNoise) tseries = ot.TimeSeries(arma.getRealization()) # Create a sample of N time series from the process N = 100 sample = arma.getSample(N) # %% # CASE 1 : we specify a (p,q) order # Specify the order (p,q) p = 4 q = 2 # Create the estimator
#! /usr/bin/env python from __future__ import print_function import openturns as ot # Time grid creation and White Noise Tmin = 0.0 deltaT = 0.1 steps = 11 # Initialization of the TimeGrid timeGrid timeGrid = ot.RegularGrid(Tmin, deltaT, steps) # Creation of the Antecedent myARMAProcess = ot.ARMA() myARMAProcess.setTimeGrid(timeGrid) print('myAntecedentProcess = ', myARMAProcess) # Creation of a function f = ot.SymbolicFunction(['x'], ['2 * x + 5.0']) # We build a dynamical function myFieldFunction = ot.FieldFunction(ot.ValueFunction(f)) # finally we get the compsite process myCompositeProcess = ot.CompositeProcess(myFieldFunction, myARMAProcess) print('myCompositeProcess = ', repr(myCompositeProcess)) # Test realization print('One realization= ') print(myCompositeProcess.getRealization())
timeGrid = ot.RegularGrid(0.0, dt, size) # white noise cov = ot.CovarianceMatrix([[0.1, 0.0], [0.0, 0.2]]) whiteNoise = ot.WhiteNoise(ot.Normal([0.0] * dim, cov), timeGrid) # AR/MA coefficients ar = ot.ARMACoefficients(p, dim) ar[0] = ot.SquareMatrix([[-0.5, -0.1], [-0.4, -0.5]]) ar[1] = ot.SquareMatrix([[0.0, 0.0], [-0.25, 0.0]]) ma = ot.ARMACoefficients(q, dim) ma[0] = ot.SquareMatrix([[-0.4, 0.0], [0.0, -0.4]]) # ARMA model creation myARMA = ot.ARMA(ar, ma, whiteNoise) # Create a realization timeSeries = ot.TimeSeries(myARMA.getRealization()) cov[0, 0] += 0.01 * ot.DistFunc.rNormal() cov[1, 1] += 0.01 * ot.DistFunc.rNormal() alpha = ot.SquareMatrix(dim) for k in range(p): for j in range(dim): for i in range(dim): alpha[i, j] = 0.01 * ot.DistFunc.rNormal() ar[k] = ar[k] + alpha
#! /usr/bin/env python import openturns as ot size = 100 # ARMA parameters arcoefficients = ot.ARMACoefficients([0.3]) macoefficients = ot.ARMACoefficients(0) timeGrid = ot.RegularGrid(0.0, 0.1, size) # White noise ==> gaussian whiteNoise = ot.WhiteNoise(ot.Normal(), timeGrid) myARMA = ot.ARMA(arcoefficients, macoefficients, whiteNoise) # A realization of the ARMA process # The realization is supposed to be of a stationnary process realization = ot.TimeSeries(myARMA.getRealization()) # In the strategy of tests, one has to detect a trend tendency # We check if the time series writes as x_t = a +b * t + c * x_{t-1} # H0 = c is equal to one and thus # p-value threshold : probability of the H0 reject zone : 0.05 # p-value : probability (test variable decision > test variable decision (statistic) evaluated on data) # Test = True <=> p-value > p-value threshold test = ot.DickeyFullerTest(realization) print("Drift and linear trend model=", test.testUnitRootInDriftAndLinearTrendModel(0.05)) print("Drift model=", test.testUnitRootInDriftModel(0.05)) print("AR1 model=", test.testUnitRootInAR1Model(0.05))
tMin = 0. time_step = 0.1 n = 100 time_grid = ot.RegularGrid(tMin, time_step, n) # Create the distribution of dimension 1 or 3 # Care : the mean must be NULL myDist_1 = ot.Triangular(-1., 0.0, 1.) # Create a white noise of dimension 1 myWN_1d = ot.WhiteNoise(myDist_1, time_grid) # Create the ARMA model : ARMA(4,2) in dimension 1 myARCoef = ot.ARMACoefficients([0.4, 0.3, 0.2, 0.1]) myMACoef = ot.ARMACoefficients([0.4, 0.3]) arma = ot.ARMA(myARCoef, myMACoef, myWN_1d) # %% # Check the linear recurrence arma # %% # Get the coefficients of the recurrence print('AR coeff = ', arma.getARCoefficients()) print('MA coeff = ', arma.getMACoefficients()) # %% # Get the white noise myWhiteNoise = arma.getWhiteNoise() myWhiteNoise
# # %% # The definition of the recurrence coefficients AR, MA (4,2) is simple : myARCoef = ot.ARMACoefficients([0.4, 0.3, 0.2, 0.1]) myMACoef = ot.ARMACoefficients([0.4, 0.3]) # %% # We build a regular time discretization of the interval [0,1] with 10 time steps. # We also set up the white noise distribution of the recurrence relation : myTimeGrid = ot.RegularGrid(0.0, 0.1, 10) myWhiteNoise = ot.WhiteNoise(ot.Triangular(-1.0, 0.0, 1.0), myTimeGrid) # %% # We are now ready to create the ARMA-process : process = ot.ARMA(myARCoef, myMACoef, myWhiteNoise) print(process) # %% # ARMA process manipulation # ------------------------- # # In this paragraph we shall expose some of the services exposed by an :math:`ARMA(p,q)` object, namely : # # - its AR and MA coefficients thanks to the methods *getARCoefficients, # getMACoefficients*, # # - its white noise thanks to the method *getWhiteNoise*, that contains # the time grid of the process, # # - its current state, that is its last :math:`p` values and the last
# %% from __future__ import print_function import openturns as ot import openturns.viewer as viewer from matplotlib import pylab as plt import math as m ot.Log.Show(ot.Log.NONE) # %% # Define the recurrence coefficients AR, MA (4,2) myARCoef = ot.ARMACoefficients([0.4, 0.3, 0.2, 0.1]) myMACoef = ot.ARMACoefficients([0.4, 0.3]) # %% # Define the white noise distribution of the recurrent relation. myTimeGrid = ot.RegularGrid(0.0, 0.1, 10) myWhiteNoise = ot.WhiteNoise(ot.Triangular(-1.0, 0.0, 1.0), myTimeGrid) # %% # Create the process: process = ot.ARMA(myARCoef, myMACoef, myWhiteNoise) print(process) # %% # Draw a sample sample = process.getSample(6) graph = sample.drawMarginal(0) view = viewer.View(graph) plt.show()
size = 400 timeGrid = ot.RegularGrid(0.0, dt, size) # white noise cov = ot.CovarianceMatrix([[0.1, 0.0], [0.0, 0.2]]) whiteNoise = ot.WhiteNoise(ot.Normal([0.0] * dim, cov), timeGrid) # AR/MA coefficients ar = ot.ARMACoefficients(p, dim) ar[0] = ot.SquareMatrix([[-0.5, -0.1], [-0.4, -0.5]]) ar[1] = ot.SquareMatrix([[0.0, 0.0], [-0.25, 0.0]]) ma = ot.ARMACoefficients(q, dim) ma[0] = ot.SquareMatrix([[-0.4, 0.0], [0.0, -0.4]]) # ARMA model creation arma = ot.ARMA(ar, ma, whiteNoise) arma # %% # Create a realization timeSeries = ot.TimeSeries(arma.getRealization()) # %% # Estimate the process from the previous realization factory = ot.ARMALikelihoodFactory(p, q, dim) factory.setInitialConditions(ar, ma, cov) arma_est = ot.ARMA(factory.build(timeSeries)) print('Estimated ARMA= ', arma_est)
import openturns as ot from matplotlib import pyplot as plt from openturns.viewer import View if ot.ARMA().__class__.__name__ == 'Process': # default to Gaussian for the interface class process = ot.GaussianProcess() elif ot.ARMA().__class__.__name__ == 'DiscreteMarkovChain': process = ot.ARMA() process.setTransitionMatrix(ot.SquareMatrix([[0.0,0.5,0.5],[0.7,0.0,0.3],[0.8,0.0,0.2]])) origin = 0 process.setOrigin(origin) else: process = ot.ARMA() process.setTimeGrid(ot.RegularGrid(0.0, 0.02, 50)) process.setDescription(['$x$']) sample = process.getSample(6) sample_graph = sample.drawMarginal(0) sample_graph.setTitle(str(process)) fig = plt.figure(figsize=(10, 4)) sample_axis = fig.add_subplot(111) View(sample_graph, figure=fig, axes=[sample_axis], add_legend=False)
import openturns as ot from matplotlib import pyplot as plt from openturns.viewer import View process = ot.ARMA() process.setTimeGrid(ot.RegularGrid(0.0, 0.02, 50)) process.setDescription(['$x$']) sample = process.getSample(6) sample_graph = sample.drawMarginal(0) fig = plt.figure(figsize=(10, 4)) plt.suptitle(str(process)) sample_axis = fig.add_subplot(111) View(sample_graph, figure=fig, axes=[sample_axis], add_legend=False)