Exemplo n.º 1
0
from matplotlib import pylab as plt
import math as m
ot.Log.Show(ot.Log.NONE)

# %%
# Create the RegularGrid
tMin = 0.
timeStep = 0.1
N = 100
myTimeGrid = ot.RegularGrid(tMin, timeStep, N)

# %%
# Case 1: Create a time series from a time grid and values
# Care! The number of steps of the time grid must correspond to the size of the values
myValues = ot.Normal(3).getSample(myTimeGrid.getVertices().getSize())
myTimeSeries = ot.TimeSeries(myTimeGrid, myValues)
myTimeSeries

# %%
# Case 2: Get a time series from a Process
myProcess = ot.WhiteNoise(ot.Normal(3), myTimeGrid)
myTimeSeries2 = myProcess.getRealization()
myTimeSeries2

# %%
# Get the number of values of the time series
myTimeSeries.getSize()

# %%
# Get the dimension of the values observed at each time
myTimeSeries.getMesh().getDimension()
Exemplo n.º 2
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
factory = ot.WhittleFactory(p, q)
print("Default spectral model factory = ", factory.getSpectralModelFactory())
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

for k in range(q):
    for j in range(dim):
        for i in range(dim):
Exemplo n.º 4
0
#! /usr/bin/env python

from __future__ import print_function
import openturns as ot

dim = 2

# We create an empty series
ts1 = ot.TimeSeries(0, dim)
ts1.setName('Ts1')

# We populate the empty ts
for p in range(3):
    pt = ot.Point(dim)
    for i in range(dim):
        pt[i] = 10. * (p + 1) + i
    ts1.add(pt)

print('ts1=', ts1)
print('len=', len(ts1))

# We get the second element of the ts
secondElement = ts1[1]
print('second element=', secondElement)

# We set the third element to a valid new element
newPoint = ot.Point(dim + 1)
for i in range(dim):
    newPoint[i + 1] = 1000. * (i + 1)
ts1[2] = newPoint
print('ts1=', ts1)
from __future__ import print_function
import openturns as ot

ot.TESTPREAMBLE()

# Create an intance
myFunc = ot.SymbolicFunction(["t", "x"], ["x + t^2"])
tg = ot.RegularGrid(0.0, 0.2, 6)
myTemporalFunc = ot.VertexValueFunction(myFunc, tg)

print("myTemporalFunc=", myTemporalFunc)
# Get the input and output description
print("myTemporalFunc input description=",
      myTemporalFunc.getInputDescription())
print("myTemporalFunc output description=",
      myTemporalFunc.getOutputDescription())
# Get the input and output dimension, based on description
print("myTemporalFunc input dimension=", myTemporalFunc.getInputDimension())
print("myTemporalFunc output dimension=", myTemporalFunc.getOutputDimension())
# Create a TimeSeries
data = ot.Sample(tg.getN(), myFunc.getInputDimension() - 1)
for i in range(data.getSize()):
    for j in range(data.getDimension()):
        data[i, j] = i * data.getDimension() + j
ts = ot.TimeSeries(tg, data)
print("input time series=", ts)
print("output time series=", myTemporalFunc(ts))
# Get the number of calls
print("called ", myTemporalFunc.getCallsNumber(), " times")
Exemplo n.º 6
0
ot.TESTPREAMBLE()

# size of timeGrid
size = 6
dimension = 1
sample = ot.Sample(size, dimension)
for i in range(size):
    for j in range(dimension):
        sample[i, j] = i + j + 1

# TimeGrid
timeGrid = ot.RegularGrid(0.0, 1.0 / (size - 1), size)

# TimeSeries
timeSeries = ot.TimeSeries(timeGrid, sample)

# We create an empty ProcessSample with default constructor
psample0 = ot.ProcessSample()
psample0.setName("PSample0")
print("Default constructor")
print("psample0=", psample0)

# We create an empty ProcessSample with timeGrid, size and dimension
# arguments
psample1 = ot.ProcessSample(timeGrid, 4, dimension)
psample1.setName("PSample1")
print("Constructor based on size, dimension and timeGrid")
print("psample1=", psample1)

# change the first component using operator []