Skip to content

Commit

Permalink
Use adaptive simpson's integration for chi^2 CDF. This produces bette…
Browse files Browse the repository at this point in the history
…r results. Probably a midpoint method would work well.
  • Loading branch information
BrentSeidel committed Jun 5, 2024
1 parent 90f8e99 commit 1ee0a64
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/BBS-Numerical-Statistics.adb
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ package body BBS.Numerical.Statistics is
end;
--
function chi2_cdf(a, b : F'Base; k, steps : Positive) return F'Base is
tol : f'Base := 0.0001;
begin
deg_freedom := k;
return integ.simpson(partial_chi2'Access, a, b, steps);
return integ.adapt_simpson(partial_chi2'Access, a, b, tol, steps);
end;
--
function partial_chi2(x : f'Base) return f'Base is
Expand Down
6 changes: 3 additions & 3 deletions test/test_stats.adb
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ begin
Ada.Text_IO.Put(" ");
float_io.Put(stat.normal_cdf(0.0, val, 20), 1, 5, 0);
Ada.Text_IO.Put(" ");
float_io.Put(stat.chi2_pdf(val, 1), 1, 5, 0);
float_io.Put(stat.chi2_pdf(val, 20), 1, 5, 0);
Ada.Text_IO.Put(" ");
float_io.Put(stat.chi2_exp(val, 1), 1, 5, 0);
float_io.Put(stat.chi2_exp(val, 20), 1, 5, 0);
Ada.Text_IO.Put(" ");
float_io.Put(stat.chi2_cdf(0.0, val, 1, 20), 1, 5, 0);
float_io.Put(stat.chi2_cdf(0.0, val, 20, 20), 1, 5, 0);
Ada.Text_IO.New_Line;
end loop;
end test_stats;

0 comments on commit 1ee0a64

Please sign in to comment.