# \#variational-bayes

**URL:** https://discourse.mc-stan.org/tag/variational-bayes/20.md

[Latest](https://discourse.mc-stan.org/latest.md) · [Categories](https://discourse.mc-stan.org/categories.md) · [Tags](https://discourse.mc-stan.org/tags.md)

---

## [CmdStanPy Variational - How to get density parameters?](https://discourse.mc-stan.org/t/cmdstanpy-variational-how-to-get-density-parameters/37280)

<div class="topic-metadata">

**Author:** [@madelynandersen](https://discourse.mc-stan.org/u/madelynandersen)\
**Replies:** 10\
**Last updated:** [November 19, 2024, 8:27pm UTC](https://discourse.mc-stan.org/t/cmdstanpy-variational-how-to-get-density-parameters/37280 "2024-11-19T20:27:22Z")

</div>

Hi! Here is the smallest reproducible code unit. I am working on the following fully conjugate normal model: Y \\sim \\mathcal{N}(\\mu, \\sigma^2)\\\\ \\mu \\sim \\mathcal{N}(\\mu\_0, \\sigma\_0^2) In my toy model, I am setting …

---

## [Variational Bayes "fitting finished unexpectedly": Arithmetic exception from scale\_matrix\_exp\_multiply()](https://discourse.mc-stan.org/t/variational-bayes-fitting-finished-unexpectedly-arithmetic-exception-from-scale-matrix-exp-multiply/35532)

<div class="topic-metadata">

**Author:** [@karimn](https://discourse.mc-stan.org/u/karimn)\
**Replies:** 3\
**Last updated:** [June 24, 2024, 2:53pm UTC](https://discourse.mc-stan.org/t/variational-bayes-fitting-finished-unexpectedly-arithmetic-exception-from-scale-matrix-exp-multiply/35532 "2024-06-24T14:53:42Z")

</div>

Hi, I’m having a problem running a variational model. I’m getting the below error when I run a Linux server, but the exact same code works perfectly fine on a Mac. \> barcode\_model$variational(experiment\_stan\_data, thre…

---

## [{cmdstanr} variational() ignores eta parameter](https://discourse.mc-stan.org/t/cmdstanr-variational-ignores-eta-parameter/35286)

<div class="topic-metadata">

**Author:** [@karimn](https://discourse.mc-stan.org/u/karimn)\
**Replies:** 2\
**Last updated:** [May 29, 2024, 2:18am UTC](https://discourse.mc-stan.org/t/cmdstanr-variational-ignores-eta-parameter/35286 "2024-05-29T02:18:20Z")

</div>

I’m using the variational() function and setting eta = 1, but that doesn’t seem to matter: Stan is still trying to find eta. Sorry if I’m misunderstanding this option (new to variational Bayes). some\_data |\> cell\_line…

---

## [How to increase the number of dropped evaluations variational bayes cmdstanr?](https://discourse.mc-stan.org/t/how-to-increase-the-number-of-dropped-evaluations-variational-bayes-cmdstanr/35115)

<div class="topic-metadata">

**Author:** [@carlos\_perez](https://discourse.mc-stan.org/u/carlos_perez)\
**Replies:** 2\
**Last updated:** [May 14, 2024, 8:39pm UTC](https://discourse.mc-stan.org/t/how-to-increase-the-number-of-dropped-evaluations-variational-bayes-cmdstanr/35115 "2024-05-14T20:39:49Z")

</div>

Kind regards. I am running a model using variational Bayes. I am able to run the model using a subsample of the data of 10K observations, but when I try with the full dataset of 500K observations I get the following er…

---

## [$output() in CmdStanVB object - Save the Number of Iterations](https://discourse.mc-stan.org/t/output-in-cmdstanvb-object-save-the-number-of-iterations/32898)

<div class="topic-metadata">

**Author:** [@Despo\_Theocharous](https://discourse.mc-stan.org/u/Despo_Theocharous)\
**Replies:** 4\
**Last updated:** [September 27, 2023, 9:23am UTC](https://discourse.mc-stan.org/t/output-in-cmdstanvb-object-save-the-number-of-iterations/32898 "2023-09-27T09:23:24Z")

</div>

Hi there! I run Stan’s variational approximation using $variational() in RStudio. My issue is that I cannot find a way to save the number of iterations at the end. To be more clear: I run the variational approximation…

---

## [Parameters way off with variational inference, not sure why](https://discourse.mc-stan.org/t/parameters-way-off-with-variational-inference-not-sure-why/32449)

<div class="topic-metadata">

**Author:** [@dherrera1911](https://discourse.mc-stan.org/u/dherrera1911)\
**Replies:** 2\
**Last updated:** [August 23, 2023, 6:44pm UTC](https://discourse.mc-stan.org/t/parameters-way-off-with-variational-inference-not-sure-why/32449 "2023-08-23T18:44:11Z")

</div>

I am trying to fit a model to some simulated neural data. In the simulated data, I have a set of neurons indexed by i={1, ..., N} and two conditions, a baseline condition Stimulation=0 and a stimulated condition Stimulat…

---

## [Why does VB struggle with bernoulli(inv\_logit(...)) vs. bernoulli\_logit(...)?](https://discourse.mc-stan.org/t/why-does-vb-struggle-with-bernoulli-inv-logit-vs-bernoulli-logit/32365)

<div class="topic-metadata">

**Author:** [@loesten](https://discourse.mc-stan.org/u/loesten)\
**Replies:** 5\
**Last updated:** [August 10, 2023, 5:57pm UTC](https://discourse.mc-stan.org/t/why-does-vb-struggle-with-bernoulli-inv-logit-vs-bernoulli-logit/32365 "2023-08-10T17:57:37Z")

</div>

I’m implementing an IRT model and have followed the relevant chapter in the user guide to the letter (except for changing the kk index to ii, to match edstan’s format). Hence the model block is simply model { alpha ~ …

---

## [New Theoretical analysis for ADVI](https://discourse.mc-stan.org/t/new-theoretical-analysis-for-advi/31529)

<div class="topic-metadata">

**Author:** [@Red-Portal](https://discourse.mc-stan.org/u/Red-Portal)\
**Replies:** 0\
**Last updated:** [May 28, 2023, 6:07am UTC](https://discourse.mc-stan.org/t/new-theoretical-analysis-for-advi/31529 "2023-05-28T06:07:39Z")

</div>

Hi all, We’ve recently uploaded to ArXiv a theoretical analysis for ADVI (although the title says black-box VI), which I believe is the first formal full convergence proof for any black-box VI-type algorithm that uses S…

---

## [Using posterior from a variational inference as prior for sampling?](https://discourse.mc-stan.org/t/using-posterior-from-a-variational-inference-as-prior-for-sampling/31422)

<div class="topic-metadata">

**Author:** [@samuelf](https://discourse.mc-stan.org/u/samuelf)\
**Replies:** 0\
**Last updated:** [May 17, 2023, 4:09am UTC](https://discourse.mc-stan.org/t/using-posterior-from-a-variational-inference-as-prior-for-sampling/31422 "2023-05-17T04:09:29Z")

</div>

Can someone talk me out of the following idea? I feel icky. If I’m having trouble getting a model to converge using sampling, how bad of an idea is it to fit an approximate posterior using meanfield variational inferenc…

---

## [Initialize MCMC with draws from variational inference in cmdstanr](https://discourse.mc-stan.org/t/initialize-mcmc-with-draws-from-variational-inference-in-cmdstanr/31075)

<div class="topic-metadata">

**Author:** [@afranks](https://discourse.mc-stan.org/u/afranks)\
**Replies:** 4\
**Last updated:** [April 17, 2023, 6:44pm UTC](https://discourse.mc-stan.org/t/initialize-mcmc-with-draws-from-variational-inference-in-cmdstanr/31075 "2023-04-17T18:44:18Z")

</div>

I’m using cmdstanr and I want to initialize 4 chains of my MCMC with draws (or maybe means) from my variational approximation. There is a nice page on how to do this with cmdstanPy, but I surprisingly can’t find anythin…

---

## [Spectral Density Analysis of Time-Series: Resulting Posterior is Independent of Data](https://discourse.mc-stan.org/t/spectral-density-analysis-of-time-series-resulting-posterior-is-independent-of-data/27401)

<div class="topic-metadata">

**Author:** [@San0ix](https://discourse.mc-stan.org/u/San0ix)\
**Replies:** 4\
**Last updated:** [May 12, 2022, 7:11am UTC](https://discourse.mc-stan.org/t/spectral-density-analysis-of-time-series-resulting-posterior-is-independent-of-data/27401 "2022-05-12T07:11:52Z")

</div>

Hello everyone, I hope this problem isn’t too specific – as a beginner in Stan, I really cannot tell how or why my issue arises, so I don’t know how to simplify it. I’m currently working on applying Variational Inferenc…

---

## [How to do VI or ADVI in pystan?](https://discourse.mc-stan.org/t/how-to-do-vi-or-advi-in-pystan/27204)

<div class="topic-metadata">

**Author:** [@patel-zeel](https://discourse.mc-stan.org/u/patel-zeel)\
**Replies:** 1\
**Last updated:** [April 20, 2022, 7:43am UTC](https://discourse.mc-stan.org/t/how-to-do-vi-or-advi-in-pystan/27204 "2022-04-20T07:43:14Z")

</div>

How to do Variational Inference (VI) or Automatic Differentiation Variational Inference (ADVI) with pystan? I would greatly appreciate a simple code example.

---

## [Variational inference with a mixture of dense and diagonal normals](https://discourse.mc-stan.org/t/variational-inference-with-a-mixture-of-dense-and-diagonal-normals/25370)

<div class="topic-metadata">

**Author:** [@adi\_r](https://discourse.mc-stan.org/u/adi_r)\
**Replies:** 3\
**Last updated:** [November 20, 2021, 7:27pm UTC](https://discourse.mc-stan.org/t/variational-inference-with-a-mixture-of-dense-and-diagonal-normals/25370 "2021-11-20T19:27:43Z")

</div>

It it possible to do VI in Stan such that some variables are approximated by an mvn with a dense covariance and others with a diagonal covariance? The use case I have in mind is a sparse gaussian process wherein the ind…

---

## [Variational inference in Rstan with errors](https://discourse.mc-stan.org/t/variational-inference-in-rstan-with-errors/22937)

<div class="topic-metadata">

**Author:** [@mary](https://discourse.mc-stan.org/u/mary)\
**Replies:** 1\
**Last updated:** [June 14, 2021, 10:09am UTC](https://discourse.mc-stan.org/t/variational-inference-in-rstan-with-errors/22937 "2021-06-14T10:09:35Z")

</div>

Hello Guys, I am a very newer here, I have trie to build my own variational inference algorithm in pure R without any package help, however my parameters were very strange at the end of iterations and I had to change. …

---

## [Performance differences between RStan's VB and CmdStan's variational](https://discourse.mc-stan.org/t/performance-differences-between-rstans-vb-and-cmdstans-variational/22655)

<div class="topic-metadata">

**Author:** [@Adam\_Haber](https://discourse.mc-stan.org/u/Adam_Haber)\
**Replies:** 3\
**Last updated:** [May 23, 2021, 9:22am UTC](https://discourse.mc-stan.org/t/performance-differences-between-rstans-vb-and-cmdstans-variational/22655 "2021-05-23T09:22:17Z")

</div>

I’m experiencing significant performance differences between CmdStan’s variational (2.26.1) and RStan’s vb (2.21.3) - wanted to know if this is expected or not. I have a relatively large model - ~42K parameters - and I’…

---

## [Problem running loo\_subsample with variational inference and cmdstanr](https://discourse.mc-stan.org/t/problem-running-loo-subsample-with-variational-inference-and-cmdstanr/22506)

<div class="topic-metadata">

**Author:** [@kdubovikov](https://discourse.mc-stan.org/u/kdubovikov)\
**Replies:** 19\
**Last updated:** [May 15, 2021, 8:10am UTC](https://discourse.mc-stan.org/t/problem-running-loo-subsample-with-variational-inference-and-cmdstanr/22506 "2021-05-15T08:10:40Z")

</div>

I am trying to run loo\_subsample for model that I have fitted using cmdstanr using variational inference. data { int\<lower=0\> N; // number of observations int\<lower=0\> year\[N\]; // year hierarchy level int\<lo…

---

## [Credibility intervals for one group](https://discourse.mc-stan.org/t/credibility-intervals-for-one-group/22091)

<div class="topic-metadata">

**Author:** [@Rani](https://discourse.mc-stan.org/u/Rani)\
**Replies:** 6\
**Last updated:** [April 30, 2021, 6:31pm UTC](https://discourse.mc-stan.org/t/credibility-intervals-for-one-group/22091 "2021-04-30T18:31:59Z")

</div>

Hello all, I would like to have a good interpret for the credible interval for one treatment group in the clinical trial, what does that mean? and how I can compute that for different sample sizes with rstanarm package. …

---

## [Intermediate between mean-field and full-rank ADVI](https://discourse.mc-stan.org/t/intermediate-between-mean-field-and-full-rank-advi/8506)

<div class="topic-metadata">

**Author:** [@wjn0](https://discourse.mc-stan.org/u/wjn0)\
**Replies:** 16\
**Last updated:** [March 26, 2021, 11:33pm UTC](https://discourse.mc-stan.org/t/intermediate-between-mean-field-and-full-rank-advi/8506 "2021-03-26T23:33:59Z")

</div>

Hello, I’m new to using the VB algorithm in Stan. I’m wondering if it’s sensible (and possible) to use an intermediate between the mean-field approximation and full-rank VB. I’m working with a latent variable model with…

---

## [Convergence of variational inference](https://discourse.mc-stan.org/t/convergence-of-variational-inference/19422)

<div class="topic-metadata">

**Author:** [@songpeng](https://discourse.mc-stan.org/u/songpeng)\
**Replies:** 4\
**Last updated:** [December 5, 2020, 9:06pm UTC](https://discourse.mc-stan.org/t/convergence-of-variational-inference/19422 "2020-12-05T21:06:56Z")

</div>

I run a stan model under cmdstanr using variational inference. And I set the tol\_rel\_obj as 0.0002 as one way to detect the convergence, and max number of iteration is 50,000. Then I notice that some times I can get the…

---

## [Variational Bayes results seems sensible, but vary - What to change?](https://discourse.mc-stan.org/t/variational-bayes-results-seems-sensible-but-vary-what-to-change/18119)

<div class="topic-metadata">

**Author:** [@Bjoern](https://discourse.mc-stan.org/u/Bjoern)\
**Replies:** 6\
**Last updated:** [November 6, 2020, 8:21pm UTC](https://discourse.mc-stan.org/t/variational-bayes-results-seems-sensible-but-vary-what-to-change/18119 "2020-11-06T20:21:49Z")

</div>

I am running a model that works nicely using NUTS (but is a bit slow) using variational Bayes (mostly because its a pretty simple model and I hope it would be a lot faster using VB, which for the particular use case wou…

---

## [Initialize variational approximation to speed-up sampling](https://discourse.mc-stan.org/t/initialize-variational-approximation-to-speed-up-sampling/16260)

<div class="topic-metadata">

**Author:** [@Dionysis\_Manousakas](https://discourse.mc-stan.org/u/Dionysis_Manousakas)\
**Replies:** 9\
**Last updated:** [November 6, 2020, 4:26pm UTC](https://discourse.mc-stan.org/t/initialize-variational-approximation-to-speed-up-sampling/16260 "2020-11-06T16:26:34Z")

</div>

Is it possible to pass an initialization to the variational approximation parameters when calling vb?

---

## [Control verbosity in rstan::vb](https://discourse.mc-stan.org/t/control-verbosity-in-rstan-vb/15971)

<div class="topic-metadata">

**Author:** [@David\_Knowles](https://discourse.mc-stan.org/u/David_Knowles)\
**Replies:** 2\
**Last updated:** [June 16, 2020, 7:52pm UTC](https://discourse.mc-stan.org/t/control-verbosity-in-rstan-vb/15971 "2020-06-16T19:52:28Z")

</div>

Is there a way to control the verbosity of rstan::vb? i.e. an equivalent to verbose for sampling or optimizing. Docs + google are failing me.

---

## [Using a different divergence measure for VI](https://discourse.mc-stan.org/t/using-a-different-divergence-measure-for-vi/15313)

<div class="topic-metadata">

**Author:** [@dzl](https://discourse.mc-stan.org/u/dzl)\
**Replies:** 2\
**Last updated:** [May 28, 2020, 7:23pm UTC](https://discourse.mc-stan.org/t/using-a-different-divergence-measure-for-vi/15313 "2020-05-28T19:23:18Z")

</div>

I understand that the KL divergence is used in Stan’s VI implementation. Is it possible to add a custom divergence measure instead?

---

## [RStan - Partsworth](https://discourse.mc-stan.org/t/rstan-partsworth/14292)

<div class="topic-metadata">

**Author:** [@Girish\_Giovanni](https://discourse.mc-stan.org/u/Girish_Giovanni)\
**Replies:** 1\
**Last updated:** [April 25, 2020, 2:03pm UTC](https://discourse.mc-stan.org/t/rstan-partsworth/14292 "2020-04-25T14:03:17Z")

</div>

dear all, for python pymc3 package we can generate the partsworth utilities in the data set undergoing kmeans/conjoint analysis. how do i generate the partsworth utilities in RStan ?

---

## [Stochastic subsampling in ADVI](https://discourse.mc-stan.org/t/stochastic-subsampling-in-advi/9240)

<div class="topic-metadata">

**Author:** [@danmichaeljones](https://discourse.mc-stan.org/u/danmichaeljones)\
**Replies:** 1\
**Last updated:** [June 18, 2019, 5:19pm UTC](https://discourse.mc-stan.org/t/stochastic-subsampling-in-advi/9240 "2019-06-18T17:19:22Z")

</div>

I was reading the ADVI in Stan paper and had a question about the Gaussian mixture example (section 3.3). The paper says that it is possible to have stochastic subsampling of the data when doing ADVI, with example code …

---

## [Change point model](https://discourse.mc-stan.org/t/change-point-model/7311)

<div class="topic-metadata">

**Author:** [@cc20002002](https://discourse.mc-stan.org/u/cc20002002)\
**Replies:** 2\
**Last updated:** [February 22, 2019, 4:42pm UTC](https://discourse.mc-stan.org/t/change-point-model/7311 "2019-02-22T16:42:47Z")

</div>

Dear Stan Forum, I have some two-dimensional data of size (5-20) that requires me to fit a change point model with two straight lines. An MCMC simulation will take 2-10 seconds to fit each model. I have about 20,000 su…

---

## [ADVI / Stochastic quasi-Newton methods](https://discourse.mc-stan.org/t/advi-stochastic-quasi-newton-methods/1917)

<div class="topic-metadata">

**Author:** [@JulianK](https://discourse.mc-stan.org/u/JulianK)\
**Replies:** 5\
**Last updated:** [September 22, 2017, 9:54pm UTC](https://discourse.mc-stan.org/t/advi-stochastic-quasi-newton-methods/1917 "2017-09-22T21:54:39Z")

</div>

Hi everyone, In this thread I note the following comment from @Bob\_Carpenter: This suggests to me that stochastic Adagrad is having trouble discovering the right length scale for the parameters. A good optimisation al…

---

## [ADVI / Rats example / Adagrad](https://discourse.mc-stan.org/t/advi-rats-example-adagrad/1859)

<div class="topic-metadata">

**Author:** [@JulianK](https://discourse.mc-stan.org/u/JulianK)\
**Replies:** 1\
**Last updated:** [September 17, 2017, 4:20pm UTC](https://discourse.mc-stan.org/t/advi-rats-example-adagrad/1859 "2017-09-17T16:20:21Z")

</div>

Curiosity drove me back to look at the in the context of ADVI that I posted on the old Google groups discussion list. I can get reasonable results from ADVI for RATS if I start with init=0 and eta=10 but not eta=1. The…

---

## [Mixed models with deterministic and random variables](https://discourse.mc-stan.org/t/mixed-models-with-deterministic-and-random-variables/1291)

<div class="topic-metadata">

**Author:** [@mehrtash](https://discourse.mc-stan.org/u/mehrtash)\
**Replies:** 7\
**Last updated:** [August 1, 2017, 6:58pm UTC](https://discourse.mc-stan.org/t/mixed-models-with-deterministic-and-random-variables/1291 "2017-08-01T18:58:57Z")

</div>

Hi, I am a relatively new Stan user. I was wondering whether Stan supports models with mixed deterministic and random variables, either directly or via a good hack. To be more specific, let’s say my log joint is a funct…

---

## [Different runs give me different estimated values](https://discourse.mc-stan.org/t/different-runs-give-me-different-estimated-values/1066)

<div class="topic-metadata">

**Author:** [@mhashemi0873](https://discourse.mc-stan.org/u/mhashemi0873)\
**Replies:** 4\
**Last updated:** [July 3, 2017, 12:11pm UTC](https://discourse.mc-stan.org/t/different-runs-give-me-different-estimated-values/1066 "2017-07-03T12:11:58Z")

</div>

Hello, I have a conceptual question. I use variational inference to fit my model to the data. But for different runnings, with same values of ELBO, I obtain different posterior distributions for parameters (regarding mea…

[Next page](https://discourse.mc-stan.org/tag/variational-bayes/20.md?match_all_tags=true&page=1&tags%5B%5D=variational-bayes)
