BayesianModelingandComputationInPython / BookCode_Edition1

https://www.bayesiancomputationbook.com
GNU General Public License v2.0
506 stars 128 forks source link

Issue on page /markdown/chp_03.html #139

Open mubagriyanik opened 2 years ago

mubagriyanik commented 2 years ago

In your book page 76, Code 3.11 :

run_mcmc = tf.function( tfp.experimental.mcmc.windowed_adaptive_nuts, autograph=False, jit_compile=True) mcmc_samples, sampler_stats = run_mcmc( 1000, jd_penguin_mass_all_species, n_chains=4, num_adaptation_steps=1000, mass=body_mass_g)

inf_data_model_penguin_mass_all_species2 = az.from_dict( posterior={

TFP mcmc returns (num_samples, num_chains, ...), we swap

    # the first and second axis below for each RV so the shape
    # is what ArviZ expected.
    k:np.swapaxes(v, 1, 0)
    for k, v in mcmc_samples._asdict().items()},
sample_stats={
    k:np.swapaxes(sampler_stats[k], 1, 0)
    for k in ["target_log_prob", "diverging", "accept_ratio", "n_steps"]}

)

When I wrote this code and run on python I encounter this error: Screen Shot 2022-03-19 at 2 24 14 PM

I looked at the codes and I have not noticed any typos. Appreciate it if you help with this issue.

Thanks!

canyon289 commented 2 years ago

ping on @junpenglao