@mark1russell7/stack-endurance 0.8.26 → 0.8.27

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 CHANGED
@@ -96,6 +96,10 @@ A draw that only the parts of `down` stop has no curve of its duration. The quer
96
96
 
97
97
  A cut can have no `duration`, as before a source gives its curve. Then each draw whose stop the cut can be part of goes in `unread`. A draw whose minimal stop sets do not have the cut keeps its curves. When the query has no minimal sets, it cannot tell, so the draw goes in `unread`. The gate gives the warning `endurance-cut-no-curve` for each such cut.
98
98
 
99
+ `stopCuts(caseCuts, draw, options)` gives the cuts that the stop of a draw uses, as indexes in `caseCuts.cuts`. A used cut has a curve and is in a minimal set of cuts that stops the supply. Since 0.8.27.
100
+
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
+
99
103
  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.
100
104
 
101
105
  | Bounds of the curves | Bound of the result |
@@ -140,7 +144,12 @@ Two groups of cuts that share no minimal set are independent, so the independent
140
144
  - The change of a draw is a finite difference of `enduranceOf`: the days after the step minus the days before it. `perUnit` gives the change for each unit of the input.
141
145
  - An input that no draw of the case uses has a change of 0.
142
146
  - 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.
143
- - `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, with no interval.
147
+ - `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
+ - `chance.interval` gives the 95% interval of the change (`ChanceInterval`: `se`, `low` and `high`). Since 0.8.27 (M2-sensitivity-interval).
149
+ - The stop of the draw must use one cut (`stopCuts`), and that cut must have counts (`Cut.counts` of the core) with no fault. Else the interval is absent.
150
+ - The change is a weighted sum of the chances of the Kaplan-Meier curve of the counts at up to four days. A read between two points of the curve has a weight on each point.
151
+ - The variance of the sum uses the covariance of each two chances: `survivalDifference` of rigor-statistics gives the Greenwood variance of each chance and each difference.
152
+ - A stop of two or more cuts has no interval. Its event curve and upper curve are not smooth functions of the curves of the cuts. Its independent curve has a term for each state of the cuts.
144
153
 
145
154
  An example on the sample:
146
155
 
