Skip to content

Return an AbstractChains object from appliying pointwise_logdensities to Abstractchains? #688

@bgctw

Description

@bgctw

Currently, pointwise_logdensities(chains::AbstractChains) returns an OrderedDict of Matrices all of the shape (sample x chain).

I find it more convenient to work with the results of the pointwise functions applied to AbstractChains as an AbstractChains again, rather than the OrderedDict{String, Matrix}.
What is a good place to support this conversion? A function in the MCMCChains extension such as:

function as_chains(lds_pointwise)
     Chains(stack(values(lds_pointwise); dims=2), collect(keys(lds_pointwise)))
end
chn = as_chains(logjoints_pointwise); # from @testset "pointwise_logdensities chain"
names(chn)
get(chn, :x)[1] == logjoints_pointwise["x"]

One could even think of letting the pointwise_logdensities(..., ::AbstractChains) routinely return a Chains object.
This could be achieved by

  • renaming the pointwise_logdensities(..., ::AbstractChains) to pointwise_logdensities_dict,
  • implementing it in the DynamicPPLMCMCChains extension by converting the result of pointwise_logdensities_dict.

What are opinions about this suggestion?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions