Skip to content

ENH: Consider representing observed scaled RVs directly in the forward graph #6332

@ricardoV94

Description

@ricardoV94

When we create a scaled RV (in relation to MiniBatching) we add an extra piece of information rvs_to_total_sizes (potentially renamed in #6331) in the Model that we use when obtaining the logp. It would be neat if we didn't have to do this, and could instead represent the RV itself as being a MiniBatchedRV or whatever (don't know if there is a mathematical concept for what we are trying to do here), which may take the total_size as an extra input.

This way we would obtain the right logp without the over-head of managing this extra mapping at the Model level. The fewer mappings we need to maintain the easier it is to transform Models, as in pymc-devs/pymc-extras#91


Relevant code sections:

pymc/pymc/model.py

Lines 750 to 756 in b4c7eb1

rv_logps = _joint_logp(
rvs=rvs,
rvs_to_values=self.rvs_to_values,
rvs_to_transforms=self.rvs_to_transforms,
rvs_to_total_sizes=self.rvs_to_total_sizes,
jacobian=jacobian,
)

total_size = rvs_to_total_sizes.get(rv, None)
if total_size is not None:
scaling = _get_scaling(total_size, value_var.shape, value_var.ndim)
logp_term *= scaling

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions