@mark1russell7/stack-endurance 0.8.29 → 0.8.31
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 +11 -4
- package/build/add-on.js +1 -1
- package/build/index.d.ts +77 -15
- package/build/index.d.ts.map +1 -1
- package/build/index.js +191 -47
- package/build/index.js.map +1 -1
- package/build/{join-NN0eFb6s.js → join-CsR-FKzr.js} +7 -3
- package/build/join-CsR-FKzr.js.map +1 -0
- package/build/schema.d.ts.map +1 -1
- package/build/schema.js +1 -0
- package/build/schema.js.map +1 -1
- package/package.json +4 -4
- package/build/join-NN0eFb6s.js.map +0 -1
package/README.md
CHANGED
|
@@ -100,6 +100,8 @@ A cut can have no `duration`, as before a source gives its curve. Then each draw
|
|
|
100
100
|
|
|
101
101
|
The gate checks the counts of a cut (`Cut.counts`) with `countsFault` of the core. Counts that do not give the curve of the cut, or counts on a cut with no curve, are the error `endurance-curve`. Since 0.8.27.
|
|
102
102
|
|
|
103
|
+
The gate checks the sums of a cut (`Cut.sums`) with `sumsFault` of the core in the same way. Since 0.8.30.
|
|
104
|
+
|
|
103
105
|
Since 0.8.4, `stopCurves`, `caseShortfall` and `yearShortfall` give a `bound`: the weakest bound of the curves that the result uses (`weakestBound` of the core). A cut with no `bound` has a law. The shortfall does not decrease when a cut lasts longer, so the bound of each curve carries to the result.
|
|
104
106
|
|
|
105
107
|
| Bounds of the curves | Bound of the result |
|
|
@@ -146,10 +148,15 @@ Two groups of cuts that share no minimal set are independent, so the independent
|
|
|
146
148
|
- The rank is by level, as the take order. It compares the sum of the changes of the first level, then of the next level, and so on. The largest sum comes first. Two equal inputs go in the order of their keys.
|
|
147
149
|
- `chance` gives the chance that the draw gets its need through the event (`lasts` of `caseOutlook`), before and after the step. It also gives the values at the two ends of the sampling bands of the cuts, before and after the step. The change of the chance is the change of the point values.
|
|
148
150
|
- `chance.interval` gives the 95% interval of the change (`ChanceInterval`: `se`, `low` and `high`). Since 0.8.27 (M2-sensitivity-interval).
|
|
149
|
-
-
|
|
150
|
-
-
|
|
151
|
-
-
|
|
152
|
-
-
|
|
151
|
+
- Each cut that the stop of the draw uses (`stopCuts`) must have sums (`Cut.sums` of the core) or counts (`Cut.counts`) with no fault. Else the interval is absent.
|
|
152
|
+
- Since 0.8.30, the sums give the interval with no counts. When a cut has good sums and good counts, the sums come first. The two give the same interval.
|
|
153
|
+
- With one cut, the change is a weighted sum of the chances of the Kaplan-Meier curve at up to four days. A read between two points of the curve has a weight on each point.
|
|
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
|
+
- 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
|
+
- 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
|
+
- This interval is for `change.event` only. `interval.runs` gives the count of runs. The option `runs` sets it, and the default is `SENSITIVITY_RUNS`, 1000.
|
|
158
|
+
- The seed is the hash of the case, the need and the input. Thus the same query gives the same interval.
|
|
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%.
|
|
153
160
|
|
|
154
161
|
An example on the sample:
|
|
155
162
|
|
package/build/add-on.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as checkEndurance, t as joinEndurance } from "./join-
|
|
1
|
+
import { r as checkEndurance, t as joinEndurance } from "./join-CsR-FKzr.js";
|
|
2
2
|
import { t as ENDURANCE_SCHEMA } from "./layer-a3Fr70Uh.js";
|
|
3
3
|
import { parseEndurance } from "./schema.js";
|
|
4
4
|
// src/add-on.ts
|
package/build/index.d.ts
CHANGED
|
@@ -433,6 +433,36 @@ export declare function stopCurves(caseCuts: CaseCuts, draw: Draw, options?: Sto
|
|
|
433
433
|
* @throws RangeError for a bad `maxSets` or `maxWork`
|
|
434
434
|
*/
|
|
435
435
|
export declare function stopCuts(caseCuts: CaseCuts, draw: Draw, options?: StopCurveOptions): readonly number[] | undefined;
|
|
436
|
+
/**
|
|
437
|
+
* The cuts of the stop of a draw, and a function that gives the curves of the stop for other curves of these cuts. Since 0.8.31.
|
|
438
|
+
* A parametric bootstrap draws the curve of each used cut, and `curvesWith` gives the curves of the stop of each draw.
|
|
439
|
+
*/
|
|
440
|
+
export interface StopRebuild {
|
|
441
|
+
/** The cuts that the stop uses, as indexes in `caseCuts.cuts`: the result of `stopCuts`. */
|
|
442
|
+
readonly used: readonly number[];
|
|
443
|
+
/** The curves of the stop (`stopCurves`) with the curves of the cuts in the case. */
|
|
444
|
+
readonly curves: StopCurves;
|
|
445
|
+
/**
|
|
446
|
+
* This function gives the curves of the stop when each used cut has the curve at its place in `used`. Each other cut keeps its curve.
|
|
447
|
+
* The minimal sets, the budgets and the bound are those of `curves`. Each curve must be good for `checkEndurance`.
|
|
448
|
+
*/
|
|
449
|
+
readonly curvesWith: (curves: readonly Survival[]) => StopCurves;
|
|
450
|
+
/** This function gives only the `event` curve of `curvesWith`. It does not calculate the other two curves, so it costs less. */
|
|
451
|
+
readonly eventWith: (curves: readonly Survival[]) => Survival;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* This function gives the cuts of the stop of a draw and the curves of the stop for other curves of these cuts. Since 0.8.31.
|
|
455
|
+
*
|
|
456
|
+
* - The sets of cuts come from the needs and the parts of the case, not from the curves. Thus one search of the sets serves each call of `curvesWith`.
|
|
457
|
+
* - `curvesWith` uses the same functions as `stopCurves`: `eventStop`, `independentStop` and `upperStop`.
|
|
458
|
+
* - The result is `undefined` when `stopCurves` gives `undefined`.
|
|
459
|
+
*
|
|
460
|
+
* @param caseCuts - The case
|
|
461
|
+
* @param draw - The draw
|
|
462
|
+
* @param options - The stack or the parts that are also down, and the budgets: as for `stopCurves`
|
|
463
|
+
* @throws RangeError for a bad `maxSets` or `maxWork`
|
|
464
|
+
*/
|
|
465
|
+
export declare function stopRebuild(caseCuts: CaseCuts, draw: Draw, options?: StopCurveOptions): StopRebuild | undefined;
|
|
436
466
|
/** The shortfall of each level, in user-days, and the draws that the query cannot read. */
|
|
437
467
|
export interface Shortfall {
|
|
438
468
|
/**
|
|
@@ -659,7 +689,8 @@ export declare function caseOutlook(layer: EnduranceLayer, caseCuts: CaseCuts, o
|
|
|
659
689
|
* A converter with a limit can take nothing: it is a source, for example a solar panel. Since 0.8.20 (M2-solar).
|
|
660
690
|
* - `endurance-curve`: a survival curve does not start at `[0, 1]`, or it does not end at a chance of 0.
|
|
661
691
|
* Or its days do not increase, or its chance increases.
|
|
662
|
-
* Or the band or the
|
|
692
|
+
* Or the band, the counts or the sums of a cut do not agree with its curve (`bandFault`, `countsFault`, `sumsFault`).
|
|
693
|
+
* Or the cut has them and no curve.
|
|
663
694
|
* - `endurance-bound`: the bound of a cut is not a value of `CUT_BOUNDS` of the core. Since 0.8.4.
|
|
664
695
|
* - `endurance-prior-case`: a prior names a case that the layer does not have.
|
|
665
696
|
* - `endurance-cycle`: converters make a resource from itself, through one converter or a chain. One fault names each cycle.
|
|
@@ -726,23 +757,43 @@ export declare const SAMPLE_ENDURANCE_STACK: Stack;
|
|
|
726
757
|
export declare const SAMPLE_ENDURANCE: EnduranceLayer;
|
|
727
758
|
/** The default step of `enduranceSensitivity`: 1 unit of each input. */
|
|
728
759
|
export declare const SENSITIVITY_STEP = 1;
|
|
729
|
-
/**
|
|
760
|
+
/**
|
|
761
|
+
* The default count of the runs of the bootstrap of the interval of a stop of two or more cuts (`SensitivityOptions.runs`). Since 0.8.31.
|
|
762
|
+
* One call on a test layer of one store, one draw and two cuts of 10 points each took approximately 40 ms at this default.
|
|
763
|
+
* The time is near the runs times the inputs whose step changes the days.
|
|
764
|
+
*/
|
|
765
|
+
export declare const SENSITIVITY_RUNS = 1e3;
|
|
766
|
+
/** The options of `enduranceSensitivity`: the options of a case, the horizon of the chance, the step and the runs of the bootstrap. */
|
|
730
767
|
export interface SensitivityOptions extends CaseOptions, ShortfallOptions {
|
|
731
768
|
/** The step of each input, a number more than 0, in the unit of the input. The default is `SENSITIVITY_STEP`. */
|
|
732
769
|
readonly step?: number | undefined;
|
|
770
|
+
/**
|
|
771
|
+
* The count of the runs of the bootstrap of the interval of a stop of two or more cuts, a whole number from 1. Since 0.8.31.
|
|
772
|
+
* The default is `SENSITIVITY_RUNS`. The cost of the interval of each draw and each input is near this count times one `eventStop`.
|
|
773
|
+
*/
|
|
774
|
+
readonly runs?: number | undefined;
|
|
733
775
|
}
|
|
734
776
|
/** The kind of an input: the amount of a store, the rate of a draw, or a parameter of a converter. */
|
|
735
777
|
export type SensitivityKind = "store" | "draw" | "converter";
|
|
736
778
|
/**
|
|
737
|
-
* The 95% interval of the change of the chance (`SensitivityChance.change`), from the sampling error of the
|
|
738
|
-
*
|
|
739
|
-
*
|
|
779
|
+
* The 95% interval of the change of the chance (`SensitivityChance.change`), from the sampling error of the curves of the cuts. Since 0.8.27.
|
|
780
|
+
*
|
|
781
|
+
* - With one cut, the ends are the change minus and plus `Z95` times `se`. It is a Wald interval.
|
|
782
|
+
* Near the ends of the range, its coverage can be less than 95%.
|
|
783
|
+
* - With two or more cuts, the ends come from a parametric bootstrap of the curves of the cuts (since 0.8.31). Refer to `enduranceSensitivity`.
|
|
784
|
+
* - The ends are clamped to 0 to 1, or to -1 to 0 for a change down.
|
|
740
785
|
*/
|
|
741
786
|
export interface ChanceInterval {
|
|
742
|
-
/**
|
|
787
|
+
/**
|
|
788
|
+
* The standard error of the change. With one cut, it is the Greenwood standard error.
|
|
789
|
+
* It includes the covariance of the chances of the curve at the days before and after the step.
|
|
790
|
+
* With two or more cuts, it is the width of the bootstrap interval before the clamp, divided by `2 * Z95`.
|
|
791
|
+
*/
|
|
743
792
|
readonly se: number;
|
|
744
793
|
readonly low: number;
|
|
745
794
|
readonly high: number;
|
|
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
|
+
readonly runs?: number | undefined;
|
|
746
797
|
}
|
|
747
798
|
/**
|
|
748
799
|
* The change in the chance that a draw gets its need through the event (`DrawOutlook.lasts`), for one input.
|
|
@@ -756,12 +807,14 @@ export interface SensitivityChance {
|
|
|
756
807
|
/** The chance after the step minus the chance before it, for each curve. It is the change of the point values. */
|
|
757
808
|
readonly change: CurveValues;
|
|
758
809
|
/**
|
|
759
|
-
* The 95% interval of `change
|
|
760
|
-
*
|
|
761
|
-
* Without counts, the interval is
|
|
810
|
+
* The 95% interval of `change.event`. Since 0.8.27.
|
|
811
|
+
* Each cut that the stop of the draw uses must have sums (`Cut.sums`) or counts (`Cut.counts`) with no fault.
|
|
812
|
+
* Without sums and counts, the interval is absent. Since 0.8.30, the sums give the interval with no counts.
|
|
762
813
|
*
|
|
763
|
-
* With
|
|
764
|
-
*
|
|
814
|
+
* - With one cut, the three curves of the stop are the curve of the cut, so the three changes are equal.
|
|
815
|
+
* The interval comes from the delta method (`survivalCombination`).
|
|
816
|
+
* - 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). It is for `change.event` only.
|
|
765
818
|
*/
|
|
766
819
|
readonly interval?: ChanceInterval | undefined;
|
|
767
820
|
/** The values before the step at the two ends of the sampling bands of the cuts (`DrawOutlook.band`). */
|
|
@@ -834,10 +887,19 @@ export interface Sensitivity {
|
|
|
834
887
|
* - The days are exact for the inputs. `chance` is the chance that a draw gets its need through the event. It comes
|
|
835
888
|
* from `caseOutlook` with the share `take`, before and after the step, with the bands of the cuts. The change of the
|
|
836
889
|
* chance is the change of the point values.
|
|
837
|
-
* - The change has a 95% interval (`SensitivityChance.interval`) when the stop of the draw
|
|
838
|
-
* A
|
|
839
|
-
*
|
|
840
|
-
*
|
|
890
|
+
* - The change has a 95% interval (`SensitivityChance.interval`) when each cut of the stop of the draw (`stopCuts`) has sums or counts.
|
|
891
|
+
* A cut with no sums and no counts, or with only reads that have a fault, gives no interval.
|
|
892
|
+
* - With one cut, the interval comes from the delta method of the Greenwood sums.
|
|
893
|
+
* - With two or more cuts, the interval comes from a parametric bootstrap of the curves of the cuts (`survivalBootstrap` of rigor-statistics).
|
|
894
|
+
* 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
|
+
* - The bootstrap interval is for `change.event` only. The type has one interval, so the independent and upper curves have none.
|
|
896
|
+
* - The bootstrap is correct only for large samples. At a kink of the event curve, its coverage is less than 95%.
|
|
897
|
+
* An example is two cuts with equal curves under a maximum: the coverage of a percentile interval is near 0.89 there.
|
|
898
|
+
* - The seed of the bootstrap is the hash of the case, the need and the input. The same query gives the same interval.
|
|
899
|
+
*
|
|
900
|
+
* 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 interval of each draw and each input adds `runs` draws of the curves and `runs` uses of `eventStop`.
|
|
902
|
+
* The function is pure.
|
|
841
903
|
*
|
|
842
904
|
* @param layer - The endurance layer
|
|
843
905
|
* @param caseCuts - The case
|
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.ts","../src/buy.ts"],"mappings":";;;;;;wBAegB,SAAS,WAAW;;wBAwBpB,SAAS,WAAW;;wBAKpB,aAAa,WAAW;;wBAKxB,cAAc,YAAY,SAAS,aAAa;;wBAOhD,QAAQ,QAAQ,wCAAwC,aAAa;;wBCnDrE,WAAW,MAAM,MAAM,UAAU;;UAKhC;WACN;WACA;WACA;WACA;;;UAIM;;WAEN,OAAO;WACP,UAAU;;WAEV,eAAe;;WAEf;;WAEA,O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;;;;;;;wBAoDhB,UAAU,iBAAiB,YAAY,QAAQ,sCAAsC;;;;;;;;wBAiBrF,YAAY,iBAAiB,aAAa;;;;;qBAU7C;;;;;wBAMG,aAAa,eAAe,QAAQ;;;;;;;;;;wBA8BpC,UAAU,iBAAiB,YAAY,mDAAmD;;qBAiB7F;;;;;;qBAOA;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA6BG,gBAAgB,iBAAiB,YAAY,kDAAkD,mBAAyC;;;;;iBAiKvI;WACN,OAAO;;WAEP,aAAa;WACb,OAAO;;;;;WAKP;;WAEA;;;;;;WAMA,OAAOA;;;;;;;;;;;;;;;;
|
|
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.ts","../src/buy.ts"],"mappings":";;;;;;wBAegB,SAAS,WAAW;;wBAwBpB,SAAS,WAAW;;wBAKpB,aAAa,WAAW;;wBAKxB,cAAc,YAAY,SAAS,aAAa;;wBAOhD,QAAQ,QAAQ,wCAAwC,aAAa;;wBCnDrE,WAAW,MAAM,MAAM,UAAU;;UAKhC;WACN;WACA;WACA;WACA;;;UAIM;;WAEN,OAAO;WACP,UAAU;;WAEV,eAAe;;WAEf;;WAEA,OAAO;;;wBCZF,QAAQ,OAAO,SAAS;;;;;wBASxB,WAAW,OAAO,SAAS;;iBCX1B;;WAEN,IAAI;;WAEJ,QAAQ;;WAER;;;;;;WAMA,QAAQ;;;;;;WAMR;;;qBAIE;;;;;wBAMG,YAAY,UAAU,UAAU,SAAS,KAAK,iCAAiC;;;;;;;wBAqB/E,aAAa,OAAO,gBAAgB,IAAI,SAAS,eAAc,sBAAkC;;;;;wBAejG,UAAU,OAAO,gBAAgB,UAAU,UAAU,cAAc,sBAAsB;;;;;;;;wBAyMzF,QAAQ,QAAQ,KAAK,wBAAwB,OAAO,S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;;;wBAgDK,cAAc,aAAa,aAAa,QAAQ,YAAY,SAAS,uBAAuB"}
|
package/build/index.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { t as ENDURANCE_SCHEMA } from "./layer-a3Fr70Uh.js";
|
|
2
|
-
import { a as hasEnduranceError, c as giftNeed, d as isSource, f as monthlyShares, i as curveFault, l as giftResource, n as ENDURANCE_CODES, o as canRun, p as shareOf, r as checkEndurance, s as deviceKey, t as joinEndurance, u as inputsOf } from "./join-
|
|
3
|
-
import { DEFAULT_MAX_SETS, STACK_SCHEMA, countsFault, dateOfDay, dayNumber, neededParts, stopSets, stopped, survivalAt, weakestBound } from "@mark1russell7/system-stack";
|
|
2
|
+
import { a as hasEnduranceError, c as giftNeed, d as isSource, f as monthlyShares, i as curveFault, l as giftResource, n as ENDURANCE_CODES, o as canRun, p as shareOf, r as checkEndurance, s as deviceKey, t as joinEndurance, u as inputsOf } from "./join-CsR-FKzr.js";
|
|
3
|
+
import { DEFAULT_MAX_SETS, STACK_SCHEMA, countsFault, dateOfDay, dayNumber, neededParts, stopSets, stopped, sumsFault, survivalAt, weakestBound } from "@mark1russell7/system-stack";
|
|
4
4
|
import { ONE, ZERO, add, div, equals, fromFloat, mul, neg, sign, sub, toNumber } from "@mark1russell7/rational";
|
|
5
5
|
import { solveLexicographic } from "@mark1russell7/linear";
|
|
6
6
|
import { pathSetReliability, stronglyConnectedComponents } from "@mark1russell7/collections/graph";
|
|
7
|
-
import {
|
|
7
|
+
import { canonicalJson, seedOf } from "@mark1russell7/rigor-generators";
|
|
8
|
+
import { Z95, greenwoodRead, kaplanMeier, survivalBootstrap, survivalCombination } from "@mark1russell7/rigor-statistics";
|
|
8
9
|
// src/fit.ts
|
|
9
10
|
/** The relative tolerance of a take and of a fit. */
|
|
10
11
|
const TOLERANCE = 1e-13;
|
|
@@ -2550,23 +2551,35 @@ function stopReadWith(caseCuts, draw, options, stoppedOf) {
|
|
|
2550
2551
|
const unsourced = given.flatMap((curve, index) => curve === void 0 ? [index] : []);
|
|
2551
2552
|
if (unsourced.length > 0 && (sets === void 0 || sets.some((set) => set.some((index) => unsourced.includes(index))))) return void 0;
|
|
2552
2553
|
const kept = given.flatMap((curve, index) => curve === void 0 ? [] : [index]);
|
|
2553
|
-
const
|
|
2554
|
+
const base = kept.map((index) => given[index] ?? []);
|
|
2554
2555
|
const keptStops = (cuts) => stops(cuts.map((index) => kept[index] ?? -1));
|
|
2555
2556
|
const keptSets = sets?.map((set) => set.map((index) => kept.indexOf(index)));
|
|
2556
|
-
const
|
|
2557
|
-
const independent = independentStop(curves, keptSets, budgetsOf(options).maxWork);
|
|
2557
|
+
const { maxWork } = budgetsOf(options);
|
|
2558
2558
|
const used = sets === void 0 ? kept : kept.filter((index) => sets.some((set) => set.includes(index)));
|
|
2559
2559
|
const bound = weakestBound(used.map((index) => caseCuts.cuts[relevant[index] ?? -1]?.bound ?? "law"));
|
|
2560
|
-
|
|
2561
|
-
curves
|
|
2560
|
+
const curvesOf = (curves) => {
|
|
2561
|
+
const upper = upperStop(curves, keptSets);
|
|
2562
|
+
const independent = independentStop(curves, keptSets, maxWork);
|
|
2563
|
+
return {
|
|
2562
2564
|
event: eventStop(curves, keptStops),
|
|
2563
2565
|
independent: independent ?? upper,
|
|
2564
2566
|
upper,
|
|
2565
2567
|
coarse: keptSets === void 0,
|
|
2566
2568
|
independentUpper: independent === void 0,
|
|
2567
2569
|
bound
|
|
2568
|
-
}
|
|
2569
|
-
|
|
2570
|
+
};
|
|
2571
|
+
};
|
|
2572
|
+
const places = used.map((index) => kept.indexOf(index));
|
|
2573
|
+
const changed = (curves) => {
|
|
2574
|
+
const out = [...base];
|
|
2575
|
+
for (const [at, place] of places.entries()) out[place] = curves[at] ?? base[place] ?? [];
|
|
2576
|
+
return out;
|
|
2577
|
+
};
|
|
2578
|
+
return {
|
|
2579
|
+
curves: curvesOf(base),
|
|
2580
|
+
used: used.map((index) => relevant[index] ?? -1),
|
|
2581
|
+
curvesWith: (curves) => curvesOf(changed(curves)),
|
|
2582
|
+
eventWith: (curves) => eventStop(changed(curves), keptStops)
|
|
2570
2583
|
};
|
|
2571
2584
|
}
|
|
2572
2585
|
function stopCurvesWith(caseCuts, draw, options, stoppedOf) {
|
|
@@ -2605,6 +2618,22 @@ function stopCuts(caseCuts, draw, options = {}) {
|
|
|
2605
2618
|
budgetsOf(options);
|
|
2606
2619
|
return stopReadWith(caseCuts, draw, options, stoppedMemo(caseCuts, options))?.used;
|
|
2607
2620
|
}
|
|
2621
|
+
/**
|
|
2622
|
+
* This function gives the cuts of the stop of a draw and the curves of the stop for other curves of these cuts. Since 0.8.31.
|
|
2623
|
+
*
|
|
2624
|
+
* - The sets of cuts come from the needs and the parts of the case, not from the curves. Thus one search of the sets serves each call of `curvesWith`.
|
|
2625
|
+
* - `curvesWith` uses the same functions as `stopCurves`: `eventStop`, `independentStop` and `upperStop`.
|
|
2626
|
+
* - The result is `undefined` when `stopCurves` gives `undefined`.
|
|
2627
|
+
*
|
|
2628
|
+
* @param caseCuts - The case
|
|
2629
|
+
* @param draw - The draw
|
|
2630
|
+
* @param options - The stack or the parts that are also down, and the budgets: as for `stopCurves`
|
|
2631
|
+
* @throws RangeError for a bad `maxSets` or `maxWork`
|
|
2632
|
+
*/
|
|
2633
|
+
function stopRebuild(caseCuts, draw, options = {}) {
|
|
2634
|
+
budgetsOf(options);
|
|
2635
|
+
return stopReadWith(caseCuts, draw, options, stoppedMemo(caseCuts, options));
|
|
2636
|
+
}
|
|
2608
2637
|
function zeroLevels(layer) {
|
|
2609
2638
|
return Object.fromEntries(layer.levels.map((level) => [level, 0]));
|
|
2610
2639
|
}
|
|
@@ -3132,6 +3161,12 @@ const SAMPLE_ENDURANCE = {
|
|
|
3132
3161
|
// src/sensitivity.ts
|
|
3133
3162
|
/** The default step of `enduranceSensitivity`: 1 unit of each input. */
|
|
3134
3163
|
const SENSITIVITY_STEP = 1;
|
|
3164
|
+
/**
|
|
3165
|
+
* The default count of the runs of the bootstrap of the interval of a stop of two or more cuts (`SensitivityOptions.runs`). Since 0.8.31.
|
|
3166
|
+
* One call on a test layer of one store, one draw and two cuts of 10 points each took approximately 40 ms at this default.
|
|
3167
|
+
* The time is near the runs times the inputs whose step changes the days.
|
|
3168
|
+
*/
|
|
3169
|
+
const SENSITIVITY_RUNS = 1e3;
|
|
3135
3170
|
/** This function gives the size of a step down from a value. It is the step, or half the value when the value is not more than the step. */
|
|
3136
3171
|
function stepDown(value, step) {
|
|
3137
3172
|
return value > step ? step : value / 2;
|
|
@@ -3291,17 +3326,77 @@ function estimateOf(counts) {
|
|
|
3291
3326
|
});
|
|
3292
3327
|
return kaplanMeier(observations);
|
|
3293
3328
|
}
|
|
3294
|
-
/**
|
|
3295
|
-
function
|
|
3329
|
+
/**
|
|
3330
|
+
* This function gives the Greenwood reads of a curve from its sums. The read at a day is the read of the last point at or before that day.
|
|
3331
|
+
* This is the step rule of a Kaplan-Meier curve. `changeInterval` reads only the days of the points, so each read is the read of a point.
|
|
3332
|
+
*/
|
|
3333
|
+
function sumsRead(curve, sums) {
|
|
3334
|
+
return (day) => {
|
|
3335
|
+
let found;
|
|
3336
|
+
for (const [index, [point, chance]] of curve.entries()) {
|
|
3337
|
+
if (point > day) break;
|
|
3338
|
+
found = {
|
|
3339
|
+
time: day,
|
|
3340
|
+
chance,
|
|
3341
|
+
sum: sums[index] ?? 0
|
|
3342
|
+
};
|
|
3343
|
+
}
|
|
3344
|
+
return found;
|
|
3345
|
+
};
|
|
3346
|
+
}
|
|
3347
|
+
/** This function gives the Greenwood reads of the Kaplan-Meier estimate of a table of counts. A day after `last` has no read. */
|
|
3348
|
+
function countsRead(counts) {
|
|
3349
|
+
const estimate = estimateOf(counts);
|
|
3350
|
+
return (day) => day > counts.last ? void 0 : greenwoodRead(estimate, day);
|
|
3351
|
+
}
|
|
3352
|
+
/**
|
|
3353
|
+
* This function gives the curve of one cut with the Greenwood reads of its estimate, when the cut has sums or counts with no fault.
|
|
3354
|
+
* The sums come first, because they are the short form. A cut with sums that have a fault uses its counts.
|
|
3355
|
+
*/
|
|
3356
|
+
function readCurveOf(cut) {
|
|
3357
|
+
if (cut?.duration === void 0) return void 0;
|
|
3358
|
+
if (cut.sums !== void 0 && sumsFault(cut.duration, cut.sums) === void 0) return {
|
|
3359
|
+
curve: cut.duration,
|
|
3360
|
+
read: sumsRead(cut.duration, cut.sums)
|
|
3361
|
+
};
|
|
3362
|
+
if (cut.counts !== void 0 && countsFault(cut.duration, cut.counts) === void 0) return {
|
|
3363
|
+
curve: cut.duration,
|
|
3364
|
+
read: countsRead(cut.counts)
|
|
3365
|
+
};
|
|
3366
|
+
}
|
|
3367
|
+
/** This function gives a Greenwood read at each point of the curve of a cut. The sums do not decrease, so a rounding below the sum before it is lifted. */
|
|
3368
|
+
function pointReads(curve) {
|
|
3369
|
+
let sum = 0;
|
|
3370
|
+
return curve.curve.map(([time, chance]) => {
|
|
3371
|
+
sum = Math.max(sum, (time > 0 ? curve.read(time)?.sum : void 0) ?? sum);
|
|
3372
|
+
return {
|
|
3373
|
+
time,
|
|
3374
|
+
chance,
|
|
3375
|
+
sum
|
|
3376
|
+
};
|
|
3377
|
+
});
|
|
3378
|
+
}
|
|
3379
|
+
/**
|
|
3380
|
+
* This function gives the reads of the stop of a draw, when each cut that the stop uses has sums or counts with no fault.
|
|
3381
|
+
* With one used cut, it gives the curve of that cut. With two or more used cuts, it gives the reads of each cut at the points of its curve.
|
|
3382
|
+
*/
|
|
3383
|
+
function stopReadsOf(layer, caseCuts, need, options) {
|
|
3296
3384
|
const draw = layer.draws.find((item) => item.need === need);
|
|
3297
|
-
const
|
|
3298
|
-
if (
|
|
3299
|
-
const
|
|
3300
|
-
if (
|
|
3385
|
+
const stop = draw === void 0 ? void 0 : stopRebuild(caseCuts, draw, options);
|
|
3386
|
+
if (stop === void 0 || stop.used.length === 0) return void 0;
|
|
3387
|
+
const curves = stop.used.map((index) => readCurveOf(caseCuts.cuts[index]));
|
|
3388
|
+
if (curves.some((curve) => curve === void 0)) return void 0;
|
|
3389
|
+
const [first] = curves;
|
|
3390
|
+
if (curves.length === 1 && first !== void 0) return {
|
|
3391
|
+
kind: "one",
|
|
3392
|
+
curve: first
|
|
3393
|
+
};
|
|
3301
3394
|
return {
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3395
|
+
kind: "many",
|
|
3396
|
+
cuts: {
|
|
3397
|
+
stop,
|
|
3398
|
+
reads: curves.map((curve) => curve === void 0 ? [] : pointReads(curve))
|
|
3399
|
+
}
|
|
3305
3400
|
};
|
|
3306
3401
|
}
|
|
3307
3402
|
/**
|
|
@@ -3322,42 +3417,76 @@ function pointWeights(curve, days) {
|
|
|
3322
3417
|
return [];
|
|
3323
3418
|
}
|
|
3324
3419
|
/**
|
|
3325
|
-
* This function gives the interval of the change of the chance, from the counts of the one cut of the stop.
|
|
3420
|
+
* This function gives the interval of the change of the chance, from the sums or the counts of the one cut of the stop.
|
|
3326
3421
|
*
|
|
3327
3422
|
* - The change is `S(before) - S(after)`. A read at or after the horizon is 0, so it adds no term.
|
|
3328
|
-
* - Each read of the curve is a weighted sum of the chances of the estimate at up to two points. A point
|
|
3329
|
-
* -
|
|
3330
|
-
*
|
|
3423
|
+
* - Each read of the curve is a weighted sum of the chances of the estimate at up to two points. A point with no read has the chance 0.
|
|
3424
|
+
* - `survivalCombination` of rigor-statistics gives the Greenwood error of the weighted sum.
|
|
3425
|
+
* The covariance of the chances at two points `a <= b` is `S(a) * S(b) * V(a)`.
|
|
3331
3426
|
*/
|
|
3332
|
-
function changeInterval(
|
|
3427
|
+
function changeInterval(curve, before, after, horizon, change) {
|
|
3333
3428
|
const terms = [];
|
|
3334
3429
|
const add = (days, sign) => {
|
|
3335
3430
|
if (days >= horizon) return;
|
|
3336
|
-
for (const [day, weight] of pointWeights(
|
|
3431
|
+
for (const [day, weight] of pointWeights(curve.curve, days)) {
|
|
3432
|
+
const read = day > 0 ? curve.read(day) : void 0;
|
|
3433
|
+
if (read !== void 0) terms.push({
|
|
3434
|
+
read,
|
|
3435
|
+
weight: sign * weight
|
|
3436
|
+
});
|
|
3437
|
+
}
|
|
3337
3438
|
};
|
|
3338
3439
|
add(before, 1);
|
|
3339
3440
|
add(after, -1);
|
|
3340
|
-
const
|
|
3341
|
-
|
|
3342
|
-
return difference === void 0 ? void 0 : difference.se * difference.se;
|
|
3343
|
-
};
|
|
3344
|
-
let variance = 0;
|
|
3345
|
-
for (const [a, weightA] of terms) for (const [b, weightB] of terms) {
|
|
3346
|
-
const atA = square(0, a);
|
|
3347
|
-
const atB = square(0, b);
|
|
3348
|
-
const between = square(a, b);
|
|
3349
|
-
if (atA === void 0 || atB === void 0 || between === void 0) return void 0;
|
|
3350
|
-
variance += weightA * weightB * ((atA + atB - between) / 2);
|
|
3351
|
-
}
|
|
3352
|
-
const se = Math.sqrt(Math.max(0, variance));
|
|
3353
|
-
const [floor, ceiling] = (after >= horizon ? 1e400 : after) >= (before >= horizon ? 1e400 : before) ? [0, 1] : [-1, 0];
|
|
3354
|
-
const clamp = (value) => Math.min(ceiling, Math.max(floor, value));
|
|
3441
|
+
const { se } = survivalCombination(terms);
|
|
3442
|
+
const clamp = clampOf(before, after, horizon);
|
|
3355
3443
|
return {
|
|
3356
3444
|
se,
|
|
3357
3445
|
low: clamp(change - Z95 * se),
|
|
3358
3446
|
high: clamp(change + Z95 * se)
|
|
3359
3447
|
};
|
|
3360
3448
|
}
|
|
3449
|
+
/** This function clamps an end of an interval of a change to 0 to 1, or to -1 to 0 for a change down. A read at or after the horizon is the last read. */
|
|
3450
|
+
function clampOf(before, after, horizon) {
|
|
3451
|
+
const [floor, ceiling] = (after >= horizon ? 1e400 : after) >= (before >= horizon ? 1e400 : before) ? [0, 1] : [-1, 0];
|
|
3452
|
+
return (value) => Math.min(ceiling, Math.max(floor, value));
|
|
3453
|
+
}
|
|
3454
|
+
/**
|
|
3455
|
+
* This function gives the interval of the change of the chance of the event curve.
|
|
3456
|
+
* The interval comes from a parametric bootstrap of the curves of two or more cuts.
|
|
3457
|
+
*
|
|
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 event curve of the stop from the drawn curves, with the same minimal sets (`StopRebuild.eventWith`).
|
|
3460
|
+
* - It reads the chance before and after the step as `caseOutlook` reads `lasts`. The statistic is the change.
|
|
3461
|
+
* - The interval is the percentile interval of `survivalBootstrap`, clamped as the interval of one cut.
|
|
3462
|
+
* - When the days do not change in the horizon, the change is 0 in each run. Then the interval is 0 to 0 with no runs.
|
|
3463
|
+
* - The seed is the hash of the case, the need and the input. Thus the same query gives the same interval.
|
|
3464
|
+
*/
|
|
3465
|
+
function cutsChangeInterval(cuts, before, after, horizon, runs, seed) {
|
|
3466
|
+
if (before === after || before >= horizon && after >= horizon) return {
|
|
3467
|
+
se: 0,
|
|
3468
|
+
low: 0,
|
|
3469
|
+
high: 0,
|
|
3470
|
+
runs
|
|
3471
|
+
};
|
|
3472
|
+
const lasts = (curve, days) => days >= horizon ? 1 : 1 - survivalAt(curve, days);
|
|
3473
|
+
const statistic = (chances) => {
|
|
3474
|
+
const curves = cuts.reads.map((reads, k) => reads.map((read, at) => [read.time, chances[k]?.[at] ?? 0]));
|
|
3475
|
+
const event = cuts.stop.eventWith(curves);
|
|
3476
|
+
return lasts(event, after) - lasts(event, before);
|
|
3477
|
+
};
|
|
3478
|
+
const { low, high } = survivalBootstrap(cuts.reads, statistic, {
|
|
3479
|
+
runs,
|
|
3480
|
+
seed
|
|
3481
|
+
});
|
|
3482
|
+
const clamp = clampOf(before, after, horizon);
|
|
3483
|
+
return {
|
|
3484
|
+
se: (high - low) / (2 * Z95),
|
|
3485
|
+
low: clamp(low),
|
|
3486
|
+
high: clamp(high),
|
|
3487
|
+
runs
|
|
3488
|
+
};
|
|
3489
|
+
}
|
|
3361
3490
|
/** 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. */
|
|
3362
3491
|
function rankOrder$1(levels) {
|
|
3363
3492
|
return (a, b) => {
|
|
@@ -3387,10 +3516,19 @@ function rankOrder$1(levels) {
|
|
|
3387
3516
|
* - The days are exact for the inputs. `chance` is the chance that a draw gets its need through the event. It comes
|
|
3388
3517
|
* from `caseOutlook` with the share `take`, before and after the step, with the bands of the cuts. The change of the
|
|
3389
3518
|
* chance is the change of the point values.
|
|
3390
|
-
* - The change has a 95% interval (`SensitivityChance.interval`) when the stop of the draw
|
|
3391
|
-
* A
|
|
3519
|
+
* - The change has a 95% interval (`SensitivityChance.interval`) when each cut of the stop of the draw (`stopCuts`) has sums or counts.
|
|
3520
|
+
* A cut with no sums and no counts, or with only reads that have a fault, gives no interval.
|
|
3521
|
+
* - With one cut, the interval comes from the delta method of the Greenwood sums.
|
|
3522
|
+
* - With two or more cuts, the interval comes from a parametric bootstrap of the curves of the cuts (`survivalBootstrap` of rigor-statistics).
|
|
3523
|
+
* 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
|
+
* - The bootstrap interval is for `change.event` only. The type has one interval, so the independent and upper curves have none.
|
|
3525
|
+
* - The bootstrap is correct only for large samples. At a kink of the event curve, its coverage is less than 95%.
|
|
3526
|
+
* An example is two cuts with equal curves under a maximum: the coverage of a percentile interval is near 0.89 there.
|
|
3527
|
+
* - The seed of the bootstrap is the hash of the case, the need and the input. The same query gives the same interval.
|
|
3392
3528
|
*
|
|
3393
|
-
* The cost is one `enduranceOf` and one `caseOutlook` for each input, and one `
|
|
3529
|
+
* 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 interval of each draw and each input adds `runs` draws of the curves and `runs` uses of `eventStop`.
|
|
3531
|
+
* The function is pure.
|
|
3394
3532
|
*
|
|
3395
3533
|
* @param layer - The endurance layer
|
|
3396
3534
|
* @param caseCuts - The case
|
|
@@ -3399,9 +3537,11 @@ function rankOrder$1(levels) {
|
|
|
3399
3537
|
* @throws RangeError for a step that is not a finite number more than 0, and for the errors of `enduranceOf` and `caseOutlook`
|
|
3400
3538
|
*/
|
|
3401
3539
|
function enduranceSensitivity(layer, caseCuts, options) {
|
|
3402
|
-
const { step: given, ...caseOptions } = options;
|
|
3540
|
+
const { step: given, runs: givenRuns, ...caseOptions } = options;
|
|
3403
3541
|
const step = given ?? 1;
|
|
3404
3542
|
if (!(step > 0) || !Number.isFinite(step)) throw new RangeError(`The step ${String(given)} is not a finite number more than 0.`);
|
|
3543
|
+
const runs = givenRuns ?? 1e3;
|
|
3544
|
+
if (!Number.isInteger(runs) || runs < 1) throw new RangeError(`The option runs is ${String(givenRuns)}: it is not a whole number from 1.`);
|
|
3405
3545
|
const base = enduranceOf(layer, caseCuts, caseOptions);
|
|
3406
3546
|
const outlookOf = (changed) => new Map(caseOutlook(changed, caseCuts, {
|
|
3407
3547
|
...caseOptions,
|
|
@@ -3409,7 +3549,7 @@ function enduranceSensitivity(layer, caseCuts, options) {
|
|
|
3409
3549
|
}).draws.map((draw) => [draw.need, draw]));
|
|
3410
3550
|
const baseOutlook = outlookOf(layer);
|
|
3411
3551
|
const counted = new Map([...baseOutlook.keys()].flatMap((need) => {
|
|
3412
|
-
const read =
|
|
3552
|
+
const read = stopReadsOf(layer, caseCuts, need, caseOptions);
|
|
3413
3553
|
return read === void 0 ? [] : [[need, read]];
|
|
3414
3554
|
}));
|
|
3415
3555
|
const horizon = caseOptions.horizon ?? 1e400;
|
|
@@ -3428,7 +3568,11 @@ function enduranceSensitivity(layer, caseCuts, options) {
|
|
|
3428
3568
|
const to = outlook?.get(need);
|
|
3429
3569
|
const read = counted.get(need);
|
|
3430
3570
|
const moved = from === void 0 || to === void 0 ? void 0 : minus(to.lasts, from.lasts);
|
|
3431
|
-
const interval = read === void 0 || from === void 0 || to === void 0 || moved === void 0 ? void 0 : changeInterval(read, from.days, to.days, horizon, moved.event)
|
|
3571
|
+
const interval = read === void 0 || from === void 0 || to === void 0 || moved === void 0 ? void 0 : read.kind === "one" ? changeInterval(read.curve, from.days, to.days, horizon, moved.event) : cutsChangeInterval(read.cuts, from.days, to.days, horizon, runs, seedOf(canonicalJson([
|
|
3572
|
+
caseCuts.case,
|
|
3573
|
+
need,
|
|
3574
|
+
variant.id
|
|
3575
|
+
])));
|
|
3432
3576
|
const chance = from === void 0 || to === void 0 || moved === void 0 ? {} : { chance: {
|
|
3433
3577
|
before: from.lasts,
|
|
3434
3578
|
after: to.lasts,
|
|
@@ -3560,6 +3704,6 @@ function daysPerDollar(sensitivity, prices, options) {
|
|
|
3560
3704
|
unused
|
|
3561
3705
|
};
|
|
3562
3706
|
}
|
|
3563
|
-
export { ENDURANCE_CODES, ENDURANCE_SCHEMA, INDEPENDENT_MAX_WORK, INDEPENDENT_TOLERANCE, MINIMAL_STOP_CUTS, SAMPLE_ENDURANCE, SAMPLE_ENDURANCE_STACK, SEASON_HORIZON_DAYS, SENSITIVITY_STEP, SHARES, YEAR_STARTS, bestEndurance, caseDraws, caseOutlook, caseShortfall, caseStopped, checkEndurance, curveFault, daysPerDollar, drawDemand, enduranceOf, enduranceSensitivity, eventStop, giftNeed, giftResource, hasEnduranceError, hasSeason, heldTail, independentStop, isSource, joinEndurance, jointDays, longestStop, minimalStops, monthEdges, monthOf, monthlyShares, seasonSupply, shareOf, sowDays, stopCurves, stopCuts, storeAmounts, survivalAt, survivalQuantile, tailDays, upperStop, yearChance, yearRate, yearShortfall };
|
|
3707
|
+
export { ENDURANCE_CODES, ENDURANCE_SCHEMA, INDEPENDENT_MAX_WORK, INDEPENDENT_TOLERANCE, MINIMAL_STOP_CUTS, SAMPLE_ENDURANCE, SAMPLE_ENDURANCE_STACK, SEASON_HORIZON_DAYS, SENSITIVITY_RUNS, SENSITIVITY_STEP, SHARES, YEAR_STARTS, bestEndurance, caseDraws, caseOutlook, caseShortfall, caseStopped, checkEndurance, curveFault, daysPerDollar, drawDemand, enduranceOf, enduranceSensitivity, eventStop, giftNeed, giftResource, hasEnduranceError, hasSeason, heldTail, independentStop, isSource, joinEndurance, jointDays, longestStop, minimalStops, monthEdges, monthOf, monthlyShares, seasonSupply, shareOf, sowDays, stopCurves, stopCuts, stopRebuild, storeAmounts, survivalAt, survivalQuantile, tailDays, upperStop, yearChance, yearRate, yearShortfall };
|
|
3564
3708
|
|
|
3565
3709
|
//# sourceMappingURL=index.js.map
|