#! /usr/bin/env python from __future__ import print_function import openturns as ot distribution = ot.Gumbel(2.0, 2.5) size = 10000 sample = distribution.getSample(size) factory = ot.GumbelFactory() print('Distribution =', repr(distribution)) result = factory.buildEstimator(sample) estimatedDistribution = result.getDistribution() print('Estimated distribution =', repr(estimatedDistribution)) parameterDistribution = result.getParameterDistribution() print('Parameter distribution =', parameterDistribution) defaultDistribution = factory.build() print('Default distribution =', defaultDistribution) fromParameterDistribution = factory.build(distribution.getParameter()) print('Distribution from parameters =', fromParameterDistribution) typedEstimatedDistribution = factory.buildAsGumbel(sample) print('Typed estimated distribution =', typedEstimatedDistribution) defaultTypedDistribution = factory.buildAsGumbel() print('Default typed distribution =', defaultTypedDistribution) typedFromParameterDistribution = factory.buildAsGumbel( distribution.getParameter()) print('Typed distribution from parameters=', typedFromParameterDistribution) result = factory.buildEstimator(sample, ot.GumbelAB()) estimatedDistribution = result.getDistribution() print('Estimated distribution (AB) =', repr(estimatedDistribution)) parameterDistribution = result.getParameterDistribution() print('Parameter distribution (AB) =', parameterDistribution)
ot.RandomGenerator.SetSeed(0) sample = ot.Normal(3).getSample(300) sample.stack(ot.Gumbel().getSample(300)) sample.setDescription(['X0', 'X1', 'X2', 'X3']) sample.exportToCSVFile(filename, ',') columns = [0, 2, 3] model = persalys.DataModel('myDataModel', "data1.csv", columns) myStudy.add(model) print(model) # Inference analysis ## analysis = persalys.InferenceAnalysis('analysis', model) variables = ["X0", "X3"] analysis.setInterestVariables(variables) factories = [ot.NormalFactory(), ot.GumbelFactory()] analysis.setDistributionsFactories("X3", factories) analysis.setLevel(0.1) myStudy.add(analysis) print(analysis) analysis.run() result = analysis.getResult() print("result=", result) print(result.getFittingTestResultForVariable('X3')) # script script = myStudy.getPythonScript() print(script) exec(script)
# %% # We compare different fitting strategies for this sample: # # - use the histogram from the data (red) # - the GEV fitted distribution (black) # - the pure Frechet fitted distribution (green) # - the pure Gumbel fitted distribution (blue) # - the pure WeibullMax fitted distribution (dashed orange) # graph = myDistribution.drawPDF() graph.add(ot.HistogramFactory().build(sample).drawPDF()) distFrechet = ot.FrechetFactory().buildAsFrechet(sample) graph.add(distFrechet.drawPDF()) distGumbel = ot.GumbelFactory().buildAsGumbel(sample) graph.add(distGumbel.drawPDF()) # We change the line style of the WeibullMax. distWeibullMax = ot.WeibullMaxFactory().buildAsWeibullMax(sample) curveWeibullMax = distWeibullMax.drawPDF().getDrawable(0) curveWeibullMax.setLineStyle("dashed") graph.add(curveWeibullMax) graph.setColors(["black", "red", "green", "blue", "orange"]) graph.setLegends([ "GEV fitting", "histogram", "Frechet fitting", "Gumbel fitting", "WeibullMax fitting",
# In this example we are going to perform a visual goodness-of-fit test for an 1-d distribution with the QQ plot. # %% from __future__ import print_function import openturns as ot import openturns.viewer as viewer from matplotlib import pylab as plt ot.Log.Show(ot.Log.NONE) # %% # Create data ot.RandomGenerator.SetSeed(0) distribution = ot.Gumbel(0.2, 0.5) sample = distribution.getSample(100) sample.setDescription(['Sample']) # %% # Fit a distribution distribution = ot.GumbelFactory().build(sample) # %% # Draw QQ plot graph = ot.VisualTest.DrawQQplot(sample, distribution) view = viewer.View(graph) # %% # Incorrect proposition graph = ot.VisualTest.DrawQQplot(sample, ot.WeibullMin()) view = viewer.View(graph) plt.show()