`log_modified_bessel_first_kind` has zero derivatives in the order at v = 0 and v = 1
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 54/100
Hướng nghiên cứu
Start with the implementation of log_modified_bessel_first_kind and the source comment about autodiff at v = 0, then inspect the reverse-mode test area under test/unit/math/rev/fun/. The issue proposes checking whether the special-case fits can be limited to non-autodiff orders so autodiff uses the general power series. Add the supplied order-gradient checks at v = 0 and v = 1 and confirm they match the expected values.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
AI use disclosure: This was written with the help of Claude Code (Opus 5.5).
Description
For v == 0 and v == 1, log_modified_bessel_first_kind(v, z) evaluates Boost's fits for $I_0$ and $I_1$, which do not depend on v. When v is an autodiff variable, every derivative with respect to v is therefore 0, in reverse and forward mode. The exact first derivative is $-K_0(z)/I_0(z)$ at v = 0 (decaying like $e^{-2z}$) and about $-1/z$ at v = 1 for large z. The source comments acknowledge this ("WARNING: will not autodiff for v = 0 correctly").
A sampler, optimizer or diagnose can start exactly there: with init=0, a real<lower=0> order starts at exp(0) = 1 and a real<lower=-1> order at 0.
do_lkj_constant, the normalizing constant of lkj_corr_lpdf, lkj_corr_cholesky_lpdf and lkj_cov_lpdf, has the same defect at eta == 1.0: develop drops the η-derivatives of the constant there, so the η-gradient keeps only the data term and the second η-derivative is 0. Open PR #3434 fixes this as part of its rewrite: on its head (35435f53dc), the first and second η-derivatives at η = 1 are within 3e-16 of the exact values (K = 2). Its tests have no η = 1 point.
Possible fix: take the two shortcuts only when v is not autodiff (!is_autodiff_v<T1> &&). The test below then passes, and an autodiff order goes through the general power series.
Example
New file test/unit/math/rev/fun/log_modified_bessel_first_kind_test.cpp:
#include <stan/math/rev.hpp>
#include <test/unit/math/rev/util.hpp>
#include <gtest/gtest.h>
TEST_F(AgradRev, log_modified_bessel_first_kind_order_gradient) {
using stan::math::var;
auto d_dv = [](double v_val) {
var v = v_val;
stan::math::log_modified_bessel_first_kind(v, 0.5).grad();
double g = v.adj();
stan::math::recover_memory();
return g;
};
// d/dv log I_v(0.5) from mpmath (50 digits); at v = 0 it is -K_0 / I_0
EXPECT_NEAR(-0.86923697789771742858, d_dv(0), 1e-12);
EXPECT_NEAR(-1.8244901560201558681, d_dv(1), 1e-12);
}
It fails on develop:
[ RUN ] AgradRev.log_modified_bessel_first_kind_order_gradient
d_dv(0) evaluates to 0
d_dv(1) evaluates to 0
[ FAILED ] AgradRev.log_modified_bessel_first_kind_order_gradient
Expected Output
The order gradient at z = 0.5 is −0.86923697789771743 at v = 0 and −1.8244901560201559 at v = 1 (mpmath).
Current Version:
v5.4.0 (develop at 1f83dc5dc4)
- Ngôn ngữ chính
- C++
- Star
- 845
- Fork
- 225
- Merge trung bình
- 3 ngày 9 giờ
- Pull request đã merge (30 ngày)
- 12
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của stan-dev/math
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 54/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 1 ngày
-
numerics performance
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
stan-dev/math#3481 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`eigendecompose_sym`, `eigenvalues_sym` and `eigenvectors_sym` do not compile for complex matrices of `fvar<var>` or `fvar<fvar<double>>`Có thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởbug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
stan-dev/math#3477 · 5 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
stan-dev/math#3474 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của stan-dev/math
Issue tương tự
-
Upstream changes to reviewĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
rhalbersma/xstd-ints#395 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] Root filesystem scope (/) incorrectly rejects all descendant pathsCó thể đã có người làm @mugenkyou đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
neutralinojs/neutralino.js#304 · 1 bình luận ·
-
zq prints a raw SQL 'no such table: index_default' error when the index has no default indexĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
mattgodbolt/zindex#67 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 67/100
NKI-AI/fastslide#105 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày