-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEnsembleParameterTable.jl
More file actions
120 lines (93 loc) · 3.96 KB
/
EnsembleParameterTable.jl
File metadata and controls
120 lines (93 loc) · 3.96 KB
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
############################################################################################
### Types
############################################################################################
mutable struct EnsembleParameterTable{C} <: AbstractParameterTable
tables::C
end
############################################################################################
### Constructors
############################################################################################
# constuct an empty table
function EnsembleParameterTable(::Nothing)
tables = Dict{Symbol, ParameterTable}()
return EnsembleParameterTable(tables)
end
############################################################################################
### Convert to other types
############################################################################################
import Base.Dict
function Dict(partable::EnsembleParameterTable)
return partable.tables
end
#= function DataFrame(
partable::ParameterTable;
columns = nothing)
if isnothing(columns) columns = keys(partable.columns) end
out = DataFrame([key => partable.columns[key] for key in columns])
return DataFrame(out)
end =#
############################################################################################
### get parameter table from RAMMatrices
############################################################################################
function EnsembleParameterTable(args...; groups)
partable = EnsembleParameterTable(nothing)
for (group, ram_matrices) in zip(groups, args)
push!(partable.tables, group => ParameterTable(ram_matrices))
end
return partable
end
############################################################################################
### Pretty Printing
############################################################################################
function Base.show(io::IO, partable::EnsembleParameterTable)
print(io, "EnsembleParameterTable with groups: ")
for key in keys(partable.tables)
print(io, "|", key, "|")
end
print(io, "\n")
for key in keys(partable.tables)
print("\n")
print(io, key, ": \n")
print(io, partable.tables[key])
end
end
############################################################################################
### Additional Methods
############################################################################################
# Sorting ----------------------------------------------------------------------------------
# Sorting ----------------------------------------------------------------------------------
function sort!(ensemble_partable::EnsembleParameterTable)
for partable in values(ensemble_partable.tables)
sort!(partable)
end
return ensemble_partable
end
function sort(partable::EnsembleParameterTable)
new_partable = deepcopy(partable)
sort!(new_partable)
return new_partable
end
# add a row --------------------------------------------------------------------------------
# do we really need this?
import Base.push!
function push!(partable::EnsembleParameterTable, d::AbstractDict, group)
push!(partable.tables[group], d)
end
push!(partable::EnsembleParameterTable, d::Nothing, group) = nothing
# get group --------------------------------------------------------------------------------
get_group(partable::EnsembleParameterTable, group) = get_group(partable.tables, group)
############################################################################################
### Update Partable from Fitted Model
############################################################################################
# update generic ---------------------------------------------------------------------------
function update_partable!(
partable::EnsembleParameterTable,
model_identifier::AbstractDict,
vec,
column,
)
for k in keys(partable.tables)
update_partable!(partable.tables[k], model_identifier, vec, column)
end
return partable
end