@almadar/std 2.0.0 → 2.1.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/dist/index.d.ts +2 -2
- package/dist/index.js +237 -4
- package/dist/index.js.map +1 -1
- package/dist/modules/array.d.ts +1 -1
- package/dist/modules/async.d.ts +1 -1
- package/dist/modules/format.d.ts +1 -1
- package/dist/modules/index.d.ts +2 -1
- package/dist/modules/index.js +227 -1
- package/dist/modules/index.js.map +1 -1
- package/dist/modules/math.d.ts +1 -1
- package/dist/modules/nn.d.ts +1 -1
- package/dist/modules/object.d.ts +1 -1
- package/dist/modules/prob.d.ts +21 -0
- package/dist/modules/prob.js +229 -0
- package/dist/modules/prob.js.map +1 -0
- package/dist/modules/str.d.ts +1 -1
- package/dist/modules/tensor.d.ts +1 -1
- package/dist/modules/time.d.ts +1 -1
- package/dist/modules/train.d.ts +1 -1
- package/dist/modules/validate.d.ts +1 -1
- package/dist/registry.d.ts +1 -1
- package/dist/registry.js +229 -3
- package/dist/registry.js.map +1 -1
- package/dist/{types-I95R8_FN.d.ts → types-CmNM_IbV.d.ts} +3 -3
- package/package.json +1 -1
package/dist/modules/math.d.ts
CHANGED
package/dist/modules/nn.d.ts
CHANGED
package/dist/modules/object.d.ts
CHANGED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { a as StdOperatorMeta } from '../types-CmNM_IbV.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Prob Module - Probabilistic Programming Operators
|
|
5
|
+
*
|
|
6
|
+
* Provides distribution sampling, Bayesian inference via rejection sampling,
|
|
7
|
+
* and statistical summary functions.
|
|
8
|
+
*
|
|
9
|
+
* @packageDocumentation
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Probabilistic module operators.
|
|
14
|
+
*/
|
|
15
|
+
declare const PROB_OPERATORS: Record<string, StdOperatorMeta>;
|
|
16
|
+
/**
|
|
17
|
+
* Get all probabilistic operators.
|
|
18
|
+
*/
|
|
19
|
+
declare function getProbOperators(): Record<string, StdOperatorMeta>;
|
|
20
|
+
|
|
21
|
+
export { PROB_OPERATORS, getProbOperators };
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
// modules/prob.ts
|
|
2
|
+
var PROB_OPERATORS = {
|
|
3
|
+
// ========================================
|
|
4
|
+
// Distribution Sampling
|
|
5
|
+
// ========================================
|
|
6
|
+
"prob/seed": {
|
|
7
|
+
module: "prob",
|
|
8
|
+
category: "std-prob",
|
|
9
|
+
minArity: 1,
|
|
10
|
+
maxArity: 1,
|
|
11
|
+
description: "Set seeded PRNG for deterministic probabilistic sampling",
|
|
12
|
+
hasSideEffects: true,
|
|
13
|
+
returnType: "void",
|
|
14
|
+
params: [{ name: "n", type: "number", description: "Seed value (integer)" }],
|
|
15
|
+
example: '["prob/seed", 42]'
|
|
16
|
+
},
|
|
17
|
+
"prob/flip": {
|
|
18
|
+
module: "prob",
|
|
19
|
+
category: "std-prob",
|
|
20
|
+
minArity: 1,
|
|
21
|
+
maxArity: 1,
|
|
22
|
+
description: "Bernoulli trial: returns true with probability p",
|
|
23
|
+
hasSideEffects: false,
|
|
24
|
+
returnType: "boolean",
|
|
25
|
+
params: [{ name: "p", type: "number", description: "Probability of true (0 to 1)" }],
|
|
26
|
+
example: '["prob/flip", 0.5] // => true or false with equal probability'
|
|
27
|
+
},
|
|
28
|
+
"prob/gaussian": {
|
|
29
|
+
module: "prob",
|
|
30
|
+
category: "std-prob",
|
|
31
|
+
minArity: 2,
|
|
32
|
+
maxArity: 2,
|
|
33
|
+
description: "Sample from a Gaussian (normal) distribution",
|
|
34
|
+
hasSideEffects: false,
|
|
35
|
+
returnType: "number",
|
|
36
|
+
params: [
|
|
37
|
+
{ name: "mu", type: "number", description: "Mean" },
|
|
38
|
+
{ name: "sigma", type: "number", description: "Standard deviation" }
|
|
39
|
+
],
|
|
40
|
+
example: '["prob/gaussian", 0, 1] // => standard normal sample'
|
|
41
|
+
},
|
|
42
|
+
"prob/uniform": {
|
|
43
|
+
module: "prob",
|
|
44
|
+
category: "std-prob",
|
|
45
|
+
minArity: 2,
|
|
46
|
+
maxArity: 2,
|
|
47
|
+
description: "Sample from a uniform distribution [lo, hi)",
|
|
48
|
+
hasSideEffects: false,
|
|
49
|
+
returnType: "number",
|
|
50
|
+
params: [
|
|
51
|
+
{ name: "lo", type: "number", description: "Lower bound (inclusive)" },
|
|
52
|
+
{ name: "hi", type: "number", description: "Upper bound (exclusive)" }
|
|
53
|
+
],
|
|
54
|
+
example: '["prob/uniform", 0, 10] // => number in [0, 10)'
|
|
55
|
+
},
|
|
56
|
+
"prob/beta": {
|
|
57
|
+
module: "prob",
|
|
58
|
+
category: "std-prob",
|
|
59
|
+
minArity: 2,
|
|
60
|
+
maxArity: 2,
|
|
61
|
+
description: "Sample from a Beta(alpha, beta) distribution",
|
|
62
|
+
hasSideEffects: false,
|
|
63
|
+
returnType: "number",
|
|
64
|
+
params: [
|
|
65
|
+
{ name: "alpha", type: "number", description: "Alpha shape parameter (> 0)" },
|
|
66
|
+
{ name: "beta", type: "number", description: "Beta shape parameter (> 0)" }
|
|
67
|
+
],
|
|
68
|
+
example: '["prob/beta", 2, 5] // => number in [0, 1], mean ~ 0.286'
|
|
69
|
+
},
|
|
70
|
+
"prob/categorical": {
|
|
71
|
+
module: "prob",
|
|
72
|
+
category: "std-prob",
|
|
73
|
+
minArity: 2,
|
|
74
|
+
maxArity: 2,
|
|
75
|
+
description: "Weighted random selection from items",
|
|
76
|
+
hasSideEffects: false,
|
|
77
|
+
returnType: "any",
|
|
78
|
+
params: [
|
|
79
|
+
{ name: "items", type: "array", description: "Array of items to choose from" },
|
|
80
|
+
{ name: "weights", type: "number[]", description: "Array of weights (same length as items)" }
|
|
81
|
+
],
|
|
82
|
+
example: '["prob/categorical", ["a", "b", "c"], [1, 2, 1]] // => "b" most likely'
|
|
83
|
+
},
|
|
84
|
+
"prob/poisson": {
|
|
85
|
+
module: "prob",
|
|
86
|
+
category: "std-prob",
|
|
87
|
+
minArity: 1,
|
|
88
|
+
maxArity: 1,
|
|
89
|
+
description: "Sample from a Poisson distribution",
|
|
90
|
+
hasSideEffects: false,
|
|
91
|
+
returnType: "number",
|
|
92
|
+
params: [{ name: "lambda", type: "number", description: "Rate parameter (> 0)" }],
|
|
93
|
+
example: '["prob/poisson", 4] // => non-negative integer, mean ~ 4'
|
|
94
|
+
},
|
|
95
|
+
// ========================================
|
|
96
|
+
// Inference
|
|
97
|
+
// ========================================
|
|
98
|
+
"prob/condition": {
|
|
99
|
+
module: "prob",
|
|
100
|
+
category: "std-prob",
|
|
101
|
+
minArity: 1,
|
|
102
|
+
maxArity: 1,
|
|
103
|
+
description: "Mark current sample as rejected if predicate is false",
|
|
104
|
+
hasSideEffects: true,
|
|
105
|
+
returnType: "void",
|
|
106
|
+
params: [{ name: "predicate", type: "boolean", description: "Condition that must hold" }],
|
|
107
|
+
example: '["prob/condition", [">", "@entity.x", 0]]'
|
|
108
|
+
},
|
|
109
|
+
"prob/sample": {
|
|
110
|
+
module: "prob",
|
|
111
|
+
category: "std-prob",
|
|
112
|
+
minArity: 2,
|
|
113
|
+
maxArity: 2,
|
|
114
|
+
description: "Evaluate an expression n times and collect results",
|
|
115
|
+
hasSideEffects: false,
|
|
116
|
+
returnType: "array",
|
|
117
|
+
params: [
|
|
118
|
+
{ name: "n", type: "number", description: "Number of samples" },
|
|
119
|
+
{ name: "expr", type: "SExpr", description: "Expression to evaluate (lazy)" }
|
|
120
|
+
],
|
|
121
|
+
example: '["prob/sample", 1000, ["prob/flip", 0.5]] // => array of booleans'
|
|
122
|
+
},
|
|
123
|
+
"prob/posterior": {
|
|
124
|
+
module: "prob",
|
|
125
|
+
category: "std-prob",
|
|
126
|
+
minArity: 4,
|
|
127
|
+
maxArity: 4,
|
|
128
|
+
description: "Rejection sampling: returns accepted query values",
|
|
129
|
+
hasSideEffects: false,
|
|
130
|
+
returnType: "array",
|
|
131
|
+
params: [
|
|
132
|
+
{ name: "model", type: "SExpr", description: "Model expression (lazy, may call set/condition)" },
|
|
133
|
+
{ name: "evidence", type: "SExpr", description: "Evidence expression (lazy, boolean)" },
|
|
134
|
+
{ name: "query", type: "SExpr", description: "Query expression (lazy, value to collect)" },
|
|
135
|
+
{ name: "n", type: "number", description: "Number of samples to attempt" }
|
|
136
|
+
],
|
|
137
|
+
example: '["prob/posterior", model, evidence, query, 5000]'
|
|
138
|
+
},
|
|
139
|
+
"prob/infer": {
|
|
140
|
+
module: "prob",
|
|
141
|
+
category: "std-prob",
|
|
142
|
+
minArity: 4,
|
|
143
|
+
maxArity: 4,
|
|
144
|
+
description: "Like posterior but returns {mean, variance, samples, acceptRate}",
|
|
145
|
+
hasSideEffects: false,
|
|
146
|
+
returnType: "object",
|
|
147
|
+
params: [
|
|
148
|
+
{ name: "model", type: "SExpr", description: "Model expression (lazy)" },
|
|
149
|
+
{ name: "evidence", type: "SExpr", description: "Evidence expression (lazy, boolean)" },
|
|
150
|
+
{ name: "query", type: "SExpr", description: "Query expression (lazy)" },
|
|
151
|
+
{ name: "n", type: "number", description: "Number of samples to attempt" }
|
|
152
|
+
],
|
|
153
|
+
example: '["prob/infer", model, evidence, query, 5000]'
|
|
154
|
+
},
|
|
155
|
+
// ========================================
|
|
156
|
+
// Statistics
|
|
157
|
+
// ========================================
|
|
158
|
+
"prob/expected-value": {
|
|
159
|
+
module: "prob",
|
|
160
|
+
category: "std-prob",
|
|
161
|
+
minArity: 1,
|
|
162
|
+
maxArity: 1,
|
|
163
|
+
description: "Mean of numeric samples",
|
|
164
|
+
hasSideEffects: false,
|
|
165
|
+
returnType: "number",
|
|
166
|
+
params: [{ name: "samples", type: "number[]", description: "Array of numeric samples" }],
|
|
167
|
+
example: '["prob/expected-value", [2, 4, 6, 8]] // => 5'
|
|
168
|
+
},
|
|
169
|
+
"prob/variance": {
|
|
170
|
+
module: "prob",
|
|
171
|
+
category: "std-prob",
|
|
172
|
+
minArity: 1,
|
|
173
|
+
maxArity: 1,
|
|
174
|
+
description: "Population variance of numeric samples",
|
|
175
|
+
hasSideEffects: false,
|
|
176
|
+
returnType: "number",
|
|
177
|
+
params: [{ name: "samples", type: "number[]", description: "Array of numeric samples" }],
|
|
178
|
+
example: '["prob/variance", [2, 4, 4, 4, 5, 5, 7, 9]] // => 4'
|
|
179
|
+
},
|
|
180
|
+
"prob/histogram": {
|
|
181
|
+
module: "prob",
|
|
182
|
+
category: "std-prob",
|
|
183
|
+
minArity: 2,
|
|
184
|
+
maxArity: 2,
|
|
185
|
+
description: "Bin numeric samples into a histogram",
|
|
186
|
+
hasSideEffects: false,
|
|
187
|
+
returnType: "object",
|
|
188
|
+
params: [
|
|
189
|
+
{ name: "samples", type: "number[]", description: "Array of numeric samples" },
|
|
190
|
+
{ name: "bins", type: "number", description: "Number of bins" }
|
|
191
|
+
],
|
|
192
|
+
example: '["prob/histogram", [1, 2, 3, 4, 5], 2] // => {binEdges, counts}'
|
|
193
|
+
},
|
|
194
|
+
"prob/percentile": {
|
|
195
|
+
module: "prob",
|
|
196
|
+
category: "std-prob",
|
|
197
|
+
minArity: 2,
|
|
198
|
+
maxArity: 2,
|
|
199
|
+
description: "Get the p-th percentile (0-100) from samples",
|
|
200
|
+
hasSideEffects: false,
|
|
201
|
+
returnType: "number",
|
|
202
|
+
params: [
|
|
203
|
+
{ name: "samples", type: "number[]", description: "Array of numeric samples" },
|
|
204
|
+
{ name: "p", type: "number", description: "Percentile (0 to 100)" }
|
|
205
|
+
],
|
|
206
|
+
example: '["prob/percentile", [1, 2, 3, 4, 5], 50] // => 3'
|
|
207
|
+
},
|
|
208
|
+
"prob/credible-interval": {
|
|
209
|
+
module: "prob",
|
|
210
|
+
category: "std-prob",
|
|
211
|
+
minArity: 2,
|
|
212
|
+
maxArity: 2,
|
|
213
|
+
description: "Compute symmetric credible interval from samples",
|
|
214
|
+
hasSideEffects: false,
|
|
215
|
+
returnType: "array",
|
|
216
|
+
params: [
|
|
217
|
+
{ name: "samples", type: "number[]", description: "Array of numeric samples" },
|
|
218
|
+
{ name: "alpha", type: "number", description: "Significance level (e.g., 0.05 for 95% interval)" }
|
|
219
|
+
],
|
|
220
|
+
example: '["prob/credible-interval", samples, 0.05] // => [lo, hi]'
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
function getProbOperators() {
|
|
224
|
+
return PROB_OPERATORS;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export { PROB_OPERATORS, getProbOperators };
|
|
228
|
+
//# sourceMappingURL=prob.js.map
|
|
229
|
+
//# sourceMappingURL=prob.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../modules/prob.ts"],"names":[],"mappings":";AAcO,IAAM,cAAA,GAAkD;AAAA;AAAA;AAAA;AAAA,EAI7D,WAAA,EAAa;AAAA,IACX,MAAA,EAAQ,MAAA;AAAA,IACR,QAAA,EAAU,UAAA;AAAA,IACV,QAAA,EAAU,CAAA;AAAA,IACV,QAAA,EAAU,CAAA;AAAA,IACV,WAAA,EAAa,0DAAA;AAAA,IACb,cAAA,EAAgB,IAAA;AAAA,IAChB,UAAA,EAAY,MAAA;AAAA,IACZ,MAAA,EAAQ,CAAC,EAAE,IAAA,EAAM,KAAK,IAAA,EAAM,QAAA,EAAU,WAAA,EAAa,sBAAA,EAAwB,CAAA;AAAA,IAC3E,OAAA,EAAS;AAAA,GACX;AAAA,EACA,WAAA,EAAa;AAAA,IACX,MAAA,EAAQ,MAAA;AAAA,IACR,QAAA,EAAU,UAAA;AAAA,IACV,QAAA,EAAU,CAAA;AAAA,IACV,QAAA,EAAU,CAAA;AAAA,IACV,WAAA,EAAa,kDAAA;AAAA,IACb,cAAA,EAAgB,KAAA;AAAA,IAChB,UAAA,EAAY,SAAA;AAAA,IACZ,MAAA,EAAQ,CAAC,EAAE,IAAA,EAAM,KAAK,IAAA,EAAM,QAAA,EAAU,WAAA,EAAa,8BAAA,EAAgC,CAAA;AAAA,IACnF,OAAA,EAAS;AAAA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AA0B;AAAA,IACxB,MAAA,EAAQ,MAAA;AAAA,IACR,QAAA,EAAU,UAAA;AAAA,IACV,QAAA,EAAU,CAAA;AAAA,IACV,QAAA,EAAU,CAAA;AAAA,IACV,WAAA,EAAa,kDAAA;AAAA,IACb,cAAA,EAAgB,KAAA;AAAA,IAChB,UAAA,EAAY,OAAA;AAAA,IACZ,MAAA,EAAQ;AAAA,MACN,EAAE,IAAA,EAAM,SAAA,EAAW,IAAA,EAAM,UAAA,EAAY,aAAa,0BAAA,EAA2B;AAAA,MAC7E,EAAE,IAAA,EAAM,OAAA,EAAS,IAAA,EAAM,QAAA,EAAU,aAAa,kDAAA;AAAmD,KACnG;AAAA,IACA,OAAA,EAAS;AAAA;AAEb;AAKO,SAAS,gBAAA,GAAoD;AAClE,EAAA,OAAO,cAAA;AACT","file":"prob.js","sourcesContent":["/**\n * Prob Module - Probabilistic Programming Operators\n *\n * Provides distribution sampling, Bayesian inference via rejection sampling,\n * and statistical summary functions.\n *\n * @packageDocumentation\n */\n\nimport type { StdOperatorMeta } from '../types.js';\n\n/**\n * Probabilistic module operators.\n */\nexport const PROB_OPERATORS: Record<string, StdOperatorMeta> = {\n // ========================================\n // Distribution Sampling\n // ========================================\n 'prob/seed': {\n module: 'prob',\n category: 'std-prob',\n minArity: 1,\n maxArity: 1,\n description: 'Set seeded PRNG for deterministic probabilistic sampling',\n hasSideEffects: true,\n returnType: 'void',\n params: [{ name: 'n', type: 'number', description: 'Seed value (integer)' }],\n example: '[\"prob/seed\", 42]',\n },\n 'prob/flip': {\n module: 'prob',\n category: 'std-prob',\n minArity: 1,\n maxArity: 1,\n description: 'Bernoulli trial: returns true with probability p',\n hasSideEffects: false,\n returnType: 'boolean',\n params: [{ name: 'p', type: 'number', description: 'Probability of true (0 to 1)' }],\n example: '[\"prob/flip\", 0.5] // => true or false with equal probability',\n },\n 'prob/gaussian': {\n module: 'prob',\n category: 'std-prob',\n minArity: 2,\n maxArity: 2,\n description: 'Sample from a Gaussian (normal) distribution',\n hasSideEffects: false,\n returnType: 'number',\n params: [\n { name: 'mu', type: 'number', description: 'Mean' },\n { name: 'sigma', type: 'number', description: 'Standard deviation' },\n ],\n example: '[\"prob/gaussian\", 0, 1] // => standard normal sample',\n },\n 'prob/uniform': {\n module: 'prob',\n category: 'std-prob',\n minArity: 2,\n maxArity: 2,\n description: 'Sample from a uniform distribution [lo, hi)',\n hasSideEffects: false,\n returnType: 'number',\n params: [\n { name: 'lo', type: 'number', description: 'Lower bound (inclusive)' },\n { name: 'hi', type: 'number', description: 'Upper bound (exclusive)' },\n ],\n example: '[\"prob/uniform\", 0, 10] // => number in [0, 10)',\n },\n 'prob/beta': {\n module: 'prob',\n category: 'std-prob',\n minArity: 2,\n maxArity: 2,\n description: 'Sample from a Beta(alpha, beta) distribution',\n hasSideEffects: false,\n returnType: 'number',\n params: [\n { name: 'alpha', type: 'number', description: 'Alpha shape parameter (> 0)' },\n { name: 'beta', type: 'number', description: 'Beta shape parameter (> 0)' },\n ],\n example: '[\"prob/beta\", 2, 5] // => number in [0, 1], mean ~ 0.286',\n },\n 'prob/categorical': {\n module: 'prob',\n category: 'std-prob',\n minArity: 2,\n maxArity: 2,\n description: 'Weighted random selection from items',\n hasSideEffects: false,\n returnType: 'any',\n params: [\n { name: 'items', type: 'array', description: 'Array of items to choose from' },\n { name: 'weights', type: 'number[]', description: 'Array of weights (same length as items)' },\n ],\n example: '[\"prob/categorical\", [\"a\", \"b\", \"c\"], [1, 2, 1]] // => \"b\" most likely',\n },\n 'prob/poisson': {\n module: 'prob',\n category: 'std-prob',\n minArity: 1,\n maxArity: 1,\n description: 'Sample from a Poisson distribution',\n hasSideEffects: false,\n returnType: 'number',\n params: [{ name: 'lambda', type: 'number', description: 'Rate parameter (> 0)' }],\n example: '[\"prob/poisson\", 4] // => non-negative integer, mean ~ 4',\n },\n\n // ========================================\n // Inference\n // ========================================\n 'prob/condition': {\n module: 'prob',\n category: 'std-prob',\n minArity: 1,\n maxArity: 1,\n description: 'Mark current sample as rejected if predicate is false',\n hasSideEffects: true,\n returnType: 'void',\n params: [{ name: 'predicate', type: 'boolean', description: 'Condition that must hold' }],\n example: '[\"prob/condition\", [\">\", \"@entity.x\", 0]]',\n },\n 'prob/sample': {\n module: 'prob',\n category: 'std-prob',\n minArity: 2,\n maxArity: 2,\n description: 'Evaluate an expression n times and collect results',\n hasSideEffects: false,\n returnType: 'array',\n params: [\n { name: 'n', type: 'number', description: 'Number of samples' },\n { name: 'expr', type: 'SExpr', description: 'Expression to evaluate (lazy)' },\n ],\n example: '[\"prob/sample\", 1000, [\"prob/flip\", 0.5]] // => array of booleans',\n },\n 'prob/posterior': {\n module: 'prob',\n category: 'std-prob',\n minArity: 4,\n maxArity: 4,\n description: 'Rejection sampling: returns accepted query values',\n hasSideEffects: false,\n returnType: 'array',\n params: [\n { name: 'model', type: 'SExpr', description: 'Model expression (lazy, may call set/condition)' },\n { name: 'evidence', type: 'SExpr', description: 'Evidence expression (lazy, boolean)' },\n { name: 'query', type: 'SExpr', description: 'Query expression (lazy, value to collect)' },\n { name: 'n', type: 'number', description: 'Number of samples to attempt' },\n ],\n example: '[\"prob/posterior\", model, evidence, query, 5000]',\n },\n 'prob/infer': {\n module: 'prob',\n category: 'std-prob',\n minArity: 4,\n maxArity: 4,\n description: 'Like posterior but returns {mean, variance, samples, acceptRate}',\n hasSideEffects: false,\n returnType: 'object',\n params: [\n { name: 'model', type: 'SExpr', description: 'Model expression (lazy)' },\n { name: 'evidence', type: 'SExpr', description: 'Evidence expression (lazy, boolean)' },\n { name: 'query', type: 'SExpr', description: 'Query expression (lazy)' },\n { name: 'n', type: 'number', description: 'Number of samples to attempt' },\n ],\n example: '[\"prob/infer\", model, evidence, query, 5000]',\n },\n\n // ========================================\n // Statistics\n // ========================================\n 'prob/expected-value': {\n module: 'prob',\n category: 'std-prob',\n minArity: 1,\n maxArity: 1,\n description: 'Mean of numeric samples',\n hasSideEffects: false,\n returnType: 'number',\n params: [{ name: 'samples', type: 'number[]', description: 'Array of numeric samples' }],\n example: '[\"prob/expected-value\", [2, 4, 6, 8]] // => 5',\n },\n 'prob/variance': {\n module: 'prob',\n category: 'std-prob',\n minArity: 1,\n maxArity: 1,\n description: 'Population variance of numeric samples',\n hasSideEffects: false,\n returnType: 'number',\n params: [{ name: 'samples', type: 'number[]', description: 'Array of numeric samples' }],\n example: '[\"prob/variance\", [2, 4, 4, 4, 5, 5, 7, 9]] // => 4',\n },\n 'prob/histogram': {\n module: 'prob',\n category: 'std-prob',\n minArity: 2,\n maxArity: 2,\n description: 'Bin numeric samples into a histogram',\n hasSideEffects: false,\n returnType: 'object',\n params: [\n { name: 'samples', type: 'number[]', description: 'Array of numeric samples' },\n { name: 'bins', type: 'number', description: 'Number of bins' },\n ],\n example: '[\"prob/histogram\", [1, 2, 3, 4, 5], 2] // => {binEdges, counts}',\n },\n 'prob/percentile': {\n module: 'prob',\n category: 'std-prob',\n minArity: 2,\n maxArity: 2,\n description: 'Get the p-th percentile (0-100) from samples',\n hasSideEffects: false,\n returnType: 'number',\n params: [\n { name: 'samples', type: 'number[]', description: 'Array of numeric samples' },\n { name: 'p', type: 'number', description: 'Percentile (0 to 100)' },\n ],\n example: '[\"prob/percentile\", [1, 2, 3, 4, 5], 50] // => 3',\n },\n 'prob/credible-interval': {\n module: 'prob',\n category: 'std-prob',\n minArity: 2,\n maxArity: 2,\n description: 'Compute symmetric credible interval from samples',\n hasSideEffects: false,\n returnType: 'array',\n params: [\n { name: 'samples', type: 'number[]', description: 'Array of numeric samples' },\n { name: 'alpha', type: 'number', description: 'Significance level (e.g., 0.05 for 95% interval)' },\n ],\n example: '[\"prob/credible-interval\", samples, 0.05] // => [lo, hi]',\n },\n};\n\n/**\n * Get all probabilistic operators.\n */\nexport function getProbOperators(): Record<string, StdOperatorMeta> {\n return PROB_OPERATORS;\n}\n"]}
|
package/dist/modules/str.d.ts
CHANGED
package/dist/modules/tensor.d.ts
CHANGED
package/dist/modules/time.d.ts
CHANGED
package/dist/modules/train.d.ts
CHANGED
package/dist/registry.d.ts
CHANGED
package/dist/registry.js
CHANGED
|
@@ -10,7 +10,8 @@ var STD_MODULES = [
|
|
|
10
10
|
"async",
|
|
11
11
|
"nn",
|
|
12
12
|
"tensor",
|
|
13
|
-
"train"
|
|
13
|
+
"train",
|
|
14
|
+
"prob"
|
|
14
15
|
];
|
|
15
16
|
function getModuleFromOperator(operator) {
|
|
16
17
|
const parts = operator.split("/");
|
|
@@ -3142,6 +3143,229 @@ var TRAIN_OPERATORS = {
|
|
|
3142
3143
|
}
|
|
3143
3144
|
};
|
|
3144
3145
|
|
|
3146
|
+
// modules/prob.ts
|
|
3147
|
+
var PROB_OPERATORS = {
|
|
3148
|
+
// ========================================
|
|
3149
|
+
// Distribution Sampling
|
|
3150
|
+
// ========================================
|
|
3151
|
+
"prob/seed": {
|
|
3152
|
+
module: "prob",
|
|
3153
|
+
category: "std-prob",
|
|
3154
|
+
minArity: 1,
|
|
3155
|
+
maxArity: 1,
|
|
3156
|
+
description: "Set seeded PRNG for deterministic probabilistic sampling",
|
|
3157
|
+
hasSideEffects: true,
|
|
3158
|
+
returnType: "void",
|
|
3159
|
+
params: [{ name: "n", type: "number", description: "Seed value (integer)" }],
|
|
3160
|
+
example: '["prob/seed", 42]'
|
|
3161
|
+
},
|
|
3162
|
+
"prob/flip": {
|
|
3163
|
+
module: "prob",
|
|
3164
|
+
category: "std-prob",
|
|
3165
|
+
minArity: 1,
|
|
3166
|
+
maxArity: 1,
|
|
3167
|
+
description: "Bernoulli trial: returns true with probability p",
|
|
3168
|
+
hasSideEffects: false,
|
|
3169
|
+
returnType: "boolean",
|
|
3170
|
+
params: [{ name: "p", type: "number", description: "Probability of true (0 to 1)" }],
|
|
3171
|
+
example: '["prob/flip", 0.5] // => true or false with equal probability'
|
|
3172
|
+
},
|
|
3173
|
+
"prob/gaussian": {
|
|
3174
|
+
module: "prob",
|
|
3175
|
+
category: "std-prob",
|
|
3176
|
+
minArity: 2,
|
|
3177
|
+
maxArity: 2,
|
|
3178
|
+
description: "Sample from a Gaussian (normal) distribution",
|
|
3179
|
+
hasSideEffects: false,
|
|
3180
|
+
returnType: "number",
|
|
3181
|
+
params: [
|
|
3182
|
+
{ name: "mu", type: "number", description: "Mean" },
|
|
3183
|
+
{ name: "sigma", type: "number", description: "Standard deviation" }
|
|
3184
|
+
],
|
|
3185
|
+
example: '["prob/gaussian", 0, 1] // => standard normal sample'
|
|
3186
|
+
},
|
|
3187
|
+
"prob/uniform": {
|
|
3188
|
+
module: "prob",
|
|
3189
|
+
category: "std-prob",
|
|
3190
|
+
minArity: 2,
|
|
3191
|
+
maxArity: 2,
|
|
3192
|
+
description: "Sample from a uniform distribution [lo, hi)",
|
|
3193
|
+
hasSideEffects: false,
|
|
3194
|
+
returnType: "number",
|
|
3195
|
+
params: [
|
|
3196
|
+
{ name: "lo", type: "number", description: "Lower bound (inclusive)" },
|
|
3197
|
+
{ name: "hi", type: "number", description: "Upper bound (exclusive)" }
|
|
3198
|
+
],
|
|
3199
|
+
example: '["prob/uniform", 0, 10] // => number in [0, 10)'
|
|
3200
|
+
},
|
|
3201
|
+
"prob/beta": {
|
|
3202
|
+
module: "prob",
|
|
3203
|
+
category: "std-prob",
|
|
3204
|
+
minArity: 2,
|
|
3205
|
+
maxArity: 2,
|
|
3206
|
+
description: "Sample from a Beta(alpha, beta) distribution",
|
|
3207
|
+
hasSideEffects: false,
|
|
3208
|
+
returnType: "number",
|
|
3209
|
+
params: [
|
|
3210
|
+
{ name: "alpha", type: "number", description: "Alpha shape parameter (> 0)" },
|
|
3211
|
+
{ name: "beta", type: "number", description: "Beta shape parameter (> 0)" }
|
|
3212
|
+
],
|
|
3213
|
+
example: '["prob/beta", 2, 5] // => number in [0, 1], mean ~ 0.286'
|
|
3214
|
+
},
|
|
3215
|
+
"prob/categorical": {
|
|
3216
|
+
module: "prob",
|
|
3217
|
+
category: "std-prob",
|
|
3218
|
+
minArity: 2,
|
|
3219
|
+
maxArity: 2,
|
|
3220
|
+
description: "Weighted random selection from items",
|
|
3221
|
+
hasSideEffects: false,
|
|
3222
|
+
returnType: "any",
|
|
3223
|
+
params: [
|
|
3224
|
+
{ name: "items", type: "array", description: "Array of items to choose from" },
|
|
3225
|
+
{ name: "weights", type: "number[]", description: "Array of weights (same length as items)" }
|
|
3226
|
+
],
|
|
3227
|
+
example: '["prob/categorical", ["a", "b", "c"], [1, 2, 1]] // => "b" most likely'
|
|
3228
|
+
},
|
|
3229
|
+
"prob/poisson": {
|
|
3230
|
+
module: "prob",
|
|
3231
|
+
category: "std-prob",
|
|
3232
|
+
minArity: 1,
|
|
3233
|
+
maxArity: 1,
|
|
3234
|
+
description: "Sample from a Poisson distribution",
|
|
3235
|
+
hasSideEffects: false,
|
|
3236
|
+
returnType: "number",
|
|
3237
|
+
params: [{ name: "lambda", type: "number", description: "Rate parameter (> 0)" }],
|
|
3238
|
+
example: '["prob/poisson", 4] // => non-negative integer, mean ~ 4'
|
|
3239
|
+
},
|
|
3240
|
+
// ========================================
|
|
3241
|
+
// Inference
|
|
3242
|
+
// ========================================
|
|
3243
|
+
"prob/condition": {
|
|
3244
|
+
module: "prob",
|
|
3245
|
+
category: "std-prob",
|
|
3246
|
+
minArity: 1,
|
|
3247
|
+
maxArity: 1,
|
|
3248
|
+
description: "Mark current sample as rejected if predicate is false",
|
|
3249
|
+
hasSideEffects: true,
|
|
3250
|
+
returnType: "void",
|
|
3251
|
+
params: [{ name: "predicate", type: "boolean", description: "Condition that must hold" }],
|
|
3252
|
+
example: '["prob/condition", [">", "@entity.x", 0]]'
|
|
3253
|
+
},
|
|
3254
|
+
"prob/sample": {
|
|
3255
|
+
module: "prob",
|
|
3256
|
+
category: "std-prob",
|
|
3257
|
+
minArity: 2,
|
|
3258
|
+
maxArity: 2,
|
|
3259
|
+
description: "Evaluate an expression n times and collect results",
|
|
3260
|
+
hasSideEffects: false,
|
|
3261
|
+
returnType: "array",
|
|
3262
|
+
params: [
|
|
3263
|
+
{ name: "n", type: "number", description: "Number of samples" },
|
|
3264
|
+
{ name: "expr", type: "SExpr", description: "Expression to evaluate (lazy)" }
|
|
3265
|
+
],
|
|
3266
|
+
example: '["prob/sample", 1000, ["prob/flip", 0.5]] // => array of booleans'
|
|
3267
|
+
},
|
|
3268
|
+
"prob/posterior": {
|
|
3269
|
+
module: "prob",
|
|
3270
|
+
category: "std-prob",
|
|
3271
|
+
minArity: 4,
|
|
3272
|
+
maxArity: 4,
|
|
3273
|
+
description: "Rejection sampling: returns accepted query values",
|
|
3274
|
+
hasSideEffects: false,
|
|
3275
|
+
returnType: "array",
|
|
3276
|
+
params: [
|
|
3277
|
+
{ name: "model", type: "SExpr", description: "Model expression (lazy, may call set/condition)" },
|
|
3278
|
+
{ name: "evidence", type: "SExpr", description: "Evidence expression (lazy, boolean)" },
|
|
3279
|
+
{ name: "query", type: "SExpr", description: "Query expression (lazy, value to collect)" },
|
|
3280
|
+
{ name: "n", type: "number", description: "Number of samples to attempt" }
|
|
3281
|
+
],
|
|
3282
|
+
example: '["prob/posterior", model, evidence, query, 5000]'
|
|
3283
|
+
},
|
|
3284
|
+
"prob/infer": {
|
|
3285
|
+
module: "prob",
|
|
3286
|
+
category: "std-prob",
|
|
3287
|
+
minArity: 4,
|
|
3288
|
+
maxArity: 4,
|
|
3289
|
+
description: "Like posterior but returns {mean, variance, samples, acceptRate}",
|
|
3290
|
+
hasSideEffects: false,
|
|
3291
|
+
returnType: "object",
|
|
3292
|
+
params: [
|
|
3293
|
+
{ name: "model", type: "SExpr", description: "Model expression (lazy)" },
|
|
3294
|
+
{ name: "evidence", type: "SExpr", description: "Evidence expression (lazy, boolean)" },
|
|
3295
|
+
{ name: "query", type: "SExpr", description: "Query expression (lazy)" },
|
|
3296
|
+
{ name: "n", type: "number", description: "Number of samples to attempt" }
|
|
3297
|
+
],
|
|
3298
|
+
example: '["prob/infer", model, evidence, query, 5000]'
|
|
3299
|
+
},
|
|
3300
|
+
// ========================================
|
|
3301
|
+
// Statistics
|
|
3302
|
+
// ========================================
|
|
3303
|
+
"prob/expected-value": {
|
|
3304
|
+
module: "prob",
|
|
3305
|
+
category: "std-prob",
|
|
3306
|
+
minArity: 1,
|
|
3307
|
+
maxArity: 1,
|
|
3308
|
+
description: "Mean of numeric samples",
|
|
3309
|
+
hasSideEffects: false,
|
|
3310
|
+
returnType: "number",
|
|
3311
|
+
params: [{ name: "samples", type: "number[]", description: "Array of numeric samples" }],
|
|
3312
|
+
example: '["prob/expected-value", [2, 4, 6, 8]] // => 5'
|
|
3313
|
+
},
|
|
3314
|
+
"prob/variance": {
|
|
3315
|
+
module: "prob",
|
|
3316
|
+
category: "std-prob",
|
|
3317
|
+
minArity: 1,
|
|
3318
|
+
maxArity: 1,
|
|
3319
|
+
description: "Population variance of numeric samples",
|
|
3320
|
+
hasSideEffects: false,
|
|
3321
|
+
returnType: "number",
|
|
3322
|
+
params: [{ name: "samples", type: "number[]", description: "Array of numeric samples" }],
|
|
3323
|
+
example: '["prob/variance", [2, 4, 4, 4, 5, 5, 7, 9]] // => 4'
|
|
3324
|
+
},
|
|
3325
|
+
"prob/histogram": {
|
|
3326
|
+
module: "prob",
|
|
3327
|
+
category: "std-prob",
|
|
3328
|
+
minArity: 2,
|
|
3329
|
+
maxArity: 2,
|
|
3330
|
+
description: "Bin numeric samples into a histogram",
|
|
3331
|
+
hasSideEffects: false,
|
|
3332
|
+
returnType: "object",
|
|
3333
|
+
params: [
|
|
3334
|
+
{ name: "samples", type: "number[]", description: "Array of numeric samples" },
|
|
3335
|
+
{ name: "bins", type: "number", description: "Number of bins" }
|
|
3336
|
+
],
|
|
3337
|
+
example: '["prob/histogram", [1, 2, 3, 4, 5], 2] // => {binEdges, counts}'
|
|
3338
|
+
},
|
|
3339
|
+
"prob/percentile": {
|
|
3340
|
+
module: "prob",
|
|
3341
|
+
category: "std-prob",
|
|
3342
|
+
minArity: 2,
|
|
3343
|
+
maxArity: 2,
|
|
3344
|
+
description: "Get the p-th percentile (0-100) from samples",
|
|
3345
|
+
hasSideEffects: false,
|
|
3346
|
+
returnType: "number",
|
|
3347
|
+
params: [
|
|
3348
|
+
{ name: "samples", type: "number[]", description: "Array of numeric samples" },
|
|
3349
|
+
{ name: "p", type: "number", description: "Percentile (0 to 100)" }
|
|
3350
|
+
],
|
|
3351
|
+
example: '["prob/percentile", [1, 2, 3, 4, 5], 50] // => 3'
|
|
3352
|
+
},
|
|
3353
|
+
"prob/credible-interval": {
|
|
3354
|
+
module: "prob",
|
|
3355
|
+
category: "std-prob",
|
|
3356
|
+
minArity: 2,
|
|
3357
|
+
maxArity: 2,
|
|
3358
|
+
description: "Compute symmetric credible interval from samples",
|
|
3359
|
+
hasSideEffects: false,
|
|
3360
|
+
returnType: "array",
|
|
3361
|
+
params: [
|
|
3362
|
+
{ name: "samples", type: "number[]", description: "Array of numeric samples" },
|
|
3363
|
+
{ name: "alpha", type: "number", description: "Significance level (e.g., 0.05 for 95% interval)" }
|
|
3364
|
+
],
|
|
3365
|
+
example: '["prob/credible-interval", samples, 0.05] // => [lo, hi]'
|
|
3366
|
+
}
|
|
3367
|
+
};
|
|
3368
|
+
|
|
3145
3369
|
// registry.ts
|
|
3146
3370
|
var STD_OPERATORS = {
|
|
3147
3371
|
...MATH_OPERATORS,
|
|
@@ -3154,7 +3378,8 @@ var STD_OPERATORS = {
|
|
|
3154
3378
|
...ASYNC_OPERATORS,
|
|
3155
3379
|
...NN_OPERATORS,
|
|
3156
3380
|
...TENSOR_OPERATORS,
|
|
3157
|
-
...TRAIN_OPERATORS
|
|
3381
|
+
...TRAIN_OPERATORS,
|
|
3382
|
+
...PROB_OPERATORS
|
|
3158
3383
|
};
|
|
3159
3384
|
var STD_OPERATORS_BY_MODULE = {
|
|
3160
3385
|
math: MATH_OPERATORS,
|
|
@@ -3167,7 +3392,8 @@ var STD_OPERATORS_BY_MODULE = {
|
|
|
3167
3392
|
async: ASYNC_OPERATORS,
|
|
3168
3393
|
nn: NN_OPERATORS,
|
|
3169
3394
|
tensor: TENSOR_OPERATORS,
|
|
3170
|
-
train: TRAIN_OPERATORS
|
|
3395
|
+
train: TRAIN_OPERATORS,
|
|
3396
|
+
prob: PROB_OPERATORS
|
|
3171
3397
|
};
|
|
3172
3398
|
function getStdOperatorMeta(operator) {
|
|
3173
3399
|
return STD_OPERATORS[operator];
|