Skip to content

Commit 7055e58

Browse files
committed
Added erorr bars
1 parent 6f87eb0 commit 7055e58

3 files changed

Lines changed: 78 additions & 10 deletions

File tree

4/generate_graphs.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,43 @@
33
import numpy as np
44
from scipy.optimize import curve_fit
55

6+
67
def model(x, a, b):
78
return a * (x ** 2) + b * (x ** 2) * np.log(x)
89

910

1011
if __name__ == "__main__":
1112
df = pd.read_csv("results.csv")
1213

13-
x = df["n"]
14-
y = df["time"]
15-
plt.scatter(x, y)
14+
grouped = df.groupby("n")["time"]
15+
16+
# Média (e desvio‑padrão) do tempo para cada tamanho
17+
x_mean = grouped.mean().index.values.astype(float)
18+
y_mean = grouped.mean().values
19+
y_std = grouped.std().values
20+
21+
params, covariance = curve_fit(model, x_mean, y_mean)
22+
a_fit, b_fit = params
23+
24+
y_fit = model(x_mean, a_fit, b_fit)
1625

17-
params, covariance = curve_fit(model, x, y)
26+
ss_res = np.sum((y_mean - y_fit) ** 2)
27+
ss_tot = np.sum((y_mean - np.mean(y_mean)) ** 2)
28+
r_squared = 1 - ss_res / ss_tot
1829

19-
a_fit = params[0]
20-
b_fit = params[1]
21-
y_fit = model(x.unique(), a_fit, b_fit)
30+
rmse = np.sqrt(np.mean((y_mean - y_fit) ** 2))
2231

23-
plt.plot(x.unique(), y_fit, label="Regressão não linear de quadrados mínimos", color="red")
32+
plt.scatter(df["n"], df["time"], label="Observações individuais")
33+
34+
plt.errorbar(x_mean, y_mean, yerr=y_std, fmt="o", color="black",
35+
capsize=4, label="Média ± desvio‑padrão")
36+
37+
x_fit = np.linspace(x_mean.min(), x_mean.max(), 300)
38+
y_fit = model(x_fit, a_fit, b_fit)
39+
plt.plot(x_fit, y_fit, color="red", label=f"Ajuste (R²={r_squared:.4f})")
2440

2541
plt.xlabel("Tamanho da matriz")
2642
plt.ylabel("Tempo (ms)")
43+
plt.legend()
44+
2745
plt.savefig("graphs/n_time.eps")

4/report.tex

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
\usepackage{graphicx}
1010
\usepackage{fontspec}
1111
\usepackage{float}
12+
%\usepackage{listings}
1213
\setlength{\parskip}{10pt}
1314
\setmainfont{texgyreheros}[
1415
UprightFont = *-regular,
@@ -44,12 +45,13 @@ \section{Detalhes de implementação}
4445
\section{Ambiente de teste}
4546

4647
A máquina de teste possui Linux Mint 22.1, processador Intel i5-12450H e 16GB de memória RAM.
47-
O compilador utilizado foi o GCC, versão 14.2, com todas as otimizações padrões habilitadas, e a implementação da biblioteca padrão do C++ é a libstdc++ versão 13.
48+
O compilador utilizado foi o GCC, versão 14.2, com todas as otimizações padrões habilitadas, e a implementação da biblioteca padrão do C++ é a libstdc++ versão 14.
4849

4950
\section{Plano de teste}
5051

5152
O gerador utilizado para gerar os grafos toma uma entrada $n$ e gera uma matriz $N \times N$ com valores no intervalo $[0, n \cdot n]$.
52-
Foram gerados e mensurados $10$ testes para cada $n$ pertencente ao intervalo $[1000, 18000]$, incrementando $1000$ a cada passo.
53+
54+
Foram gerados $10$ testes para cada $n$ pertencente ao intervalo $[1000, 20000]$, incrementando $1000$ a cada passo. Para cada teste, mensurou-se o tempo de execução.
5355

5456
\section{Resultados}
5557

4/test.sh

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
generator="/home/menges/repos/advanced_algorithms/cmake-build-gcc/bin/generator"
3+
target="/home/menges/repos/advanced_algorithms/cmake-build-gcc/bin/hungarian_algorithm"
4+
5+
# Your commands here
6+
7+
sizes=(
8+
1000
9+
2000
10+
3000
11+
4000
12+
5000
13+
6000
14+
7000
15+
8000
16+
9000
17+
10000
18+
11000
19+
12000
20+
13000
21+
14000
22+
15000
23+
16000
24+
17000
25+
18000
26+
19000
27+
20000
28+
)
29+
30+
echo "n,time,result"
31+
32+
for i in {1..10}; do
33+
for size in "${sizes[@]}"; do
34+
(
35+
$generator $size >"tests/test_${size}"
36+
37+
start=$(date +%s%N)
38+
39+
result=$($target <"tests/test_${size}")
40+
41+
end=$(date +%s%N)
42+
elapsed=$(((end - start) / 1000000))
43+
44+
echo "$size,$elapsed,$result"
45+
) &
46+
done
47+
wait
48+
done

0 commit comments

Comments
 (0)