Skip to content

Commit

Permalink
use stdlib gamma, use beta and binom instead of gamma.
Browse files Browse the repository at this point in the history
  • Loading branch information
PauloCampana committed Jan 11, 2024
1 parent d944535 commit 76ccc3f
Show file tree
Hide file tree
Showing 35 changed files with 1,086 additions and 4,345 deletions.
2 changes: 1 addition & 1 deletion docs/data-astNodes.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/data-calls.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/data-decls.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/data-exprs.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/data-files.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/data-types.js

Large diffs are not rendered by default.

322 changes: 0 additions & 322 deletions docs/src/root/LinearModel.zig.html

This file was deleted.

4 changes: 2 additions & 2 deletions docs/src/root/distribution/beta.zig.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<span class="line" id="L4"></span>
<span class="line" id="L5"><span class="tok-kw">const</span> std = <span class="tok-builtin">@import</span>(<span class="tok-str">&quot;std&quot;</span>);</span>
<span class="line" id="L6"><span class="tok-kw">const</span> gamma = <span class="tok-builtin">@import</span>(<span class="tok-str">&quot;gamma.zig&quot;</span>);</span>
<span class="line" id="L7"><span class="tok-kw">const</span> lgamma = <span class="tok-builtin">@import</span>(<span class="tok-str">&quot;../thirdyparty/prob.zig&quot;</span>).lnGamma;</span>
<span class="line" id="L7"><span class="tok-kw">const</span> math = <span class="tok-builtin">@import</span>(<span class="tok-str">&quot;math.zig&quot;</span>);</span>
<span class="line" id="L8"><span class="tok-kw">const</span> incompleteBeta = <span class="tok-builtin">@import</span>(<span class="tok-str">&quot;../thirdyparty/prob.zig&quot;</span>).incompleteBeta;</span>
<span class="line" id="L9"><span class="tok-kw">const</span> inverseIncompleteBeta = <span class="tok-builtin">@import</span>(<span class="tok-str">&quot;../thirdyparty/prob.zig&quot;</span>).inverseIncompleteBeta;</span>
<span class="line" id="L10"><span class="tok-kw">const</span> assert = std.debug.assert;</span>
Expand Down Expand Up @@ -151,7 +151,7 @@
<span class="line" id="L37"> <span class="tok-kw">return</span> <span class="tok-kw">if</span> (shape2 &lt; <span class="tok-number">1</span>) inf <span class="tok-kw">else</span> <span class="tok-number">0</span>;</span>
<span class="line" id="L38"> }</span>
<span class="line" id="L39"> <span class="tok-kw">const</span> num = (shape1 - <span class="tok-number">1</span>) * <span class="tok-builtin">@log</span>(x) + (shape2 - <span class="tok-number">1</span>) * std.math.log1p(-x);</span>
<span class="line" id="L40"> <span class="tok-kw">const</span> den = lgamma(shape1) + lgamma(shape2) - lgamma(shape1 + shape2);</span>
<span class="line" id="L40"> <span class="tok-kw">const</span> den = math.lbeta(shape1, shape2);</span>
<span class="line" id="L41"> <span class="tok-kw">return</span> <span class="tok-builtin">@exp</span>(num - den);</span>
<span class="line" id="L42">}</span>
<span class="line" id="L43"></span>
Expand Down
362 changes: 177 additions & 185 deletions docs/src/root/distribution/betabinomial.zig.html

Large diffs are not rendered by default.

325 changes: 162 additions & 163 deletions docs/src/root/distribution/binomial.zig.html

Large diffs are not rendered by default.

590 changes: 0 additions & 590 deletions docs/src/root/distribution/density.zig.html

This file was deleted.

213 changes: 106 additions & 107 deletions docs/src/root/distribution/f.zig.html

Large diffs are not rendered by default.

313 changes: 156 additions & 157 deletions docs/src/root/distribution/gamma.zig.html

Large diffs are not rendered by default.

