|
| 1 | +struct Summary |
| 2 | + μ |
| 3 | + σ |
| 4 | + n |
| 5 | + |
| 6 | + Summary(data::Matrix{Float64}) = new( |
| 7 | + mean(data,dims=2), |
| 8 | + std(data,corrected=true,dims=2) / √(size(data)[2]-1), |
| 9 | + size(data)[2] |
| 10 | + ) |
| 11 | + |
| 12 | + Summary(data::Vector{Float64}) = new( |
| 13 | + data, |
| 14 | + zeros(length(data)), |
| 15 | + 1 |
| 16 | + ) |
| 17 | +end |
| 18 | + |
| 19 | +# Saving/Loading data |
| 20 | +save!(self::ConfigManager, data::Dict) = save!(self.dataManager, get_datafile(self), data) |
| 21 | +save(self::ConfigManager, data::Dict) = save(self.dataManager, get_datafile(self), data) |
| 22 | +load(self::ConfigManager) = load(self.dataManager, get_datafile(self)) |
| 23 | +load(self::ConfigManager, idx::Int) = load(parse!(self, idx)) |
| 24 | + |
| 25 | +# Parsing saved data |
| 26 | + |
| 27 | +function get_run_data(self::ConfigManager, idx, run) |
| 28 | + parse!(self, idx, run) |
| 29 | + return load(self) |
| 30 | +end |
| 31 | + |
| 32 | +function get_data(self::ConfigManager, idx) |
| 33 | + runs = get_max_runs(self,idx) |
| 34 | + all_data = Dict() |
| 35 | + for r in 1:runs |
| 36 | + data = get_run_data(self, idx, r) |
| 37 | + for k in keys(data) |
| 38 | + if haskey(all_data, k) |
| 39 | + all_data[k] = hcat(all_data[k], data[k]) |
| 40 | + else |
| 41 | + all_data[k] = data[k] |
| 42 | + end |
| 43 | + end |
| 44 | + end |
| 45 | + return all_data |
| 46 | +end |
| 47 | + |
| 48 | +function get_fields(self::ConfigManager) |
| 49 | + return keys(get_run_data(copy(self),1,1)) |
| 50 | +end |
| 51 | + |
| 52 | +function get_summary(self::ConfigManager, idx::Int, key::String) |
| 53 | + data = get_data(self,idx) |
| 54 | + return Summary(data[key]) |
| 55 | +end |
| 56 | + |
| 57 | +function get_best(self::ConfigManager, key; metric=mean, selector=argmin) |
| 58 | + return get_best(self, key, 1:self.total_combinations, metric=metric, selector=selector) |
| 59 | +end |
| 60 | + |
| 61 | +function get_best(self::ConfigManager, key, indices; metric=mean, selector=argmin) |
| 62 | + data = [] |
| 63 | + parsed_indices = [] |
| 64 | + for idx in indices |
| 65 | + d = get_summary(self, idx, key).μ |
| 66 | + m = metric(d) |
| 67 | + if isfinite(m) |
| 68 | + push!(data, metric(d)) |
| 69 | + push!(parsed_indices, idx) |
| 70 | + end |
| 71 | + end |
| 72 | + if length(data) == 0 |
| 73 | + return nothing # all configs diverged |
| 74 | + end |
| 75 | + best = selector(data) |
| 76 | + return parsed_indices[best] |
| 77 | +end |
| 78 | + |
| 79 | +function sensitivity(self::ConfigManager, key; metric=mean) |
| 80 | + best_idx = get_best(self,key) |
| 81 | + cfg = parse!(self, best_idx) |
| 82 | + |
| 83 | + keys = get_sweep_params(self) |
| 84 | + d = Dict( k=> self[k] for k in keys ) |
| 85 | + |
| 86 | + # delete the key we're looking for sensitivity over |
| 87 | + delete!(d,key) |
| 88 | + |
| 89 | + indices = configs_with(self, d) |
| 90 | + sens_data = [] |
| 91 | + for idx in indices |
| 92 | + value = metric(get_summary(self,idx).μ) |
| 93 | + push!(sens_data, value) |
| 94 | + end |
| 95 | + return sens_data |
| 96 | +end |
| 97 | + |
| 98 | +function get_max_runs(self::ConfigManager, idx::Int) |
| 99 | + cfg = parse!(self,idx,1) |
| 100 | + runs = readdir(get_expdir(self)) |
| 101 | + return length(runs) |
| 102 | +end |
0 commit comments