Pedantic warning for unnormalized densities inside log_mix and log_sum_exp

Aperta
#1,757 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
1-2 giorni
Idoneità per principianti
52/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
ocaml
Ambito
compilers

Direzione di ricerca

Start by reading the pedantic warning checks in the Stan compiler and the existing tests for --warn-pedantic; the issue does not name specific files or tests. Add coverage for _lupdf and _lupmf calls used directly or inside expressions passed to log_mix and log_sum_exp, including same-distribution components with differing data and parameter arguments. Done means those cases produce warnings while the stated parameter-dependent ~ case remains out of scope.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

feature
Summary:

The pedantic-mode could include a warning for an _lupdf or _lupmf call that is an argument of log_mix or log_sum_exp. The unnormalized densities of different distributions drop different constants, and the mixture then may have the wrong mixing proportions.

Description:

This program compiles without a warning, also with --warn-pedantic (stanc3 v2.40.0):

data {
  real y;
}
parameters {
  real mu;
  real<lower=0> sigma;
  real<lower=0, upper=1> lambda;
}
model {
  target += log_mix(lambda,
                    normal_lupdf(y | mu, sigma),
                    cauchy_lupdf(y | mu, sigma));
}

normal_lupdf drops -log(sqrt(2 * pi)) and cauchy_lupdf drops -log(pi), so the effective mixing proportion differs from lambda. With normal_lpdf and cauchy_lpdf the program is correct. The same happens with log_sum_exp, and also with two components of the same distribution if an argument is data in one component and a parameter in the other.

The docs describe this case (stan-dev/docs#998, for stan-dev/docs#588). A warning would also find it in existing programs.

Proposed rule: warn when a call to an _lupdf or _lupmf function is a direct argument of log_mix or log_sum_exp, or appears in an expression that is a direct argument, for example log(theta) + normal_lupdf(...). The check can ignore whether the components drop the same terms.

This request does not cover the similar case where a condition that depends on parameters selects between ~ statements with different distributions. That case is harder to detect.

Current Version:

v2.40.0

Lingua principale
OCaml
Stelle
162
Fork
60
Merge medio
2g 22h
PR unite (30g)
14

Preparare l'ambiente

  • Nessun Dockerfile né file Docker Compose
  • Ha un modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di stan-dev/stanc3

Tutte le issue di stan-dev/stanc3

Issue simili

Altre issue su Compilers

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.