blackjax-devs / blackjax

BlackJAX is a Bayesian Inference library designed for ease of use, speed and modularity.
https://blackjax-devs.github.io/blackjax/
Apache License 2.0
806 stars 105 forks source link

Update `run_inference_algorithm` to split `initial_position` and `initial_state` #672

Closed reubenharry closed 4 months ago

reubenharry commented 4 months ago

Improvement to run_inference_algorithm

Description:

run_inference_algorithm currently uses a try-except clause to allow the user to either provide an initial position or an initial state. This has led to some problems, when the except clause fails to trigger.

run_inference_algorithm also produces an array of [num_steps, n_dims], which for long chains on high-dim problems can be prohibitively large.

Solution:

Make run_inference_algorithm take initial_state or initial_position explicitly, so that the caller of run_inference_algorithm is responsible for providing initial_state or initial_position, rather than deferring this task.

Add a streaming mode for run_inference_algorithm.

A few important guidelines and requirements before we can merge your PR:

reubenharry commented 4 months ago

The other argument returned, average, is the expectation. I'm not sure expectation(transform(x)) would work, because they are both functions of x (the state).

junpenglao commented 4 months ago

The other argument returned, average, is the expectation. I'm not sure expectation(transform(x)) would work, because they are both functions of x (the state).

What i meant here is that:

  1. The function intially returns transform(x), which is a function of x (the state). For examples with transform is lambda x: x.position. If user wants to compute expectation eg $E[x^2]$, they need to do np.mean(mcmc_samples ** 2)
  2. Now with the new functionarity that computes the expectation and not storing the full trace, my arguement here is that we should have trasnform being a function of the state, but function expectation being a function of the output of transform.

Does this makes sense?

reubenharry commented 4 months ago

Yeah, that makes sense. Updated.