@seantalts/stanli 0.11.1 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.mjs CHANGED
@@ -127,7 +127,8 @@ function pathfinderInitOptions(value) {
127
127
  * `stanc --O1 --debug-optimized-mir` at build time). When given, neither
128
128
  * browser compiler loads: the runtime alone is ~1.5 MB gzipped.
129
129
  * @param {Object|string} [opts.data] Data as an object or JSON text.
130
- * @param {number} [opts.seed=1] Chain seed (sampler and GQ RNG).
130
+ * @param {number} [opts.seed=1] Run seed: transformed-data RNG at
131
+ * model construction (as CmdStan seeds it), then sampler and GQ RNG.
131
132
  * @param {number} [opts.warmup=1000]
132
133
  * @param {number} [opts.samples=1000]
133
134
  * @param {number} [opts.delta=0.8] Adaptation target acceptance (NUTS).
@@ -167,6 +168,14 @@ function pathfinderInitOptions(value) {
167
168
  * lp__, accept_stat__, stepsize__, treedepth__, n_leapfrog__,
168
169
  * divergent__, energy__. Other methods return null for samplerStats.
169
170
  */
171
+ // JSON.stringify writes null for a non-finite number, which Stan's data
172
+ // reader rejects. It takes these quoted tokens.
173
+ function stanNumber(key, value) {
174
+ if (typeof value !== "number" || Number.isFinite(value)) return value;
175
+ if (Number.isNaN(value)) return "NaN";
176
+ return value > 0 ? "Infinity" : "-Infinity";
177
+ }
178
+
170
179
  export function sample(opts) {
171
180
  const sampler = opts.sampler === "walnuts" || opts.sampler === "pathfinder"
172
181
  ? opts.sampler : "nuts";
@@ -180,7 +189,7 @@ export function sample(opts) {
180
189
  live: !!opts.onLive,
181
190
  dataJson: typeof opts.data === "string"
182
191
  ? opts.data
183
- : JSON.stringify(opts.data || {}),
192
+ : JSON.stringify(opts.data || {}, stanNumber),
184
193
  seed: opts.seed == null ? 1 : opts.seed,
185
194
  warmup: opts.warmup == null ? 1000 : opts.warmup,
186
195
  samples: opts.samples == null ? 1000 : opts.samples,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@seantalts/stanli",
3
- "version": "0.11.1",
3
+ "version": "0.13.0",
4
4
  "description": "Full Stan in the browser: stanc3 compiles the model in JS, a WASM runtime lowers it to an op graph and runs NUTS. No server, no C++ toolchain.",
5
5
  "type": "module",
6
6
  "main": "index.mjs",