@@ -7,6 +7,7 @@ struct ParameterTable{C} <: AbstractParameterTable
77 observed_vars:: Vector{Symbol}
88 latent_vars:: Vector{Symbol}
99 sorted_vars:: Vector{Symbol}
10+ params:: Vector{Symbol}
1011end
1112
1213# ###########################################################################################
@@ -31,11 +32,32 @@ function ParameterTable(
3132 columns:: Dict{Symbol, Vector} = empty_partable_columns ();
3233 observed_vars:: Union{AbstractVector{Symbol}, Nothing} = nothing ,
3334 latent_vars:: Union{AbstractVector{Symbol}, Nothing} = nothing ,
35+ params:: Union{AbstractVector{Symbol}, Nothing} = nothing ,
3436)
35- return ParameterTable (columns,
37+ params = isnothing (params) ? unique! (filter (!= (:const ), columns[:param ])) : copy (params)
38+ check_params (params, columns[:param ])
39+ return ParameterTable (
40+ columns,
3641 ! isnothing (observed_vars) ? copy (observed_vars) : Vector {Symbol} (),
3742 ! isnothing (latent_vars) ? copy (latent_vars) : Vector {Symbol} (),
38- Vector {Symbol} ())
43+ Vector {Symbol} (),
44+ params,
45+ )
46+ end
47+
48+ # new parameter table with different parameters order
49+ function ParameterTable (
50+ partable:: ParameterTable ;
51+ params:: Union{AbstractVector{Symbol}, Nothing} = nothing ,
52+ )
53+ isnothing (params) || check_params (params, partable. columns[:param ])
54+
55+ return ParameterTable (
56+ Dict (col => copy (values) for (col, values) in pairs (partable. columns)),
57+ observed_vars = copy (partable. observed_vars),
58+ latent_vars = copy (partable. latent_vars),
59+ params = params,
60+ )
3961end
4062
4163# ###########################################################################################
@@ -46,6 +68,15 @@ function Base.convert(::Type{Dict}, partable::ParameterTable)
4668 return partable. columns
4769end
4870
71+ function Base. convert (
72+ :: Type{ParameterTable} ,
73+ partable:: ParameterTable ;
74+ params:: Union{AbstractVector{Symbol}, Nothing} = nothing ,
75+ )
76+ return isnothing (params) || partable. params == params ? partable :
77+ ParameterTable (partable; params)
78+ end
79+
4980function DataFrames. DataFrame (
5081 partable:: ParameterTable ;
5182 columns:: Union{AbstractVector{Symbol}, Nothing} = nothing ,
@@ -111,12 +142,8 @@ Base.iterate(partable::ParameterTable) = iterate(partable, 1)
111142Base. iterate (partable:: ParameterTable , i:: Integer ) =
112143 i > length (partable) ? nothing : (partable[i], i + 1 )
113144
114-
115- # get the vector of all parameters in the table
116- # the position of the parameter is based on its first appearance in the table (and the ensemble)
117- params (partable:: ParameterTable ) =
118- filter! (!= (:const ), unique (partable. columns[:param ]))
119-
145+ params (partable:: ParameterTable ) = partable. params
146+ n_par (partable:: ParameterTable ) = length (params (partable))
120147
121148# Sorting ----------------------------------------------------------------------------------
122149
0 commit comments