Select Git revision
doc_import.html
g.py 3.05 KiB
import plotly
import plotly.subplots
import plotly.graph_objects as go
import numpy as np
from . import data_lib
import pathlib
import sys, os
d = pathlib.Path("/".join(__file__.split("/")[:-1]))
def load(name):
return data_lib.Data(d/name, validate_versions=False, remove_duplications=True)
def load_main_test():
return load(d/"main_test/log")
algo_to_name = {
"greedy": "Hladové ř.",
"rg": "Rekurzivní ř.",
"rsg": "Hvězdičkové r. ř.",
"semidef_prog(10)": "Semidefinitní ř.",
}
algo_to_color = {
"greedy": '#8a00d4',
"rg": '#d527b7',
"rsg": '#f782c2',
"semidef_prog(10)": '#f9c46b',
}
def draw_algo_graph(fig, data, algo, n, val_getter=lambda x:x.score, name=None, color=None):
d = data_lib.group_by_n(data.pipelines[algo])[n]
y = [0 for i in range(2*n)]
for i in d:
y[val_getter(i)] += 1
fig.add_trace(go.Histogram(x=[val_getter(i) for i in d], name=name or algo_to_name[algo], xbins=dict(size=1), marker=dict(color=color or algo_to_color[algo])))
fig.add_trace(go.Box(x=[val_getter(i) for i in d], name="", showlegend=False, marker=dict(color=color or algo_to_color[algo]), boxmean=True), row=2, col=1)
fig.update_xaxes(range=[0, 2*n])
# xaxis=np.arange(0, 2*n)
fig.update_layout(yaxis_title="Počet řešení.")
fig.update_xaxes(title_text="Skóre.", row=2, col=1)
def intro_graph(algo):
fig = plotly.subplots.make_subplots(rows=2, cols=1, row_heights=[0.8, 0.2], shared_xaxes=True, vertical_spacing = 0.05)
draw_algo_graph(fig, load_main_test(), algo, 200)
fig.update_layout(showlegend=False)
return fig
def nonzero_coords(n, seeds, max_dim=20):
data_dir = d/"main_test/sdp/nonzero_coord"
nonzero_coords = [[float(i) for i in open(data_dir/f).read().split()] for f in os.listdir(data_dir) if f.startswith(f"{n}-")]
fig = go.Figure(data=[go.Box(
y=[x[i] for x in nonzero_coords],
name=f"{i}"
) for i in range(max_dim)]
+ [go.Box(
y=[sum(x[max_dim:]) for x in nonzero_coords],
name=f"≥{max_dim}"
)])
fig.update_layout(
xaxis_title="Index souřadnice.",
yaxis_title="Počet bodů s hodnotou dané souřadnice ≥ 0.05.",
xaxis=dict(showgrid=False),
yaxis=dict(range=[0, n]),
showlegend=False
)
return fig
def max_coords(n, seeds, max_dim=20):
data_dir = d/"main_test/sdp/max_coord"
max_coords = [[float(i) for i in open(data_dir/f).read().split()] for f in os.listdir(data_dir) if f.startswith(f"{n}-")]
fig = go.Figure(data=[go.Box(
y=[x[i] for x in max_coords],
name=f"{i}"
) for i in range(max_dim)]
+ [go.Box(
y=[max(x[max_dim:]) for x in max_coords],
name=f"≥{max_dim}"
)])
fig.update_layout(
xaxis_title="Index souřadnice.",
yaxis_title="Max. hodnota dané souřadnice všech bodů řešení.",
xaxis=dict(showgrid=False),
yaxis=dict(range=[0, 1]),
showlegend=False
)
return fig