@lucern/confidence 0.3.0-alpha.0 → 0.3.0-alpha.1
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/README.md +5 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.js +214 -87
- package/dist/index.js.map +1 -1
- package/dist/v1/codec.d.ts +42 -0
- package/dist/v1/codec.js +62 -0
- package/dist/v1/codec.js.map +1 -0
- package/dist/v1/index.d.ts +5 -3
- package/dist/v1/index.js +214 -87
- package/dist/v1/index.js.map +1 -1
- package/dist/v1/operations/approximation.js +30 -21
- package/dist/v1/operations/approximation.js.map +1 -1
- package/dist/v1/operations/bridge/index.d.ts +3 -3
- package/dist/v1/operations/bridge/index.js +27 -13
- package/dist/v1/operations/bridge/index.js.map +1 -1
- package/dist/v1/operations/canonical.d.ts +2 -2
- package/dist/v1/operations/canonical.js +16 -19
- package/dist/v1/operations/canonical.js.map +1 -1
- package/dist/v1/operations/contradiction/detectTupleContradiction.js.map +1 -1
- package/dist/v1/operations/contradiction/index.js.map +1 -1
- package/dist/v1/operations/dynamics/cascade.js +19 -6
- package/dist/v1/operations/dynamics/cascade.js.map +1 -1
- package/dist/v1/operations/dynamics/decay.js +5 -4
- package/dist/v1/operations/dynamics/decay.js.map +1 -1
- package/dist/v1/operations/dynamics/defeat.js +22 -17
- package/dist/v1/operations/dynamics/defeat.js.map +1 -1
- package/dist/v1/operations/dynamics/propagation.js +66 -33
- package/dist/v1/operations/dynamics/propagation.js.map +1 -1
- package/dist/v1/operations/dynamics/revision.d.ts +6 -6
- package/dist/v1/operations/dynamics/revision.js +31 -19
- package/dist/v1/operations/dynamics/revision.js.map +1 -1
- package/dist/v1/operations/index.js +9 -5
- package/dist/v1/operations/index.js.map +1 -1
- package/dist/v1/operations/lucern.d.ts +4 -2
- package/dist/v1/operations/lucern.js +179 -76
- package/dist/v1/operations/lucern.js.map +1 -1
- package/dist/v1/operations/operatorTaxonomy.d.ts +23 -1
- package/dist/v1/operations/operatorTaxonomy.js +28 -0
- package/dist/v1/operations/operatorTaxonomy.js.map +1 -1
- package/dist/v1/operations/scoring.d.ts +30 -12
- package/dist/v1/operations/scoring.js +82 -40
- package/dist/v1/operations/scoring.js.map +1 -1
- package/dist/v1/operations/subjectiveLogic/index.d.ts +20 -19
- package/dist/v1/operations/subjectiveLogic/index.js +11 -10
- package/dist/v1/operations/subjectiveLogic/index.js.map +1 -1
- package/dist/v1/operations/temporalDecay.js +9 -5
- package/dist/v1/operations/temporalDecay.js.map +1 -1
- package/dist/v1/types.d.ts +5 -1
- package/package.json +5 -1
package/dist/v1/index.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// src/v1/codec.ts
|
|
4
|
+
|
|
1
5
|
// src/v1/operations/subjectiveLogic/index.ts
|
|
2
|
-
function
|
|
3
|
-
const b =
|
|
4
|
-
const d =
|
|
5
|
-
const u =
|
|
6
|
+
function mkOpinion(belief, disbelief, uncertainty, baseRate) {
|
|
7
|
+
const b = Number.isFinite(belief) ? Math.max(0, belief) : 0;
|
|
8
|
+
const d = Number.isFinite(disbelief) ? Math.max(0, disbelief) : 0;
|
|
9
|
+
const u = Number.isFinite(uncertainty) ? Math.max(0, uncertainty) : 0;
|
|
6
10
|
const a = Math.max(0, Math.min(1, baseRate));
|
|
7
11
|
const sum = b + d + u;
|
|
8
12
|
if (sum === 0) {
|
|
@@ -15,12 +19,13 @@ function opinion(belief, disbelief, uncertainty, baseRate = 0.5) {
|
|
|
15
19
|
a
|
|
16
20
|
};
|
|
17
21
|
}
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
var opinion = mkOpinion;
|
|
23
|
+
function vacuous(baseRate) {
|
|
24
|
+
return mkOpinion(0, 0, 1, baseRate);
|
|
20
25
|
}
|
|
21
|
-
function dogmatic(probability, baseRate
|
|
26
|
+
function dogmatic(probability, baseRate) {
|
|
22
27
|
const p = Math.max(0, Math.min(1, probability));
|
|
23
|
-
return
|
|
28
|
+
return mkOpinion(p, 1 - p, 0, baseRate);
|
|
24
29
|
}
|
|
25
30
|
function project(o) {
|
|
26
31
|
return o.b + o.a * o.u;
|
|
@@ -217,7 +222,7 @@ function conditionalAbduction(opinionY, ifTrue, ifFalse, baseRateX) {
|
|
|
217
222
|
);
|
|
218
223
|
}
|
|
219
224
|
function negate(o) {
|
|
220
|
-
return
|
|
225
|
+
return mkOpinion(o.d, o.b, o.u, 1 - o.a);
|
|
221
226
|
}
|
|
222
227
|
function constraintFusion(left, right, mode = "pressure") {
|
|
223
228
|
if (mode === "redistribute") {
|
|
@@ -280,6 +285,43 @@ function informationGain(o) {
|
|
|
280
285
|
return o.u * (1 - Math.abs(o.b - o.d));
|
|
281
286
|
}
|
|
282
287
|
|
|
288
|
+
// src/v1/codec.ts
|
|
289
|
+
var SL_EPSILON = 1e-9;
|
|
290
|
+
var SLOpinionRefinement = z.object({
|
|
291
|
+
b: z.number(),
|
|
292
|
+
d: z.number(),
|
|
293
|
+
u: z.number(),
|
|
294
|
+
a: z.number()
|
|
295
|
+
}).refine((o) => Math.abs(o.b + o.d + o.u - 1) < SL_EPSILON, {
|
|
296
|
+
message: "SL invariant b+d+u=1 violated"
|
|
297
|
+
});
|
|
298
|
+
function fromStorage(fields) {
|
|
299
|
+
const sum = fields.belief + fields.disbelief + fields.uncertainty;
|
|
300
|
+
const opinion2 = mkOpinion(
|
|
301
|
+
fields.belief,
|
|
302
|
+
fields.disbelief,
|
|
303
|
+
fields.uncertainty,
|
|
304
|
+
fields.baseRate
|
|
305
|
+
);
|
|
306
|
+
if (Math.abs(sum - 1) < SL_EPSILON) {
|
|
307
|
+
return { ok: true, opinion: opinion2 };
|
|
308
|
+
}
|
|
309
|
+
return {
|
|
310
|
+
ok: false,
|
|
311
|
+
opinion: opinion2,
|
|
312
|
+
repairNeeded: true,
|
|
313
|
+
reason: `Stored fields sum to ${sum.toFixed(6)}, not 1; normalized on read`
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
function toStorage(opinion2) {
|
|
317
|
+
return {
|
|
318
|
+
belief: opinion2.b,
|
|
319
|
+
disbelief: opinion2.d,
|
|
320
|
+
uncertainty: opinion2.u,
|
|
321
|
+
baseRate: opinion2.a
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
|
|
283
325
|
// src/v1/operations/temporalDecay.ts
|
|
284
326
|
var DEFAULT_TEMPORAL_DECAY_HALF_LIFE_MS = 90 * 24 * 60 * 60 * 1e3;
|
|
285
327
|
function toEpochMs(value) {
|
|
@@ -313,7 +355,10 @@ function temporalDecay(sourceOpinion, now, decayParams) {
|
|
|
313
355
|
return { ...sourceOpinion };
|
|
314
356
|
}
|
|
315
357
|
const retainedEvidenceWeight = Math.pow(0.5, ageMs / halfLifeMs);
|
|
316
|
-
return trustDiscount(
|
|
358
|
+
return trustDiscount(
|
|
359
|
+
mkOpinion(sourceOpinion.b, sourceOpinion.d, sourceOpinion.u, sourceOpinion.a),
|
|
360
|
+
retainedEvidenceWeight
|
|
361
|
+
);
|
|
317
362
|
}
|
|
318
363
|
|
|
319
364
|
// src/v1/operations/bridge/index.ts
|
|
@@ -334,10 +379,6 @@ function normalizeBaseRateVector(baseRate, size) {
|
|
|
334
379
|
if (size === 0) {
|
|
335
380
|
return [];
|
|
336
381
|
}
|
|
337
|
-
const fallback = Array.from({ length: size }, () => 1 / size);
|
|
338
|
-
if (!baseRate) {
|
|
339
|
-
return fallback;
|
|
340
|
-
}
|
|
341
382
|
if (baseRate.length !== size) {
|
|
342
383
|
throw new Error(
|
|
343
384
|
`Base-rate vector length ${baseRate.length} must match evidence vector length ${size}.`
|
|
@@ -346,11 +387,11 @@ function normalizeBaseRateVector(baseRate, size) {
|
|
|
346
387
|
const normalized = baseRate.map((value) => clampNonNegative(value));
|
|
347
388
|
const total = normalized.reduce((sum, value) => sum + value, 0);
|
|
348
389
|
if (total === 0) {
|
|
349
|
-
|
|
390
|
+
throw new Error("Base-rate vector must contain at least one positive value.");
|
|
350
391
|
}
|
|
351
392
|
return normalized.map((value) => value / total);
|
|
352
393
|
}
|
|
353
|
-
function opinionFromDirichlet(alpha, nonInformativeWeight
|
|
394
|
+
function opinionFromDirichlet(alpha, nonInformativeWeight, baseRate) {
|
|
354
395
|
const evidence = alpha.map((value) => clampNonNegative(value));
|
|
355
396
|
const safeWeight = normalizeNonInformativeWeight(nonInformativeWeight);
|
|
356
397
|
const normalizedBaseRate = normalizeBaseRateVector(baseRate, evidence.length);
|
|
@@ -374,18 +415,18 @@ function projectDirichletOpinion(opinion2) {
|
|
|
374
415
|
(belief, index) => belief + (opinion2.a[index] ?? 0) * opinion2.u
|
|
375
416
|
);
|
|
376
417
|
}
|
|
377
|
-
function opinionFromBeta(alpha, beta, nonInformativeWeight
|
|
418
|
+
function opinionFromBeta(alpha, beta, nonInformativeWeight, baseRate) {
|
|
378
419
|
const dirichlet = opinionFromDirichlet(
|
|
379
420
|
[alpha, beta],
|
|
380
421
|
nonInformativeWeight,
|
|
381
422
|
[clamp01(baseRate), 1 - clamp01(baseRate)]
|
|
382
423
|
);
|
|
383
|
-
return
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
424
|
+
return mkOpinion(
|
|
425
|
+
dirichlet.b[0] ?? 0,
|
|
426
|
+
dirichlet.b[1] ?? 0,
|
|
427
|
+
dirichlet.u,
|
|
428
|
+
dirichlet.a[0] ?? clamp01(baseRate)
|
|
429
|
+
);
|
|
389
430
|
}
|
|
390
431
|
function betaFromOpinion(opinion2, nonInformativeWeight = DEFAULT_NON_INFORMATIVE_WEIGHT) {
|
|
391
432
|
if (opinion2.u === 0) {
|
|
@@ -406,13 +447,22 @@ function betaFromOpinion(opinion2, nonInformativeWeight = DEFAULT_NON_INFORMATIV
|
|
|
406
447
|
function finiteNumber(value) {
|
|
407
448
|
return typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
408
449
|
}
|
|
450
|
+
function requiredOpinionNumber(label, ...values) {
|
|
451
|
+
for (const value of values) {
|
|
452
|
+
const numberValue = finiteNumber(value);
|
|
453
|
+
if (numberValue !== void 0) {
|
|
454
|
+
return numberValue;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
throw new Error(`Opinion record is missing required ${label}.`);
|
|
458
|
+
}
|
|
409
459
|
function clamp012(value) {
|
|
410
460
|
return Math.max(0, Math.min(1, value));
|
|
411
461
|
}
|
|
412
462
|
function confidenceFromOpinion(opinion2) {
|
|
413
463
|
return clamp012(opinion2.b + opinion2.a * opinion2.u);
|
|
414
464
|
}
|
|
415
|
-
function confidenceFromSL(belief, _disbelief, uncertainty, baseRate
|
|
465
|
+
function confidenceFromSL(belief, _disbelief, uncertainty, baseRate) {
|
|
416
466
|
return confidenceFromOpinion({
|
|
417
467
|
b: belief,
|
|
418
468
|
u: uncertainty,
|
|
@@ -427,34 +477,56 @@ function toStoredOpinionFields(opinion2) {
|
|
|
427
477
|
baseRate: opinion2.a
|
|
428
478
|
};
|
|
429
479
|
}
|
|
430
|
-
function readOpinionFromRecord(source
|
|
480
|
+
function readOpinionFromRecord(source) {
|
|
431
481
|
const record = source && typeof source === "object" ? source : {};
|
|
432
|
-
return
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
482
|
+
return mkOpinion(
|
|
483
|
+
requiredOpinionNumber(
|
|
484
|
+
"belief",
|
|
485
|
+
record.b,
|
|
486
|
+
record.belief,
|
|
487
|
+
record.slBelief,
|
|
488
|
+
record.opinion_b
|
|
489
|
+
),
|
|
490
|
+
requiredOpinionNumber(
|
|
491
|
+
"disbelief",
|
|
492
|
+
record.d,
|
|
493
|
+
record.disbelief,
|
|
494
|
+
record.slDisbelief,
|
|
495
|
+
record.opinion_d
|
|
496
|
+
),
|
|
497
|
+
requiredOpinionNumber(
|
|
498
|
+
"uncertainty",
|
|
499
|
+
record.u,
|
|
500
|
+
record.uncertainty,
|
|
501
|
+
record.slUncertainty,
|
|
502
|
+
record.opinion_u
|
|
503
|
+
),
|
|
504
|
+
requiredOpinionNumber(
|
|
505
|
+
"baseRate",
|
|
506
|
+
record.a,
|
|
507
|
+
record.baseRate,
|
|
508
|
+
record.slBaseRate,
|
|
509
|
+
record.opinion_a
|
|
510
|
+
)
|
|
511
|
+
);
|
|
438
512
|
}
|
|
439
513
|
function opinionFromScalar(value, mode, options) {
|
|
440
514
|
const clampedValue = clamp012(value);
|
|
441
|
-
const baseRate =
|
|
515
|
+
const baseRate = options?.baseRate === void 0 ? void 0 : clamp012(options.baseRate);
|
|
442
516
|
switch (mode) {
|
|
443
517
|
case "base_rate":
|
|
444
|
-
return
|
|
445
|
-
b: 0,
|
|
446
|
-
d: 0,
|
|
447
|
-
u: 1,
|
|
448
|
-
a: clampedValue
|
|
449
|
-
};
|
|
518
|
+
return mkOpinion(0, 0, 1, clampedValue);
|
|
450
519
|
case "dogmatic":
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
a: baseRate
|
|
456
|
-
};
|
|
520
|
+
if (baseRate === void 0) {
|
|
521
|
+
throw new Error('opinionFromScalar(value, "dogmatic") requires options.baseRate.');
|
|
522
|
+
}
|
|
523
|
+
return mkOpinion(clampedValue, 1 - clampedValue, 0, baseRate);
|
|
457
524
|
case "projected_with_u": {
|
|
525
|
+
if (baseRate === void 0) {
|
|
526
|
+
throw new Error(
|
|
527
|
+
'opinionFromScalar(value, "projected_with_u") requires options.baseRate.'
|
|
528
|
+
);
|
|
529
|
+
}
|
|
458
530
|
const uncertainty = options?.uncertainty;
|
|
459
531
|
if (uncertainty === void 0) {
|
|
460
532
|
throw new Error(
|
|
@@ -463,35 +535,30 @@ function opinionFromScalar(value, mode, options) {
|
|
|
463
535
|
}
|
|
464
536
|
const clampedUncertainty = clamp012(uncertainty);
|
|
465
537
|
const evidenceWeight = 1 - clampedUncertainty;
|
|
466
|
-
return
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
538
|
+
return mkOpinion(
|
|
539
|
+
clampedValue * evidenceWeight,
|
|
540
|
+
(1 - clampedValue) * evidenceWeight,
|
|
541
|
+
clampedUncertainty,
|
|
542
|
+
baseRate
|
|
543
|
+
);
|
|
472
544
|
}
|
|
473
545
|
}
|
|
474
546
|
throw new Error(`Unsupported opinionFromScalar mode: ${mode}`);
|
|
475
547
|
}
|
|
476
|
-
function toDogmaticOpinion(confidence, baseRate
|
|
548
|
+
function toDogmaticOpinion(confidence, baseRate) {
|
|
477
549
|
return opinionFromScalar(confidence, "dogmatic", { baseRate });
|
|
478
550
|
}
|
|
479
551
|
function opinionFromBaseRate(probability) {
|
|
480
552
|
return vacuous(clamp012(probability));
|
|
481
553
|
}
|
|
482
|
-
function opinionFromDogmatic(probability, baseRate
|
|
554
|
+
function opinionFromDogmatic(probability, baseRate) {
|
|
483
555
|
return dogmatic(clamp012(probability), clamp012(baseRate));
|
|
484
556
|
}
|
|
485
|
-
function opinionFromProjected(probability, uncertainty, baseRate
|
|
557
|
+
function opinionFromProjected(probability, uncertainty, baseRate) {
|
|
486
558
|
const p = clamp012(probability);
|
|
487
559
|
const u = clamp012(uncertainty);
|
|
488
560
|
const remainingMass = 1 - u;
|
|
489
|
-
return
|
|
490
|
-
b: p * remainingMass,
|
|
491
|
-
d: (1 - p) * remainingMass,
|
|
492
|
-
u,
|
|
493
|
-
a: clamp012(baseRate)
|
|
494
|
-
};
|
|
561
|
+
return mkOpinion(p * remainingMass, (1 - p) * remainingMass, u, clamp012(baseRate));
|
|
495
562
|
}
|
|
496
563
|
function hasProjectedOpinionChanged(current, next, tolerance = 0.01) {
|
|
497
564
|
return Math.abs(confidenceFromOpinion(next) - confidenceFromOpinion(current)) >= tolerance;
|
|
@@ -531,7 +598,14 @@ function evaluateTupleContradictionTransition(args) {
|
|
|
531
598
|
|
|
532
599
|
// src/v1/operations/dynamics/cascade.ts
|
|
533
600
|
function dampedDependencyOpinion(dependencyOpinion, beliefOpinion, mode = "continuous", threshold = 0.3) {
|
|
534
|
-
const dependencyProjection = project(
|
|
601
|
+
const dependencyProjection = project(
|
|
602
|
+
mkOpinion(
|
|
603
|
+
dependencyOpinion.b,
|
|
604
|
+
dependencyOpinion.d,
|
|
605
|
+
dependencyOpinion.u,
|
|
606
|
+
dependencyOpinion.a
|
|
607
|
+
)
|
|
608
|
+
);
|
|
535
609
|
if (mode === "threshold") {
|
|
536
610
|
if (dependencyProjection < threshold) {
|
|
537
611
|
return opinion(
|
|
@@ -556,40 +630,49 @@ function dampedDependencyCascade(dependencyOpinion, beliefOpinion, mode = "conti
|
|
|
556
630
|
opinion: dampedDependencyOpinion(dependencyOpinion, beliefOpinion, mode),
|
|
557
631
|
operator: "dependency_cascade",
|
|
558
632
|
rationale: `Damped dependency cascade (${mode}): prerequisite at ${project(
|
|
559
|
-
|
|
633
|
+
mkOpinion(
|
|
634
|
+
dependencyOpinion.b,
|
|
635
|
+
dependencyOpinion.d,
|
|
636
|
+
dependencyOpinion.u,
|
|
637
|
+
dependencyOpinion.a
|
|
638
|
+
)
|
|
560
639
|
).toFixed(2)}`
|
|
561
640
|
};
|
|
562
641
|
}
|
|
563
642
|
|
|
564
643
|
// src/v1/operations/dynamics/defeat.ts
|
|
565
644
|
function applyNegativeSupport(source, target, weight, metadata = {}) {
|
|
645
|
+
const sourceOpinion = mkOpinion(source.b, source.d, source.u, source.a);
|
|
646
|
+
const targetOpinion = mkOpinion(target.b, target.d, target.u, target.a);
|
|
566
647
|
if (metadata.constraint === "xor") {
|
|
567
648
|
const result = constraintFusion(
|
|
568
|
-
|
|
569
|
-
|
|
649
|
+
sourceOpinion,
|
|
650
|
+
targetOpinion,
|
|
570
651
|
metadata.normalization ?? "pressure"
|
|
571
652
|
);
|
|
572
653
|
return {
|
|
573
654
|
opinion: result.o2,
|
|
574
655
|
operator: "constraint_fusion",
|
|
575
|
-
rationale: `XOR constraint: source belief at ${project(
|
|
576
|
-
|
|
577
|
-
)} pressures target`
|
|
656
|
+
rationale: `XOR constraint: source belief at ${project(
|
|
657
|
+
sourceOpinion
|
|
658
|
+
).toFixed(2)} pressures target`
|
|
578
659
|
};
|
|
579
660
|
}
|
|
580
|
-
const discounted = trustDiscount(negate(
|
|
661
|
+
const discounted = trustDiscount(negate(sourceOpinion), Math.abs(weight));
|
|
581
662
|
return {
|
|
582
|
-
opinion: cumulativeFusion(
|
|
663
|
+
opinion: cumulativeFusion(targetOpinion, discounted),
|
|
583
664
|
operator: "cumulative_fusion",
|
|
584
665
|
rationale: `Contradicting evidence (weight=${weight.toFixed(
|
|
585
666
|
2
|
|
586
|
-
)}) from source at ${project(
|
|
667
|
+
)}) from source at ${project(sourceOpinion).toFixed(2)}`
|
|
587
668
|
};
|
|
588
669
|
}
|
|
589
670
|
function applyNegativeEvidence(source, target, weight) {
|
|
590
|
-
const
|
|
671
|
+
const sourceOpinion = mkOpinion(source.b, source.d, source.u, source.a);
|
|
672
|
+
const targetOpinion = mkOpinion(target.b, target.d, target.u, target.a);
|
|
673
|
+
const discounted = trustDiscount(negate(sourceOpinion), Math.abs(weight));
|
|
591
674
|
return {
|
|
592
|
-
opinion: cumulativeFusion(
|
|
675
|
+
opinion: cumulativeFusion(targetOpinion, discounted),
|
|
593
676
|
operator: "cumulative_fusion",
|
|
594
677
|
rationale: `Contradicting evidence (weight=${weight.toFixed(2)})`
|
|
595
678
|
};
|
|
@@ -600,28 +683,32 @@ var EDGE_PROPAGATION_RULES = {
|
|
|
600
683
|
supports: {
|
|
601
684
|
direction: "outgoing",
|
|
602
685
|
handler: (source, target, weight, metadata) => {
|
|
686
|
+
const sourceOpinion = mkOpinion(source.b, source.d, source.u, source.a);
|
|
687
|
+
const targetOpinion = mkOpinion(target.b, target.d, target.u, target.a);
|
|
603
688
|
if (weight < 0) {
|
|
604
|
-
return applyNegativeSupport(
|
|
689
|
+
return applyNegativeSupport(sourceOpinion, targetOpinion, weight, metadata);
|
|
605
690
|
}
|
|
606
|
-
const discounted = trustDiscount(
|
|
691
|
+
const discounted = trustDiscount(sourceOpinion, weight);
|
|
607
692
|
return {
|
|
608
|
-
opinion: cumulativeFusion(
|
|
693
|
+
opinion: cumulativeFusion(targetOpinion, discounted),
|
|
609
694
|
operator: "cumulative_fusion",
|
|
610
695
|
rationale: `Supporting evidence (weight=${weight.toFixed(
|
|
611
696
|
2
|
|
612
|
-
)}) from source at ${project(
|
|
697
|
+
)}) from source at ${project(sourceOpinion).toFixed(2)}`
|
|
613
698
|
};
|
|
614
699
|
}
|
|
615
700
|
},
|
|
616
701
|
informs: {
|
|
617
702
|
direction: "outgoing",
|
|
618
703
|
handler: (source, target, weight) => {
|
|
704
|
+
const sourceOpinion = mkOpinion(source.b, source.d, source.u, source.a);
|
|
705
|
+
const targetOpinion = mkOpinion(target.b, target.d, target.u, target.a);
|
|
619
706
|
if (weight < 0) {
|
|
620
|
-
return applyNegativeEvidence(
|
|
707
|
+
return applyNegativeEvidence(sourceOpinion, targetOpinion, weight);
|
|
621
708
|
}
|
|
622
|
-
const discounted = trustDiscount(
|
|
709
|
+
const discounted = trustDiscount(sourceOpinion, Math.abs(weight));
|
|
623
710
|
return {
|
|
624
|
-
opinion: cumulativeFusion(
|
|
711
|
+
opinion: cumulativeFusion(targetOpinion, discounted),
|
|
625
712
|
operator: "cumulative_fusion",
|
|
626
713
|
rationale: `Supporting evidence (weight=${weight.toFixed(2)})`
|
|
627
714
|
};
|
|
@@ -630,23 +717,35 @@ var EDGE_PROPAGATION_RULES = {
|
|
|
630
717
|
depends_on: {
|
|
631
718
|
direction: "incoming",
|
|
632
719
|
handler: (source, target, _weight, metadata) => {
|
|
720
|
+
const sourceOpinion = mkOpinion(source.b, source.d, source.u, source.a);
|
|
721
|
+
const targetOpinion = mkOpinion(target.b, target.d, target.u, target.a);
|
|
633
722
|
if (metadata.conditionalA && metadata.conditionalNotA) {
|
|
634
723
|
return {
|
|
635
724
|
opinion: conditionalDeduction(
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
725
|
+
sourceOpinion,
|
|
726
|
+
mkOpinion(
|
|
727
|
+
metadata.conditionalA.b,
|
|
728
|
+
metadata.conditionalA.d,
|
|
729
|
+
metadata.conditionalA.u,
|
|
730
|
+
metadata.conditionalA.a
|
|
731
|
+
),
|
|
732
|
+
mkOpinion(
|
|
733
|
+
metadata.conditionalNotA.b,
|
|
734
|
+
metadata.conditionalNotA.d,
|
|
735
|
+
metadata.conditionalNotA.u,
|
|
736
|
+
metadata.conditionalNotA.a
|
|
737
|
+
),
|
|
738
|
+
targetOpinion.a
|
|
640
739
|
),
|
|
641
740
|
operator: "conditional_deduction",
|
|
642
741
|
rationale: `Conditional deduction: prerequisite at ${project(
|
|
643
|
-
|
|
742
|
+
sourceOpinion
|
|
644
743
|
).toFixed(2)}`
|
|
645
744
|
};
|
|
646
745
|
}
|
|
647
746
|
return dampedDependencyCascade(
|
|
648
|
-
|
|
649
|
-
|
|
747
|
+
sourceOpinion,
|
|
748
|
+
targetOpinion,
|
|
650
749
|
metadata.propagation ?? "continuous"
|
|
651
750
|
);
|
|
652
751
|
}
|
|
@@ -752,7 +851,7 @@ function reviseConfidenceOpinion(args) {
|
|
|
752
851
|
priorEvidence.alpha + newEvidence.alpha,
|
|
753
852
|
priorEvidence.beta + newEvidence.beta,
|
|
754
853
|
args.nonInformativeWeight ?? DEFAULT_NON_INFORMATIVE_WEIGHT,
|
|
755
|
-
args.baseRate
|
|
854
|
+
args.baseRate
|
|
756
855
|
);
|
|
757
856
|
}
|
|
758
857
|
|
|
@@ -1338,6 +1437,7 @@ var SL_APPROXIMATION_OPERATOR_NAMES = [
|
|
|
1338
1437
|
|
|
1339
1438
|
// src/v1/operations/canonical.ts
|
|
1340
1439
|
var SL_CANONICAL_OPERATOR_NAMES = [
|
|
1440
|
+
"mkOpinion",
|
|
1341
1441
|
"opinion",
|
|
1342
1442
|
"vacuous",
|
|
1343
1443
|
"dogmatic",
|
|
@@ -1355,6 +1455,8 @@ var SL_CANONICAL_OPERATOR_NAMES = [
|
|
|
1355
1455
|
// src/v1/operations/lucern.ts
|
|
1356
1456
|
var LUCERN_SPECIFIC_OPERATOR_NAMES = [
|
|
1357
1457
|
"clamp01",
|
|
1458
|
+
"fromStorage",
|
|
1459
|
+
"toStorage",
|
|
1358
1460
|
"toStoredOpinionFields",
|
|
1359
1461
|
"readOpinionFromRecord",
|
|
1360
1462
|
"opinionFromScalar",
|
|
@@ -1375,6 +1477,7 @@ var LUCERN_SPECIFIC_OPERATOR_NAMES = [
|
|
|
1375
1477
|
"propagateAllEdges",
|
|
1376
1478
|
"bayesianUpdate",
|
|
1377
1479
|
"reviseConfidence",
|
|
1480
|
+
"reviseConfidenceOpinion",
|
|
1378
1481
|
"computeBaseDecay",
|
|
1379
1482
|
"computeDeadlineUrgency",
|
|
1380
1483
|
"computeEffectiveDecay",
|
|
@@ -1414,6 +1517,12 @@ var PUBLIC_OPERATOR_EXPORT_NAMES = [
|
|
|
1414
1517
|
...LUCERN_SPECIFIC_OPERATOR_NAMES
|
|
1415
1518
|
];
|
|
1416
1519
|
var OPERATOR_TAXONOMY_ENTRIES = [
|
|
1520
|
+
{
|
|
1521
|
+
operator: "mkOpinion",
|
|
1522
|
+
tag: "SL_CANONICAL",
|
|
1523
|
+
sourceModule: "operations/subjectiveLogic/index.ts",
|
|
1524
|
+
rationale: "Constructs the canonical binomial SL opinion tuple and normalizes it into valid mass components."
|
|
1525
|
+
},
|
|
1417
1526
|
{
|
|
1418
1527
|
operator: "opinion",
|
|
1419
1528
|
tag: "SL_CANONICAL",
|
|
@@ -1546,6 +1655,18 @@ var OPERATOR_TAXONOMY_ENTRIES = [
|
|
|
1546
1655
|
sourceModule: "operations/scoring.ts",
|
|
1547
1656
|
rationale: "Implementation helper for Lucern APIs; it has no direct J\xF8sang operator analogue."
|
|
1548
1657
|
},
|
|
1658
|
+
{
|
|
1659
|
+
operator: "fromStorage",
|
|
1660
|
+
tag: "LUCERN_SPECIFIC",
|
|
1661
|
+
sourceModule: "codec.ts",
|
|
1662
|
+
rationale: "Reads Lucern storage fields into a normalized opinion and reports repair metadata; it is storage glue, not SL algebra."
|
|
1663
|
+
},
|
|
1664
|
+
{
|
|
1665
|
+
operator: "toStorage",
|
|
1666
|
+
tag: "LUCERN_SPECIFIC",
|
|
1667
|
+
sourceModule: "codec.ts",
|
|
1668
|
+
rationale: "Serializes a normalized opinion into Lucern storage fields rather than implementing an SL algebra operator."
|
|
1669
|
+
},
|
|
1549
1670
|
{
|
|
1550
1671
|
operator: "toStoredOpinionFields",
|
|
1551
1672
|
tag: "LUCERN_SPECIFIC",
|
|
@@ -1666,6 +1787,12 @@ var OPERATOR_TAXONOMY_ENTRIES = [
|
|
|
1666
1787
|
sourceModule: "operations/dynamics/revision.ts",
|
|
1667
1788
|
rationale: "Lucern wrapper around the scalar Bayesian revision helper rather than a direct SL operator."
|
|
1668
1789
|
},
|
|
1790
|
+
{
|
|
1791
|
+
operator: "reviseConfidenceOpinion",
|
|
1792
|
+
tag: "LUCERN_SPECIFIC",
|
|
1793
|
+
sourceModule: "operations/dynamics/revision.ts",
|
|
1794
|
+
rationale: "Lucern revision helper that exposes the Beta-bridge opinion behind scalar confidence revision."
|
|
1795
|
+
},
|
|
1669
1796
|
{
|
|
1670
1797
|
operator: "computeBaseDecay",
|
|
1671
1798
|
tag: "LUCERN_SPECIFIC",
|
|
@@ -1828,6 +1955,6 @@ var OPERATOR_TAXONOMY_BY_TAG = Object.freeze({
|
|
|
1828
1955
|
LUCERN_SPECIFIC: LUCERN_SPECIFIC_OPERATOR_NAMES
|
|
1829
1956
|
});
|
|
1830
1957
|
|
|
1831
|
-
export { BUILT_IN_EVIDENTIAL_ALIASES, BUILT_IN_EVIDENTIAL_EVALUATOR, BUILT_IN_MARKET_INDEX_COMPARATOR, BUILT_IN_METRIC_CHECKER, BUILT_IN_REFERENCE_CHECK_COUNTER, BUILT_IN_TEMPORAL_DEADLINE, DEADLINE_URGENCY, DECAY_TIERS, DEFAULT_NON_INFORMATIVE_WEIGHT, DEFAULT_TEMPORAL_DECAY_HALF_LIFE_MS, DEFAULT_TUPLE_CONTRADICTION_BELIEF_THRESHOLD, DEFAULT_TUPLE_CONTRADICTION_DISBELIEF_THRESHOLD, OPERATOR_TAXONOMY, OPERATOR_TAXONOMY_BY_TAG, OPERATOR_TAXONOMY_ENTRIES, OPERATOR_TAXONOMY_TAGS, PROPAGATION_TRAVERSAL_SPECS, PUBLIC_OPERATOR_EXPORT_NAMES, applyNegativeEvidence, applyNegativeSupport, areTensioned, averagingFusion, bayesianUpdate, betaFromOpinion, buildComparisonRationale, buildEvidentialRationale, clamp012 as clamp01, compareMetricValue, computeBaseDecay, computeDeadlineUrgency, computeEffectiveDecay, conditionalAbduction, conditionalDeduction, confidenceFromOpinion, confidenceFromSL, confidenceLevel, constraintFusion, createInheritedContractRecord, cumulativeFusion, dampedDependencyCascade, dampedDependencyOpinion, decay, deriveContractModulationPlan, deriveContractStatus, deriveVerificationTrigger, detectTupleContradiction, dogmatic, evaluateTupleContradictionTransition, evidenceBalance, getEvaluatorInputRecord, getPropagationTraversalSpecs, getRescoringSchedule, hasProjectedOpinionChanged, informationGain, isPropagationEdgeType, negate, normalizeEvidentialAction, normalizeTupleContradictionPolicy, opinion, opinionFromBaseRate, opinionFromBeta, opinionFromDirichlet, opinionFromDogmatic, opinionFromProjected, opinionFromScalar, parseComparisonOperator, parseEvidentialEvaluatorConfig, parseMarketIndexComparatorConfig, parseMetricCheckerConfig, parseNumericThreshold, parseReferenceCheckCounterConfig, parseTemporalDeadlineConfig, pickFiniteNumber, project, projectDirichletOpinion, propagateAllEdges, propagateThroughEdge, readOpinionFromRecord, resolveComparisonResult, reviseConfidence, reviseConfidenceOpinion, temporalDecay, toDogmaticOpinion, toStoredOpinionFields, trustDiscount, vacuous };
|
|
1958
|
+
export { BUILT_IN_EVIDENTIAL_ALIASES, BUILT_IN_EVIDENTIAL_EVALUATOR, BUILT_IN_MARKET_INDEX_COMPARATOR, BUILT_IN_METRIC_CHECKER, BUILT_IN_REFERENCE_CHECK_COUNTER, BUILT_IN_TEMPORAL_DEADLINE, DEADLINE_URGENCY, DECAY_TIERS, DEFAULT_NON_INFORMATIVE_WEIGHT, DEFAULT_TEMPORAL_DECAY_HALF_LIFE_MS, DEFAULT_TUPLE_CONTRADICTION_BELIEF_THRESHOLD, DEFAULT_TUPLE_CONTRADICTION_DISBELIEF_THRESHOLD, OPERATOR_TAXONOMY, OPERATOR_TAXONOMY_BY_TAG, OPERATOR_TAXONOMY_ENTRIES, OPERATOR_TAXONOMY_TAGS, PROPAGATION_TRAVERSAL_SPECS, PUBLIC_OPERATOR_EXPORT_NAMES, SLOpinionRefinement, applyNegativeEvidence, applyNegativeSupport, areTensioned, averagingFusion, bayesianUpdate, betaFromOpinion, buildComparisonRationale, buildEvidentialRationale, clamp012 as clamp01, compareMetricValue, computeBaseDecay, computeDeadlineUrgency, computeEffectiveDecay, conditionalAbduction, conditionalDeduction, confidenceFromOpinion, confidenceFromSL, confidenceLevel, constraintFusion, createInheritedContractRecord, cumulativeFusion, dampedDependencyCascade, dampedDependencyOpinion, decay, deriveContractModulationPlan, deriveContractStatus, deriveVerificationTrigger, detectTupleContradiction, dogmatic, evaluateTupleContradictionTransition, evidenceBalance, fromStorage, getEvaluatorInputRecord, getPropagationTraversalSpecs, getRescoringSchedule, hasProjectedOpinionChanged, informationGain, isPropagationEdgeType, mkOpinion, negate, normalizeEvidentialAction, normalizeTupleContradictionPolicy, opinion, opinionFromBaseRate, opinionFromBeta, opinionFromDirichlet, opinionFromDogmatic, opinionFromProjected, opinionFromScalar, parseComparisonOperator, parseEvidentialEvaluatorConfig, parseMarketIndexComparatorConfig, parseMetricCheckerConfig, parseNumericThreshold, parseReferenceCheckCounterConfig, parseTemporalDeadlineConfig, pickFiniteNumber, project, projectDirichletOpinion, propagateAllEdges, propagateThroughEdge, readOpinionFromRecord, resolveComparisonResult, reviseConfidence, reviseConfidenceOpinion, temporalDecay, toDogmaticOpinion, toStorage, toStoredOpinionFields, trustDiscount, vacuous };
|
|
1832
1959
|
//# sourceMappingURL=index.js.map
|
|
1833
1960
|
//# sourceMappingURL=index.js.map
|