Skip to content
Snippets Groups Projects
Commit 4c009fe5 authored by Jiří Kalvoda's avatar Jiří Kalvoda
Browse files

Prezentace na obhajobu

parent 7d9e2bf2
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
set -euo pipefail
./gen_plotly.py
lualatex main
biber main
#for i in main-*asy
#do
#asy $i
#done
lualatex main
#!/bin/env python3
from bakalarka import g, data_lib
import plotly as plotly_lib
import plotly.graph_objects as go
import pathlib
d = pathlib.Path("/".join(__file__.split("/")[:-1]))
def plotly_decorator():
def l(f):
fig = f()
fig.update_layout(
margin = {'l':0,'r':0,'t':0,'b':0},
font=dict(
size=10,
),
)
name = f.__name__
file = name + ".pdf"
plotly_lib.io.kaleido.scope.mathjax = None
plotly_lib.io.write_image(fig, file, format='pdf', width=440, height=290)
return l
data = g.load_main_test()
data_oponent = g.load(d/"oponent_test_log")
shift_unit = 1.06
@plotly_decorator()
def score():
fig = go.Figure(data=[go.Box(
x=[i.n * shift for i in d],
y=[i.score/i.n for i in d],
name=name
) for d,name, shift in [
[data.pipelines["greedy"], "g", 1/shift_unit],
[data.pipelines["rg"], "rg", shift_unit],
[data.pipelines["rsg"], "rsg", 1/shift_unit],
[data.pipelines["semidef_prog_sage.sage(10, CVXOPT)"], "sdp – Sage", 1/shift_unit],
[data.pipelines["semidef_prog(10)"], "sdp – SDPA-C", shift_unit],
]])
fig.add_hline(y=0.34,
annotation_text="0.34", annotation_position="top left",
fillcolor="green")
fig.update_traces(width=0.05)
fig.update_layout(
xaxis_title="Počet typů aut (logaritmická stupnice)",
yaxis_title="Relativní skóre",
xaxis=dict(showgrid=False, type="log"),
yaxis=dict(range=[0, 1]),
xaxis_title_standoff = 0,
margin_b = 15,
legend=dict(orientation="h"),
)
return fig
@plotly_decorator()
def time():
from math import log, exp
from sklearn.linear_model import LinearRegression
def gen(d, name, minim, color, color_line):
pred_x = list(range(minim, max(i.n for i in d)+1))
regr = LinearRegression()
regr_res = regr.fit([[log(i.n)] for i in d if i.resources_cpu_time_s and i.n>minim], [log(i.resources_cpu_time_s) for i in d if i.resources_cpu_time_s and i.n>minim])
predict = [exp(i) for i in regr.predict([[log(i)] for i in pred_x])]
return [
go.Box(
x=[i.n for i in d],
y=[i.resources_cpu_time_s for i in d],
name=name,
marker_color=color,
),
go.Scatter(x=pred_x, y=predict, mode="lines", marker_color=color_line, name=f"n^{regr.coef_[0]:.3} * {exp(regr.intercept_):.1g}".replace("-0", "-")),
]
data = g.load_main_test()
fig = go.Figure(data=[
*gen(data.pipelines["semidef_prog(10)"], "SDPA-C", 400, "blue", "lightblue"),
*gen(data.pipelines["semidef_prog_sage.sage(10, CVXOPT)"], "Sage", 100, "red", "pink"),
])
fig.update_layout(
xaxis_title="Počet typů aut (logaritmická stupnice)",
yaxis_title="Čas běhu v sekundách (logaritmická stupnice)",
xaxis=dict(showgrid=False, type="log"),
yaxis=dict(type="log"),
)
return fig
@plotly_decorator()
def oponent_score():
data = data_oponent
shift_unit = 1.5
fig = go.Figure(data=[go.Box(
x=[i.n + shift for i in d],
y=[i.score/i.n for i in d],
name=name
) for d,name, shift in [
[data.pipelines["greedy"], "g", -shift_unit],
[data.pipelines["rg"], "rg", shift_unit],
[data.pipelines["rsg"], "rsg", -shift_unit],
[data.pipelines["semidef_prog_sage.sage(10, CVXOPT)"], "sdp – Sage", shift_unit],
[data.pipelines["opt_int_prog.sage(GLPK)"], "opt – GLPK", -shift_unit],
[data.pipelines["opt_int_prog.sage(PPL)"], "sdp – PPL", shift_unit],
]])
fig.add_hline(y=0.34,
annotation_text="0.34", annotation_position="top left",
fillcolor="green")
fig.update_traces(width=2)
fig.update_layout(
xaxis_title="Počet typů aut",
yaxis_title="Relativní skóre",
xaxis=dict(showgrid=False),
yaxis=dict(range=[0, 1]),
xaxis_title_standoff = 0,
margin_b = 15,
legend=dict(orientation="h"),
)
return fig
@plotly_decorator()
def oponent_time():
data = data_oponent
from math import log, exp
from bakalarka import g, data_lib
from sklearn.linear_model import LinearRegression
def gen(d, name, minim, color, color_line, shift):
#pred_x = list(range(minim, max(i.n for i in d)+1))
#regr = LinearRegression()
#regr_res = regr.fit([[log(i.n)] for i in d if i.resources_cpu_time_s and i.n>minim], [log(i.resources_cpu_time_s) for i in d if i.resources_cpu_time_s and i.n>minim])
#predict = [exp(i) for i in regr.predict([[log(i)] for i in pred_x])]
return [
go.Box(
x=[i.n + shift for i in d],
y=[i.resources_cpu_time_s for i in d],
name=name,
marker_color=color,
),
#go.Scatter(x=pred_x, y=predict, mode="lines", marker_color=color_line, name=f"n^{regr.coef_[0]:.3} * {exp(regr.intercept_):.1g}".replace("-0", "-")),
]
shift = 1.2
fig = go.Figure(data=[
*gen(data.pipelines["semidef_prog(10)"], "sdp – SDPA-C", 400, "blue", None, -shift),
*gen(data.pipelines["semidef_prog_sage.sage(10, CVXOPT)"], "sdp – Sage", 100, "purple", None, shift),
*gen(data.pipelines["opt_int_prog.sage(GLPK)"], "opt – GLPK", 400, "red", None, -shift),
*gen(data.pipelines["opt_int_prog.sage(PPL)"], "opt – PPL", 100, "orange", None, shift),
])
fig.update_layout(
xaxis_title="Počet typů aut",
yaxis_title="Čas běhu v sekundách (logaritmická stupnice)",
xaxis=dict(showgrid=False),
yaxis=dict(type="log"),
)
return fig
\documentclass[pdf]{beamer}
\usepackage{pgfpages}
%\setbeameroption{show notes on second screen}
\usepackage[english,czech]{babel}
\usepackage{csquotes}
\usepackage[style=iso-authoryear]{biblatex}
\addbibresource{sample.bib}
\usepackage{graphicx}
\usepackage {mathtools}
\usepackage{utopia} %font utopia imported
\usetheme{Ilmenau}
\usepackage{amsthm}
\newtheorem{problemTH}{Problém}
\newtheorem{notaceTH}{Notace}
\newtheorem{veta}{Věta}
\newtheorem{hipoteza}{Hypotéza}
% set colors
\definecolor{myNewColorA}{RGB}{255,103,0} % eric orange
\definecolor{myNewColorB}{RGB}{169,169,169}
\definecolor{myNewColorC}{RGB}{255,103,0}
\setbeamercolor*{palette primary}{bg=myNewColorC}
\setbeamercolor*{palette secondary}{bg=myNewColorB, fg = white}
\setbeamercolor*{palette tertiary}{bg=myNewColorA, fg = white}
\setbeamercolor*{titlelike}{fg=myNewColorA}
\setbeamercolor*{title}{bg=myNewColorA, fg = white}
\setbeamercolor*{item}{fg=myNewColorA}
\setbeamercolor*{caption name}{fg=myNewColorA}
\usefonttheme{professionalfonts}
\usepackage{hyperref}
%------------------------------------------------------------
%\titlegraphic{\includegraphics[height=2cm]{logo.png}}
\setbeamerfont{title}{size=\large}
\setbeamerfont{subtitle}{size=\small}
\setbeamerfont{author}{size=\small}
\setbeamerfont{date}{size=\small}
\setbeamerfont{institute}{size=\small}
\title{Binární paint shop problém}
\author[]{Jiří Kalvoda\\ Vedoucí: doc. Mgr. Robert Šámal, Ph.D.\\ Oponent: Mgr. Michal Opler, Ph.D.} %% Change author name here
\institute{IÚUK MFF}
\date[\textcolor{white}{}] %% Change presentation date here
{V Hnojníku dne 2024-09-04}
\protected\def\APX{{\rm APX}}
\protected\def\P{{\rm P}}
\protected\def\NP{{\rm NP}}
\protected\def\alg{{\rm alg}}
\def\E{{\mathbb E}}
\begin{document}
\frame{\titlepage}
%\def\pause{\hrule}
%------------------------------------------------------------
\section{Úvod}
\begin{frame}[fragile]{Definice problému}
\begin{problemTH}[Binární paint shop problém]
\begin{itemize}
\item $2n$ aut v řadě
\item $n$ typů, od každého dvě auta
\pause
\item Barvení aut v pořadí dle vstupu
\item Chceme: každý typ $\rightarrow$ jedno červeně a jedno zeleně
\item Co nejméně změn barev v posloupnosti
\end{itemize}
\end{problemTH}
\pause
\vskip 3mm
\begin{tabular}{ll}
Vstup: & Typy aut v řadě\\
Výstup: & Přiřazení barev autům\\
Hodnota výstupu: & Počet změn barev\\
\end{tabular}
\end{frame}
\begin{frame}[fragile]{Doposud známé výsledky}
\begin{problemTH}[Binární paint shop problém]
\begin{itemize}
\item $2n$ aut v řadě
\item $n$ typů, od každého dvě auta
\item Barvení aut v pořadí dle vstupu
\item Chceme: každý typ $\rightarrow$ jedno červeně a jedno zeleně
\item Co nejméně změn barev v posloupnosti
\end{itemize}
\end{problemTH}
\begin{itemize}
\item Rozhodovací problém (Existuje řešení s nejvýše $k$ změnami?) je $\NP$-těžký
\item Optimalizační problém je $\APX$-těžký \parencite{apx}
\item[$\Rightarrow$] $( \P \neq \NP \rightarrow \hbox{Neexistuje aproximační schéma})$
\item Unique games conjecture $\Rightarrow$ neexistuje $c$-aproximace \parencite{neaprox}
\end{itemize}
\end{frame}
\begin{frame}[fragile]
Dává smysl zkoumat chování v průměrném případě.
\begin{notaceTH}
$$\gamma(\alpha) = \hbox{Hodnota (počet změn barev) optimálního řešení vstupu $\alpha$}$$
$$ \gamma(n)
= \frac{\sum_{\hbox{$\alpha$: vstup velikosti $n$}} \gamma(\alpha)}{(2n)!/2^n}
= \E_{\hbox{\alpha}}[\gamma(\alpha)]
$$
$\alpha_{\alg}(n)$, $\gamma{\alg}(\alpha)$ \dots{} totéž pro hodnotu výstupu algoritmu
\end{notaceTH}
\pause
\begin{itemize}
\item Hladový algoritmus \parencite{gr}:
$$\gamma(n) \le \gamma_{\alg}(n) = \sum_{0\le k < n} {2k^2-1 \over 4k^2-1} \sim {1\over 2} \cdot n$$
\end{itemize}
\end{frame}
\begin{frame}[fragile]
\begin{itemize}
\item Hladový algoritmus \parencite{gr}:
$$\gamma(n) \le \gamma_{\alg}(n) = \sum_{0\le k < n} {2k^2-1 \over 4k^2-1} \sim {1\over 2} \cdot n$$
\pause
\item Rekurzivní hladový algoritmus \parencite{gr}:
$${2\over 5}\,n - {8\over 15} \le \gamma_{\alg}(n) \le {2\over 5}\,n + {7\over 10} \Rightarrow \gamma(n) \le \gamma_{\alg}(n) \sim 0.4n$$
\pause
\item Hvězdičkový rekurzivní algoritmus \parencite{docw}:
$$\hbox{Hypotéza:\ }\gamma_{\alg} \sim \left({1\over 13} \cdot \sqrt{61} - {3\over 13} \right)n \doteq 0.370 n$$
\pause
\item Dolní odhad pomocí pravděpodobnosti \parencite{docw}:
$$\gamma_{\alg}(n) \ge 0.214n$$
\end{itemize}
\end{frame}
\section{Vlastní přínos}
\begin{frame}[fragile]{Nové řešení založené na semidefinitním programování}
\newtheorem{tmp}{Semidefinitní programování}%
{
\setbeamercolor{block title}{use=example text,fg=black,bg=yellow!75!black}%
\setbeamercolor{block body}{parent=normal text,use=block title example,bg=yellow!10}%
\begin{tmp}
\begin{itemize}
\item Optimalizační technika podobna lineárnímu programování
\item Jedna z forem: Rozmísťování $n$ bodů na $n-1$ dimenzionální sféru,
podmínky a optimalizační funkce pracující se skalárními součiny bodů
\end{itemize}
\end{tmp}
}
\begin{itemize}
\item Založeno na Goemans-Williamsově algoritmu na maximální řez \parencite{semidef}
\item Pro každé auto bod, podmínky na protilehlost dvojic stejného typu, minimalizujeme vzdálenost sousedních aut
\item Zaokrouhlení pomocí řezu náhodnou rovinou
\end{itemize}
\end{frame}
\begin{frame}[fragile]{Nové řešení založené na semidefinitním programování}
\begin{itemize}
\item Pro každé auto bod, podmínky na protilehlost dvojic stejného typu, minimalizujeme vzdálenost sousedních aut
\item Zaokrouhlení pomocí řezu náhodnou rovinou
\end{itemize}
\begin{hipoteza}
Pro dostatečně velká $n$ platí:
$$ \gamma_{\alg}(n) \le 0.34n$$
\end{hipoteza}
\pause
\begin{veta}
Pro každý vstup $\alpha$ platí:
$$ \E_{\hbox{Náhodné bity}}[\gamma_{\alg}(\alpha)] \ \le\ \gamma(\alpha) + 0.212n$$
\end{veta}
\end{frame}
\begin{frame}[fragile]{Implementace a testování}
\begin{itemize}
\item Implementace původních i nového algoritmu
\item Různé implementace semidefinitního programování
\pause
\item Různé velikosti vstupů ($n$ od $10$ do $3\,200$)
\item Pokaždé $1\,000$ nezávisle náhodně vybraných vstupů
\item Několik dní na 4 strojích (moderní workstations)
\end{itemize}
\end{frame}
\def\pic#1{
\hbox to \hsize{\hskip -1cm\hfill\includegraphics[]{#1}\hbox{}\hfill\hskip -1cm}
}
\begin{frame}
\pic{score.pdf}
\end{frame}
\begin{frame}
\pic{time.pdf}
\end{frame}
\section{Otázky}
\begin{frame}[fragile]{Otázky?}
\hbox to \hsize{\hfil \emph{Prostor pro vaše otázky.} \hfil}
\end{frame}
\begin{frame}[fragile]{Otázka od oponenta}
\emph{
Zkoušel jste (na menších vstupech) porovnat výsledek Vašeho
algoritmu s optimálním obarvením? Pokud ano, jak daleko se typicky pohyboval?
}
\end{frame}
\begin{frame}
\pic{oponent_score.pdf}
\end{frame}
\begin{frame}
\pic{oponent_time.pdf}
\end{frame}
\section{Poděkování}
\begin{frame}[fragile]{Poděkování}
Děkuji vedoucímu práce za oporu při zkoumání a psaní, oponentovi za napsání posudku a všem posluchačům za pozornost.
\end{frame}
\end{document}
../prace/bakalarka/sample.bib
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment