@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 CHANGED
@@ -1,5 +1,5 @@
1
- import { S as StdModule, a as StdOperatorMeta } from './types-I95R8_FN.js';
2
- export { b as STD_MODULES, c as STD_OPERATOR_CATEGORIES, d as StdOperatorCategory, g as getFunctionFromOperator, e as getModuleFromOperator, i as isStdCategory, f as isStdOperator, m as makeStdOperator } from './types-I95R8_FN.js';
1
+ import { S as StdModule, a as StdOperatorMeta } from './types-CmNM_IbV.js';
2
+ export { b as STD_MODULES, c as STD_OPERATOR_CATEGORIES, d as StdOperatorCategory, g as getFunctionFromOperator, e as getModuleFromOperator, i as isStdCategory, f as isStdOperator, m as makeStdOperator } from './types-CmNM_IbV.js';
3
3
  export { STD_OPERATORS, STD_OPERATORS_BY_MODULE, getAllStdOperators, getLambdaOperators, getModuleOperators, getOperatorMetaExtended, getStdEffectOperators, getStdLibStats, getStdOperatorMeta, getStdOperatorsByModule, getStdPureOperators, isEffectOperatorExtended, isKnownOperatorExtended, isKnownStdOperator, isStdEffectOperator, isStdGuardOperator, validateOperatorArityExtended, validateStdOperatorArity } from './registry.js';
4
4
  export { MATH_OPERATORS } from './modules/math.js';
5
5
  export { STR_OPERATORS } from './modules/str.js';
