r/BayesianProgramming • u/[deleted] • Feb 05 '18
r/BayesianProgramming • u/[deleted] • Dec 14 '17
Two views on regression
colcarroll.github.ior/BayesianProgramming • u/[deleted] • Dec 01 '17
A conversation with Thomas Wiecki on the use of probabilistic programming and machine learning in quant finance.
r/BayesianProgramming • u/[deleted] • Nov 14 '17
A Bayesian Optimization Library using TensorFlow
r/BayesianProgramming • u/[deleted] • Oct 03 '17
Probabilistic programming: an annotated bibliography
r/BayesianProgramming • u/[deleted] • Sep 22 '17
A Library for Bayesian Deep Learning, Generative Models, Based on Tensorflow
r/BayesianProgramming • u/vladislavsd • Sep 05 '17
Diagram of probability distribution relationships
r/BayesianProgramming • u/[deleted] • Aug 29 '17
MCMC Interactive Gallery
chi-feng.github.ior/BayesianProgramming • u/[deleted] • Aug 02 '17
Probabilistic Programming
adriansampson.netr/BayesianProgramming • u/[deleted] • Jul 10 '17
Austin Rochford - MRPyMC3 — Multilevel Regression and Poststratification with PyMC3
r/BayesianProgramming • u/tarraxa • Jun 28 '17
Scaling up bayesian inference for big and complex data
r/BayesianProgramming • u/iamasharkskin • Jun 22 '17
R alternatives to Probabilistic Programming for Hackers?
Is there any literature as detailed as the Probabilistic Programming for Hackers book but in R? Was just wondering..
r/BayesianProgramming • u/[deleted] • May 24 '17
JWarmenhoven/DBDA-python: Doing Bayesian Data Analysis, 2nd Edition (Kruschke, 2015): Python/PyMC3 code
r/BayesianProgramming • u/MixSerious2 • Sep 19 '26
Laplace Language (Open-Source Bayesian Statistics Software)
r/BayesianProgramming • u/Dense-Sky8692 • Dec 26 '25
How to vary allocated budgets across dims in pymc-marketing ?
I have been trying to create a budget optimization tool using pymc-marketing library. The goal is to create a fully deployed solution that allocates budget based on total spend provided by the user. By any means, I'm not a marketing expert or a person who has any background in bayesian statistics, I simply studied up a little bit about adstock effects, saturation etc and with my research found out that pymc marketing does this kind of budget optimization.
I have to create this as a project / POC for my organisation so I have implemented a rough pipeline. But I am stuck on an issue which I'm not able to solve.
I have a dims column products. The budget allocated for marketing spend for each one of the product should be different, because from the data I've observed that the cost per click for a spend varies based on channel and the product the money is being spent on.
I have written the following code for creating the MMM.
from pymc_extras.prior import Prior
from pymc_marketing.mmm.multidimensional import HMMM
from pymc_marketing.mmm import GeometricAdstock, LogisticSaturation
model_config = {
"intercept": Prior("Normal", mu=0.0, sigma=0.5),
"beta_channel": Prior("HalfNormal", sigma=1.0),
# "saturation_beta": Prior(
# "Normal",
# mu=0.5,
# sigma=1.0,
# dims=("product_name", "channel"),
# ),
# "saturation_lam": Prior(
# "HalfNormal",
# sigma=1.0,
# dims="channel"
# )
}
channel_columns = ["Meta", "Linkedin", "Google Ads", "Media"]
saturation = LogisticSaturation()
adstock = GeometricAdstock(
l_max=4
)
mmm = HMMM(
date_column="time",
channel_columns=channel_columns,
target_column="sales",
adstock=adstock,
saturation=saturation,
model_config=model_config,
dims=("product_name",)
)
mmm.fit(
X=x_train,
y=y_train,
draws=1000,
chains=4,
tune=1000,
target_accept=0.98,
)The commented out priors are priors that I tried to make the budget optimization vary across product_name's because chatgpt recommended it, but the MMM didn't converge and the r2 score dropped from 0.46 to -1.87. So that obviously wasn't a great choice.
(xarray.DataArray (product_name: 7, channel: 4) Size: 224B)
array([
[ 0. , 0. , 0. , 1643.32019222],
[ 0. , 0. , 7260.96163190, 1643.32019222],
[ 0. , 0. , 0. , 1643.32019222],
[1763.53069175, 3390.22216117, 7260.96163190, 1643.32019222],
[ 0. , 0. , 0. , 1643.32019222],
[1763.53069175, 3390.22216117, 7260.96163190, 1643.32019222],
[1763.53069175, 3390.22216117, 0. , 1643.32019222],
])The optimization it gave varied across channels but it didn't vary across the product names, but from the data I observe that it really should.
So I just wanted to understand, what I can do to fix this?
Does anyone have any idea and can help me figure out what I'm doing wrong?
r/BayesianProgramming • u/reb390 • Sep 09 '25
Favorite MCMC sampling algorithms for python?
I've mostly used emcee in the past and was curious what others recommendations were for physics applications. Interested in improving the speed of my inferences mostly.
r/BayesianProgramming • u/Creative-Repair5 • Apr 27 '25
Confused by MCMC convergence plot: Why only 3 points instead of chains?
Hey fellow statisticians/modelers, I'm working through some Bayesian regression stuff and trying to code for convergence of MCMC (Markov chain Monte Carlo) chains and am getting a plot that doesn't look right.
I'm using MCMC to sample from the posterior distribution the intercept (β0), slope (β1), and error variance (σε^2). I'm trying to figure out whether the chains have converged so that I can interpret the results. To do this, the trace plots and summary stats should look something like this:


