@mark1russell7/stack-endurance 0.8.31 → 0.8.32
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 +7 -1
- package/build/index.d.ts +20 -4
- package/build/index.d.ts.map +1 -1
- package/build/index.js +54 -29
- package/build/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -154,9 +154,15 @@ Two groups of cuts that share no minimal set are independent, so the independent
|
|
|
154
154
|
- `survivalCombination` of rigor-statistics gives the Greenwood error of the sum. The covariance of the chances at two days `a <= b` is `S(a) * S(b) * V(a)`.
|
|
155
155
|
- With two or more cuts, the curves of the stop are not smooth functions of the curves of the cuts. Thus the interval comes from a parametric bootstrap. Since 0.8.31.
|
|
156
156
|
- Each run of the bootstrap draws the curve of each cut (`survivalBootstrap` of rigor-statistics). Then it makes the event curve of the stop again (`stopRebuild`) and reads the change.
|
|
157
|
-
-
|
|
157
|
+
- `interval` is for `change.event`. `interval.runs` gives the count of runs. The option `runs` sets it, and the default is `SENSITIVITY_RUNS`, 1000.
|
|
158
158
|
- The seed is the hash of the case, the need and the input. Thus the same query gives the same interval.
|
|
159
159
|
- At a kink of the event curve, as for two cuts with equal curves, the coverage of the interval is near 89%, not 95%.
|
|
160
|
+
- `chance.intervals` gives the 95% interval of the change of each curve of the stop: `event`, `independent` and `upper` (`CurveIntervals`). Since 0.8.32 (M2-interval-independent-upper).
|
|
161
|
+
- `intervals.event` is equal to `interval`.
|
|
162
|
+
- With one cut, the three changes are equal, so the three intervals are the interval of the delta method.
|
|
163
|
+
- With two or more cuts, one bootstrap gives the three intervals (`survivalBootstrapMany` of rigor-statistics). Each run makes the three curves of the stop again (`StopRebuild.curvesWith`) from the same drawn curves.
|
|
164
|
+
- The draws are the draws of 0.8.31, so the event interval does not change.
|
|
165
|
+
- The upper curve has a kink where the sum of the chances of the cuts reaches 1. There, its coverage can be less than 95%.
|
|
160
166
|
|
|
161
167
|
An example on the sample:
|
|
162
168
|
|
package/build/index.d.ts
CHANGED
|
@@ -795,6 +795,12 @@ export interface ChanceInterval {
|
|
|
795
795
|
/** The count of the runs of the bootstrap, for a stop of two or more cuts. With one cut, it is absent. Since 0.8.31. */
|
|
796
796
|
readonly runs?: number | undefined;
|
|
797
797
|
}
|
|
798
|
+
/** The 95% interval of the change of the chance for each curve of the stop (`SensitivityChance.intervals`). Since 0.8.32. */
|
|
799
|
+
export interface CurveIntervals {
|
|
800
|
+
readonly event: ChanceInterval;
|
|
801
|
+
readonly independent: ChanceInterval;
|
|
802
|
+
readonly upper: ChanceInterval;
|
|
803
|
+
}
|
|
798
804
|
/**
|
|
799
805
|
* The change in the chance that a draw gets its need through the event (`DrawOutlook.lasts`), for one input.
|
|
800
806
|
* The chance comes from the curves of the stop. Only the days change, so the curves are the same before and after.
|
|
@@ -814,9 +820,19 @@ export interface SensitivityChance {
|
|
|
814
820
|
* - With one cut, the three curves of the stop are the curve of the cut, so the three changes are equal.
|
|
815
821
|
* The interval comes from the delta method (`survivalCombination`).
|
|
816
822
|
* - With two or more cuts, the curves of the stop are not smooth functions of the curves of the cuts. Thus the delta method does not apply.
|
|
817
|
-
* The interval comes from a parametric bootstrap of the curves of the cuts (since 0.8.31).
|
|
823
|
+
* The interval comes from a parametric bootstrap of the curves of the cuts (since 0.8.31).
|
|
824
|
+
* - It is equal to `intervals.event`. `intervals` also gives the intervals of the independent and upper curves.
|
|
818
825
|
*/
|
|
819
826
|
readonly interval?: ChanceInterval | undefined;
|
|
827
|
+
/**
|
|
828
|
+
* The 95% interval of the change of each curve of the stop. It is present when `interval` is present. Since 0.8.32.
|
|
829
|
+
*
|
|
830
|
+
* - With one cut, the three changes are equal. Thus the three intervals are the interval of the delta method.
|
|
831
|
+
* - With two or more cuts, one bootstrap gives the three intervals. Each run makes the three curves of the stop from the same drawn curves.
|
|
832
|
+
* - When `StopCurves.independentUpper` is true, the independent curve is the upper curve. Then their intervals are equal.
|
|
833
|
+
* - Each interval has the rules of `interval`, and the same kink caveat. The upper curve has a kink where the sum of the chances reaches 1.
|
|
834
|
+
*/
|
|
835
|
+
readonly intervals?: CurveIntervals | undefined;
|
|
820
836
|
/** The values before the step at the two ends of the sampling bands of the cuts (`DrawOutlook.band`). */
|
|
821
837
|
readonly beforeBand?: DrawBand | undefined;
|
|
822
838
|
/** The values after the step at the two ends of the sampling bands of the cuts. */
|
|
@@ -892,13 +908,13 @@ export interface Sensitivity {
|
|
|
892
908
|
* - With one cut, the interval comes from the delta method of the Greenwood sums.
|
|
893
909
|
* - With two or more cuts, the interval comes from a parametric bootstrap of the curves of the cuts (`survivalBootstrap` of rigor-statistics).
|
|
894
910
|
* Each run draws each curve, makes the event curve of the stop from the drawn curves, and reads the change. The draws of the cuts are independent.
|
|
895
|
-
* -
|
|
896
|
-
* - The bootstrap is correct only for large samples. At a kink of
|
|
911
|
+
* - `intervals` gives the interval of the change of each of the three curves. One bootstrap gives the three, from the same runs (since 0.8.32).
|
|
912
|
+
* - The bootstrap is correct only for large samples. At a kink of a curve, its coverage is less than 95%.
|
|
897
913
|
* An example is two cuts with equal curves under a maximum: the coverage of a percentile interval is near 0.89 there.
|
|
898
914
|
* - The seed of the bootstrap is the hash of the case, the need and the input. The same query gives the same interval.
|
|
899
915
|
*
|
|
900
916
|
* The cost is one `enduranceOf` and one `caseOutlook` for each input, and one `stopRebuild` for each draw of the base.
|
|
901
|
-
* With two or more cuts, the
|
|
917
|
+
* With two or more cuts, the intervals of each draw and each input add `runs` draws of the curves and `runs` uses of `StopRebuild.curvesWith`.
|
|
902
918
|
* The function is pure.
|
|
903
919
|
*
|
|
904
920
|
* @param layer - The endurance layer
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":["CutBound"],"sources":["../src/converter.ts","../src/supply.ts","../src/calendar.ts","../src/endurance.ts","../src/joint.ts","../src/best.ts","../src/shortfall.ts","../src/check.ts","../src/join.ts","../src/sample.ts","../src/sensitivity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A;;;iBAIM;WACN,OAAO;WACP,aAAa;WACb,OAAO;;;;;;iBAOD;;WAEN,QAAQ;;WAER,OAAO;;WAEP,QAAQ;;;;;;;;;;;;WAYR,WAAW;;;;;;;;;WASX,YAAY;;WAEZ,aAAa;;WAEb,YAAY;;;iBAIN;WACN;WACA;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA,SAAS;;;iBAIH;;;;;WAKN;WACA,MAAM;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA,gBAAgB;;WAEhB,QAAQ,SAAS;;;iBAIX;WACN;WACA,IAAI;;WAEJ;;WAEA,MAAM;;WAEN,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAiSZ,qBAAqB,OAAO,gBAAgB,UAAU,UAAU,SAAS,qBAAqB;;;;;;;iBCza7F;;WAEN;;WAEA,QAAQ,SAAS;;;iBAIX;;WAEN;;;YAIC;;iBAGK;WACN;WACA,MAAM;WACN;WACA;;WAEA;;WAEA,SAAS,SAAS;;WAElB,WAAW,SAAS;;;iBAId;WACN;WACA,MAAM;WACN;WACA;;WAEA,SAAS,SAAS;WAClB,QAAQ;;;iBAIF;WACN;WACA,IAAI;;WAEJ;;WAEA,iBAAiB;;WAEjB,mBAAmB;;WAEnB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAgDK,cAAc,aAAa,aAAa,QAAQ,YAAY,SAAS,uBAAuB"}
|
package/build/index.js
CHANGED
|
@@ -5,7 +5,7 @@ import { ONE, ZERO, add, div, equals, fromFloat, mul, neg, sign, sub, toNumber }
|
|
|
5
5
|
import { solveLexicographic } from "@mark1russell7/linear";
|
|
6
6
|
import { pathSetReliability, stronglyConnectedComponents } from "@mark1russell7/collections/graph";
|
|
7
7
|
import { canonicalJson, seedOf } from "@mark1russell7/rigor-generators";
|
|
8
|
-
import { Z95, greenwoodRead, kaplanMeier,
|
|
8
|
+
import { Z95, greenwoodRead, kaplanMeier, survivalBootstrapMany, survivalCombination } from "@mark1russell7/rigor-statistics";
|
|
9
9
|
// src/fit.ts
|
|
10
10
|
/** The relative tolerance of a take and of a fit. */
|
|
11
11
|
const TOLERANCE = 1e-13;
|
|
@@ -3452,39 +3452,56 @@ function clampOf(before, after, horizon) {
|
|
|
3452
3452
|
return (value) => Math.min(ceiling, Math.max(floor, value));
|
|
3453
3453
|
}
|
|
3454
3454
|
/**
|
|
3455
|
-
* This function gives the
|
|
3456
|
-
* The
|
|
3455
|
+
* This function gives the intervals of the change of the chance of the three curves of the stop.
|
|
3456
|
+
* The intervals come from one parametric bootstrap of the curves of two or more cuts.
|
|
3457
3457
|
*
|
|
3458
3458
|
* - Each run draws the curve of each used cut with `survivalDraw` of rigor-statistics, at the points of its curve.
|
|
3459
|
-
* - The run makes the
|
|
3460
|
-
* - It reads the chance before and after the step as `caseOutlook` reads `lasts`. The
|
|
3461
|
-
* - The
|
|
3462
|
-
*
|
|
3463
|
-
* -
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
|
|
3471
|
-
|
|
3459
|
+
* - The run makes the three curves of the stop from the drawn curves, with the same minimal sets (`StopRebuild.curvesWith`).
|
|
3460
|
+
* - It reads the chance of each curve before and after the step as `caseOutlook` reads `lasts`. The three statistics are the changes.
|
|
3461
|
+
* - The intervals are the percentile intervals of `survivalBootstrapMany`, clamped as the interval of one cut.
|
|
3462
|
+
* The draws are those of `survivalBootstrap` with the same seed. Thus the event interval is the event interval of 0.8.31.
|
|
3463
|
+
* - When the days do not change in the horizon, the change is 0 in each run. Then each interval is 0 to 0 with no runs.
|
|
3464
|
+
* - The seed is the hash of the case, the need and the input. Thus the same query gives the same intervals.
|
|
3465
|
+
*/
|
|
3466
|
+
function cutsChangeIntervals(cuts, before, after, horizon, runs, seed) {
|
|
3467
|
+
if (before === after || before >= horizon && after >= horizon) {
|
|
3468
|
+
const none = {
|
|
3469
|
+
se: 0,
|
|
3470
|
+
low: 0,
|
|
3471
|
+
high: 0,
|
|
3472
|
+
runs
|
|
3473
|
+
};
|
|
3474
|
+
return {
|
|
3475
|
+
event: none,
|
|
3476
|
+
independent: none,
|
|
3477
|
+
upper: none
|
|
3478
|
+
};
|
|
3479
|
+
}
|
|
3472
3480
|
const lasts = (curve, days) => days >= horizon ? 1 : 1 - survivalAt(curve, days);
|
|
3473
|
-
const
|
|
3481
|
+
const statistics = (chances) => {
|
|
3474
3482
|
const curves = cuts.reads.map((reads, k) => reads.map((read, at) => [read.time, chances[k]?.[at] ?? 0]));
|
|
3475
|
-
const
|
|
3476
|
-
return
|
|
3483
|
+
const stop = cuts.stop.curvesWith(curves);
|
|
3484
|
+
return [
|
|
3485
|
+
stop.event,
|
|
3486
|
+
stop.independent,
|
|
3487
|
+
stop.upper
|
|
3488
|
+
].map((curve) => lasts(curve, after) - lasts(curve, before));
|
|
3477
3489
|
};
|
|
3478
|
-
const
|
|
3490
|
+
const clamp = clampOf(before, after, horizon);
|
|
3491
|
+
const [event, independent, upper] = survivalBootstrapMany(cuts.reads, statistics, {
|
|
3479
3492
|
runs,
|
|
3480
3493
|
seed
|
|
3481
|
-
})
|
|
3482
|
-
const clamp = clampOf(before, after, horizon);
|
|
3483
|
-
return {
|
|
3494
|
+
}).map(({ low, high }) => ({
|
|
3484
3495
|
se: (high - low) / (2 * Z95),
|
|
3485
3496
|
low: clamp(low),
|
|
3486
3497
|
high: clamp(high),
|
|
3487
3498
|
runs
|
|
3499
|
+
}));
|
|
3500
|
+
if (event === void 0 || independent === void 0 || upper === void 0) throw new Error("survivalBootstrapMany gave fewer than 3 intervals.");
|
|
3501
|
+
return {
|
|
3502
|
+
event,
|
|
3503
|
+
independent,
|
|
3504
|
+
upper
|
|
3488
3505
|
};
|
|
3489
3506
|
}
|
|
3490
3507
|
/** This function compares two inputs for the rank: the sums of the levels in the order of the levels, the largest first, then the key. */
|
|
@@ -3521,13 +3538,13 @@ function rankOrder$1(levels) {
|
|
|
3521
3538
|
* - With one cut, the interval comes from the delta method of the Greenwood sums.
|
|
3522
3539
|
* - With two or more cuts, the interval comes from a parametric bootstrap of the curves of the cuts (`survivalBootstrap` of rigor-statistics).
|
|
3523
3540
|
* Each run draws each curve, makes the event curve of the stop from the drawn curves, and reads the change. The draws of the cuts are independent.
|
|
3524
|
-
* -
|
|
3525
|
-
* - The bootstrap is correct only for large samples. At a kink of
|
|
3541
|
+
* - `intervals` gives the interval of the change of each of the three curves. One bootstrap gives the three, from the same runs (since 0.8.32).
|
|
3542
|
+
* - The bootstrap is correct only for large samples. At a kink of a curve, its coverage is less than 95%.
|
|
3526
3543
|
* An example is two cuts with equal curves under a maximum: the coverage of a percentile interval is near 0.89 there.
|
|
3527
3544
|
* - The seed of the bootstrap is the hash of the case, the need and the input. The same query gives the same interval.
|
|
3528
3545
|
*
|
|
3529
3546
|
* The cost is one `enduranceOf` and one `caseOutlook` for each input, and one `stopRebuild` for each draw of the base.
|
|
3530
|
-
* With two or more cuts, the
|
|
3547
|
+
* With two or more cuts, the intervals of each draw and each input add `runs` draws of the curves and `runs` uses of `StopRebuild.curvesWith`.
|
|
3531
3548
|
* The function is pure.
|
|
3532
3549
|
*
|
|
3533
3550
|
* @param layer - The endurance layer
|
|
@@ -3568,18 +3585,26 @@ function enduranceSensitivity(layer, caseCuts, options) {
|
|
|
3568
3585
|
const to = outlook?.get(need);
|
|
3569
3586
|
const read = counted.get(need);
|
|
3570
3587
|
const moved = from === void 0 || to === void 0 ? void 0 : minus(to.lasts, from.lasts);
|
|
3571
|
-
const
|
|
3588
|
+
const one = read?.kind === "one" && from !== void 0 && to !== void 0 && moved !== void 0 ? changeInterval(read.curve, from.days, to.days, horizon, moved.event) : void 0;
|
|
3589
|
+
const intervals = one !== void 0 ? {
|
|
3590
|
+
event: one,
|
|
3591
|
+
independent: one,
|
|
3592
|
+
upper: one
|
|
3593
|
+
} : read?.kind === "many" && from !== void 0 && to !== void 0 ? cutsChangeIntervals(read.cuts, from.days, to.days, horizon, runs, seedOf(canonicalJson([
|
|
3572
3594
|
caseCuts.case,
|
|
3573
3595
|
need,
|
|
3574
3596
|
variant.id
|
|
3575
|
-
])));
|
|
3597
|
+
]))) : void 0;
|
|
3576
3598
|
const chance = from === void 0 || to === void 0 || moved === void 0 ? {} : { chance: {
|
|
3577
3599
|
before: from.lasts,
|
|
3578
3600
|
after: to.lasts,
|
|
3579
3601
|
change: moved,
|
|
3580
3602
|
...from.band === void 0 ? {} : { beforeBand: from.band },
|
|
3581
3603
|
...to.band === void 0 ? {} : { afterBand: to.band },
|
|
3582
|
-
...
|
|
3604
|
+
...intervals === void 0 ? {} : {
|
|
3605
|
+
interval: intervals.event,
|
|
3606
|
+
intervals
|
|
3607
|
+
}
|
|
3583
3608
|
} };
|
|
3584
3609
|
return {
|
|
3585
3610
|
need,
|