import openturns as ot
from matplotlib import pyplot as plt
from openturns.viewer import View
ot.RandomGenerator.SetSeed(0)
factory = ot.LogNormalFactory()
ref = factory.build()
dimension = ref.getDimension()
if dimension <= 2:
    sample = ref.getSample(50)
    distribution = factory.build(sample)
    if dimension == 1:
        distribution.setDescription(['$t$'])
        pdf_graph = distribution.drawPDF(256)
        cloud = ot.Cloud(sample, ot.Sample(sample.getSize(), 1))
        cloud.setColor('blue')
        cloud.setPointStyle('fcircle')
        pdf_graph.add(cloud)
        fig = plt.figure(figsize=(10, 4))
        plt.suptitle(str(distribution))
        pdf_axis = fig.add_subplot(111)
        View(pdf_graph, figure=fig, axes=[pdf_axis], add_legend=False)
    else:
        sample = ref.getSample(500)
        distribution.setDescription(['$t_0$', '$t_1$'])
        pdf_graph = distribution.drawPDF([256] * 2)
        cloud = ot.Cloud(sample)
        cloud.setColor('red')
        cloud.setPointStyle('fcircle')
        pdf_graph.add(cloud)
        fig = plt.figure(figsize=(10, 4))
        plt.suptitle(str(distribution))
예제 #2
0
    # graph.draw('curve7.png')
    view = View(graph)
    # view.save('curve7.png')
    view.ShowAll(block=True)

    # Pie
    graph = ot.SobolIndicesAlgorithm.DrawImportanceFactors(
        [.4, .3, .2, .1], ['a0', 'a1', 'a2', 'a3'], 'Zou')
    # graph.draw('curve8.png')
    view = View(graph)
    # view.save('curve8.png')
    view.show()

    # Convergence graph curve
    aCollection = []
    aCollection.append(ot.LogNormalFactory().build(
        ot.LogNormalMuSigma()([300.0, 30.0, 0.0])))
    aCollection.append(ot.Normal(75e3, 5e3))
    myDistribution = ot.ComposedDistribution(aCollection)
    vect = ot.RandomVector(myDistribution)
    LimitState = ot.SymbolicFunction(('R', 'F'), ('R-F/(pi_*100.0)', ))
    G = ot.CompositeRandomVector(LimitState, vect)
    myEvent = ot.ThresholdEvent(G, ot.Less(), 0.0)
    experiment = ot.MonteCarloExperiment()
    myAlgo = ot.ProbabilitySimulationAlgorithm(myEvent, experiment)
    myAlgo.setMaximumCoefficientOfVariation(0.05)
    myAlgo.setMaximumOuterSampling(int(1e5))
    myAlgo.run()
    graph = myAlgo.drawProbabilityConvergence()
    # graph.draw('curve10.png')
    view = View(graph)
    # view.save('curve10.png')
예제 #3
0
from __future__ import print_function
import openturns as ot
from openturns.viewer import View

# Generate some data
size = 250
sample = ot.LogNormal(0.0, 0.4).getSample(size)

# Estimate the distribution
parametric_estimate = ot.LogNormalFactory().build(sample)
nonparametric_estimate = ot.KernelSmoothing().build(sample)

# Draw a non parametric estimate and the parametric estimate
graph = parametric_estimate.drawPDF(0.0, 4.0)
graph.add(nonparametric_estimate.drawPDF(0.0, 4.0))
graph.add(ot.Cloud(sample, ot.Sample(size, 1)))
graph.setLegendPosition("topright")
graph.setXTitle(r"$x$")
graph.setYTitle(r"$p_X$")
graph.setTitle(r"Parametric vs nonparametric estimation")
graph.setColors(["red", "blue", "green"])
graph.setLegends(["parametric", "nonparametric", "data"])
view = View(graph, (800, 600))
view.save("../plot_distribution_fitting.png")
view.close()