Instead of showing the trace of the MCMC chains, I encountered a plot that only displays 3 points (the intercept, predictor variable, and sigma).

I need to graph DIAGNOSTICS for these three points. Has anyone seen this or know how to edit the code so that it plots the "fuzzy caterpillar" visualization for assessing MCMC convergence? Thanks friends!
Code included below so someone may correct the error in my ways:
#specify priors
fitted.model <- stan_glm(
prior_intercept = normal(175, 20, autoscale = FALSE),
prior = normal(0.6, 0.3, autoscale = FALSE),
prior_aux = exponential(0.025, autoscale = FALSE),,
#MCMC settings
chains = n.chains = 4
warmup = n.warmup = 1000
n.iters.per.chain.after.warmup = 5000
n.iters.total.per.chain = n.iters.per.chain.after.warmup+n.warmup
#plot
plot(fitted.model)
r/BayesianProgramming • u/bean_the_great • Apr 18 '25
HMM model in NumPyro - help!
I'm trying to build a HMM in NumPyro however, I can't work out why the dimensions of the initial states are changing for each iteration of the MCMC. In particular, for the first iteration, the initial states are of dimension (1000,) - this is expected, the batch size is 1000-however, this becomes (5,1,1) on the second iteration.
I have attached a reproducible example below. Thanks in advance for any help!
from typing import List, Tuple, Callable, Dict, Union, Literal, Optional
import pandas as pd
import numpy as np
from tqdm import tqdm
from jax import random
from numpyro.infer import MCMC, NUTS, Predictive, DiscreteHMCGibbs
import numpyro
import numpyro.distributions as dist
from numpyro.handlers import seed
from numpyro import sample, plate
import jax.numpy as jnp
from numpyro.util import format_shapes
X = np.random.normal(size=(1000,200,1))
mask = np.ones((1000,200))
def first_order_hmm_batched(
X: np.ndarray,
mask: np.ndarray,
n_states: int,
obs_dim: int,
transition_prior: float,
transition_prior_type: Literal["eye", "full"],
transition_base: Optional[float] = None,
):
assert len(X.shape) == 3 # (batch, time, obs_dim)
batch_size, seq_len, _ = X.shape
if transition_prior_type == "eye":
assert transition_base is not None
# Transition matrix
if transition_prior_type == "full":
concentration = jnp.full((n_states, n_states), transition_prior)
else:
concentration = jnp.full((n_states, n_states), transition_base)
concentration = concentration.at[jnp.diag_indices(n_states)].add(transition_prior)
# Add plate since each row of the transition matrix prior is independent
with plate("states_rows", n_states):
trans_probs = sample('trans_probs', dist.Dirichlet(concentration))
assert trans_probs.shape == (n_states, n_states)
# Emission parameters
# Defining a prior for each dimension of the observation and
# each state independently
with plate("obs_dim", obs_dim):
with plate("states_emissions", n_states):
em_means = sample(
'em_means',
dist.Normal(0,1)
)
assert em_means.shape == (n_states, obs_dim)
em_var = sample('obs_var', dist.InverseGamma(1.0, 1.0)) # scalar variance
em_cov = jnp.eye(obs_dim) * em_var
# Initial hidden states
# Generate initial state for each row independently
with plate("batch_size", batch_size):
# Initial state probabilities
start_probs = sample('start_probs', dist.Dirichlet(jnp.ones(n_states)))
assert start_probs.shape == (batch_size,n_states)
print(f"start_probs.shape: {start_probs.shape}")
ih_dist = dist.Categorical(start_probs)
# print(f"ih_dist.event_shape: {ih_dist.event_shape}")
# print(f"ih_dist.batch_shape: {ih_dist.batch_shape}")
init_states = sample(
"init_hidden_states",
ih_dist
)
print(f"init_states.shape: {init_states.shape}")
assert len(init_states.shape) == 1, f"{init_states.shape}"
assert init_states.shape[0] == batch_size, f"{init_states.shape}"
hidden_states = [init_states]
# Transition over time
for t in range(1, seq_len):
prev_states = hidden_states[-1] # shape (batch,)
probs_t = trans_probs[prev_states] # shape (batch, n_states)
next_state = sample(f"hidden_state_{t}", dist.Categorical(probs_t))
assert len(next_state.shape) == 1
assert next_state.shape[0] == batch_size
hidden_states.append(next_state)
hidden_states = jnp.stack(hidden_states, axis=1) # (batch, time)
assert hidden_states.shape == (batch_size, seq_len)
# Get emission means for each (batch, time)
means = em_means[hidden_states] # shape (batch, time, obs_dim)
assert means.shape == (batch_size, seq_len, obs_dim)
# Expand emission distribution
flat_means = means.reshape(-1, obs_dim)
flat_obs = X.reshape(-1, obs_dim)
cov = jnp.broadcast_to(em_cov, (flat_means.shape[0], obs_dim, obs_dim))
with plate("batch_seq_len", batch_size*seq_len):
joint_obs = sample(
"joint_obs",
dist.MultivariateNormal(loc=flat_means, covariance_matrix=cov),
obs=flat_obs
)
assert joint_obs.shape == (batch_size*seq_len, obs_dim)
return joint_obs
n_states=5
obs_dim=1
transition_prior=1.0
transition_prior_type="eye"
transition_base=1.0
nuts_kernel = NUTS(first_order_hmm_batched)
mcmc = MCMC(nuts_kernel, num_warmup=500, num_samples=1000, num_chains=1)
mcmc.run(
random.PRNGKey(1),
X=X,
n_states=5,
mask=mask,
obs_dim=1,
#transition_prior=100.0,
transition_prior=1.0,
transition_prior_type="eye",
transition_base=1.0
)r/BayesianProgramming • u/Krizo89 • Feb 05 '25
Datasets for Bayesian Analysis with Python Third Edition
I'm reading the book Bayesian Analysis with Python - a practical guide to probalistic modeling third edition
But i can't seem to find half of the datasets they use, anybody know where they can be found?
I can find datasets for the second edition on Github, but it only contains a few that they also used in the third edition.
r/BayesianProgramming • u/reb390 • Oct 23 '24
Markov Chain Monte Carlo Inference of Parametrized Function Question
I've used MCMC several times now and I'm a little confused about the correct way to update a prior. Say I have some function that is parametrized by several variables that have some "true" value I am trying to infer. Say y = A*xB. I'm trying to infer A and B and I have measured y as a function of x. Numerically, I can discretize x however I want, however if I use a very fine discretization, the joint likelihood would dwarf any prior I assign which seems intuitively wrong... In the past I have rescaled my likelihood by dividing it by the number of independent "measurements". Does anybody know the correct way to handle such a problem?
r/BayesianProgramming • u/Plane-Response-2488 • Aug 21 '24
Couldn’t help but share
Please tell me someone else finds the article funny
r/BayesianProgramming • u/bmarshall110 • Jun 13 '24
Sequential experimentation w/ Gaussian Process
Hey,
I am running a sequential experiment using a Gaussian process.
I am unsure how to specify the variance and the lengthscale in my kernels in a way which isn't just arbitrary.
Is it ok to just run the experiment for a few weeks and then use the actual date to determine the kernel ?
r/BayesianProgramming • u/Norman-Atomic43 • Jun 13 '24
Hamiltonian Monte Carlo Implementation
Hello. I hope this is a good community to ask this question in. I wanted to learn more about HMC methods and it's mathematical underpinnings. I read a lot of papers and wrote up a program that implemented HMC with a dynamic metric adapted in a similar method to stan during an extended warm-up period.
Two of my parameters are constrained to be > 0. I worked around this by exponentiating those values in the position space so that they could be used in calculating the likelihood/potential energy of the system. I added a jacobian correction as well. The results match the same model in Stan, so I believe I have done everything right. Or at least, I have not made any grave mistakes. I was writing up my results/method and when I came to explaining the jacobian. I could not grasp what exact process was happening. Was I really doing a change of variables/a process that would require a correction. I never had a probability distribution defined on the unconstrained space that collapses to the probability distribution I selected for the model when i exponentiated the parameters. Is the jacobian even needed? Is what I did just an implementation trick with no implications? I can explain more, but I want to keep this short. Any help or direction/references would be greatly appreciated. I feel as though I should be able to figure this out on my own, but i am finding it difficult to know what questions exactly to ask. This is just a project for fun, but I want to do everything correctly.
Many thanks!