26 changes: 13 additions & 13 deletions docs/src/root/distribution/hypergeometric.zig.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<span class="line" id="L4"><span class="tok-comment">//! - n: `n` ∈ {0,1,⋯,N}</span></span>
<span class="line" id="L5"></span>
<span class="line" id="L6"><span class="tok-kw">const</span> std = <span class="tok-builtin">@import</span>(<span class="tok-str">&quot;std&quot;</span>);</span>
<span class="line" id="L7"><span class="tok-kw">const</span> lgamma = <span class="tok-builtin">@import</span>(<span class="tok-str">&quot;../thirdyparty/prob.zig&quot;</span>).lnGamma;</span>
<span class="line" id="L7"><span class="tok-kw">const</span> math = <span class="tok-builtin">@import</span>(<span class="tok-str">&quot;math.zig&quot;</span>);</span>
<span class="line" id="L8"><span class="tok-kw">const</span> assert = std.debug.assert;</span>
<span class="line" id="L9"><span class="tok-kw">const</span> isNan = std.math.isNan;</span>
<span class="line" id="L10"><span class="tok-kw">const</span> inf = std.math.inf(<span class="tok-type">f64</span>);</span>
Expand All @@ -135,9 +135,9 @@
<span class="line" id="L21"> <span class="tok-kw">if</span> (x &lt; <span class="tok-number">0</span> <span class="tok-kw">or</span> x &gt; nf <span class="tok-kw">or</span> x &gt; Kf <span class="tok-kw">or</span> x != <span class="tok-builtin">@round</span>(x)) {</span>
<span class="line" id="L22"> <span class="tok-kw">return</span> <span class="tok-number">0</span>;</span>
<span class="line" id="L23"> }</span>
<span class="line" id="L24"> <span class="tok-kw">const</span> num1 = lgamma(Kf + <span class="tok-number">1</span>) - lgamma(x + <span class="tok-number">1</span>) - lgamma(Kf - x + <span class="tok-number">1</span>);</span>
<span class="line" id="L25"> <span class="tok-kw">const</span> num2 = lgamma(Nf - Kf + <span class="tok-number">1</span>) - lgamma(nf - x + <span class="tok-number">1</span>) - lgamma(x + <span class="tok-number">1</span> + Nf - Kf - nf);</span>
<span class="line" id="L26"> <span class="tok-kw">const</span> den = lgamma(Nf + <span class="tok-number">1</span>) - lgamma(nf + <span class="tok-number">1</span>) - lgamma(Nf - nf + <span class="tok-number">1</span>);</span>
<span class="line" id="L24"> <span class="tok-kw">const</span> num1 = math.lbinomial(Kf, x);</span>
<span class="line" id="L25"> <span class="tok-kw">const</span> num2 = math.lbinomial(Nf - Kf, nf - x);</span>
<span class="line" id="L26"> <span class="tok-kw">const</span> den = math.lbinomial(Nf, nf);</span>
<span class="line" id="L27"> <span class="tok-kw">return</span> <span class="tok-builtin">@exp</span>(num1 + num2 - den);</span>
<span class="line" id="L28">}</span>
<span class="line" id="L29"></span>
Expand All @@ -157,9 +157,9 @@
<span class="line" id="L43"> <span class="tok-kw">if</span> (K == N <span class="tok-kw">or</span> n == N) {</span>
<span class="line" id="L44"> <span class="tok-kw">return</span> <span class="tok-number">0</span>;</span>
<span class="line" id="L45"> }</span>
<span class="line" id="L46"> <span class="tok-kw">const</span> p0_num = lgamma(Nf - Kf + <span class="tok-number">1</span>) - lgamma(nf + <span class="tok-number">1</span>) - lgamma(Nf - Kf - nf + <span class="tok-number">1</span>);</span>
<span class="line" id="L47"> <span class="tok-kw">const</span> p0_den = lgamma(Nf + <span class="tok-number">1</span>) - lgamma(nf + <span class="tok-number">1</span>) - lgamma(Nf - nf + <span class="tok-number">1</span>);</span>
<span class="line" id="L48"> <span class="tok-kw">var</span> mass = <span class="tok-builtin">@exp</span>(p0_num - p0_den);</span>
<span class="line" id="L46"> <span class="tok-kw">const</span> mass_num = math.lbinomial(Nf - Kf, nf);</span>
<span class="line" id="L47"> <span class="tok-kw">const</span> mass_den = math.lbinomial(Nf, nf);</span>
<span class="line" id="L48"> <span class="tok-kw">var</span> mass = <span class="tok-builtin">@exp</span>(mass_num - mass_den);</span>
<span class="line" id="L49"> <span class="tok-kw">var</span> cumu: <span class="tok-type">f64</span> = mass;</span>
<span class="line" id="L50"> <span class="tok-kw">const</span> qu = <span class="tok-builtin">@as</span>(<span class="tok-type">usize</span>, <span class="tok-builtin">@intFromFloat</span>(q));</span>
<span class="line" id="L51"> <span class="tok-kw">for</span> (<span class="tok-number">0</span>..qu) |x| {</span>
Expand Down Expand Up @@ -190,9 +190,9 @@
<span class="line" id="L76"> <span class="tok-kw">if</span> (p == <span class="tok-number">1</span>) {</span>
<span class="line" id="L77"> <span class="tok-kw">return</span> <span class="tok-builtin">@min</span>(nf, Kf);</span>
<span class="line" id="L78"> }</span>
<span class="line" id="L79"> <span class="tok-kw">const</span> p0_num = lgamma(Nf - Kf + <span class="tok-number">1</span>) - lgamma(nf + <span class="tok-number">1</span>) - lgamma(Nf - Kf - nf + <span class="tok-number">1</span>);</span>
<span class="line" id="L80"> <span class="tok-kw">const</span> p0_den = lgamma(Nf + <span class="tok-number">1</span>) - lgamma(nf + <span class="tok-number">1</span>) - lgamma(Nf - nf + <span class="tok-number">1</span>);</span>
<span class="line" id="L81"> <span class="tok-kw">var</span> mass = <span class="tok-builtin">@exp</span>(p0_num - p0_den);</span>
<span class="line" id="L79"> <span class="tok-kw">const</span> mass_num = math.lbinomial(Nf - Kf, nf);</span>
<span class="line" id="L80"> <span class="tok-kw">const</span> mass_den = math.lbinomial(Nf, nf);</span>
<span class="line" id="L81"> <span class="tok-kw">var</span> mass = <span class="tok-builtin">@exp</span>(mass_num - mass_den);</span>
<span class="line" id="L82"> <span class="tok-kw">var</span> cumu = mass;</span>
<span class="line" id="L83"> <span class="tok-kw">var</span> hyper: <span class="tok-type">u64</span> = <span class="tok-number">0</span>;</span>
<span class="line" id="L84"> <span class="tok-kw">while</span> (p &gt;= cumu) : (hyper += <span class="tok-number">1</span>) {</span>
Expand All @@ -219,9 +219,9 @@
<span class="line" id="L105"> <span class="tok-kw">if</span> (n == N) {</span>
<span class="line" id="L106"> <span class="tok-kw">return</span> Kf;</span>
<span class="line" id="L107"> }</span>
<span class="line" id="L108"> <span class="tok-kw">const</span> p0_num = lgamma(Nf - Kf + <span class="tok-number">1</span>) - lgamma(nf + <span class="tok-number">1</span>) - lgamma(Nf - Kf - nf + <span class="tok-number">1</span>);</span>
<span class="line" id="L109"> <span class="tok-kw">const</span> p0_den = lgamma(Nf + <span class="tok-number">1</span>) - lgamma(nf + <span class="tok-number">1</span>) - lgamma(Nf - nf + <span class="tok-number">1</span>);</span>
<span class="line" id="L110"> <span class="tok-kw">var</span> mass = <span class="tok-builtin">@exp</span>(p0_num - p0_den);</span>
<span class="line" id="L108"> <span class="tok-kw">const</span> mass_num = math.lbinomial(Nf - Kf, nf);</span>
<span class="line" id="L109"> <span class="tok-kw">const</span> mass_den = math.lbinomial(Nf, nf);</span>
<span class="line" id="L110"> <span class="tok-kw">var</span> mass = <span class="tok-builtin">@exp</span>(mass_num - mass_den);</span>
<span class="line" id="L111"> <span class="tok-kw">var</span> cumu = mass;</span>
<span class="line" id="L112"> <span class="tok-kw">var</span> hyper: <span class="tok-type">u64</span> = <span class="tok-number">0</span>;</span>
<span class="line" id="L113"> <span class="tok-kw">const</span> uni = generator.float(<span class="tok-type">f64</span>);</span>
Expand Down
140 changes: 140 additions & 0 deletions docs/src/root/distribution/math.zig.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>distribution/math.zig - source view</title>
<link rel="icon" href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAgklEQVR4AWMYWuD7EllJIM4G4g4g5oIJ/odhOJ8wToOxSTXgNxDHoeiBMfA4+wGShjyYOCkG/IGqWQziEzYAoUAeiF9D5U+DxEg14DRU7jWIT5IBIOdCxf+A+CQZAAoopEB7QJwBCBwHiip8UYmRdrAlDpIMgApwQZNnNii5Dq0MBgCxxycBnwEd+wAAAABJRU5ErkJggg==">
<link rel="icon" href="data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNTMgMTQwIj48ZyBmaWxsPSIjRjdBNDFEIj48Zz48cG9seWdvbiBwb2ludHM9IjQ2LDIyIDI4LDQ0IDE5LDMwIi8+PHBvbHlnb24gcG9pbnRzPSI0NiwyMiAzMywzMyAyOCw0NCAyMiw0NCAyMiw5NSAzMSw5NSAyMCwxMDAgMTIsMTE3IDAsMTE3IDAsMjIiIHNoYXBlLXJlbmRlcmluZz0iY3Jpc3BFZGdlcyIvPjxwb2x5Z29uIHBvaW50cz0iMzEsOTUgMTIsMTE3IDQsMTA2Ii8+PC9nPjxnPjxwb2x5Z29uIHBvaW50cz0iNTYsMjIgNjIsMzYgMzcsNDQiLz48cG9seWdvbiBwb2ludHM9IjU2LDIyIDExMSwyMiAxMTEsNDQgMzcsNDQgNTYsMzIiIHNoYXBlLXJlbmRlcmluZz0iY3Jpc3BFZGdlcyIvPjxwb2x5Z29uIHBvaW50cz0iMTE2LDk1IDk3LDExNyA5MCwxMDQiLz48cG9seWdvbiBwb2ludHM9IjExNiw5NSAxMDAsMTA0IDk3LDExNyA0MiwxMTcgNDIsOTUiIHNoYXBlLXJlbmRlcmluZz0iY3Jpc3BFZGdlcyIvPjxwb2x5Z29uIHBvaW50cz0iMTUwLDAgNTIsMTE3IDMsMTQwIDEwMSwyMiIvPjwvZz48Zz48cG9seWdvbiBwb2ludHM9IjE0MSwyMiAxNDAsNDAgMTIyLDQ1Ii8+PHBvbHlnb24gcG9pbnRzPSIxNTMsMjIgMTUzLDExNyAxMDYsMTE3IDEyMCwxMDUgMTI1LDk1IDEzMSw5NSAxMzEsNDUgMTIyLDQ1IDEzMiwzNiAxNDEsMjIiIHNoYXBlLXJlbmRlcmluZz0iY3Jpc3BFZGdlcyIvPjxwb2x5Z29uIHBvaW50cz0iMTI1LDk1IDEzMCwxMTAgMTA2LDExNyIvPjwvZz48L2c+PC9zdmc+">
<style>
body{
font-family: system-ui, -apple-system, Roboto, "Segoe UI", sans-serif;
margin: 0;
line-height: 1.5;
}

pre > code {
display: block;
overflow: auto;
line-height: normal;
margin: 0em;
}
.tok-kw {
color: #333;
font-weight: bold;
}
.tok-str {
color: #d14;
}
.tok-builtin {
color: #005C7A;
}
.tok-comment {
color: #545454;
font-style: italic;
}
.tok-fn {
color: #900;
font-weight: bold;
}
.tok-null {
color: #005C5C;
}
.tok-number {
color: #005C5C;
}
.tok-type {
color: #458;
font-weight: bold;
}
pre {
counter-reset: line;
}
pre .line:before {
counter-increment: line;
content: counter(line);
display: inline-block;
padding-right: 1em;
width: 2em;
text-align: right;
color: #999;
}

.line {
width: 100%;
display: inline-block;
}
.line:target {
border-top: 1px solid #ccc;
border-bottom: 1px solid #ccc;
background: #fafafa;
}

@media (prefers-color-scheme: dark) {
body{
background:#222;
color: #ccc;
}
pre > code {
color: #ccc;
background: #222;
border: unset;
}
.line:target {
border-top: 1px solid #444;
border-bottom: 1px solid #444;
background: #333;
}
.tok-kw {
color: #eee;
}
.tok-str {
color: #2e5;
}
.tok-builtin {
color: #ff894c;
}
.tok-comment {
color: #aa7;
}
.tok-fn {
color: #B1A0F8;
}
.tok-null {
color: #ff8080;
}
.tok-number {
color: #ff8080;
}
.tok-type {
color: #68f;
}
}
</style>
</head>
<body>
<pre><code><span class="line" id="L1"><span class="tok-kw">const</span> std = <span class="tok-builtin">@import</span>(<span class="tok-str">&quot;std&quot;</span>);</span>
<span class="line" id="L2"></span>
<span class="line" id="L3"><span class="tok-kw">pub</span> <span class="tok-kw">fn</span> <span class="tok-fn">lbinomial</span>(n: <span class="tok-type">f64</span>, k: <span class="tok-type">f64</span>) <span class="tok-type">f64</span> {</span>
<span class="line" id="L4"> <span class="tok-kw">const</span> num = std.math.lgamma(<span class="tok-type">f64</span>, n + <span class="tok-number">1</span>);</span>
<span class="line" id="L5"> <span class="tok-kw">const</span> den1 = std.math.lgamma(<span class="tok-type">f64</span>, k + <span class="tok-number">1</span>);</span>
<span class="line" id="L6"> <span class="tok-kw">const</span> den2 = std.math.lgamma(<span class="tok-type">f64</span>, n - k + <span class="tok-number">1</span>);</span>
<span class="line" id="L7"> <span class="tok-kw">return</span> num - den1 - den2;</span>
<span class="line" id="L8">}</span>
<span class="line" id="L9"></span>
<span class="line" id="L10"><span class="tok-kw">pub</span> <span class="tok-kw">fn</span> <span class="tok-fn">binomial</span>(n: <span class="tok-type">f64</span>, k: <span class="tok-type">f64</span>) <span class="tok-type">f64</span> {</span>
<span class="line" id="L11"> <span class="tok-kw">return</span> <span class="tok-builtin">@exp</span>(lbinomial(n, k));</span>
<span class="line" id="L12">}</span>
<span class="line" id="L13"></span>
<span class="line" id="L14"><span class="tok-kw">pub</span> <span class="tok-kw">fn</span> <span class="tok-fn">lbeta</span>(a: <span class="tok-type">f64</span>, b: <span class="tok-type">f64</span>) <span class="tok-type">f64</span> {</span>
<span class="line" id="L15"> <span class="tok-kw">const</span> num1 = std.math.lgamma(<span class="tok-type">f64</span>, a);</span>
<span class="line" id="L16"> <span class="tok-kw">const</span> num2 = std.math.lgamma(<span class="tok-type">f64</span>, b);</span>
<span class="line" id="L17"> <span class="tok-kw">const</span> den = std.math.lgamma(<span class="tok-type">f64</span>, a + b);</span>
<span class="line" id="L18"> <span class="tok-kw">return</span> num1 + num2 - den;</span>
<span class="line" id="L19">}</span>
<span class="line" id="L20"></span>
<span class="line" id="L21"><span class="tok-kw">pub</span> <span class="tok-kw">fn</span> <span class="tok-fn">beta</span>(a: <span class="tok-type">f64</span>, b: <span class="tok-type">f64</span>) <span class="tok-type">f64</span> {</span>
<span class="line" id="L22"> <span class="tok-kw">return</span> <span class="tok-builtin">@exp</span>(lbeta(a, b));</span>
<span class="line" id="L23">}</span>
<span class="line" id="L24"></span>
</code></pre></body>
</html>
Loading

0 comments on commit 76ccc3f

Please sign in to comment.