# Developing Services

**URL:** <https://discourse.mc-stan.org/t/developing-services/10036>\
**Category:** Developers\
**Tags:** features, cmdstan, rstan\
**Created:** [August 2, 2019, 8:30pm UTC](https://discourse.mc-stan.org/t/developing-services/10036 "2019-08-02T20:30:00Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon79882417](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@anon79882417](https://discourse.mc-stan.org/u/anon79882417)\
**Post date:** [August 2, 2019, 8:30pm UTC](https://discourse.mc-stan.org/t/developing-services/10036/1 "2019-08-02T20:30:00Z")

</div>

I’m adding some functionality to services, that is, K-hat and ESS for the VI diagnostics.

Is there anything else that we’re currently implementing in one of our interfaces that we’d like to add to services?

---

<div class="post-metadata">

**Author:** ![anon79882417](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@anon79882417](https://discourse.mc-stan.org/u/anon79882417)\
**Post date:** [August 7, 2019, 7:07pm UTC](https://discourse.mc-stan.org/t/developing-services/10036/2 "2019-08-07T19:07:40Z")

</div>

@roualdes is this: [https://github.com/stan-dev/stan/blob/a820fb06108c0edac8606e4362ff808441691141/src/stan/analyze/mcmc/compute\_effective\_sample\_size.hpp#L2](https://github.com/stan-dev/stan/blob/a820fb06108c0edac8606e4362ff808441691141/src/stan/analyze/mcmc/compute_effective_sample_size.hpp#L2)

The same ESS/Neff we want in services? If so I’m going to skip implementing this, or just write a wrapper that calls your function.

Andre

---

<div class="post-metadata">

**Author:** ![avehtari](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/avehtari/32/5935_2.png) [@avehtari](https://discourse.mc-stan.org/u/avehtari)\
**Post date:** [August 7, 2019, 7:25pm UTC](https://discourse.mc-stan.org/t/developing-services/10036/3 "2019-08-07T19:25:13Z")

</div>

See PR [https://github.com/stan-dev/stan/pull/2794](https://github.com/stan-dev/stan/pull/2794) and issues mentioned there

---

<div class="post-metadata">

**Author:** ![roualdes](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/roualdes/32/1594_2.png) [@roualdes](https://discourse.mc-stan.org/u/roualdes)\
**Post date:** [August 8, 2019, 3:05pm UTC](https://discourse.mc-stan.org/t/developing-services/10036/4 "2019-08-08T15:05:05Z")

</div>

@anon79882417, I don’t feel versed well enough on VI to make a definitive judgment on this. This thread seems to have a proposal for ESS applied to ADVI as a diagnostic…

> [@Analysis API](https://discourse.mc-stan.org/t/analysis-api/3486/2):
>
> I’ll add non-MCMC analysis to this system. Now we have only ADVI, but we may have something else later, but all distributional approximations can use the new Pareto diagnostic. Given draws theta^{(s)} from any distributional approximation q, and log(q(theta^{(s)})) and log(p(theta^{(s)})) we can compute Pareto k (khat) and effective sample size (N\_eff) estimates. These should be reported in every interface similarly as Rhat and N\_eff are reported for HMC/NUTS.

---

<div class="post-metadata">

**Author:** ![anon79882417](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@anon79882417](https://discourse.mc-stan.org/u/anon79882417)\
**Post date:** [August 8, 2019, 3:19pm UTC](https://discourse.mc-stan.org/t/developing-services/10036/5 "2019-08-08T15:19:21Z")

</div>

> [@roualdes](#):
>
> This thread seems to have a proposal for ESS applied to ADVI as a diagnostic…

Updating the VI diagnostic began a discussion that would make diagnostics for other algorithms Stan supports available in services. I should have updated the thread.

So if we have ESS available in services, then Pystan, Rstan, Cmdstan, etc can just call stan-dev/stan’s service. This will help with maintainability, replicability, consistency in the future.

> [@roualdes](#):
>
> I don’t feel versed well enough on VI to make a definitive judgment on this.

I’m looking at it as a learning opportunity. I’m familiar with simple importance sampling, but this is great because it shows one example about how it’s used in practice.

---

<div class="post-metadata">

**Author:** ![roualdes](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/roualdes/32/1594_2.png) [@roualdes](https://discourse.mc-stan.org/u/roualdes)\
**Post date:** [August 8, 2019, 3:43pm UTC](https://discourse.mc-stan.org/t/developing-services/10036/6 "2019-08-08T15:43:19Z")

</div>

> [@anon79882417](#):
>
> So if we have ESS available in services, then Pystan, Rstan, Cmdstan

Re that same thread, isn’t this what the Analysis API was/is meant to do?

---

<div class="post-metadata">

**Author:** ![anon79882417](https://avatars.discourse-cdn.com/v4/letter/a/f05b48/32.png) [@anon79882417](https://discourse.mc-stan.org/u/anon79882417)\
**Post date:** [August 8, 2019, 3:50pm UTC](https://discourse.mc-stan.org/t/developing-services/10036/7 "2019-08-08T15:50:27Z")

</div>

Looks like it from my skim:

> <https://github.com/stan-dev/stan/issues/2569>

But from the PR we’re implementing stuff only applicable to MCMC, where this is more general, for other algorithms.

I’m hoping someone more senior will say something?

May be we should move this ESS into services. Because we could use an ESS for MCMC and VI.

I haven’t checked Aki’s reference though, could be a different ESS.

I’ll do some reading then leave a more thoughtful comment.

---

<div class="post-metadata">

**Author:** ![avehtari](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mc-stan.org/avehtari/32/5935_2.png) [@avehtari](https://discourse.mc-stan.org/u/avehtari)\
**Post date:** [August 8, 2019, 4:43pm UTC](https://discourse.mc-stan.org/t/developing-services/10036/8 "2019-08-08T16:43:36Z")

</div>

> [@anon79882417](#):
>
> I haven’t checked Aki’s reference though, could be a different ESS.

Yes, different equations to compute ESS for MCMC and for IS (and vb and optimizing can be used to form the proposal for IS)
