tensorflow / tensorflow/probability

Gathering values from the HMC kernel: How to?

Open
#1,064 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Jupyter Notebook
Stars
4.4k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

Hi!

I'm new to TFP and I'm playing with HMC implementation included in TFP. Thanks for the library, it's very nice.

I stumbled upon a scenario where my kernel does some heavy computations that I would like not to redo. The computations would return a 2D matrix where the first dimension is the chains' dimension. For example:

def joint_log_prob(data, param_obs):
    heavy_computation_results = heavy_computation(data, param_obs)
    return tf.reduce_logsumexp(heavy_computation_results, axis=1)

def unnormalized_log_posterior(param_obs):
    return joint_log_prob(data, param_obs)

(...)

res = tfp.mcmc.sample_chain(
        num_results=num_steps,
        num_burnin_steps=num_burnin,
        current_state=inits,
        kernel=kernel,
        trace_fn=trace_fn
    )

Then I would like to store/access the values of heavy_computation_results for each accepted iteration.

I noticed the acceptance info is available in the previous kernel results. Then I need to either add my results to the trace_fn or store it somehow on the side. What would be the right way to achieve this goal?

Thanks!

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

Start by reading the sample_chain API and its trace_fn and previous kernel results references. Determine whether heavy_computation_results can be exposed for accepted iterations through existing kernel outputs or whether a new mechanism is needed. Done means the supported approach is documented or implemented with coverage for the requested per-iteration values.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, tensorflow
Domain
machine-learning
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.