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)
# %% # 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) estimatedModel_PS = factory.build(sample)
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.ExponentialCauchy(scale, amplitude) myNormalProcess = ot.SpectralGaussianProcess(model, myTimeGrid) # Get a time series or a sample of time series # myTimeSeries = myNormalProcess.getRealization() mySample = myNormalProcess.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)
import openturns as ot from matplotlib import pyplot as plt from openturns.viewer import View if ot.SpectralGaussianProcess().__class__.__name__ == 'Process': # default to Gaussian for the interface class process = ot.GaussianProcess() elif ot.SpectralGaussianProcess().__class__.__name__ == 'DiscreteMarkovChain': process = ot.SpectralGaussianProcess() 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.SpectralGaussianProcess() 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)
# 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") view = viewer.View(graph) # %% # Display figures plt.show()
import openturns as ot from matplotlib import pyplot as plt from openturns.viewer import View process = ot.SpectralGaussianProcess() 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)