package/dist/index.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
  var STD_OPERATOR_CATEGORIES = [
16
17
  "std-math",
@@ -23,7 +24,8 @@ var STD_OPERATOR_CATEGORIES = [
23
24
  "std-async",
24
25
  "std-nn",
25
26
  "std-tensor",
26
- "std-train"
27
+ "std-train",
28
+ "std-prob"
27
29
  ];
28
30
  function isStdCategory(category) {
29
31
  return STD_OPERATOR_CATEGORIES.includes(category);
@@ -3165,6 +3167,229 @@ var TRAIN_OPERATORS = {
3165
3167
  }
3166
3168
  };
3167
3169
 
3170
+ // modules/prob.ts
3171
+ var PROB_OPERATORS = {
3172
+ // ========================================
3173
+ // Distribution Sampling
3174
+ // ========================================
3175
+ "prob/seed": {
3176
+ module: "prob",
3177
+ category: "std-prob",
3178
+ minArity: 1,
3179
+ maxArity: 1,
3180
+ description: "Set seeded PRNG for deterministic probabilistic sampling",
3181
+ hasSideEffects: true,
3182
+ returnType: "void",
3183
+ params: [{ name: "n", type: "number", description: "Seed value (integer)" }],
3184
+ example: '["prob/seed", 42]'
3185
+ },
3186
+ "prob/flip": {
3187
+ module: "prob",
3188
+ category: "std-prob",
3189
+ minArity: 1,
3190
+ maxArity: 1,
3191
+ description: "Bernoulli trial: returns true with probability p",
3192
+ hasSideEffects: false,
3193
+ returnType: "boolean",
3194
+ params: [{ name: "p", type: "number", description: "Probability of true (0 to 1)" }],
3195
+ example: '["prob/flip", 0.5] // => true or false with equal probability'
3196
+ },
3197
+ "prob/gaussian": {
3198
+ module: "prob",
3199
+ category: "std-prob",
3200
+ minArity: 2,
3201
+ maxArity: 2,
3202
+ description: "Sample from a Gaussian (normal) distribution",
3203
+ hasSideEffects: false,
3204
+ returnType: "number",
3205
+ params: [
3206
+ { name: "mu", type: "number", description: "Mean" },
3207
+ { name: "sigma", type: "number", description: "Standard deviation" }
3208
+ ],
3209
+ example: '["prob/gaussian", 0, 1] // => standard normal sample'
3210
+ },
3211
+ "prob/uniform": {
3212
+ module: "prob",
3213
+ category: "std-prob",
3214
+ minArity: 2,
3215
+ maxArity: 2,
3216
+ description: "Sample from a uniform distribution [lo, hi)",
3217
+ hasSideEffects: false,
3218
+ returnType: "number",
3219
+ params: [
3220
+ { name: "lo", type: "number", description: "Lower bound (inclusive)" },
3221
+ { name: "hi", type: "number", description: "Upper bound (exclusive)" }
3222
+ ],
3223
+ example: '["prob/uniform", 0, 10] // => number in [0, 10)'
3224
+ },
3225
+ "prob/beta": {
3226
+ module: "prob",
3227
+ category: "std-prob",
3228
+ minArity: 2,
3229
+ maxArity: 2,
3230
+ description: "Sample from a Beta(alpha, beta) distribution",
3231
+ hasSideEffects: false,
3232
+ returnType: "number",
3233
+ params: [
3234
+ { name: "alpha", type: "number", description: "Alpha shape parameter (> 0)" },
3235
+ { name: "beta", type: "number", description: "Beta shape parameter (> 0)" }
3236
+ ],
3237
+ example: '["prob/beta", 2, 5] // => number in [0, 1], mean ~ 0.286'
3238
+ },
3239
+ "prob/categorical": {
3240
+ module: "prob",
3241
+ category: "std-prob",
3242
+ minArity: 2,
3243
+ maxArity: 2,
3244
+ description: "Weighted random selection from items",
3245
+ hasSideEffects: false,
3246
+ returnType: "any",
3247
+ params: [
3248
+ { name: "items", type: "array", description: "Array of items to choose from" },
3249
+ { name: "weights", type: "number[]", description: "Array of weights (same length as items)" }
3250
+ ],
3251
+ example: '["prob/categorical", ["a", "b", "c"], [1, 2, 1]] // => "b" most likely'
3252
+ },
3253
+ "prob/poisson": {
3254
+ module: "prob",
3255
+ category: "std-prob",
3256
+ minArity: 1,
3257
+ maxArity: 1,
3258
+ description: "Sample from a Poisson distribution",
3259
+ hasSideEffects: false,
3260
+ returnType: "number",
3261
+ params: [{ name: "lambda", type: "number", description: "Rate parameter (> 0)" }],
3262
+ example: '["prob/poisson", 4] // => non-negative integer, mean ~ 4'
3263
+ },
3264
+ // ========================================
3265
+ // Inference
3266
+ // ========================================
3267
+ "prob/condition": {
3268
+ module: "prob",
3269
+ category: "std-prob",
3270
+ minArity: 1,
3271
+ maxArity: 1,
3272
+ description: "Mark current sample as rejected if predicate is false",
3273
+ hasSideEffects: true,
3274
+ returnType: "void",
3275
+ params: [{ name: "predicate", type: "boolean", description: "Condition that must hold" }],
3276
+ example: '["prob/condition", [">", "@entity.x", 0]]'
3277
+ },
3278
+ "prob/sample": {
3279
+ module: "prob",
3280
+ category: "std-prob",
3281
+ minArity: 2,
3282
+ maxArity: 2,
3283
+ description: "Evaluate an expression n times and collect results",
3284
+ hasSideEffects: false,
3285
+ returnType: "array",
3286
+ params: [
3287
+ { name: "n", type: "number", description: "Number of samples" },
3288
+ { name: "expr", type: "SExpr", description: "Expression to evaluate (lazy)" }
3289
+ ],
3290
+ example: '["prob/sample", 1000, ["prob/flip", 0.5]] // => array of booleans'
3291
+ },
3292
+ "prob/posterior": {
3293
+ module: "prob",
3294
+ category: "std-prob",
3295
+ minArity: 4,
3296
+ maxArity: 4,
3297
+ description: "Rejection sampling: returns accepted query values",
3298
+ hasSideEffects: false,
3299
+ returnType: "array",
3300
+ params: [
3301
+ { name: "model", type: "SExpr", description: "Model expression (lazy, may call set/condition)" },
3302
+ { name: "evidence", type: "SExpr", description: "Evidence expression (lazy, boolean)" },
3303
+ { name: "query", type: "SExpr", description: "Query expression (lazy, value to collect)" },
3304
+ { name: "n", type: "number", description: "Number of samples to attempt" }
3305
+ ],
3306
+ example: '["prob/posterior", model, evidence, query, 5000]'
3307
+ },
3308
+ "prob/infer": {
3309
+ module: "prob",
3310
+ category: "std-prob",
3311
+ minArity: 4,
3312
+ maxArity: 4,
3313
+ description: "Like posterior but returns {mean, variance, samples, acceptRate}",
3314
+ hasSideEffects: false,
3315
+ returnType: "object",
3316
+ params: [
3317
+ { name: "model", type: "SExpr", description: "Model expression (lazy)" },
3318
+ { name: "evidence", type: "SExpr", description: "Evidence expression (lazy, boolean)" },
3319
+ { name: "query", type: "SExpr", description: "Query expression (lazy)" },
3320
+ { name: "n", type: "number", description: "Number of samples to attempt" }
3321
+ ],
3322
+ example: '["prob/infer", model, evidence, query, 5000]'
3323
+ },
3324
+ // ========================================
3325
+ // Statistics
3326
+ // ========================================
3327
+ "prob/expected-value": {
3328
+ module: "prob",
3329
+ category: "std-prob",
3330
+ minArity: 1,
3331
+ maxArity: 1,
3332
+ description: "Mean of numeric samples",
3333
+ hasSideEffects: false,
3334
+ returnType: "number",
3335
+ params: [{ name: "samples", type: "number[]", description: "Array of numeric samples" }],
3336
+ example: '["prob/expected-value", [2, 4, 6, 8]] // => 5'
3337
+ },
3338
+ "prob/variance": {
3339
+ module: "prob",
3340
+ category: "std-prob",
3341
+ minArity: 1,
3342
+ maxArity: 1,
3343
+ description: "Population variance of numeric samples",
3344
+ hasSideEffects: false,
3345
+ returnType: "number",
3346
+ params: [{ name: "samples", type: "number[]", description: "Array of numeric samples" }],
3347
+ example: '["prob/variance", [2, 4, 4, 4, 5, 5, 7, 9]] // => 4'
3348
+ },
3349
+ "prob/histogram": {
3350
+ module: "prob",
3351
+ category: "std-prob",
3352
+ minArity: 2,
3353
+ maxArity: 2,
3354
+ description: "Bin numeric samples into a histogram",
3355
+ hasSideEffects: false,
3356
+ returnType: "object",
3357
+ params: [
3358
+ { name: "samples", type: "number[]", description: "Array of numeric samples" },
3359
+ { name: "bins", type: "number", description: "Number of bins" }
3360
+ ],
3361
+ example: '["prob/histogram", [1, 2, 3, 4, 5], 2] // => {binEdges, counts}'
3362
+ },
3363
+ "prob/percentile": {
3364
+ module: "prob",
3365
+ category: "std-prob",
3366
+ minArity: 2,
3367
+ maxArity: 2,
3368
+ description: "Get the p-th percentile (0-100) from samples",
3369
+ hasSideEffects: false,
3370
+ returnType: "number",
3371
+ params: [
3372
+ { name: "samples", type: "number[]", description: "Array of numeric samples" },
3373
+ { name: "p", type: "number", description: "Percentile (0 to 100)" }
3374
+ ],
3375
+ example: '["prob/percentile", [1, 2, 3, 4, 5], 50] // => 3'
3376
+ },
3377
+ "prob/credible-interval": {
3378
+ module: "prob",
3379
+ category: "std-prob",
3380
+ minArity: 2,
3381
+ maxArity: 2,
3382
+ description: "Compute symmetric credible interval from samples",
3383
+ hasSideEffects: false,
3384
+ returnType: "array",
3385
+ params: [
3386
+ { name: "samples", type: "number[]", description: "Array of numeric samples" },
3387
+ { name: "alpha", type: "number", description: "Significance level (e.g., 0.05 for 95% interval)" }
3388
+ ],
3389
+ example: '["prob/credible-interval", samples, 0.05] // => [lo, hi]'
3390
+ }
3391
+ };
3392
+
3168
3393
  // registry.ts
3169
3394
  var STD_OPERATORS = {
3170
3395
  ...MATH_OPERATORS,
@@ -3177,7 +3402,8 @@ var STD_OPERATORS = {
3177
3402
  ...ASYNC_OPERATORS,
3178
3403
  ...NN_OPERATORS,
3179
3404
  ...TENSOR_OPERATORS,
3180
- ...TRAIN_OPERATORS
3405
+ ...TRAIN_OPERATORS,
3406
+ ...PROB_OPERATORS
3181
3407
  };
3182
3408
  var STD_OPERATORS_BY_MODULE = {
3183
3409
  math: MATH_OPERATORS,
@@ -3190,7 +3416,8 @@ var STD_OPERATORS_BY_MODULE = {
3190
3416
  async: ASYNC_OPERATORS,
3191
3417
  nn: NN_OPERATORS,
3192
3418
  tensor: TENSOR_OPERATORS,
3193
- train: TRAIN_OPERATORS
3419
+ train: TRAIN_OPERATORS,
3420
+ prob: PROB_OPERATORS
3194
3421
  };
3195
3422
  function getStdOperatorMeta(operator) {
3196
3423
  return STD_OPERATORS[operator];
@@ -8860,6 +9087,12 @@ var MODULE_DESCRIPTIONS = {
8860
9087
  displayName: "Training Operations",
8861
9088
  description: "Training loops, loss functions, and optimization for neural networks.",
8862
9089
  icon: "\u{1F3AF}"
9090
+ },
9091
+ prob: {
9092
+ name: "Probabilistic",
9093
+ displayName: "Probabilistic Programming",
9094
+ description: "Distribution sampling, Bayesian inference via rejection sampling, and statistical summaries.",
9095
+ icon: "\u{1F3B2}"
8863
9096
  }
8864
9097
  };
8865
9098
  var BEHAVIOR_GROUPINGS = {