From 5881276bd4e84d363804aee0e109d6dc6f35aabc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Holzm=C3=BCller?= Date: Wed, 10 Apr 2019 12:51:59 +0200 Subject: [PATCH] added plotting to latex, changed performance measurement for more evenly spaced data --- test/performance.cpp | 29 ++-- test/{plot.py => surf_plot.py} | 0 test/tex_head.txt | 279 +++++++++++++++++++++++++++++++++ test/tex_line_plot.py | 33 ++++ test/tex_tail.txt | 4 + 5 files changed, 336 insertions(+), 9 deletions(-) rename test/{plot.py => surf_plot.py} (100%) create mode 100644 test/tex_head.txt create mode 100644 test/tex_line_plot.py create mode 100644 test/tex_tail.txt diff --git a/test/performance.cpp b/test/performance.cpp index 4483343..9ac77fc 100644 --- a/test/performance.cpp +++ b/test/performance.cpp @@ -34,26 +34,35 @@ void measurePerformance() { // std::vector < size_t > dimensions = {2, 3, 4, 6, 8, 12, 16, 24, 32, 48, 64 }; // std::vector dimensions = {5, 10}; - std::vector dimensions = {2, 4, 8, 16, 32}; + std::vector dimensions = {2, 4, 8, 16, 32, 64}; // size_t maxNumPoints = 20000000; - size_t maxNumPoints = 500000; + size_t maxNumPoints = 30000000; std::ostringstream stream; - size_t approxNumSteps = 8; + // minimum quotient of number of points of current configuration to + // previous configuration + double minQuotient = 4.0; + + // maximum runtime in seconds + // if exceeded, we do not try higher numbers of points + double maxRuntime = 2.0; + + // perform 2*k+1 measurements per configuration size_t k = 1; for (size_t d : dimensions) { std::cout << "Dimension: " << d << "\n"; - size_t maxBound = 0; - while (fsi::binom(maxBound + d, d) <= maxNumPoints) { - maxBound += 1; - } + size_t last_num_points = 0; - size_t stepsize = maxBound / approxNumSteps + 1; + for (size_t bound = 1; true; ++bound) { + size_t num_points = fsi::binom(bound + d, d); + if (num_points > maxNumPoints) break; + if (num_points < last_num_points * minQuotient) continue; + + last_num_points = num_points; - for (size_t bound = 2; bound < maxBound; bound += stepsize) { std::cout << "Bound: " << bound << "\n"; double runtime = measureRuntime( [&]() { @@ -73,6 +82,8 @@ void measurePerformance() { k); stream << d << ", " << bound << ", " << fsi::binom(bound + d, d) << ", " << runtime << "\n"; + + if (runtime > maxRuntime) break; } } diff --git a/test/plot.py b/test/surf_plot.py similarity index 100% rename from test/plot.py rename to test/surf_plot.py diff --git a/test/tex_head.txt b/test/tex_head.txt new file mode 100644 index 0000000..110a4aa --- /dev/null +++ b/test/tex_head.txt @@ -0,0 +1,279 @@ +\documentclass[tikz,border=0.1cm]{standalone} + +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{lmodern} +\usepackage[ngerman]{babel} +\usepackage{amsmath} +\usepackage{amssymb} +\usepackage{amsthm} +\usepackage{mathtools} +\usepackage{IEEEtrantools} +\usepackage{microtype} +\usepackage{amsopn} +\usepackage{varwidth} +\usepackage{xcolor,colortbl} +\usepackage{tabu} +\usepackage{comment} +\usepackage{enumerate} +\usepackage{array} +\usepackage{csquotes} +\usepackage{tikz} +\usepackage{tikz-qtree} +\usepackage{tikz-3dplot} +\usepackage{nicefrac} +\usetikzlibrary{trees,positioning,shapes,calc,patterns,angles,quotes} +%\usepackage[squaren]{SIunits} +\usepackage{pgfplots} +\usepackage{algpseudocode} +\usepackage{algorithm} +%\usepackage{hyperref} +\usepackage{booktabs} +\usepackage{amsfonts} +\usepackage{color} +\usepackage{stmaryrd} +\usepackage[shortlabels]{enumitem} +\usepackage{todonotes} +\usepackage{mathdots} +\usepackage{empheq} +\usepgfplotslibrary{fillbetween} + +\pgfplotsset{compat=1.11} +\usepackage[caption=false]{subfig} + +\usepackage{etoolbox} + +\makeatletter +\providerobustcmd*{\bigcupdot}{% + \mathop{% + \mathpalette\bigop@dot\bigcup + }% +} +\newrobustcmd*{\bigop@dot}[2]{% + \setbox0=\hbox{$\m@th#1#2$}% + \vbox{% + \lineskiplimit=\maxdimen + \lineskip=-0.7\dimexpr\ht0+\dp0\relax + \ialign{% + \hfil##\hfil\cr + $\m@th\cdot$\cr + \box0\cr + }% + }% +} +\makeatother + +\newcommand*\widefbox[1]{\fbox{\hspace{2em}#1\hspace{2em}}} + +\newlength\Origarrayrulewidth + +% horizontal rule equivalent to \cline but with 2pt width +\newcommand{\Cline}[1]{% + \noalign{\global\setlength\Origarrayrulewidth{\arrayrulewidth}}% + \noalign{\global\setlength\arrayrulewidth{2pt}}\cline{#1}% + \noalign{\global\setlength\arrayrulewidth{\Origarrayrulewidth}}% +} + +% draw a vertical rule of width 2pt on both sides of a cell +\newcommand\Thickvrule[1]{% + \multicolumn{1}{!{\vrule width 2pt}c!{\vrule width 2pt}}{#1}% +} + +% draw a vertical rule of width 2pt on the left side of a cell +\newcommand\Thickvrulel[1]{% + \multicolumn{1}{!{\vrule width 2pt}c|}{#1}% +} + +% draw a vertical rule of width 2pt on the right side of a cell +\newcommand\Thickvruler[1]{% + \multicolumn{1}{|c!{\vrule width 2pt}}{#1}% +} + +\theoremstyle{plain} +\newtheorem{theorem}{Satz} +\newtheorem{satz}{Satz} +\newtheorem{lemma}[theorem]{Lemma} +\newtheorem{proposition}[theorem]{Proposition} +\newtheorem{Theorem}[theorem]{Theorem} +\newtheorem{corollary}[theorem]{Korollar} + +\theoremstyle{definition} +\newtheorem{defi}[theorem]{Definition} +\newtheorem{definition}[theorem]{Definition} +\newtheorem{algorithmThm}[theorem]{Algorithmus} +\newtheorem{remark}[theorem]{Bemerkung} +\newtheorem{bem}[theorem]{Bemerkung} +\newtheorem{example}[theorem]{Beispiel} +\newtheorem{bsp}[theorem]{Beispiel} +\newtheorem{outlook}[theorem]{Ausblick} +\newtheorem{notation}[theorem]{Notation} + +%\newenvironment{bsp}{\par\noindent\textbf{\thechapter. Beispiel}}{} + +\newcommand{\myworries}[1]{\textcolor{red}{#1}} + +\newtheorem{exercise}{Aufgabe} + +\numberwithin{exercise}{section} +\numberwithin{equation}{section} +\numberwithin{theorem}{section} + +\newcommand{\bbA}{\mathbb{A}} +\newcommand{\bbB}{\mathbb{B}} +\newcommand{\bbC}{\mathbb{C}} +\newcommand{\bbD}{\mathbb{D}} +\newcommand{\bbE}{\mathbb{E}} +\newcommand{\bbF}{\mathbb{F}} +\newcommand{\bbG}{\mathbb{G}} +\newcommand{\bbH}{\mathbb{H}} +\newcommand{\bbI}{\mathbb{I}} +\newcommand{\bbJ}{\mathbb{J}} +\newcommand{\bbK}{\mathbb{K}} +\newcommand{\bbL}{\mathbb{L}} +\newcommand{\bbM}{\mathbb{M}} +\newcommand{\bbN}{\mathbb{N}} +\newcommand{\bbO}{\mathbb{O}} +\newcommand{\bbP}{\mathbb{P}} +\newcommand{\bbQ}{\mathbb{Q}} +\newcommand{\bbR}{\mathbb{R}} +\newcommand{\bbS}{\mathbb{S}} +\newcommand{\bbT}{\mathbb{T}} +\newcommand{\bbU}{\mathbb{U}} +\newcommand{\bbV}{\mathbb{V}} +\newcommand{\bbW}{\mathbb{W}} +\newcommand{\bbX}{\mathbb{X}} +\newcommand{\bbY}{\mathbb{Y}} +\newcommand{\bbZ}{\mathbb{Z}} + +\newcommand{\calA}{\mathcal{A}} +\newcommand{\calB}{\mathcal{B}} +\newcommand{\calC}{\mathcal{C}} +\newcommand{\calD}{\mathcal{D}} +\newcommand{\calE}{\mathcal{E}} +\newcommand{\calF}{\mathcal{F}} +\newcommand{\calG}{\mathcal{G}} +\newcommand{\calH}{\mathcal{H}} +\newcommand{\calI}{\mathcal{I}} +\newcommand{\calJ}{\mathcal{J}} +\newcommand{\calK}{\mathcal{K}} +\newcommand{\calL}{\mathcal{L}} +\newcommand{\calM}{\mathcal{M}} +\newcommand{\calN}{\mathcal{N}} +\newcommand{\calO}{\mathcal{O}} +\newcommand{\calP}{\mathcal{P}} +\newcommand{\calQ}{\mathcal{Q}} +\newcommand{\calR}{\mathcal{R}} +\newcommand{\calS}{\mathcal{S}} +\newcommand{\calT}{\mathcal{T}} +\newcommand{\calU}{\mathcal{U}} +\newcommand{\calV}{\mathcal{V}} +\newcommand{\calW}{\mathcal{W}} +\newcommand{\calX}{\mathcal{X}} +\newcommand{\calY}{\mathcal{Y}} +\newcommand{\calZ}{\mathcal{Z}} + +%Miscellaneous +\newcommand{\diff}{d} %{\,\mathrm{d}} +\newcommand{\ddx}{\frac{\diff}{\diff x}} +\newcommand{\quot}[1]{\enquote{#1}} +\newcommand{\setof}[1]{\widehat{#1}} %die Menge einer Algebra +\newcommand{\WLOG}{without loss of generality} +\DeclareMathOperator{\fst}{fst} +\DeclareMathOperator{\snd}{snd} + +%Functions +\newcommand{\successor}[1]{s(#1)} +\newcommand{\predecessor}[1]{p(#1)} +\newcommand{\successors}[1]{S_{#1}} +\newcommand{\predecessors}[1]{P_{#1}} +\newcommand{\innerSet}[1]{\widehat{#1}} + +%Operators for Relations +\newcommand{\equalDef}{\coloneqq} +\newcommand{\defEqual}{\eqqcolon} +\newcommand{\equivDef}{:\Leftrightarrow} + +%Operators for Functions +\newcommand{\dProd}[2]{\left\langle #1, #2 \right\rangle} +\newcommand{\revdProd}[2]{\,\overleftrightarrow{\!\dProd{#1}{#2}\!}\,} +\newcommand{\revrevdProd}[2]{\,\overleftrightarrow{\overleftrightarrow{\!\dProd{#1}{#2}\!}}\,} +\newcommand{\dProdFunc}{\dProd{\cdot}{\cdot}} +\newcommand{\revdProdFunc}{\revdProd{\cdot}{\cdot}} +\newcommand{\revrevdProdFunc}{\revrevdProd{\cdot}{\cdot}} +\newcommand{\norm}[1]{\| #1 \|} +\newcommand{\logtwo}{\log_2} + +%Operators for Sets +\newcommand{\powerset}[1]{\calP(#1)} +\newcommand{\card}[1]{|#1|} + +\DeclareMathOperator{\Hom}{Hom} +\DeclareMathOperator{\Kern}{Kern} +\DeclareMathOperator{\Bild}{Bild} +\DeclareMathOperator{\im}{im} +\DeclareMathOperator{\id}{id} +\DeclareMathOperator{\cod}{cod} +\DeclareMathOperator{\dom}{dom} +\DeclareMathOperator*{\argmax}{argmax} + +%Concrete Set Identifiers +\newcommand{\steadyOn}[1]{C(#1)} + +\newcommand{\natOne}{\bbZ^+} +\newcommand{\natZero}{\bbN_0} +\newcommand{\oneToN}[1]{\bbN^{(#1)}} +\newcommand{\integers}{\bbZ} +\newcommand{\rationals}{\bbQ} +\newcommand{\reals}{\bbR} +\newcommand{\complex}{\bbC} + +\newcommand{\posReals}{\bbR^+} +\newcommand{\nonNegReals}{\bbR_0^+} +\newcommand{\negReals}{\bbR^-} +\newcommand{\nonPosReals}{\bbR_0^-} + +\newcommand{\domain}[1]{\dom \left( #1 \right)} +\newcommand{\codomain}[1]{\cod \left( #1 \right)} +\newcommand{\image}[1]{\im \left( #1 \right)} + +\DeclareMathOperator{\rePart}{Re} +\DeclareMathOperator{\imPart}{Im} + +%Complexity Sets +%\newcommand{\compEq}[2][]{\Theta_{#1} \left( #2 \right)} +%\newcommand{\compLess}[2][]{o_{#1} \left( #2 \right)} +%\newcommand{\compLeq}[2][]{\calO_{#1} \left( #2 \right)} +%\newcommand{\compGreater}[2][]{\omega_{#1} \left( #2 \right)} +%\newcommand{\compGeq}[2][]{\Omega_{#1} \left( #2 \right)} +\newcommand{\compEq}[1]{\Theta \left( #1 \right)} +\newcommand{\compLess}[1]{o\left( #1 \right)} +\newcommand{\compLeq}[1]{O\left( #1 \right)} +\newcommand{\compGreater}[1]{\omega\left( #1 \right)} +\newcommand{\compGeq}[1]{\Omega\left( #1 \right)} +\newcommand{\subsEq}{\subseteq} +\newcommand{\subsNeq}{\subsetneq} + +\newcommand{\assign}{\coloneqq} + +\newcommand{\mybracketl}[1]{[} +\newcommand{\mybracketr}[1]{]} + +\providecommand{\piValue}{3.1415926535897932384626433832795028841} + +\pgfplotscreateplotcyclelist{custom black white}{% +solid, every mark/.append style={solid, fill=gray}, mark=*\\% +dotted, every mark/.append style={solid, fill=gray}, mark=square*\\% +densely dotted, every mark/.append style={solid, fill=gray}, mark=triangle*\\% +dashdotted, every mark/.append style={solid, fill=gray}, mark=star\\% +dashed, every mark/.append style={solid, fill=gray},mark=diamond*\\% +loosely dashed, every mark/.append style={solid, fill=gray},mark=*\\% +densely dashed, every mark/.append style={solid, fill=gray},mark=square*\\% +dashdotted, every mark/.append style={solid, fill=gray},mark=otimes*\\% +dashdotdotted, every mark/.append style={solid},mark=star\\% +densely dashdotted,every mark/.append style={solid, fill=gray},mark=diamond*\\% +} + +\begin{document} + +\begin{tikzpicture} +\begin{axis}[xmin = , xmax = , ymin = 0, ymax = , xlabel = Number of Interpolation points, ylabel = time \mybracketl{}s\mybracketr{}, legend pos = south east, width = 14cm, height = 10cm, cycle list name = custom black white, xmode=log, ymode=log] diff --git a/test/tex_line_plot.py b/test/tex_line_plot.py new file mode 100644 index 0000000..906da59 --- /dev/null +++ b/test/tex_line_plot.py @@ -0,0 +1,33 @@ +import numpy as np +import os.path + +def readFromFile(filename): + if not os.path.isfile(filename): + return '' + + file = open(filename, 'r') + result = file.read() + file.close() + return result + +def writeToFile(filename, content): + file = open(filename, 'w') + file.truncate() + file.write(content) + file.close() + +datastr = readFromFile("../performance_data.csv") +rows = datastr.split("\n")[:-1] +values = [[s for s in r.split(', ')] for r in rows] + +dimensions = list(set([int(r[0]) for r in values])) +dimensions.sort() + +tex_str = '' + +for d in dimensions: + lines = ['({}, {})'.format(r[2], r[3]) for r in values if int(r[0]) == d] + tex_str += '\\addplot coordinates {\n' + '\n'.join(lines) + '};\n\\addlegendentry{$d = ' + str(d) + '$}\n' + +tex_str = readFromFile('tex_head.txt') + tex_str + readFromFile('tex_tail.txt') +writeToFile('runtime_plot.tex', tex_str) diff --git a/test/tex_tail.txt b/test/tex_tail.txt new file mode 100644 index 0000000..74271da --- /dev/null +++ b/test/tex_tail.txt @@ -0,0 +1,4 @@ +\end{axis} +\end{tikzpicture} + +\end{document}