Corner case in `dirichlet_lpdf`: error when both alpha - 1 = theta = 0

Offen
#3,186 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
35/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Veraltet
Tech-Stack
cpp

Rechercherichtung

Beginnen Sie in stan/math/prim/prob/dirichlet_lpdf.hpp bei der verlinkten theta_log-Berechnung und untersuchen Sie anschließend die entsprechende Handhabung von partials_vec<1>. Bestimmen Sie, ob der Fall alpha - 1 = theta = 0 ohne einen Fehler zu erzeugen null beitragen sollte, und stellen Sie sicher, dass sich das zugehörige autodiff-Verhalten konsistent verhält.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

In the code there is currently:

  const auto& theta_log
      = to_ref_if<!is_constant_all<T_prior_size>::value>(theta_dbl.log());

  if (include_summand<propto, T_prob, T_prior_size>::value) {
    lp += (theta_log * alpha_m_1).sum();
  }

I understand that by the convention (and also by Stan documentation) for Dirichlet distribution, we usually require theta > 0. But when you think about it, for the corner case when alpha -1 == theta == 0, it is reasonable to define the lpdf to be 0 by the same logic why we define pow(0,0)=1. This is relevant in my application, where I may have on input an information that certain index of theta is a forbidden state and may thus be represented as hard constrained to be equal to 0, but then the Dirichlet prior crashes no matter what. This would be very inefficient for me to workaround by deleting the offending array element as I need to do this over a matrix with many rows each of which may have different constraints, so currently I needed to make my custom implementation of dirichlet_lpdf just to deal with that. I thus propose we change the code to something like:

  if (include_summand<propto, T_prob, T_prior_size>::value) {
    lp += lmultiply(alpha_m_1, theta).sum();
  }

The partials_vec<1> may need a corresponding adjustment.

Vorherrschende Sprache
C++
Sterne
845
Forks
225
Ø Merge
4 T. 21 Std.
Gemergte PRs (30 T.)
13

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus stan-dev/math

Alle Issues in stan-dev/math

Ähnliche Issues

Weitere Issues zu C++

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.