Skip to content

Commit 72165da

Browse files
committed
param_values(ParTable)
1 parent a569d0e commit 72165da

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

src/frontend/specification/ParameterTable.jl

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,3 +318,59 @@ function update_se_hessian!(
318318
se = se_hessian(sem_fit; hessian = hessian)
319319
return update_partable!(partable, params(sem_fit), se, :se)
320320
end
321+
322+
"""
323+
param_values!(out::AbstractVector, partable::ParameterTable,
324+
col::Symbol = :estimate)
325+
326+
Extract parameter values from the `col` column of `partable`
327+
into the `out` vector.
328+
329+
The `out` vector should be of `nparams(partable)` length.
330+
The *i*-th element of the `out` vector will contain the
331+
value of the *i*-th parameter from `params(partable)`.
332+
333+
Note that the function combines the duplicate occurences of the
334+
same parameter in `partable` and will raise an error if the
335+
values do not match.
336+
"""
337+
function param_values!(
338+
out::AbstractVector,
339+
partable::ParameterTable,
340+
col::Symbol = :estimate,
341+
)
342+
(length(out) == nparams(partable)) || throw(
343+
DimensionMismatch(
344+
"The length of parameter values vector ($(length(out))) does not match the number of parameters ($(nparams(partable)))",
345+
),
346+
)
347+
param_index = Dict(param => i for (i, param) in enumerate(params(partable)))
348+
param_values_col = partable.columns[col]
349+
for (i, param) in enumerate(partable.columns[:param])
350+
(param == :const) && continue
351+
param_ind = get(param_index, param, nothing)
352+
@assert !isnothing(param_ind) "Parameter table contains unregistered parameter :$param at row #$i"
353+
val = param_values_col[i]
354+
if !isnan(out[param_ind])
355+
@assert out[param_ind] val atol = 1E-10 "Parameter :$param value at row #$i ($val) differs from the earlier encountered value ($(out[param_ind]))"
356+
else
357+
out[param_ind] = val
358+
end
359+
end
360+
return out
361+
end
362+
363+
"""
364+
param_values(out::AbstractVector, col::Symbol = :estimate)
365+
366+
Extract parameter values from the `col` column of `partable`.
367+
368+
Returns the values vector. The *i*-th element corresponds to
369+
the value of *i*-th parameter from `params(partable)`.
370+
371+
Note that the function combines the duplicate occurences of the
372+
same parameter in `partable` and will raise an error if the
373+
values do not match.
374+
"""
375+
param_values(partable::ParameterTable, col::Symbol = :estimate) =
376+
param_values!(fill(NaN, nparams(partable)), partable, col)

0 commit comments

Comments
 (0)