pragmastat 10.0.5 → 11.0.0

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
@@ -3,10 +3,10 @@
3
3
  Install from npm:
4
4
 
5
5
  ```bash
6
- npm i pragmastat@10.0.5
6
+ npm i pragmastat@11.0.0
7
7
  ```
8
8
 
9
- Source code: https://github.com/AndreyAkinshin/pragmastat/tree/v10.0.5/ts
9
+ Source code: https://github.com/AndreyAkinshin/pragmastat/tree/v11.0.0/ts
10
10
 
11
11
  Pragmastat on npm: https://www.npmjs.com/package/pragmastat
12
12
 
@@ -14,68 +14,81 @@ Pragmastat on npm: https://www.npmjs.com/package/pragmastat
14
14
 
15
15
  ```typescript
16
16
  import {
17
- center, spread, shift, ratio, disparity,
18
- centerBounds, shiftBounds, ratioBounds,
19
- spreadBounds, disparityBounds,
20
- Rng, Additive, Multiplic, Exp, Power, Uniform
17
+ center,
18
+ spread,
19
+ shift,
20
+ ratio,
21
+ disparity,
22
+ centerBounds,
23
+ shiftBounds,
24
+ ratioBounds,
25
+ spreadBounds,
26
+ disparityBounds,
27
+ Rng,
28
+ Additive,
29
+ Multiplic,
30
+ Exp,
31
+ Power,
32
+ Uniform,
33
+ Sample,
21
34
  } from 'pragmastat';
22
35
 
23
- function main() {
24
- // --- One-Sample ---
36
+ function main(): void {
37
+ // --- One-Sample ---
25
38
 
26
- let x = Array.from({ length: 20 }, (_, i) => i + 1);
39
+ let sx = Sample.of(Array.from({ length: 22 }, (_, i) => i + 1));
27
40
 
28
- console.log(center(x)); // 10.5
29
- console.log(centerBounds(x, 0.05)); // { lower: 7.5, upper: 13.5 }
30
- console.log(spread(x)); // 6
31
- console.log(spreadBounds(x, 0.05, "demo")); // { lower: 2, upper: 10 }
41
+ console.log(center(sx).value); // 11.5
42
+ console.log(centerBounds(sx, 1e-3)); // { lower: 6, upper: 17, unit: ... }
43
+ console.log(spread(sx).value); // 7
44
+ console.log(spreadBounds(sx, 1e-3, 'demo')); // { lower: 1, upper: 18, unit: ... }
32
45
 
33
- // --- Two-Sample ---
46
+ // --- Two-Sample ---
34
47
 
35
- x = Array.from({ length: 30 }, (_, i) => i + 1);
36
- let y = Array.from({ length: 30 }, (_, i) => i + 21);
48
+ sx = Sample.of(Array.from({ length: 30 }, (_, i) => i + 1));
49
+ const sy = Sample.of(Array.from({ length: 30 }, (_, i) => i + 21));
37
50
 
38
- console.log(shift(x, y)); // -20
39
- console.log(shiftBounds(x, y, 0.05)); // { lower: -25, upper: -15 }
40
- console.log(ratio(x, y)); // 0.4366979828269513
41
- console.log(ratioBounds(x, y, 0.05)); // { lower: 0.31250000000000006, upper: 0.5600000000000003 }
42
- console.log(disparity(x, y)); // -2.2222222222222223
43
- console.log(disparityBounds(x, y, 0.05, "demo")); // { lower: -13, upper: -0.8235294117647058 }
51
+ console.log(shift(sx, sy).value); // -20
52
+ console.log(shiftBounds(sx, sy, 1e-3)); // { lower: -28, upper: -12, unit: ... }
53
+ console.log(ratio(sx, sy).value); // 0.4366979828269513
54
+ console.log(ratioBounds(sx, sy, 1e-3)); // { lower: 0.2325..., upper: 0.6428..., unit: ... }
55
+ console.log(disparity(sx, sy).value); // -2.2222222222222223
56
+ console.log(disparityBounds(sx, sy, 1e-3, 'demo')); // { lower: -29, upper: -0.478..., unit: ... }
44
57
 
45
- // --- Randomization ---
58
+ // --- Randomization ---
46
59
 
47
- let rng = new Rng("demo-uniform");
48
- console.log(rng.uniformFloat()); // 0.2640554428629759
49
- console.log(rng.uniformFloat()); // 0.9348534835582796
60
+ let rng = new Rng('demo-uniform');
61
+ console.log(rng.uniformFloat()); // 0.2640554428629759
62
+ console.log(rng.uniformFloat()); // 0.9348534835582796
50
63
 
51
- rng = new Rng("demo-uniform-int");
52
- console.log(rng.uniformInt(0, 100)); // 41
64
+ rng = new Rng('demo-uniform-int');
65
+ console.log(rng.uniformInt(0, 100)); // 41
53
66
 
54
- rng = new Rng("demo-sample");
55
- console.log(rng.sample([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 3)); // [3, 8, 9]
67
+ rng = new Rng('demo-sample');
68
+ console.log(JSON.stringify(rng.sample([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], 3))); // [3,8,9]
56
69
 
57
- rng = new Rng("demo-resample");
58
- console.log(rng.resample([1, 2, 3, 4, 5], 7)); // [3, 1, 3, 2, 4, 1, 2]
70
+ rng = new Rng('demo-resample');
71
+ console.log(JSON.stringify(rng.resample([1, 2, 3, 4, 5], 7))); // [3,1,3,2,4,1,2]
59
72
 
60
- rng = new Rng("demo-shuffle");
61
- console.log(rng.shuffle([1, 2, 3, 4, 5])); // [4, 2, 3, 5, 1]
73
+ rng = new Rng('demo-shuffle');
74
+ console.log(JSON.stringify(rng.shuffle([1, 2, 3, 4, 5]))); // [4,2,3,5,1]
62
75
 
63
- // --- Distributions ---
76
+ // --- Distributions ---
64
77
 
65
- rng = new Rng("demo-dist-additive");
66
- console.log(new Additive(0, 1).sample(rng)); // 0.17410448679568188
78
+ rng = new Rng('demo-dist-additive');
79
+ console.log(new Additive(0, 1).sample(rng)); // 0.17410448679568188
67
80
 
68
- rng = new Rng("demo-dist-multiplic");
69
- console.log(new Multiplic(0, 1).sample(rng)); // 1.1273244602673853
81
+ rng = new Rng('demo-dist-multiplic');
82
+ console.log(new Multiplic(0, 1).sample(rng)); // 1.1273244602673853
70
83
 
71
- rng = new Rng("demo-dist-exp");
72
- console.log(new Exp(1).sample(rng)); // 0.6589065267276553
84
+ rng = new Rng('demo-dist-exp');
85
+ console.log(new Exp(1).sample(rng)); // 0.6589065267276553
73
86
 
74
- rng = new Rng("demo-dist-power");
75
- console.log(new Power(1, 2).sample(rng)); // 1.023677535537084
87
+ rng = new Rng('demo-dist-power');
88
+ console.log(new Power(1, 2).sample(rng)); // 1.023677535537084
76
89
 
77
- rng = new Rng("demo-dist-uniform");
78
- console.log(new Uniform(0, 10).sample(rng)); // 6.54043657816832
90
+ rng = new Rng('demo-dist-uniform');
91
+ console.log(new Uniform(0, 10).sample(rng)); // 6.54043657816832
79
92
  }
80
93
 
81
94
  main();
@@ -23,8 +23,8 @@ export interface Violation {
23
23
  subject: Subject;
24
24
  }
25
25
  export declare class AssumptionError extends Error {
26
- readonly violation: Violation;
27
- constructor(violation: Violation);
26
+ readonly violation: Violation | null;
27
+ constructor(violationOrMessage: Violation | string);
28
28
  static validity(subject: Subject): AssumptionError;
29
29
  static positivity(subject: Subject): AssumptionError;
30
30
  static sparity(subject: Subject): AssumptionError;
@@ -1 +1 @@
1
- {"version":3,"file":"assumptions.d.ts","sourceRoot":"","sources":["../src/assumptions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,eAAO,MAAM,YAAY;;;;;CAKf,CAAC;AAEX,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,YAAY,CAAC,CAAC,MAAM,OAAO,YAAY,CAAC,CAAC;AAE5E,MAAM,MAAM,OAAO,GAAG,GAAG,GAAG,GAAG,GAAG,SAAS,CAAC;AAE5C,MAAM,WAAW,SAAS;IACxB,EAAE,EAAE,YAAY,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,qBAAa,eAAgB,SAAQ,KAAK;IACxC,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;gBAElB,SAAS,EAAE,SAAS;IAOhC,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,eAAe;IAIlD,MAAM,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,GAAG,eAAe;IAIpD,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,eAAe;IAIjD,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,eAAe;CAGjD;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAOtE;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,OAAO,EAAE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ionId = {
23
23
  SPARITY: 'sparity',
24
24
  };
25
25
  class AssumptionError extends Error {
26
- constructor(violation) {
27
- const violationStr = `${violation.id}(${violation.subject})`;
28
- super(violationStr);
26
+ constructor(violationOrMessage) {
27
+ if (typeof violationOrMessage === 'string') {
28
+ super(violationOrMessage);
29
+ this.violation = null;
30
+ }
31
+ else {
32
+ const violationStr = `${violationOrMessage.id}(${violationOrMessage.subject})`;
33
+ super(violationStr);
34
+ this.violation = violationOrMessage;
35
+ }
29
36
  this.name = 'AssumptionError';
30
- this.violation = violation;
31
37
  }
32
38
  static validity(subject) {
33
39
  return new AssumptionError({ id: exports.AssumptionId.VALIDITY, subject });
@@ -1 +1 @@
1
- {"version":3,"file":"assumptions.js","sourceRoot":"","sources":["../src/assumptions.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;GAWG;;;AA6CH,sCAOC;AAED,0CAIC;AAKD,kBASC;AAtEY,QAAA,YAAY,GAAG;IAC1B,QAAQ,EAAE,UAAU;IACpB,MAAM,EAAE,QAAQ;IAChB,UAAU,EAAE,YAAY;IACxB,OAAO,EAAE,SAAS;CACV,CAAC;AAWX,MAAa,eAAgB,SAAQ,KAAK;IAGxC,YAAY,SAAoB;QAC9B,MAAM,YAAY,GAAG,GAAG,SAAS,CAAC,EAAE,IAAI,SAAS,CAAC,OAAO,GAAG,CAAC;QAC7D,KAAK,CAAC,YAAY,CAAC,CAAC;QACpB,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED,MAAM,CAAC,QAAQ,CAAC,OAAgB;QAC9B,OAAO,IAAI,eAAe,CAAC,EAAE,EAAE,EAAE,oBAAY,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;IACrE,CAAC;IAED,MAAM,CAAC,UAAU,CAAC,OAAgB;QAChC,OAAO,IAAI,eAAe,CAAC,EAAE,EAAE,EAAE,oBAAY,CAAC,UAAU,EAAE,O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C,UAAU,CAAC,OAAO,CAAC,CAAC;QAC5C,CAAC;QACD,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAClC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -1,171 +1,121 @@
1
1
  /**
2
2
  * Pragmastat estimators implementation
3
3
  */
4
+ import { MeasurementUnit } from './measurement-unit';
5
+ import { Measurement } from './measurement';
6
+ import { Sample } from './sample';
7
+ /**
8
+ * Represents an interval with lower and upper bounds and a unit.
9
+ */
10
+ export declare class Bounds {
11
+ readonly lower: number;
12
+ readonly upper: number;
13
+ readonly unit: MeasurementUnit;
14
+ constructor(lower: number, upper: number, unit: MeasurementUnit);
15
+ contains(value: number): boolean;
16
+ }
17
+ export declare const DEFAULT_MISRATE = 0.001;
4
18
  /**
5
19
  * Calculate the Center - median of all pairwise averages (x[i] + x[j])/2
6
20
  * Uses fast O(n log n) algorithm.
7
- * @param x Array of sample values
8
- * @returns The center estimate
21
+ * @param x Sample
22
+ * @returns The center measurement
9
23
  */
10
- export declare function center(x: number[]): number;
24
+ export declare function center(x: Sample): Measurement;
11
25
  /**
12
26
  * Calculate the Spread - median of all pairwise absolute differences |x[i] - x[j]|
13
27
  * Uses fast O(n log n) algorithm.
14
28
  *
15
- * Assumptions:
16
- * sparity(x) - sample must be non tie-dominant (Spread > 0)
17
- *
18
- * @param x Array of sample values
19
- * @returns The spread estimate
20
- * @throws AssumptionError if sample is empty, contains NaN/Inf, or is tie-dominant
29
+ * @param x Sample
30
+ * @returns The spread measurement
31
+ * @throws AssumptionError if sample is tie-dominant
21
32
  */
22
- export declare function spread(x: number[]): number;
23
- /**
24
- * Calculate the RelSpread - ratio of Spread to absolute Center
25
- *
26
- * @deprecated Use `spread(x) / Math.abs(center(x))` instead.
27
- *
28
- * Assumptions:
29
- * positivity(x) - all values must be strictly positive (ensures Center > 0)
30
- *
31
- * @param x Array of sample values
32
- * @returns The relative spread estimate
33
- * @throws AssumptionError if sample is empty, contains NaN/Inf, or contains non-positive values
34
- */
35
- export declare function relSpread(x: number[]): number;
33
+ export declare function spread(x: Sample): Measurement;
36
34
  /**
37
35
  * Calculate the Shift - median of all pairwise differences (x[i] - y[j])
38
36
  * Uses fast O((m + n) * log(precision)) algorithm.
39
37
  * @param x First sample
40
38
  * @param y Second sample
41
- * @returns The shift estimate
39
+ * @returns The shift measurement
42
40
  */
43
- export declare function shift(x: number[], y: number[]): number;
41
+ export declare function shift(x: Sample, y: Sample): Measurement;
44
42
  /**
45
43
  * Calculate the Ratio - median of all pairwise ratios (x[i] / y[j]) via log-transformation
46
44
  * Equivalent to: exp(Shift(log(x), log(y)))
47
- * Uses fast O((m + n) * log(precision)) algorithm.
48
- *
49
- * Assumptions:
50
- * positivity(x) - all values in x must be strictly positive
51
- * positivity(y) - all values in y must be strictly positive
52
45
  *
53
46
  * @param x First sample
54
47
  * @param y Second sample
55
- * @returns The ratio estimate
56
- * @throws AssumptionError if either sample is empty, contains NaN/Inf, or contains non-positive values
48
+ * @returns The ratio measurement
49
+ * @throws AssumptionError if either sample contains non-positive values
57
50
  */
58
- export declare function ratio(x: number[], y: number[]): number;
51
+ export declare function ratio(x: Sample, y: Sample): Measurement;
59
52
  /**
60
53
  * Calculate the AvgSpread - weighted average of spreads: (n*Spread(x) + m*Spread(y))/(n+m)
61
54
  *
62
- * Assumptions:
63
- * sparity(x) - first sample must be non tie-dominant (Spread > 0)
64
- * sparity(y) - second sample must be non tie-dominant (Spread > 0)
65
- *
66
55
  * @internal
67
56
  * @param x First sample
68
57
  * @param y Second sample
69
- * @returns The combined spread estimate
70
- * @throws AssumptionError if either sample is empty, contains NaN/Inf, or is tie-dominant
58
+ * @returns The combined spread measurement
71
59
  */
72
- declare function avgSpread(x: number[], y: number[]): number;
60
+ declare function avgSpread(x: Sample, y: Sample): Measurement;
73
61
  /**
74
62
  * Calculate the Disparity - Shift / AvgSpread
75
63
  *
76
- * Assumptions:
77
- * sparity(x) - first sample must be non tie-dominant (Spread > 0)
78
- * sparity(y) - second sample must be non tie-dominant (Spread > 0)
79
- *
80
64
  * @param x First sample
81
65
  * @param y Second sample
82
- * @returns The disparity estimate
83
- * @throws AssumptionError if either sample is empty, contains NaN/Inf, or is tie-dominant
66
+ * @returns The disparity measurement
84
67
  */
85
- export declare function disparity(x: number[], y: number[]): number;
86
- export declare const DEFAULT_MISRATE = 0.001;
87
- /**
88
- * Represents an interval with lower and upper bounds
89
- */
90
- export interface Bounds {
91
- lower: number;
92
- upper: number;
93
- }
68
+ export declare function disparity(x: Sample, y: Sample): Measurement;
94
69
  /**
95
70
  * Provides bounds on the Shift estimator with specified misclassification rate (ShiftBounds)
96
71
  *
97
- * The misrate represents the probability that the true shift falls outside the computed bounds.
98
- * This is a pragmatic alternative to traditional confidence intervals for the Hodges-Lehmann estimator.
99
- *
100
72
  * @param x First sample
101
73
  * @param y Second sample
102
- * @param misrate Misclassification rate (probability that true shift falls outside bounds)
103
- * @returns An object containing the lower and upper bounds
104
- * @throws AssumptionError if either sample is empty or contains NaN/Inf
74
+ * @param misrate Misclassification rate
75
+ * @returns Bounds with lower, upper, and unit
105
76
  */
106
- export declare function shiftBounds(x: number[], y: number[], misrate?: number): Bounds;
77
+ export declare function shiftBounds(x: Sample, y: Sample, misrate?: number): Bounds;
107
78
  /**
108
79
  * Provides bounds on the Ratio estimator with specified misclassification rate (RatioBounds)
109
80
  *
110
- * Computes bounds via log-transformation and ShiftBounds delegation:
111
- * RatioBounds(x, y, misrate) = exp(ShiftBounds(log(x), log(y), misrate))
112
- *
113
- * Assumptions:
114
- * positivity(x) - all values in x must be strictly positive
115
- * positivity(y) - all values in y must be strictly positive
116
- *
117
81
  * @param x First sample
118
82
  * @param y Second sample
119
- * @param misrate Misclassification rate (probability that true ratio falls outside bounds)
120
- * @returns An object containing the lower and upper bounds
121
- * @throws AssumptionError if either sample is empty, contains NaN/Inf, or contains non-positive values
83
+ * @param misrate Misclassification rate
84
+ * @returns Bounds with lower, upper, and unit
122
85
  */
123
- export declare function ratioBounds(x: number[], y: number[], misrate?: number): Bounds;
86
+ export declare function ratioBounds(x: Sample, y: Sample, misrate?: number): Bounds;
124
87
  /**
125
- * Provides exact bounds on the Center (Hodges-Lehmann pseudomedian) with specified misclassification rate
88
+ * Provides exact bounds on the Center (Hodges-Lehmann pseudomedian)
126
89
  *
127
- * Uses SignedRankMargin to determine which pairwise averages form the bounds.
128
- *
129
- * @param x Sample array
130
- * @param misrate Misclassification rate (probability that true center falls outside bounds)
131
- * @returns An object containing the lower and upper bounds
132
- * @throws AssumptionError if sample is empty or contains NaN/Inf
90
+ * @param x Sample
91
+ * @param misrate Misclassification rate
92
+ * @returns Bounds with lower, upper, and unit
133
93
  */
134
- export declare function centerBounds(x: number[], misrate?: number): Bounds;
94
+ export declare function centerBounds(x: Sample, misrate?: number): Bounds;
135
95
  /**
136
- * Provides distribution-free bounds for the Spread estimator using disjoint pairs
137
- * with sign-test inversion.
96
+ * Provides distribution-free bounds for the Spread estimator
138
97
  *
139
- * @param x Sample array
140
- * @param misrate Misclassification rate (probability that true spread falls outside bounds)
141
- * @param seed Optional string seed for deterministic randomization
142
- * @returns An object containing the lower and upper bounds
143
- * @throws AssumptionError if sample is invalid, misrate is out of domain, or sample is tie-dominant
98
+ * @param x Sample
99
+ * @param misrate Misclassification rate
100
+ * @param seed Optional string seed
101
+ * @returns Bounds with lower, upper, and unit
144
102
  */
145
- export declare function spreadBounds(x: number[], misrate?: number, seed?: string): Bounds;
103
+ export declare function spreadBounds(x: Sample, misrate?: number, seed?: string): Bounds;
146
104
  /**
147
- * Provides distribution-free bounds for AvgSpread using Bonferroni combination.
105
+ * Internal AvgSpreadBounds using Bonferroni combination.
148
106
  *
149
107
  * @internal
150
- * @param x First sample array
151
- * @param y Second sample array
152
- * @param misrate Misclassification rate (probability that true avg_spread falls outside bounds)
153
- * @param seed Optional string seed for deterministic randomization
154
- * @returns An object containing the lower and upper bounds
155
- * @throws AssumptionError if input is invalid, misrate is out of domain, or sample is tie-dominant
156
108
  */
157
- declare function avgSpreadBounds(x: number[], y: number[], misrate?: number, seed?: string): Bounds;
109
+ declare function avgSpreadBounds(x: Sample, y: Sample, misrate?: number, seed?: string): Bounds;
158
110
  /**
159
- * Provides distribution-free bounds for the Disparity estimator (Shift / AvgSpread)
160
- * using Bonferroni combination of ShiftBounds and AvgSpreadBounds.
111
+ * Provides distribution-free bounds for the Disparity estimator
161
112
  *
162
113
  * @param x First sample
163
114
  * @param y Second sample
164
115
  * @param misrate Misclassification rate
165
- * @param seed Optional string seed for deterministic randomization
166
- * @returns An object containing the lower and upper bounds
167
- * @throws AssumptionError if inputs are invalid, misrate is out of domain, or samples are tie-dominant
116
+ * @param seed Optional string seed
117
+ * @returns Bounds with lower, upper, and unit
168
118
  */
169
- export declare function disparityBounds(x: number[], y: number[], misrate?: number, seed?: string): Bounds;
119
+ export declare function disparityBounds(x: Sample, y: Sample, misrate?: number, seed?: string): Bounds;
170
120
  export { avgSpread as _avgSpread, avgSpreadBounds as _avgSpreadBounds };
171
121
  //# sourceMappingURL=estimators.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"estimators.d.ts","sourceRoot":"","sources":["../src/estimators.ts"],"names":[],"mappings":"AAAA;;GAEG;AAaH;;;;;GAKG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAI1C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAQ1C;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,SAAS,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAW7C;AAED;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAMtD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,KAAK,CAAC,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