Created
April 13, 2023 09:22
-
-
Save sofianehaddad/a6f94bf992f8bde3810f9013bb1f3665 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import openturns as ot | |
import openturns.viewer as otv | |
import numpy as np | |
def draw_loo(error): | |
g = ot.Graph() | |
g.setXTitle("step") | |
g.setYTitle("error") | |
g.setAxes(True) | |
g.setGrid(True) | |
g.setLogScale(2) | |
step_list = [i for i in range(len(error))] | |
g.add(ot.Curve(step_list, error)) | |
return g | |
def draw_path(path_indices, enumerate_function): | |
# Activation path | |
g = ot.Graph() | |
g.setXTitle("step") | |
g.setYTitle("Function index") | |
g.setAxes(True) | |
g.setGrid(True) | |
if len(path_indices) > 0: | |
step_list = [i for i in range(len(path_indices))] | |
input_dimension = enumerate_function.getDimension() | |
hue_step = 360 / input_dimension; | |
hue = 0.0 | |
# Create one drawable per input dimension for the legend | |
for i in range(input_dimension): | |
color = ot.Drawable.ConvertFromHSV(hue, 1.0, 1.0) | |
base = ot.Curve([[step_list[0], 0.0], [step_list[-1], 0.0]]) | |
base.setColor(color) | |
g.add(base) | |
hue += hue_step | |
for i, index in enumerate(path_indices): | |
indices = enumerate_function(index) | |
sumComponents = sum(indices) | |
maxComponent = np.array(indices).argmax() | |
if sumComponents > 0: | |
hue = maxComponent * hue_step | |
saturation = indices[maxComponent] / sumComponents | |
color = ot.Drawable.ConvertFromHSV(hue, saturation, 1.0) | |
else: | |
color = "black" | |
path = ot.Curve([[step_list[0], 0], [step_list[i], 0], [step_list[i], index], [step_list[-1], index]]) | |
path.setColor(color) | |
g.add(path) | |
legend = ot.Description.BuildDefault(input_dimension, "X") | |
for i in range(g.getDrawables().getSize() - input_dimension): | |
legend.add("") | |
g.setLegends(legend) | |
g.setLegendPosition("topleft") | |
return g |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment