stan-dev / stan

Stan development repository. The master branch contains the current release. The develop branch contains the latest stable development. See the Developer Process Wiki for details.
https://mc-stan.org
BSD 3-Clause "New" or "Revised" License
2.57k stars 368 forks source link

*_rng() functions that match all existing signatures available for corresponding *_lpdf() functions #3185

Open mike-lawrence opened 1 year ago

mike-lawrence commented 1 year ago

At present, most *_rng() functions for quantities have a single signature, requiring loops to accommodate expressions that are otherwise expressable with a single line when using the corresponding *_lpdf() in the model block. What would it take to get equivalence in available signatures between *_lpdf() and corresponding *_rng() functions? Happy to help, but wouldn't know where to start!

WardBrian commented 1 year ago

I think the primary work for this issue would be in the math library.

Based on the compiler, here are a list of distributions for which I believe the RNG and density signatures do match:

Details

``` beta beta_binomial bernoulli bernoulli_logit binomial cauchy chi_square discrete_range double_exponential exp_mod_normal exponential frechet gamma gumbel hypergeometric inv_chi_square inv_gamma logistic loglogistic lognormal neg_binomial neg_binomial_2 neg_binomial_2_log normal pareto pareto_type_2 poisson poisson_log rayleigh scaled_inv_chi_square skew_double_exponential skew_normal student_t std_normal uniform von_mises weibull ```

There is one _rng function with no corresponding density:

hmm_latent

And the following densities have incomplete RNG signatures (usually missing vectorization):

beta_proportion
bernoulli_logit_glm
categorical
categorical_logit
dirichlet
inv_wishart_cholesky
inv_wishart
lkj_corr
lkj_corr_cholesky
multinomial
multinomial_logit
multi_normal
multi_normal_cholesky
multi_student_t
multi_student_t_cholesky
ordered_logistic
ordered_probit
wishart_cholesky
wishart_rng

And finally, missing RNG functions entirely:

binomial_logit
categorical_logit_glm
gaussian_dlm_obs
lkj_cov
multi_gp
multi_gp_cholesky
multi_normal_prec
neg_binomial_2_log_glm
normal_id_glm
ordered_logistic_glm
poisson_log_glm
wiener

For any given distribution above it would be pretty easy to have the compiler spit out the signatures which are still needed.