from math import exp
from matplotlib import pyplot as plt
from openturns.viewer import View

# Create the time grid
# In the context of the spectral estimate or Fourier transform use,
# we use data blocs with size of form 2^p
tMin = 0.
timeStep = 0.1
size = pow(2, 12)
myTimeGrid = ot.RegularGrid(tMin, timeStep, size)

# We fix the parameter of the Cauchy model
amplitude = [5]
scale = [3]
model = ot.CauchyModel(scale, amplitude)
gp = ot.SpectralGaussianProcess(model, myTimeGrid)

# Get a time series or a sample of time series
# myTimeSeries = gp.getRealization()
mySample = gp.getSample(1000)

mySegmentNumber = 10
myOverlapSize = 0.3

# Build a spectral model factory
myFactory = ot.WelchFactory(ot.Hanning(), mySegmentNumber, myOverlapSize)

# Estimation on a TimeSeries or on a ProcessSample
# myEstimatedModel_TS = myFactory.build(myTimeSeries)
myEstimatedModel_PS = myFactory.buildAsUserDefinedSpectralModel(mySample)
예제 #2
0
# %%
# generate some data

# Create the time grid
# In the context of the spectral estimate or Fourier transform use,
# we use data blocs with size of form 2^p
tMin = 0.
tstep = 0.1
size = 2**12
tgrid = ot.RegularGrid(tMin, tstep, size)

# We fix the parameter of the Cauchy model
amplitude = [5.0]
scale = [3.0]
model = ot.CauchyModel(amplitude, scale)
process = ot.SpectralGaussianProcess(model, tgrid)

# Get a time series or a sample of time series
tseries = process.getRealization()
sample = process.getSample(1000)

# %%
# Build a spectral model factory
segmentNumber = 10
overlapSize = 0.3
factory = ot.WelchFactory(ot.Hann(), segmentNumber, overlapSize)

# %%
# Estimation on a TimeSeries or on a ProcessSample
estimatedModel_TS = factory.build(tseries)
예제 #3
0
view = viewer.View(graph)

# %%
# Create a gaussian process from spectral density
# -----------------------------------------------
#
# In this paragraph we build a gaussian process from its spectral density.
#

# %%
# We first define a spectral model :
amplitude = [1.0, 2.0]
scale = [4.0, 5.0]
spatialCorrelation = ot.CorrelationMatrix(2)
spatialCorrelation[0, 1] = 0.8
mySpectralModel = ot.CauchyModel(scale, amplitude, spatialCorrelation)

# %%
# As usual we define a mesh,
myTimeGrid = ot.RegularGrid(0.0, 0.1, 20)

# %%
# and create the process thereafter
process = ot.SpectralGaussianProcess(mySpectralModel, myTimeGrid)
print(process)

# %%
# Eventually we draw the first marginal of a sample of size 6 :
sample = process.getSample(6)
graph = sample.drawMarginal(0)
graph.setTitle("First marginal of six realizations of the process")
import openturns as ot
from matplotlib import pyplot as plt
from openturns.viewer import View
spectralModel = ot.CauchyModel()
if spectralModel.getInputDimension() == 1:
    spec_graph = spectralModel.draw(0, 0, True)
    spec_graph.setXTitle('f')
    spec_graph.setYTitle('Spectral Density')
    fig = plt.figure(figsize=(10, 4))
    plt.suptitle(str(spectralModel))
    spec_axis = fig.add_subplot(111)
    View(spec_graph, figure=fig, axes=[spec_axis], add_legend=False)
예제 #5
0
# %%
import openturns as ot
import openturns.viewer as viewer
from matplotlib import pylab as plt

ot.Log.Show(ot.Log.NONE)

# %%
# 1. Define a spectral density function from correlation matrix
amplitude = [1.0, 2.0, 3.0]
scale = [4.0, 5.0, 6.0]
spatialCorrelation = ot.CorrelationMatrix(3)
spatialCorrelation[0, 1] = 0.8
spatialCorrelation[0, 2] = 0.6
spatialCorrelation[1, 2] = 0.1
spectralModel_Corr = ot.CauchyModel(amplitude, scale, spatialCorrelation)
spectralModel_Corr

# %%
# 2. Define a spectral density function from a covariance matrix
spatialCovariance = ot.CovarianceMatrix(3)
spatialCovariance[0, 0] = 4.0
spatialCovariance[1, 1] = 5.0
spatialCovariance[2, 2] = 6.0
spatialCovariance[0, 1] = 1.2
spatialCovariance[0, 2] = 0.9
spatialCovariance[1, 2] = -0.2
spectralModel_Cov = ot.CauchyModel(scale, spatialCovariance)
spectralModel_Cov