import openturns as ot
from matplotlib import pyplot as plt
from openturns.viewer import View
if ot.WhiteNoise().__class__.__name__ == 'Process':
    # default to Gaussian for the interface class
    process = ot.GaussianProcess()
elif ot.WhiteNoise().__class__.__name__ == 'DiscreteMarkovChain':
    process = ot.WhiteNoise()
    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.WhiteNoise()
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)
Esempio n. 2
0
# 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()

# %%
# Get the value Xi at index i
i = 37
print('Xi = ', myTimeSeries.getValueAtIndex(i))
# %%
from __future__ import print_function
import openturns as ot
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
Esempio n. 4
0
from matplotlib import pylab as plt
import math as m
ot.Log.Show(ot.Log.NONE)

# %%
# Define the distribution
sigma = 1.0
dist = ot.Normal(0.0, sigma)

# %%
# Define the mesh
tgrid = ot.RegularGrid(0.0, 1.0, 100)

# %%
# Create the process
process = ot.WhiteNoise(dist, tgrid)
process

# %%
# Draw a realization
realization = process.getRealization()
graph = realization.drawMarginal(0)
graph.setTitle('Realization of a white noise with distribution N(0,1)')
view = viewer.View(graph)

# %%
# Draw a sample
sample = process.getSample(5)
graph = sample.drawMarginal(0)
graph.setTitle(
    str(sample.getSize()) +
Esempio n. 5
0
    inVars[i] = "x" + str(i)
model = ot.SymbolicFunction(inVars, inVars)
# The output vector
Y = ot.CompositeRandomVector(model, X)
# The domain: [0, 1]^dim
domain = ot.Interval(dim)
# The event
event = ot.DomainEvent(Y, domain)

print("sample=", event.getSample(10))

#
# Case 2: process based event
#

# The input process
X = ot.WhiteNoise(distribution)
# The domain: [0, 1]^dim
domain = ot.Interval(dim)
# The event
event = ot.ProcessEvent(X, domain)

print("sample=", event.getSample(10))

# 3. from distribution
antecedent = ot.RandomVector(ot.Normal(2))
domain = ot.LevelSet(ot.SymbolicFunction(['x', 'y'], ['x^2+y^2']), ot.Less(),
                     1.0)
event = ot.DomainEvent(antecedent, domain)
print('sample=', event.getSample(10))
import openturns as ot

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

# Make a realization of an ARMA model
# Tmin , Tmax and N points for TimeGrid
dt = 1.0
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
myARMA = ot.ARMA(ar, ma, whiteNoise)

# Create a realization
timeSeries = ot.TimeSeries(myARMA.getRealization())
Esempio n. 7
0
# In this example we are going to concatenate several processes that share the same mesh.

# %%
import openturns as ot
import openturns.viewer as viewer
from matplotlib import pylab as plt
ot.Log.Show(ot.Log.NONE)

# %%
# Create processes to aggregate
myMesher = ot.IntervalMesher([100, 10])
lowerbound = [0.0, 0.0]
upperBound = [2.0, 4.0]
myInterval = ot.Interval(lowerbound, upperBound)
myMesh = myMesher.build(myInterval)
myProcess1 = ot.WhiteNoise(ot.Normal(), myMesh)
myProcess2 = ot.WhiteNoise(ot.Triangular(), myMesh)

# %%
# Draw values of a realization of the 2nd process
marginal = ot.HistogramFactory().build(myProcess1.getRealization().getValues())
graph = marginal.drawPDF()
view = viewer.View(graph)

# %%
# Create an aggregated process
myAggregatedProcess = ot.AggregatedProcess([myProcess1, myProcess2])

# %%
# Draw values of the realization on the 2nd marginal
marginal = ot.HistogramFactory().build(
# %%
# Create an ARMA process

# Create the mesh
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())
#! /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))
Esempio n. 10
0
dim = 2
distribution = ot.Normal(dim)
Xvector = ot.RandomVector(distribution)
f = ot.SymbolicFunction(['x0', 'x1'], ['x0+x1'])
Yvector = ot.CompositeRandomVector(f, Xvector)
s = 1.0
event1 = ot.Event(Yvector, ot.Greater(), s)
description.add('composite vector/domain event')
domain1D = ot.LevelSet(ot.SymbolicFunction(['x0'], ['sin(x0)']),
                       ot.LessOrEqual(), -0.5)
event2 = ot.Event(Yvector, domain1D)
description.add('composite vector/interval event')
interval = ot.Interval(0.5, 1.5)
event3 = ot.Event(Yvector, interval)
description.add('process/domain event')
Xprocess = ot.WhiteNoise(distribution, ot.RegularGrid(0.0, 0.1, 10))
domain2D = ot.LevelSet(ot.SymbolicFunction(['x0', 'x1'], ['(x0-1)^2+x1^2']),
                       ot.LessOrEqual(), 1.0)
event4 = ot.Event(Xprocess, domain2D)
all_events = [event1, event2, event3, event4]
for i, event in enumerate(all_events):
    print(description[i])
    if event.isComposite():
        experiment = ot.MonteCarloExperiment()
        myAlgo = ot.ProbabilitySimulationAlgorithm(event, experiment)
    else:
        myAlgo = ot.ProbabilitySimulationAlgorithm(event)
    myAlgo.setMaximumOuterSampling(250)
    myAlgo.setBlockSize(4)
    myAlgo.setMaximumCoefficientOfVariation(0.1)
    myAlgo.run()
import openturns as ot
from matplotlib import pyplot as plt
from openturns.viewer import View
process = ot.WhiteNoise()
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)