package/build/add-on.js CHANGED
@@ -1,4 +1,4 @@
1
- import { r as checkEndurance, t as joinEndurance } from "./join-BwTee3Ue.js";
1
+ import { r as checkEndurance, t as joinEndurance } from "./join-r5ht3vQ9.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
@@ -421,6 +421,18 @@ export interface StopCurves {
421
421
  * - `bound` is the weakest bound of the curves of the cuts that the stop uses. A cut with no `bound` has a law.
422
422
  */
423
423
  export declare function stopCurves(caseCuts: CaseCuts, draw: Draw, options?: StopCurveOptions): StopCurves | undefined;
424
+ /**
425
+ * This function gives the cuts that the stop of a draw uses, as indexes in `caseCuts.cuts`, or `undefined` when `stopCurves` has no curve. Since 0.8.27.
426
+ *
427
+ * - A used cut has a curve, and it is in a minimal set of cuts that stops the supply. With no minimal sets, each cut with a curve is used.
428
+ * - With one used cut, each curve of `stopCurves` is the curve of that cut. `enduranceSensitivity` reads the interval of a change of the chance from it.
429
+ *
430
+ * @param caseCuts - The case
431
+ * @param draw - The draw
432
+ * @param options - The stack or the parts that are also down, and the budgets: as for `stopCurves`
433
+ * @throws RangeError for a bad `maxSets` or `maxWork`
434
+ */
435
+ export declare function stopCuts(caseCuts: CaseCuts, draw: Draw, options?: StopCurveOptions): readonly number[] | undefined;
424
436
  /** The shortfall of each level, in user-days, and the draws that the query cannot read. */
425
437
  export interface Shortfall {
426
438
  /**
@@ -647,6 +659,7 @@ export declare function caseOutlook(layer: EnduranceLayer, caseCuts: CaseCuts, o
647
659
  * A converter with a limit can take nothing: it is a source, for example a solar panel. Since 0.8.20 (M2-solar).
648
660
  * - `endurance-curve`: a survival curve does not start at `[0, 1]`, or it does not end at a chance of 0.
649
661
  * Or its days do not increase, or its chance increases.
662
+ * Or the band or the counts of a cut do not agree with its curve (`bandFault`, `countsFault`), or the cut has them and no curve.
650
663
  * - `endurance-bound`: the bound of a cut is not a value of `CUT_BOUNDS` of the core. Since 0.8.4.
651
664
  * - `endurance-prior-case`: a prior names a case that the layer does not have.
652
665
  * - `endurance-cycle`: converters make a resource from itself, through one converter or a chain. One fault names each cycle.
@@ -720,6 +733,17 @@ export interface SensitivityOptions extends CaseOptions, ShortfallOptions {
720
733
  }
721
734
  /** The kind of an input: the amount of a store, the rate of a draw, or a parameter of a converter. */
722
735
  export type SensitivityKind = "store" | "draw" | "converter";
736
+ /**
737
+ * The 95% interval of the change of the chance (`SensitivityChance.change`), from the sampling error of the curve of one cut. Since 0.8.27.
738
+ * The ends are the change minus and plus `Z95` times `se`, clamped to 0 to 1, or to -1 to 0 for a change down.
739
+ * It is a Wald interval. Near the ends of the range, its coverage can be less than 95%.
740
+ */
741
+ export interface ChanceInterval {
742
+ /** The Greenwood standard error of the change. It includes the covariance of the chances of the curve at the days before and after the step. */
743
+ readonly se: number;
744
+ readonly low: number;
745
+ readonly high: number;
746
+ }
723
747
  /**
724
748
  * The change in the chance that a draw gets its need through the event (`DrawOutlook.lasts`), for one input.
725
749
  * The chance comes from the curves of the stop. Only the days change, so the curves are the same before and after.
@@ -729,8 +753,17 @@ export interface SensitivityChance {
729
753
  readonly before: CurveValues;
730
754
  /** The chance after the step, for each curve of the stop. */
731
755
  readonly after: CurveValues;
732
- /** The chance after the step minus the chance before it, for each curve. It is the change of the point values, not an interval. */
756
+ /** The chance after the step minus the chance before it, for each curve. It is the change of the point values. */
733
757
  readonly change: CurveValues;
758
+ /**
759
+ * The 95% interval of `change`, when the stop of the draw uses one cut, and that cut has counts (`Cut.counts`) with no fault. Since 0.8.27.
760
+ * With one cut, the three curves of the stop are the curve of the cut, so the three changes are equal.
761
+ * Without counts, the interval is also absent.
762
+ *
763
+ * With two or more cuts, the interval is absent. The event curve and the upper curve are not smooth functions of the curves
764
+ * of the cuts (a maximum, and a sum with a limit). The independent curve is a polynomial with a term for each state of the cuts.
765
+ */
766
+ readonly interval?: ChanceInterval | undefined;
734
767
  /** The values before the step at the two ends of the sampling bands of the cuts (`DrawOutlook.band`). */
735
768
  readonly beforeBand?: DrawBand | undefined;
736
769
  /** The values after the step at the two ends of the sampling bands of the cuts. */
@@ -800,9 +833,11 @@ export interface Sensitivity {
800
833
  * The largest sum comes first. Two equal inputs go in the order of their keys. Thus the order is stable.
801
834
  * - The days are exact for the inputs. `chance` is the chance that a draw gets its need through the event. It comes
802
835
  * from `caseOutlook` with the share `take`, before and after the step, with the bands of the cuts. The change of the
803
- * chance is the change of the point values. It has no interval.
836
+ * chance is the change of the point values.
837
+ * - The change has a 95% interval (`SensitivityChance.interval`) when the stop of the draw uses one cut (`stopCuts`) with counts.
838
+ * A stop of two or more cuts has no interval. A cut with no counts, or with counts that have a fault, also has no interval.
804
839
  *
805
- * The cost is one `enduranceOf` and one `caseOutlook` for each input. The function is pure.
840
+ * The cost is one `enduranceOf` and one `caseOutlook` for each input, and one `stopCuts` for each draw of the base. The function is pure.
806
841
  *
807
842
  * @param layer - The endurance layer
808
843
  * @param caseCuts - The case
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":["CutBound"],"sources":["../src/converter.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;;iB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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"}
1
+ {"version":3,"file":"index.d.ts","names":["CutBound"],"sources":["../src/converter.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;;iBCJnB;;WAEN,IAAI;;WAEJ,QAAQ;;WAER;;;;;;WAMA,QAAQ;;;;;;WAMR;;;qBAIE;;;;;wBAMG,YAAY,UAAU,UAAU,SAAS,KAAK,iCAAiC;;wBAiB/E,QAAQ,OAAO,SAAS;;;;;wBASxB,WAAW,OAAO,SAAS;;wBAc3B,cAAc,YAAY,SAAS,aAAa;;wBAOhD,QAAQ,QAAQ,wCAAwC,aAAa;;;;;;;wBAarE,aAAa,OAAO,gBAAgB,IAAI,SAAS,eAAc,sBAAkC;;wBAYjG,WAAW,MAAM,MAAM,UAAU;;;;;wBAQjC,UAAU,OAAO,gBAAgB,UAAU,UAAU,cAAc,sBAAsB;;wBAWzF,SAAS,WAAW;;wBAKpB,aAAa,WAAW;;;;;;;;wBAmMxB,QAAQ,QAAQ,KAAK,wBAAwB,OAAO,SAAS;;iBAkG5D;WACN;WACA;WACA;WACA;;;iBAIM;;WAEN,OAAO;WACP,UAAU;;WAEV,eAAe;;WAEf;;WAEA,OAAO;;;;;;wBAOF,aAAa,OAAO,gBAAgB,cAAc,qBAAqB,SAAS,cAAc;;;;;;wBAkB9F,UAA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iB;;;;;;;;;;;;;;;;;wBCvSnC,cAAc,iBAAiB,WAAW,oBAAoB,WAAW;;qBCf5E,wBAAwB;;;;;;;;;qBAkBxB,kBAAkB;;qBCdlB;;iBAGI,2BAA2B,aAAa;;WAE9C;;;YAIC;;;;;;iBAOK;;WAEN;WACA;WACA;;;;;;iBAOM;;WAEN,QAAQ;;WAER,OAAO;;WAEP,QAAQ;;;;;;;;;WASR,WAAW;;WAEX,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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAoMZ,qBAAqB,OAAO,gBAAgB,UAAU,UAAU,SAAS,qBAAqB;;;;;;;iBCnS7F;;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
@@ -1,9 +1,10 @@
1
1
  import { t as ENDURANCE_SCHEMA } from "./layer-a3Fr70Uh.js";
2
- import { A as deviceUse, C as fixStops, D as storeCapacities, E as seasonPlan, F as addTo, I as dense, L as exact, M as fewestRow, N as reachOf, O as Program, P as valueAt, R as deviceKey, S as firstStop, T as seasonJoint, _ as seasonSupply, a as hasEnduranceError, b as storeAmounts, c as caseStopped, d as giftNeed, f as giftResource, g as monthlyShares, h as monthOf, i as curveFault, j as drawBlock, k as caseParts, l as drawDemand, m as monthEdges, n as ENDURANCE_CODES, o as SEASON_HORIZON_DAYS, p as hasSeason, r as checkEndurance, s as caseDraws, t as joinEndurance, u as enduranceOf, v as shareOf, w as seasonBest, x as fewestOpen, y as sowDays, z as isSource } from "./join-BwTee3Ue.js";
3
- import { DEFAULT_MAX_SETS, STACK_SCHEMA, dateOfDay, dayNumber, neededParts, stopSets, survivalAt, weakestBound } from "@mark1russell7/system-stack";
2
+ import { A as deviceUse, C as fixStops, D as storeCapacities, E as seasonPlan, F as addTo, I as dense, L as exact, M as fewestRow, N as reachOf, O as Program, P as valueAt, R as deviceKey, S as firstStop, T as seasonJoint, _ as seasonSupply, a as hasEnduranceError, b as storeAmounts, c as caseStopped, d as giftNeed, f as giftResource, g as monthlyShares, h as monthOf, i as curveFault, j as drawBlock, k as caseParts, l as drawDemand, m as monthEdges, n as ENDURANCE_CODES, o as SEASON_HORIZON_DAYS, p as hasSeason, r as checkEndurance, s as caseDraws, t as joinEndurance, u as enduranceOf, v as shareOf, w as seasonBest, x as fewestOpen, y as sowDays, z as isSource } from "./join-r5ht3vQ9.js";
3
+ import { DEFAULT_MAX_SETS, STACK_SCHEMA, countsFault, dateOfDay, dayNumber, neededParts, stopSets, survivalAt, weakestBound } from "@mark1russell7/system-stack";
4
4
  import { ONE, ZERO, add, div, equals, 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 { Z95, kaplanMeier, survivalDifference } from "@mark1russell7/rigor-statistics";
7
8
  // src/joint.ts
8
9
  /**
9
10
  * This function gives the joint days of a set of draws. These are the largest count of days `d` at which each draw holds `d` days.
@@ -872,7 +873,7 @@ function supplyReach(supply, options) {
872
873
  reach.add(supply);
873
874
  return reach;
874
875
  }
875
- function stopCurvesWith(caseCuts, draw, options, stoppedOf) {
876
+ function stopReadWith(caseCuts, draw, options, stoppedOf) {
876
877
  const reach = supplyReach(draw.supply, options);
877
878
  const relevant = caseCuts.cuts.flatMap((cut, index) => reach.has(cut.part) ? [index] : []);
878
879
  const stops = (cuts) => stoppedOf(cuts.map((index) => relevant[index] ?? -1)).has(draw.supply);
@@ -892,14 +893,20 @@ function stopCurvesWith(caseCuts, draw, options, stoppedOf) {
892
893
  const used = sets === void 0 ? kept : kept.filter((index) => sets.some((set) => set.includes(index)));
893
894
  const bound = weakestBound(used.map((index) => caseCuts.cuts[relevant[index] ?? -1]?.bound ?? "law"));
894
895
  return {
895
- event: eventStop(curves, keptStops),
896
- independent: independent ?? upper,
897
- upper,
898
- coarse: keptSets === void 0,
899
- independentUpper: independent === void 0,
900
- bound
896
+ curves: {
897
+ event: eventStop(curves, keptStops),
898
+ independent: independent ?? upper,
899
+ upper,
900
+ coarse: keptSets === void 0,
901
+ independentUpper: independent === void 0,
902
+ bound
903
+ },
904
+ used: used.map((index) => relevant[index] ?? -1)
901
905
  };
902
906
  }
907
+ function stopCurvesWith(caseCuts, draw, options, stoppedOf) {
908
+ return stopReadWith(caseCuts, draw, options, stoppedOf)?.curves;
909
+ }
903
910
  /**
904
911
  * This function gives the curves of the duration of the stop of a draw, or `undefined` when the query has no curve.
905
912
  *
@@ -918,6 +925,21 @@ function stopCurves(caseCuts, draw, options = {}) {
918
925
  budgetsOf(options);
919
926
  return stopCurvesWith(caseCuts, draw, options, stoppedMemo(caseCuts, options));
920
927
  }
928
+ /**
929
+ * This function gives the cuts that the stop of a draw uses, as indexes in `caseCuts.cuts`, or `undefined` when `stopCurves` has no curve. Since 0.8.27.
930
+ *
931
+ * - A used cut has a curve, and it is in a minimal set of cuts that stops the supply. With no minimal sets, each cut with a curve is used.
932
+ * - With one used cut, each curve of `stopCurves` is the curve of that cut. `enduranceSensitivity` reads the interval of a change of the chance from it.
933
+ *
934
+ * @param caseCuts - The case
935
+ * @param draw - The draw
936
+ * @param options - The stack or the parts that are also down, and the budgets: as for `stopCurves`
937
+ * @throws RangeError for a bad `maxSets` or `maxWork`
938
+ */
939
+ function stopCuts(caseCuts, draw, options = {}) {
940
+ budgetsOf(options);
941
+ return stopReadWith(caseCuts, draw, options, stoppedMemo(caseCuts, options))?.used;
942
+ }
921
943
  function zeroLevels(layer) {
922
944
  return Object.fromEntries(layer.levels.map((level) => [level, 0]));
923
945
  }
@@ -1579,6 +1601,98 @@ function minus(a, b) {
1579
1601
  upper: a.upper - b.upper
1580
1602
  };
1581
1603
  }
1604
+ /**
1605
+ * This function gives the Kaplan-Meier estimate of a table of counts, with the same chance and Greenwood sum at each step.
1606
+ * The observations that leave after a step, with no event, are censored at the day of that step, or at `last` after the last step.
1607
+ */
1608
+ function estimateOf(counts) {
1609
+ const observations = [];
1610
+ for (const [index, [days, atRisk, events]] of counts.steps.entries()) {
1611
+ const next = counts.steps[index + 1];
1612
+ const left = atRisk - events - (next?.[1] ?? 0);
1613
+ observations.push({
1614
+ time: days,
1615
+ count: events
1616
+ });
1617
+ if (left > 0) observations.push({
1618
+ time: next === void 0 ? counts.last : days,
1619
+ censored: true,
1620
+ count: left
1621
+ });
1622
+ }
1623
+ if (observations.length === 0) observations.push({
1624
+ time: counts.last,
1625
+ censored: true
1626
+ });
1627
+ return kaplanMeier(observations);
1628
+ }
1629
+ /** This function gives the curve of the one cut of the stop of a draw, when that cut has counts with no fault. */
1630
+ function countedCurveOf(layer, caseCuts, need, options) {
1631
+ const draw = layer.draws.find((item) => item.need === need);
1632
+ const used = draw === void 0 ? void 0 : stopCuts(caseCuts, draw, options);
1633
+ if (used === void 0 || used.length !== 1) return void 0;
1634
+ const cut = caseCuts.cuts[used[0] ?? -1];
1635
+ if (cut?.duration === void 0 || cut.counts === void 0 || countsFault(cut.duration, cut.counts) !== void 0) return void 0;
1636
+ return {
1637
+ curve: cut.duration,
1638
+ last: cut.counts.last,
1639
+ estimate: estimateOf(cut.counts)
1640
+ };
1641
+ }
1642
+ /**
1643
+ * This function gives the points of a curve and their weights in the read of `survivalAt` of the core at `days`.
1644
+ * Between two points, the read is linear, so it has a weight on each of the two points. After the last point, the read is 0.
1645
+ */
1646
+ function pointWeights(curve, days) {
1647
+ if (days <= 0) return [[curve[0]?.[0] ?? 0, 1]];
1648
+ for (let index = 1; index < curve.length; index += 1) {
1649
+ const [t0] = curve[index - 1] ?? [0, 1];
1650
+ const [t1] = curve[index] ?? [0, 0];
1651
+ if (days < t1) {
1652
+ const weight = (days - t0) / (t1 - t0);
1653
+ return weight === 0 ? [[t0, 1]] : [[t0, 1 - weight], [t1, weight]];
1654
+ }
1655
+ if (days === t1) return [[t1, 1]];
1656
+ }
1657
+ return [];
1658
+ }
1659
+ /**
1660
+ * This function gives the interval of the change of the chance, from the counts of the one cut of the stop.
1661
+ *
1662
+ * - The change is `S(before) - S(after)`. A read at or after the horizon is 0, so it adds no term.
1663
+ * - Each read of the curve is a weighted sum of the chances of the estimate at up to two points. A point after `last` has the chance 0.
1664
+ * - The variance of the weighted sum uses the covariance of each two chances. `survivalDifference` of rigor-statistics gives
1665
+ * the variance of each chance and of each difference, so `Cov(a, b) = (Var S(a) + Var S(b) - Var(S(a) - S(b))) / 2`.
1666
+ */
1667
+ function changeInterval(read, before, after, horizon, change) {
1668
+ const terms = [];
1669
+ const add = (days, sign) => {
1670
+ if (days >= horizon) return;
1671
+ for (const [day, weight] of pointWeights(read.curve, days)) if (day > 0 && day <= read.last) terms.push([day, sign * weight]);
1672
+ };
1673
+ add(before, 1);
1674
+ add(after, -1);
1675
+ const square = (from, to) => {
1676
+ const difference = survivalDifference(read.estimate, from, to);
1677
+ return difference === void 0 ? void 0 : difference.se * difference.se;
1678
+ };
1679
+ let variance = 0;
1680
+ for (const [a, weightA] of terms) for (const [b, weightB] of terms) {
1681
+ const atA = square(0, a);
1682
+ const atB = square(0, b);
1683
+ const between = square(a, b);
1684
+ if (atA === void 0 || atB === void 0 || between === void 0) return void 0;
1685
+ variance += weightA * weightB * ((atA + atB - between) / 2);
1686
+ }
1687
+ const se = Math.sqrt(Math.max(0, variance));
1688
+ const [floor, ceiling] = (after >= horizon ? 1e400 : after) >= (before >= horizon ? 1e400 : before) ? [0, 1] : [-1, 0];
1689
+ const clamp = (value) => Math.min(ceiling, Math.max(floor, value));
1690
+ return {
1691
+ se,
1692
+ low: clamp(change - Z95 * se),
1693
+ high: clamp(change + Z95 * se)
1694
+ };
1695
+ }
1582
1696
  /** 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. */
1583
1697
  function rankOrder$1(levels) {
1584
1698
  return (a, b) => {
@@ -1607,9 +1721,11 @@ function rankOrder$1(levels) {
1607
1721
  * The largest sum comes first. Two equal inputs go in the order of their keys. Thus the order is stable.
1608
1722
  * - The days are exact for the inputs. `chance` is the chance that a draw gets its need through the event. It comes
1609
1723
  * from `caseOutlook` with the share `take`, before and after the step, with the bands of the cuts. The change of the
1610
- * chance is the change of the point values. It has no interval.
1724
+ * chance is the change of the point values.
1725
+ * - The change has a 95% interval (`SensitivityChance.interval`) when the stop of the draw uses one cut (`stopCuts`) with counts.
1726
+ * A stop of two or more cuts has no interval. A cut with no counts, or with counts that have a fault, also has no interval.
1611
1727
  *
1612
- * The cost is one `enduranceOf` and one `caseOutlook` for each input. The function is pure.
1728
+ * The cost is one `enduranceOf` and one `caseOutlook` for each input, and one `stopCuts` for each draw of the base. The function is pure.
1613
1729
  *
1614
1730
  * @param layer - The endurance layer
1615
1731
  * @param caseCuts - The case
@@ -1627,6 +1743,11 @@ function enduranceSensitivity(layer, caseCuts, options) {
1627
1743
  share: "take"
1628
1744
  }).draws.map((draw) => [draw.need, draw]));
1629
1745
  const baseOutlook = outlookOf(layer);
1746
+ const counted = new Map([...baseOutlook.keys()].flatMap((need) => {
1747
+ const read = countedCurveOf(layer, caseCuts, need, caseOptions);
1748
+ return read === void 0 ? [] : [[need, read]];
1749
+ }));
1750
+ const horizon = caseOptions.horizon ?? 1e400;
1630
1751
  const levelOf = new Map(layer.draws.map((draw) => [draw.need, draw.level]));
1631
1752
  const inputs = variantsOf(layer, step).map(({ layer: changed, ...variant }) => {
1632
1753
  const after = enduranceOf(changed, caseCuts, caseOptions);
@@ -1640,12 +1761,16 @@ function enduranceSensitivity(layer, caseCuts, options) {
1640
1761
  if (sum !== void 0) sums.set(level, sum + change);
1641
1762
  const from = baseOutlook.get(need);
1642
1763
  const to = outlook?.get(need);
1643
- const chance = from === void 0 || to === void 0 ? {} : { chance: {
1764
+ const read = counted.get(need);
1765
+ const moved = from === void 0 || to === void 0 ? void 0 : minus(to.lasts, from.lasts);
1766
+ 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);
1767
+ const chance = from === void 0 || to === void 0 || moved === void 0 ? {} : { chance: {
1644
1768
  before: from.lasts,
1645
1769
  after: to.lasts,
1646
- change: minus(to.lasts, from.lasts),
1770
+ change: moved,
1647
1771
  ...from.band === void 0 ? {} : { beforeBand: from.band },
1648
- ...to.band === void 0 ? {} : { afterBand: to.band }
1772
+ ...to.band === void 0 ? {} : { afterBand: to.band },
1773
+ ...interval === void 0 ? {} : { interval }
1649
1774
  } };
1650
1775
  return {
1651
1776
  need,
@@ -1770,6 +1895,6 @@ function daysPerDollar(sensitivity, prices, options) {
1770
1895
  unused
1771
1896
  };
1772
1897
  }
1773
- 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, storeAmounts, survivalAt, survivalQuantile, tailDays, upperStop, yearChance, yearRate, yearShortfall };
1898
+ 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 };
1774
1899
 
1775
1900
  //# sourceMappingURL=index.js.map