@mark1russell7/stack-endurance 0.8.34 → 0.8.36
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 +3 -1
- package/build/index.d.ts +18 -2
- package/build/index.d.ts.map +1 -1
- package/build/index.js +85 -14
- package/build/index.js.map +1 -1
- package/build/schema.d.ts.map +1 -1
- package/build/schema.js +6 -1
- package/build/schema.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -163,7 +163,9 @@ Two groups of cuts that share no minimal set are independent, so the independent
|
|
|
163
163
|
- With one cut, the three changes are equal, so the three intervals are the interval of the delta method.
|
|
164
164
|
- 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.
|
|
165
165
|
- The draws are the draws of 0.8.31. Since 0.8.34, each of the three intervals is bias-corrected.
|
|
166
|
-
- The upper curve has a kink where the sum of the chances of the cuts reaches 1.
|
|
166
|
+
- The upper curve has a kink where the sum of the chances of the cuts reaches 1. Since 0.8.36, its interval comes from the terms of its change before the cap (`StopRebuild.upperSumWith`).
|
|
167
|
+
There, a percentile interval of the capped change held the true change in 356 of 400 samples. The interval from the terms holds it in 387.
|
|
168
|
+
When the terms can tie, the high end uses the quantile 1 - alpha / 4 of each term. Thus the interval is wider there.
|
|
167
169
|
|
|
168
170
|
An example on the sample:
|
|
169
171
|
|
package/build/index.d.ts
CHANGED
|
@@ -337,6 +337,16 @@ export declare const MINIMAL_STOP_CUTS = 12;
|
|
|
337
337
|
* With more than `MINIMAL_STOP_CUTS` cuts, the result is `undefined`.
|
|
338
338
|
*/
|
|
339
339
|
export declare function minimalStops(count: number, stops: (cuts: readonly number[]) => boolean): number[][] | undefined;
|
|
340
|
+
/**
|
|
341
|
+
* This function gives the sum of `upperStop` before its cap of 1, at each time. Since 0.8.36.
|
|
342
|
+
* It is the sum over the minimal sets of the smallest chance of the set. With no minimal sets, it is the sum of the chances.
|
|
343
|
+
* The curve of `upperStop` is `min(1, sum)`. The sum does not increase with the time.
|
|
344
|
+
*
|
|
345
|
+
* @param curves - The curves of the cuts
|
|
346
|
+
* @param sets - The minimal sets of `minimalStops`, or `undefined`
|
|
347
|
+
* @returns The sum at a time in days
|
|
348
|
+
*/
|
|
349
|
+
export declare function upperSum(curves: readonly Survival[], sets: readonly (readonly number[])[] | undefined): (days: number) => number;
|
|
340
350
|
/**
|
|
341
351
|
* This function gives an upper limit of the curve of a stop for each dependence of the cuts.
|
|
342
352
|
* At each time it is `min(1, sum over the minimal sets of the smallest chance of the set)`.
|
|
@@ -449,6 +459,11 @@ export interface StopRebuild {
|
|
|
449
459
|
readonly curvesWith: (curves: readonly Survival[]) => StopCurves;
|
|
450
460
|
/** This function gives only the `event` curve of `curvesWith`. It does not calculate the other two curves, so it costs less. */
|
|
451
461
|
readonly eventWith: (curves: readonly Survival[]) => Survival;
|
|
462
|
+
/**
|
|
463
|
+
* This function gives the sum of the `upper` curve of `curvesWith` before its cap of 1 (`upperSum`), with the same minimal sets. Since 0.8.36.
|
|
464
|
+
* The `upper` curve is `min(1, sum)`. A statistic of the sum is smooth also where the cap starts.
|
|
465
|
+
*/
|
|
466
|
+
readonly upperSumWith: (curves: readonly Survival[]) => (days: number) => number;
|
|
452
467
|
}
|
|
453
468
|
/**
|
|
454
469
|
* 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.
|
|
@@ -910,8 +925,9 @@ export interface Sensitivity {
|
|
|
910
925
|
* 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.
|
|
911
926
|
* - `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
927
|
* - The bootstrap is correct only for large samples. Its interval is bias-corrected (since 0.8.34, M2-interval-kink).
|
|
913
|
-
*
|
|
914
|
-
*
|
|
928
|
+
* In the tests of rigor-statistics, a maximum of two equal curves is in 277 of 300 intervals, and in 266 with no correction.
|
|
929
|
+
* - The upper curve is `min(1, sum)`. Its interval comes from the intervals of the terms of its change before the cap (since 0.8.36).
|
|
930
|
+
* At the start of the cap, the percentile interval of the capped change held the truth in 356 of 400 samples. This interval holds it in 387.
|
|
915
931
|
* - The seed of the bootstrap is the hash of the case, the need and the input. The same query gives the same interval.
|
|
916
932
|
*
|
|
917
933
|
* The cost is one `enduranceOf` and one `caseOutlook` for each input, and one `stopRebuild` for each draw of the base.
|
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,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,SAAS;;;;;wBAqG7D,aAAa,OAAO,gBAAgB,cAAc,qBAAqB,SAAS,cAAc;;;;;;wBAkB9F,UAAU,OAAO,gBAAgB,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBA8C/C,YAAY,OAAO,gBAAgB,UAAU,UAAU,SAAS,cAAc;;iBC/a7E;WACN;WACA,IAAI;;;;;WAKJ;;WAEA;;WAEA;;;;;;WAMA,OAAO,SAAS,eAAe,SAAS;;;;;WAKxC;;WAEA,MAAM,SAAS;;;;;;WAMf;;WAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAkCK,UAAU,OAAO,gBAAgB,UAAU,UAAU,SAAS,aAAa,2BAA2B;;iBCpDrG,oBAAoB;;;;;;WAM1B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAkEK,cAAc,OAAO,gBAAgB,UAAU,UAAU,SAAS,cAAc;;;;;;wBCjFhF,SAAS,OAAO,UAAU,cAAc;;;;;;;;;wBAoBxC,SAAS,OAAO,UAAU,MAAM,KAAK,kCAAkC;;;;;;;;;;iBAetE,yBAAyB,KAAK,gCAAgC,KAAK;;WAEzE;;iBAGM,yBAAyB;;WAE/B;;;;;;wBAqBK,iBAAiB,OAAO,UAAU;;wBAWlC,WAAW,OAAO;;wBAKlB,SAAS,OAAO;;;;;;;;;;;;;;;;wBAoDhB,UAAU,iBAAiB,YAAY,QAAQ,sCAAsC;;;;;;;;wBAiBrF,YAAY,iBAAiB,aAAa;;;;;qBAU7C;;;;;wBAMG,aAAa,eAAe,QAAQ;;;;;;;;;;wBA8BpC,UAAU,iBAAiB,YAAY,mDAAmD;;
|
|
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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ER,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAiVZ,qBAAqB,OAAO,gBAAgB,UAAU,UAAU,SAAS,qBAAqB;;;;;;;iBCzd7F;;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
|
@@ -2327,6 +2327,19 @@ function popCount(mask) {
|
|
|
2327
2327
|
return total;
|
|
2328
2328
|
}
|
|
2329
2329
|
/**
|
|
2330
|
+
* This function gives the sum of `upperStop` before its cap of 1, at each time. Since 0.8.36.
|
|
2331
|
+
* It is the sum over the minimal sets of the smallest chance of the set. With no minimal sets, it is the sum of the chances.
|
|
2332
|
+
* The curve of `upperStop` is `min(1, sum)`. The sum does not increase with the time.
|
|
2333
|
+
*
|
|
2334
|
+
* @param curves - The curves of the cuts
|
|
2335
|
+
* @param sets - The minimal sets of `minimalStops`, or `undefined`
|
|
2336
|
+
* @returns The sum at a time in days
|
|
2337
|
+
*/
|
|
2338
|
+
function upperSum(curves, sets) {
|
|
2339
|
+
const groups = sets ?? curves.map((_, index) => [index]);
|
|
2340
|
+
return (days) => groups.reduce((total, set) => total + Math.min(...set.map((index) => survivalAt(curves[index] ?? [], days))), 0);
|
|
2341
|
+
}
|
|
2342
|
+
/**
|
|
2330
2343
|
* This function gives an upper limit of the curve of a stop for each dependence of the cuts.
|
|
2331
2344
|
* At each time it is `min(1, sum over the minimal sets of the smallest chance of the set)`.
|
|
2332
2345
|
* With no minimal sets, as for too many cuts, it is `min(1, sum of the chances)`.
|
|
@@ -2336,8 +2349,7 @@ function popCount(mask) {
|
|
|
2336
2349
|
* @throws RangeError when a curve does not end at a chance of 0
|
|
2337
2350
|
*/
|
|
2338
2351
|
function upperStop(curves, sets) {
|
|
2339
|
-
const
|
|
2340
|
-
const sum = (days) => groups.reduce((total, set) => total + Math.min(...set.map((index) => survivalAt(curves[index] ?? [], days))), 0);
|
|
2352
|
+
const sum = upperSum(curves, sets);
|
|
2341
2353
|
const times = bendTimes(curves);
|
|
2342
2354
|
const bends = new Set(times);
|
|
2343
2355
|
for (let index = 1; index < times.length; index += 1) {
|
|
@@ -2579,7 +2591,8 @@ function stopReadWith(caseCuts, draw, options, stoppedOf) {
|
|
|
2579
2591
|
curves: curvesOf(base),
|
|
2580
2592
|
used: used.map((index) => relevant[index] ?? -1),
|
|
2581
2593
|
curvesWith: (curves) => curvesOf(changed(curves)),
|
|
2582
|
-
eventWith: (curves) => eventStop(changed(curves), keptStops)
|
|
2594
|
+
eventWith: (curves) => eventStop(changed(curves), keptStops),
|
|
2595
|
+
upperSumWith: (curves) => upperSum(changed(curves), keptSets)
|
|
2583
2596
|
};
|
|
2584
2597
|
}
|
|
2585
2598
|
function stopCurvesWith(caseCuts, draw, options, stoppedOf) {
|
|
@@ -3451,6 +3464,8 @@ function clampOf(before, after, horizon) {
|
|
|
3451
3464
|
const [floor, ceiling] = (after >= horizon ? 1e400 : after) >= (before >= horizon ? 1e400 : before) ? [0, 1] : [-1, 0];
|
|
3452
3465
|
return (value) => Math.min(ceiling, Math.max(floor, value));
|
|
3453
3466
|
}
|
|
3467
|
+
/** One minus the level of the intervals of the change: 0.05 for 95%. */
|
|
3468
|
+
const ALPHA = .05;
|
|
3454
3469
|
/**
|
|
3455
3470
|
* This function gives the intervals of the change of the chance of the three curves of the stop.
|
|
3456
3471
|
* The intervals come from one parametric bootstrap of the curves of two or more cuts.
|
|
@@ -3478,33 +3493,88 @@ function cutsChangeIntervals(cuts, before, after, horizon, runs, seed) {
|
|
|
3478
3493
|
};
|
|
3479
3494
|
}
|
|
3480
3495
|
const lasts = (curve, days) => days >= horizon ? 1 : 1 - survivalAt(curve, days);
|
|
3496
|
+
const up = (after >= horizon ? 1e400 : after) >= (before >= horizon ? 1e400 : before);
|
|
3497
|
+
const [early, late] = up ? [before, after] : [after, before];
|
|
3481
3498
|
const statistics = (chances) => {
|
|
3482
3499
|
const curves = cuts.reads.map((reads, k) => reads.map((read, at) => [read.time, chances[k]?.[at] ?? 0]));
|
|
3483
3500
|
const stop = cuts.stop.curvesWith(curves);
|
|
3484
|
-
|
|
3485
|
-
|
|
3486
|
-
stop.independent,
|
|
3487
|
-
stop.upper
|
|
3488
|
-
].map((curve) => lasts(curve, after) - lasts(curve, before));
|
|
3501
|
+
const sum = cuts.stop.upperSumWith(curves);
|
|
3502
|
+
return [...[stop.event, stop.independent].map((curve) => lasts(curve, after) - lasts(curve, before)), ...upperTerms(sum(early), sum(late), late >= horizon)];
|
|
3489
3503
|
};
|
|
3490
3504
|
const clamp = clampOf(before, after, horizon);
|
|
3491
|
-
const [
|
|
3505
|
+
const [eventEnds, independentEnds, ...termEnds] = survivalBootstrapMany(cuts.reads, statistics, {
|
|
3492
3506
|
runs,
|
|
3493
3507
|
seed,
|
|
3494
3508
|
biasCorrected: true
|
|
3495
|
-
})
|
|
3509
|
+
});
|
|
3510
|
+
if (eventEnds === void 0 || independentEnds === void 0 || termEnds.length === 0) throw new Error("survivalBootstrapMany gave fewer than 3 intervals.");
|
|
3511
|
+
const termStatistics = (chances) => {
|
|
3512
|
+
const curves = cuts.reads.map((reads, k) => reads.map((read, at) => [read.time, chances[k]?.[at] ?? 0]));
|
|
3513
|
+
const sum = cuts.stop.upperSumWith(curves);
|
|
3514
|
+
return upperTerms(sum(early), sum(late), late >= horizon);
|
|
3515
|
+
};
|
|
3516
|
+
const wideHighs = termEnds.length === 1 ? termEnds.map((term) => term.high) : survivalBootstrapMany(cuts.reads, termStatistics, {
|
|
3517
|
+
runs,
|
|
3518
|
+
seed,
|
|
3519
|
+
biasCorrected: true,
|
|
3520
|
+
ends: [ALPHA / 2, 1 - ALPHA / 4]
|
|
3521
|
+
}).map((term) => term.high);
|
|
3522
|
+
const [event, independent, upper] = [
|
|
3523
|
+
eventEnds,
|
|
3524
|
+
independentEnds,
|
|
3525
|
+
upperInterval(termEnds.map((term, index) => ({
|
|
3526
|
+
low: term.low,
|
|
3527
|
+
high: term.high,
|
|
3528
|
+
wideHigh: wideHighs[index] ?? term.high
|
|
3529
|
+
})), late >= horizon, up)
|
|
3530
|
+
].map(({ low, high }) => ({
|
|
3496
3531
|
se: (high - low) / (2 * Z95),
|
|
3497
3532
|
low: clamp(low),
|
|
3498
3533
|
high: clamp(high),
|
|
3499
3534
|
runs
|
|
3500
3535
|
}));
|
|
3501
|
-
if (event === void 0 || independent === void 0 || upper === void 0) throw new Error("
|
|
3536
|
+
if (event === void 0 || independent === void 0 || upper === void 0) throw new Error("The intervals are fewer than 3.");
|
|
3502
3537
|
return {
|
|
3503
3538
|
event,
|
|
3504
3539
|
independent,
|
|
3505
3540
|
upper
|
|
3506
3541
|
};
|
|
3507
3542
|
}
|
|
3543
|
+
/**
|
|
3544
|
+
* This function gives the smooth statistics of the change of the chance of the upper curve, from the sum before its cap.
|
|
3545
|
+
* The upper curve is `min(1, sum)`, and the chance that the stop ends by a day is `max(0, 1 - sum)`. Thus the change from the early day to the late day is
|
|
3546
|
+
* `max(0, min(sum(early) - sum(late), 1 - sum(late)))`. At or after the horizon, the late chance is 1 and the change is `min(1, sum(early))`.
|
|
3547
|
+
* The terms are those of the minimum, with no constant. The clamp of the interval gives the maximum with 0.
|
|
3548
|
+
*/
|
|
3549
|
+
function upperTerms(early, late, lateAtHorizon) {
|
|
3550
|
+
return lateAtHorizon ? [early] : [early - late, 1 - late];
|
|
3551
|
+
}
|
|
3552
|
+
/**
|
|
3553
|
+
* This function gives the interval of the change of the upper curve from the intervals of its terms (`upperTerms`).
|
|
3554
|
+
* Thus the interval holds also where the cap starts, where a percentile interval of the capped change is too narrow (M2-interval-kink-residual).
|
|
3555
|
+
*
|
|
3556
|
+
* - The low end is the minimum of the low ends. It is above the minimum only when the low end of the term that is the minimum is above that term.
|
|
3557
|
+
* - When the high end of one term is below the low end of each other term, that term is the minimum. Its high end is the high end.
|
|
3558
|
+
* - Else the terms can tie, and the high end can miss when one of them misses. Then the high end is the minimum of the high ends
|
|
3559
|
+
* at the quantile 1 - alpha / 4 (`wideHigh`). Thus the two terms together miss at most alpha / 2 (Bonferroni).
|
|
3560
|
+
* - At the horizon, the constant 1 is a term with the interval 1 to 1. A change down is the change up with the other sign.
|
|
3561
|
+
*/
|
|
3562
|
+
function upperInterval(terms, lateAtHorizon, up) {
|
|
3563
|
+
const all = lateAtHorizon ? [...terms, {
|
|
3564
|
+
low: 1,
|
|
3565
|
+
high: 1,
|
|
3566
|
+
wideHigh: 1
|
|
3567
|
+
}] : terms;
|
|
3568
|
+
const low = Math.min(...all.map((term) => term.low));
|
|
3569
|
+
const high = all.find((term, index) => all.every((other, at) => at === index || term.high < other.low))?.high ?? Math.min(...all.map((term) => term.wideHigh));
|
|
3570
|
+
return up ? {
|
|
3571
|
+
low,
|
|
3572
|
+
high
|
|
3573
|
+
} : {
|
|
3574
|
+
low: -high,
|
|
3575
|
+
high: -low
|
|
3576
|
+
};
|
|
3577
|
+
}
|
|
3508
3578
|
/** 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. */
|
|
3509
3579
|
function rankOrder$1(levels) {
|
|
3510
3580
|
return (a, b) => {
|
|
@@ -3541,8 +3611,9 @@ function rankOrder$1(levels) {
|
|
|
3541
3611
|
* 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.
|
|
3542
3612
|
* - `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).
|
|
3543
3613
|
* - The bootstrap is correct only for large samples. Its interval is bias-corrected (since 0.8.34, M2-interval-kink).
|
|
3544
|
-
*
|
|
3545
|
-
*
|
|
3614
|
+
* In the tests of rigor-statistics, a maximum of two equal curves is in 277 of 300 intervals, and in 266 with no correction.
|
|
3615
|
+
* - The upper curve is `min(1, sum)`. Its interval comes from the intervals of the terms of its change before the cap (since 0.8.36).
|
|
3616
|
+
* At the start of the cap, the percentile interval of the capped change held the truth in 356 of 400 samples. This interval holds it in 387.
|
|
3546
3617
|
* - The seed of the bootstrap is the hash of the case, the need and the input. The same query gives the same interval.
|
|
3547
3618
|
*
|
|
3548
3619
|
* The cost is one `enduranceOf` and one `caseOutlook` for each input, and one `stopRebuild` for each draw of the base.
|
|
@@ -3731,6 +3802,6 @@ function daysPerDollar(sensitivity, prices, options) {
|
|
|
3731
3802
|
unused
|
|
3732
3803
|
};
|
|
3733
3804
|
}
|
|
3734
|
-
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 };
|
|
3805
|
+
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, upperSum, yearChance, yearRate, yearShortfall };
|
|
3735
3806
|
|
|
3736
3807
|
//# sourceMappingURL=index.js.map
|