-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patheval.jl
62 lines (56 loc) · 2.49 KB
/
eval.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using JLD2, SimilaritySearch, DataFrames, CSV, Glob, UnicodePlots
function evaluate_results(gfile, resultfiles, k)
gold_knns = jldopen(f->f["knns"][1:k, :], gfile)
res = DataFrame(size=[], algo=[], modelingtime=[], encdatabasetime=[], encqueriestime=[], buildtime=[], querytime=[], params=[], recall=[])
for resfile in resultfiles
@info resfile
reg = jldopen(resfile) do f
knns = f["knns"][1:k, :]
recall = macrorecall(gold_knns, knns)
push!(res, (f["size"], f["algo"],
get(f, "modelingtime", 0.0),
get(f, "encdatabasetime", 0.0),
get(f, "encqueriestime", 0.0),
f["buildtime"], f["querytime"], f["params"], recall))
end
end
sort!(res, :recall)
res
end
function print_results(f, D, gfile, files, task, dbsize)
show(f, "text/plain", gfile => files); println(f)
show(f, "text/plain", D); println(f)
p = lineplot(D.recall; ylim=(0, 1), title=String(D.algo[1]), ylabel="recall", xlabel="$(D.params[1]) to $(D.params[end])")
show(f, "text/plain", p); println(f)
end
if !isinteractive()
goldsuffix = "private-queries-2024-laion2B-en-clip768v2-n=10k-epsilon=0.2.h5"
k = 30
if length(ARGS) == 0
open("results-summary.txt", "w") do f
for path in sort!(glob("results-task*/*"))
task, dbsize = splitpath(path)
lastpath = glob(joinpath(path, "*")) |> sort! |> last
gfile = joinpath("data2024", "gold-standard-dbsize=$dbsize--$goldsuffix")
files = glob(joinpath(lastpath, "*.h5"))
length(files) == 0 && continue
D = evaluate_results(gfile, files, k)
println(f, "\n\n=== results for $dbsize $goldsuffix ===")
print_results(stdout, D, gfile, files, task, dbsize)
print_results(f, D, gfile, files, task, dbsize)
CSV.write("$task-$dbsize.csv", D)
end
end
else
for path in ARGS
task, dbsize, _ = splitpath(path)
gfile = joinpath("data2024", "gold-standard-dbsize=$dbsize--$goldsuffix")
files = glob(joinpath(path, "*.h5"))
D = evaluate_results(gfile, files, k)
println("\n\n=== results for $dbsize $goldsuffix ===")
print_results(stdout, D, gfile, files, task, dbsize)
CSV.write(task * "-$dbsize-private-gold.csv", D)
end
end
nothing
end