Esempio n. 1
0
def ot_drawcontour(ot_draw):
    ot.ResourceMap_SetAsUnsignedInteger("Contour-DefaultLevelsNumber", 7)
    drawables = ot_draw.getDrawables()
    levels = []
    for i in range(len(drawables)):
        contours = drawables[i]
        levels.append(contours.getLevels()[0])
    ot.ResourceMap.SetAsUnsignedInteger('Drawable-DefaultPalettePhase',
                                        len(levels))  #Colors
    palette = ot.Drawable.BuildDefaultPalette(len(levels))  #Colors
    newcontour = ot_draw.getDrawable(0)
    drawables = list()
    for i in range(len(levels)):
        newcontour.setLevels([levels[i]])  # Inline the level values
        newcontour.setDrawLabels(True)
        newcontour.setLabels([str("{:.3e}".format(levels[i]))])
        # We have to copy the drawable because a Python list stores only pointers
        drawables.append(ot.Drawable(newcontour))
    graphFineTune = ot.Graph("", "", "", True, '')
    graphFineTune.setDrawables(drawables)
    graphFineTune.setColors(palette)  # Add colors
    return graphFineTune
Esempio n. 2
0
graph = ot.Graph(
    "Evolution of the number of exceedances",
    "iteration nb",
    "number of exceedances",
    True,
)
graph.add(curve)
graph.setLegends(["number of exceedances"])
graph.setLegendPosition("bottomright")
view = otv.View(graph)

# %%
# The following plot shows that the probability of exceeding the threshold converges.

# %%
palette = ot.Drawable().BuildDefaultPalette(2)
iterationSample = ot.Sample.BuildFromPoint(range(1, size + 1))
curve = ot.Curve(iterationSample, probabilityEstimateSample)
curve.setLegend("Prob. of exceeding the threshold")
curve.setColor(palette[0])
#
exactCurve = ot.Curve([1, size], [exactProbability, exactProbability])
exactCurve.setLegend("Exact")
exactCurve.setColor(palette[1])
#
graph = ot.Graph(
    "Evolution of the sample probability",
    "iteration nb",
    "estimate of the probability",
    True,
)
graph.setAxes(True)
graph.setGrid(True)
graph.setTitle('Subset sampling: samples')
graph.setXTitle(r'$x_1$')
graph.setYTitle(r'$x_2$')
graph.setLegendPosition('bottomleft')

# %%
# Add all the subset samples:

# %%
for i in range(Ns):
    cloud = ot.Cloud(list_subSamples[i])
    # cloud.setPointStyle("dot")
    graph.add(cloud)
col = ot.Drawable().BuildDefaultPalette(Ns)
graph.setColors(col)

# %%
# Add the frontiers :math:`g(x_1, x_2) = l_i` where :math:`l_i` is the threshold at the step :math:`i`:

# %%
gIsoLines = g.draw([-3] * 2, [5] * 2, [128] * 2)
dr = gIsoLines.getDrawable(0)
for i in range(levels.getSize()):
    dr.setLevels([levels[i]])
    dr.setLineStyle('solid')
    dr.setLegend(r'$g(X) = $' + str(round(levels[i], 2)))
    dr.setLineWidth(3)
    dr.setColor(col[i])
    graph.add(dr)
# We now build fancy isolines :

# Take the first contour as the only one with multiple levels
contour = graphBasic.getDrawable(0)
# Build a range of colors
ot.ResourceMap.SetAsUnsignedInteger('Drawable-DefaultPalettePhase',
                                    len(levels))
palette = ot.Drawable.BuildDefaultPalette(len(levels))
# Create the drawables list, appending each contour with its own color
drawables = list()
for i in range(len(levels)):
    contour.setLevels([levels[i]])
    # Inline the level values
    contour.setDrawLabels(True)
    # We have to copy the drawable because a Python list stores only pointers
    drawables.append(ot.Drawable(contour))

graphFineTune = ot.Graph("The exact Branin model", r"$x_1$", r"$x_2$", True,
                         '')
graphFineTune.setDrawables(drawables)  # Replace the drawables
graphFineTune.setLegendPosition("")  # Remove the legend
graphFineTune.setColors(palette)  # Add colors

# %%
# We also represent the three minima of the Branin function with orange diamonds :
sample1 = ot.Sample([bm.xexact1, bm.xexact2, bm.xexact3])
cloud1 = ot.Cloud(sample1, 'orange', 'diamond', 'First Cloud')
graphFineTune.add(cloud1)
view = otv.View(graphFineTune)

#