|
1 | | -function plotmetrics(res_path, metrics_filename) |
2 | | - metrics = CSV.read("$res_path/$metrics_filename", DataFrame) |
3 | | - |
4 | | - methods = reverse(unique(metrics.method)) |
5 | | - #methods = ["cur_sample", "kmeans_sample", "simple_random_sample"] |
6 | | - |
7 | | - batch_sizes = unique(metrics.batch_size) |
8 | | - batch_size_prop = unique(metrics.batch_size_prop) |
9 | | - xticks_label = ("$b\n$(round(p*100, digits=3))%" for (b, p) in zip(batch_sizes, batch_size_prop)) |
10 | | - colors = palette(:tab10) |
11 | | - metrics_cols = [:e_train_mae, :f_train_mae, :e_test_mae, :f_test_mae, :time] |
12 | | - metric_labels = ["E MAE | eV/atom", |
13 | | - "F MAE | eV/Å", |
14 | | - "E MAE | eV/atom", |
15 | | - "F MAE | eV/Å", |
16 | | - "Time | s"] |
17 | | - for (i, metric) in enumerate(metrics_cols) |
18 | | - plot() |
19 | | - metric_max = 0.0 |
20 | | - for (j, method) in enumerate(methods) |
21 | | - metric_means = []; metric_se = [] |
22 | | - metric_q3 = []; metric_q2 = []; metric_q1 = [] |
23 | | - for batch_size in batch_sizes |
24 | | - ms = metrics[ metrics.method .== method .&& |
25 | | - metrics.batch_size .== batch_size , metric] |
26 | | - |
27 | | - # Calculation of mean and standard error |
28 | | - m = mean(ms) |
29 | | - se = stdm(ms, m) / sqrt(length(ms)) |
30 | | - push!(metric_means, m) |
31 | | - push!(metric_se, se) |
32 | | - |
33 | | - # Calculation of quantiles |
34 | | - qs = quantile(ms, [0.25, 0.5, 0.75]) |
35 | | - push!(metric_q3, qs[3]) |
36 | | - push!(metric_q2, qs[2]) |
37 | | - push!(metric_q1, qs[1]) |
38 | | - |
39 | | - metric_max = maximum([metric_max, maximum(metric_q3)]) |
40 | | - end |
41 | | - plot!(batch_sizes, |
42 | | - metric_q2, |
43 | | - #metric_means, |
44 | | - #ribbon = metric_se, |
45 | | - ribbon = (metric_q2 .- metric_q1, metric_q3 .- metric_q2), |
46 | | - #yerror = (metric_q2 .- metric_q1, metric_q3 .- metric_q2), |
47 | | - color = colors[j], |
48 | | - fillalpha=.05, |
49 | | - label=method) |
50 | | - plot!(batch_sizes, |
51 | | - #metric_means, |
52 | | - metric_q2, |
53 | | - seriestype = :scatter, |
54 | | - thickness_scaling = 1.35, |
55 | | - markersize = 3, |
56 | | - markerstrokewidth = 0, |
57 | | - markerstrokecolor = :black, |
58 | | - markercolor = colors[j], |
59 | | - label="") |
60 | | - #plot!(batch_sizes, [0.1 for _ in 1:length(batch_sizes)]; |
61 | | - # color=:red, linestyle=:dot, label=false) |
62 | | - max = metric == :time ? 1 : metric_max*1.1 # 1.0 |
63 | | - min = metric == :time ? -0.1 : 0.001 #minimum(metric_q2)*0.5 |
64 | | - plot!(dpi = 300, |
65 | | - label = "", |
66 | | - #xscale=:log2, |
67 | | - #yscale=:log2, |
68 | | - xticks = (batch_sizes, xticks_label), |
69 | | - ylim=(min, max), |
70 | | - xlabel = "Training Dataset Size (Sample Size)", |
71 | | - ylabel = metric_labels[i]) |
72 | | - end |
73 | | - plot!(legend=:topright) |
74 | | - savefig("$res_path/$metric.png") |
75 | | - end |
76 | | -end |
77 | | - |
78 | | -function plotmetrics2(res_path, metrics_filename) |
| 1 | +function plot_err_per_sample(res_path, metrics_filename) |
79 | 2 | # ---------------- Load & prep ---------------- |
80 | 3 | df = CSV.read("$res_path/metrics.csv", DataFrame) |
81 | 4 | sort!(df, [:batch_size]) |
@@ -187,3 +110,81 @@ function plotmetrics2(res_path, metrics_filename) |
187 | 110 | println(" - e_test_mae_by_sample.pdf") |
188 | 111 | println(" - f_test_mae_by_sample.pdf") |
189 | 112 | end |
| 113 | + |
| 114 | +function plot_err_per_sample_2(res_path, metrics_filename) |
| 115 | + metrics = CSV.read("$res_path/$metrics_filename", DataFrame) |
| 116 | + |
| 117 | + methods = reverse(unique(metrics.method)) |
| 118 | + #methods = ["cur_sample", "kmeans_sample", "simple_random_sample"] |
| 119 | + |
| 120 | + batch_sizes = unique(metrics.batch_size) |
| 121 | + batch_size_prop = unique(metrics.batch_size_prop) |
| 122 | + xticks_label = ("$b\n$(round(p*100, digits=3))%" for (b, p) in zip(batch_sizes, batch_size_prop)) |
| 123 | + colors = palette(:tab10) |
| 124 | + metrics_cols = [:e_train_mae, :f_train_mae, :e_test_mae, :f_test_mae, :time] |
| 125 | + metric_labels = ["E MAE | eV/atom", |
| 126 | + "F MAE | eV/Å", |
| 127 | + "E MAE | eV/atom", |
| 128 | + "F MAE | eV/Å", |
| 129 | + "Time | s"] |
| 130 | + for (i, metric) in enumerate(metrics_cols) |
| 131 | + plot() |
| 132 | + metric_max = 0.0 |
| 133 | + for (j, method) in enumerate(methods) |
| 134 | + metric_means = []; metric_se = [] |
| 135 | + metric_q3 = []; metric_q2 = []; metric_q1 = [] |
| 136 | + for batch_size in batch_sizes |
| 137 | + ms = metrics[ metrics.method .== method .&& |
| 138 | + metrics.batch_size .== batch_size , metric] |
| 139 | + |
| 140 | + # Calculation of mean and standard error |
| 141 | + m = mean(ms) |
| 142 | + se = stdm(ms, m) / sqrt(length(ms)) |
| 143 | + push!(metric_means, m) |
| 144 | + push!(metric_se, se) |
| 145 | + |
| 146 | + # Calculation of quantiles |
| 147 | + qs = quantile(ms, [0.25, 0.5, 0.75]) |
| 148 | + push!(metric_q3, qs[3]) |
| 149 | + push!(metric_q2, qs[2]) |
| 150 | + push!(metric_q1, qs[1]) |
| 151 | + |
| 152 | + metric_max = maximum([metric_max, maximum(metric_q3)]) |
| 153 | + end |
| 154 | + plot!(batch_sizes, |
| 155 | + metric_q2, |
| 156 | + #metric_means, |
| 157 | + #ribbon = metric_se, |
| 158 | + ribbon = (metric_q2 .- metric_q1, metric_q3 .- metric_q2), |
| 159 | + #yerror = (metric_q2 .- metric_q1, metric_q3 .- metric_q2), |
| 160 | + color = colors[j], |
| 161 | + fillalpha=.05, |
| 162 | + label=method) |
| 163 | + plot!(batch_sizes, |
| 164 | + #metric_means, |
| 165 | + metric_q2, |
| 166 | + seriestype = :scatter, |
| 167 | + thickness_scaling = 1.35, |
| 168 | + markersize = 3, |
| 169 | + markerstrokewidth = 0, |
| 170 | + markerstrokecolor = :black, |
| 171 | + markercolor = colors[j], |
| 172 | + label="") |
| 173 | + #plot!(batch_sizes, [0.1 for _ in 1:length(batch_sizes)]; |
| 174 | + # color=:red, linestyle=:dot, label=false) |
| 175 | + max = metric == :time ? 1 : metric_max*1.1 # 1.0 |
| 176 | + min = metric == :time ? -0.1 : 0.001 #minimum(metric_q2)*0.5 |
| 177 | + plot!(dpi = 300, |
| 178 | + label = "", |
| 179 | + #xscale=:log2, |
| 180 | + #yscale=:log2, |
| 181 | + xticks = (batch_sizes, xticks_label), |
| 182 | + ylim=(min, max), |
| 183 | + xlabel = "Training Dataset Size (Sample Size)", |
| 184 | + ylabel = metric_labels[i]) |
| 185 | + end |
| 186 | + plot!(legend=:topright) |
| 187 | + savefig("$res_path/$metric.png") |
| 188 | + end |
| 189 | +end |
| 190 | + |
0 commit comments