stan-dev / stan-dev/posterior

Control Variates

Open
#273 32 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
R
Stars
171
Forks
26
Avg merge
2d 18h
Merged PRs (30d)
3

Description

It would be really great if posterior had a capacity to have reduced the standard errors associated with the expectations it can produce (eg mean, var and sd). Recent work [1] has shown that, if we use the score function as a control variate, we can reduce such standard errors and do so in a way that is effective in the context of constrained variables (as often considered in applications of interest in the context of, for example, estimating volatility or a frequency).

Based on initial discussion, we think the approach to adopt is to augment posterior with the capacity to accept, alongside the samples, the gradient of the log posterior of mapped parameters with respect to those mapped parameters (these mapped parameters are unconstrained but are nonlinear functions of the constrained variables). The implementation then decomposes into three components:
* Storage: we will need to use protected variables (called something like .grad_log_p_unconstrained) within the posterior object itself to pass the samples and gradients around the code such that anything we contribute is compatible with existing functionality.
* Interface: We would sensibly subtly augment the functionality of summarise_draws such that it has additional measures such that the user can use (eg summarise_draws(x, "mean_control_variates",”sd_control_variates”), where "mean_control_variates" calculates the mean using control variates and “sd_control_variates” does the same for the standard deviation).
* Estimation: writing the functions to calculate the estimates themselves in such a way that, for example, mean__control_variates fails gracefully (eg by calling mean, without control variates) when .grad_log_p_unconstrained is not populated. These functions are likely to be based heavily on a combination of the code written (in Python here: https://github.com/zhouyifan233/ControlVariates) for [1] and a pre-existing R repo (here: https://github.com/LeahPrice/ZVCV).

We would welcome advice on how to progress towards a pull-request associated with this issue.

[1] S Maskell, Y Zhou and A Mira. Control Variates for Constrained Parameters. IEEE Signal Processing Letters. Vol 29, pp. 2333-2337. 2022

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read the existing posterior object and summarise_draws implementation first, then compare the cited Python ControlVariates and R ZVCV implementations. Define how gradients are stored, how control-variate summary measures are exposed, and how estimation falls back when gradients are unavailable; done means the new summaries work with populated gradients and preserve existing behavior otherwise.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, r
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.