-
Notifications
You must be signed in to change notification settings - Fork 1
/
ts_utils.jl
124 lines (100 loc) · 2.72 KB
/
ts_utils.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
using Revise
using Reproduce
using FileIO
using JLD2
using Statistics
using Plots; pyplot()
using Reproduce.Config
includet("experiment/timeseries.jl")
const default_config = "configs/test_gvfn.toml"
const saveDir = string(@__DIR__)
# =============================
# --- D E B U G U T I L S ---
# =============================
function exp(cfg, idx, run=1)
cfg = ConfigManager(cfg, saveDir)
parse!(cfg, idx, run)
TimeSeriesExperiment.main_experiment(cfg; progress=true)
end
exp(run) = exp(default_config, 1, run)
exp() = exp(default_config, 1)
# ===============
# --- D A T A ---
# ===============
function getResults()
cfg = ConfigManager(default_config, saveDir)
parse!(cfg,1,1)
return get_run_data(cfg,1,1)
end
function getData()
results = getResults()
return results["GroundTruth"], results["Predictions"]
end
function plotData()
g,p = getData()
plot(p, label="Predictions")
plot!(g, label="Ground Truth")
end
function NRMSE(cfg, idx)
parse!(cfg, idx)
nruns = cfg["args"]["nruns"]
all_values = Vector{Float64}[]
for r=1:nruns
results = get_run_data(cfg, idx, r)
g,p = results["GroundTruth"], results["Predictions"]
p = p[1:length(g)]
values = Float64[]
start = 1000
for i=start+1:10:length(p)
ĝ = g[i-start:i]
P̂ = p[i-start:i]
push!(values, sqrt(mean((ĝ.-P̂).^2) / mean((ĝ.-mean(ĝ)).^2)))
end
push!(all_values, values)
end
if length(all_values)==0
return [Inf]
end
vals = zeros(length(all_values),length(all_values[1]))
for i=1:length(all_values)
vals[i,:] .= all_values[i]
end
return vals
end
function getBestNRMSE(cfgFile)
cfg = ConfigManager(cfgFile, saveDir)
best = Inf
bestData = nothing
bestIdx = nothing
for idx=1:total_combinations(cfg)
data = NRMSE(cfg, idx)
value = mean(data)
if value<best
best = value
bestData = data
bestIdx = idx
end
end
@assert bestData != nothing
println("best parameter index: $(bestIdx)")
return bestData
end
getBestNRMSE() = getBestNRMSE(default_config)
function plotNRMSE(cfgFiles::Vector{String})
p = plot()
for cfgFile in cfgFiles
values = getBestNRMSE(cfgFile)
av = mean(values, dims=1)
σ = std(values, dims=1, corrected=true) / sqrt(size(values,1))
plot!(av', ribbon=σ', grid=false, label="NRMSE",ylim=[0,2])
end
return p
end
plotNRMSE(cfgFile::String) = plotNRMSE([cfgFile])
plotNRMSE() = plotNRMSE(default_config)
function plotData(b::Dict)
p=plot()
plot!(b["Predictions"])
plot!(b["GroundTruth"])
plot(p, ylim=[0,2])
end