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

オープン
#3,186 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
35/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
cpp

調査の方向性

stan/math/prim/prob/dirichlet_lpdf.hpp のリンクされた theta_log 計算から始め、続いて対応する partials_vec<1> の処理を調べてください。alpha - 1 = theta = 0 の場合はエラーを発生させずにゼロを寄与すべきかを判断し、関連する autodiff の動作に一貫性があることを確認してください。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
C++
スター
845
フォーク
225
平均マージ
4日 21時間
マージ済み PR(30日)
13

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

stan-dev/math のほかの issue

stan-dev/math の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。