@the-situation/core 0.5.0-alpha.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/dist/distributions/distribution.d.ts +60 -0
- package/dist/distributions/distribution.d.ts.map +1 -0
- package/dist/distributions/distribution.js +10 -0
- package/dist/distributions/distribution.js.map +1 -0
- package/dist/distributions/normal-distribution.d.ts +125 -0
- package/dist/distributions/normal-distribution.d.ts.map +1 -0
- package/dist/distributions/normal-distribution.js +310 -0
- package/dist/distributions/normal-distribution.js.map +1 -0
- package/dist/distributions/normal-sqrt-hints-raw.d.ts +18 -0
- package/dist/distributions/normal-sqrt-hints-raw.d.ts.map +1 -0
- package/dist/distributions/normal-sqrt-hints-raw.js +9 -0
- package/dist/distributions/normal-sqrt-hints-raw.js.map +1 -0
- package/dist/errors/index.d.ts +90 -0
- package/dist/errors/index.d.ts.map +1 -0
- package/dist/errors/index.js +45 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/math/sq128-raw.d.ts +69 -0
- package/dist/math/sq128-raw.d.ts.map +1 -0
- package/dist/math/sq128-raw.js +84 -0
- package/dist/math/sq128-raw.js.map +1 -0
- package/dist/math/sq128.d.ts +191 -0
- package/dist/math/sq128.d.ts.map +1 -0
- package/dist/math/sq128.js +611 -0
- package/dist/math/sq128.js.map +1 -0
- package/package.json +29 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic distribution interface.
|
|
3
|
+
*
|
|
4
|
+
* Defines the contract that all distribution types must satisfy
|
|
5
|
+
* for use in collateral computation, trade planning, and contract interaction.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
import type { SQ128x128 } from '../math/sq128';
|
|
10
|
+
/**
|
|
11
|
+
* Generic distribution interface parameterised by its raw DTO shape.
|
|
12
|
+
*
|
|
13
|
+
* Every concrete distribution (Normal, LogNormal, ...) implements this so
|
|
14
|
+
* that collateral, starknet, and SDK packages can program against the
|
|
15
|
+
* interface without knowing the concrete type.
|
|
16
|
+
*
|
|
17
|
+
* @typeParam TRaw - The raw DTO type used for serialization/deserialization
|
|
18
|
+
*/
|
|
19
|
+
export interface Distribution<TRaw> {
|
|
20
|
+
/** The mean of the distribution. */
|
|
21
|
+
readonly mean: SQ128x128;
|
|
22
|
+
/** The variance of the distribution. */
|
|
23
|
+
readonly variance: SQ128x128;
|
|
24
|
+
/** The standard deviation (sigma). */
|
|
25
|
+
readonly sigma: SQ128x128;
|
|
26
|
+
/**
|
|
27
|
+
* Evaluates the probability density function at point x.
|
|
28
|
+
*
|
|
29
|
+
* @param x - The point at which to evaluate
|
|
30
|
+
* @returns The PDF value, or null if computation fails
|
|
31
|
+
*/
|
|
32
|
+
pdf(x: SQ128x128): SQ128x128 | null;
|
|
33
|
+
/**
|
|
34
|
+
* Evaluates the first derivative of the PDF at point x.
|
|
35
|
+
*
|
|
36
|
+
* @param x - The point at which to evaluate
|
|
37
|
+
* @returns The derivative value, or null if computation fails
|
|
38
|
+
*/
|
|
39
|
+
pdfDerivative(x: SQ128x128): SQ128x128 | null;
|
|
40
|
+
/**
|
|
41
|
+
* Evaluates the second derivative of the PDF at point x.
|
|
42
|
+
*
|
|
43
|
+
* @param x - The point at which to evaluate
|
|
44
|
+
* @returns The second derivative value, or null if computation fails
|
|
45
|
+
*/
|
|
46
|
+
pdfSecondDerivative(x: SQ128x128): SQ128x128 | null;
|
|
47
|
+
/**
|
|
48
|
+
* Returns true if this is a degenerate (point mass) distribution.
|
|
49
|
+
*/
|
|
50
|
+
isDegenerate(): boolean;
|
|
51
|
+
/**
|
|
52
|
+
* Returns true if this distribution is identical to another.
|
|
53
|
+
*/
|
|
54
|
+
isIdentical(other: Distribution<TRaw>): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Converts to the raw DTO for Starknet serialization.
|
|
57
|
+
*/
|
|
58
|
+
toRaw(): TRaw;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=distribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"distribution.d.ts","sourceRoot":"","sources":["../../src/distributions/distribution.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE/C;;;;;;;;GAQG;AACH,MAAM,WAAW,YAAY,CAAC,IAAI;IAChC,oCAAoC;IACpC,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IAEzB,wCAAwC;IACxC,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAE7B,sCAAsC;IACtC,QAAQ,CAAC,KAAK,EAAE,SAAS,CAAC;IAE1B;;;;;OAKG;IACH,GAAG,CAAC,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,IAAI,CAAC;IAEpC;;;;;OAKG;IACH,aAAa,CAAC,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,IAAI,CAAC;IAE9C;;;;;OAKG;IACH,mBAAmB,CAAC,CAAC,EAAE,SAAS,GAAG,SAAS,GAAG,IAAI,CAAC;IAEpD;;OAEG;IACH,YAAY,IAAI,OAAO,CAAC;IAExB;;OAEG;IACH,WAAW,CAAC,KAAK,EAAE,YAAY,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC;IAEhD;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;CACf"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic distribution interface.
|
|
3
|
+
*
|
|
4
|
+
* Defines the contract that all distribution types must satisfy
|
|
5
|
+
* for use in collateral computation, trade planning, and contract interaction.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=distribution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"distribution.js","sourceRoot":"","sources":["../../src/distributions/distribution.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normal distribution type for prediction market pricing.
|
|
3
|
+
*
|
|
4
|
+
* Represents a Gaussian distribution N(μ, σ²) with fixed-point arithmetic.
|
|
5
|
+
*
|
|
6
|
+
* ## Invariants
|
|
7
|
+
* - variance >= 0
|
|
8
|
+
* - sigma = sqrt(variance) (computed at construction)
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
import { SQ128x128 } from '../math/sq128';
|
|
13
|
+
import type { SQ128x128Raw } from '../math/sq128-raw';
|
|
14
|
+
/**
|
|
15
|
+
* Raw representation for serialization.
|
|
16
|
+
*/
|
|
17
|
+
export interface NormalDistributionRaw {
|
|
18
|
+
readonly mean: SQ128x128Raw;
|
|
19
|
+
readonly variance: SQ128x128Raw;
|
|
20
|
+
readonly sigma: SQ128x128Raw;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A normal (Gaussian) distribution with fixed-point parameters.
|
|
24
|
+
*
|
|
25
|
+
* Immutable: all fields are readonly.
|
|
26
|
+
*/
|
|
27
|
+
export declare class NormalDistribution {
|
|
28
|
+
/** The mean (μ) of the distribution */
|
|
29
|
+
readonly mean: SQ128x128;
|
|
30
|
+
/** The variance (σ²) of the distribution */
|
|
31
|
+
readonly variance: SQ128x128;
|
|
32
|
+
/** The standard deviation (σ = √variance) */
|
|
33
|
+
readonly sigma: SQ128x128;
|
|
34
|
+
private constructor();
|
|
35
|
+
/**
|
|
36
|
+
* Creates a normal distribution, computing sigma from variance.
|
|
37
|
+
*
|
|
38
|
+
* @param mean - The mean of the distribution
|
|
39
|
+
* @param variance - The variance (must be >= 0)
|
|
40
|
+
* @returns The distribution, or null if variance < 0
|
|
41
|
+
*/
|
|
42
|
+
static create(mean: SQ128x128, variance: SQ128x128): NormalDistribution | null;
|
|
43
|
+
/**
|
|
44
|
+
* Creates a normal distribution with a precomputed sigma.
|
|
45
|
+
*
|
|
46
|
+
* Use this when sigma has already been computed (e.g., from contract state)
|
|
47
|
+
* to avoid redundant sqrt computation.
|
|
48
|
+
*
|
|
49
|
+
* @param mean - The mean
|
|
50
|
+
* @param variance - The variance (must be >= 0)
|
|
51
|
+
* @param sigma - The precomputed sigma (must be >= 0, and sigma² ≈ variance)
|
|
52
|
+
* @returns The distribution, or null if invalid
|
|
53
|
+
*/
|
|
54
|
+
static withSigma(mean: SQ128x128, variance: SQ128x128, sigma: SQ128x128): NormalDistribution | null;
|
|
55
|
+
/**
|
|
56
|
+
* Creates from a raw representation.
|
|
57
|
+
*
|
|
58
|
+
* @param raw - The raw representation
|
|
59
|
+
* @returns The distribution, or null if invalid
|
|
60
|
+
*/
|
|
61
|
+
static fromRaw(raw: NormalDistributionRaw): NormalDistribution | null;
|
|
62
|
+
/**
|
|
63
|
+
* Converts to a raw representation for serialization.
|
|
64
|
+
*/
|
|
65
|
+
toRaw(): NormalDistributionRaw;
|
|
66
|
+
/**
|
|
67
|
+
* Returns true if this is a degenerate (point mass) distribution.
|
|
68
|
+
*
|
|
69
|
+
* A degenerate distribution has zero variance, representing
|
|
70
|
+
* a certain outcome at the mean value.
|
|
71
|
+
*/
|
|
72
|
+
isDegenerate(): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Returns the standard deviation (sigma).
|
|
75
|
+
*
|
|
76
|
+
* This is a convenience accessor; use `.sigma` for direct access.
|
|
77
|
+
*/
|
|
78
|
+
stdDev(): SQ128x128;
|
|
79
|
+
/**
|
|
80
|
+
* Computes the probability density function (PDF) at point x.
|
|
81
|
+
*
|
|
82
|
+
* φ(x; μ, σ) = (1/σ) * (1/√(2π)) * exp(-z²/2)
|
|
83
|
+
* where z = (x - μ) / σ
|
|
84
|
+
*
|
|
85
|
+
* For degenerate distributions (σ = 0), returns ZERO.
|
|
86
|
+
*
|
|
87
|
+
* @param x - The point at which to evaluate the PDF
|
|
88
|
+
* @returns The PDF value, or null if computation fails
|
|
89
|
+
*/
|
|
90
|
+
pdf(x: SQ128x128): SQ128x128 | null;
|
|
91
|
+
/**
|
|
92
|
+
* Computes the first derivative of the PDF at point x.
|
|
93
|
+
*
|
|
94
|
+
* φ'(x; μ, σ) = -((x - μ) / σ²) * φ(x; μ, σ)
|
|
95
|
+
*
|
|
96
|
+
* For degenerate distributions (σ = 0), returns ZERO.
|
|
97
|
+
*
|
|
98
|
+
* @param x - The point at which to evaluate the derivative
|
|
99
|
+
* @returns The derivative value, or null if computation fails
|
|
100
|
+
*/
|
|
101
|
+
pdfDerivative(x: SQ128x128): SQ128x128 | null;
|
|
102
|
+
/**
|
|
103
|
+
* Computes the second derivative of the PDF at point x.
|
|
104
|
+
*
|
|
105
|
+
* φ''(x; μ, σ) = (((x - μ)² / σ⁴) - (1 / σ²)) * φ(x; μ, σ)
|
|
106
|
+
*
|
|
107
|
+
* For degenerate distributions (σ = 0), returns ZERO.
|
|
108
|
+
*
|
|
109
|
+
* @param x - The point at which to evaluate the second derivative
|
|
110
|
+
* @returns The second derivative value, or null if computation fails
|
|
111
|
+
*/
|
|
112
|
+
pdfSecondDerivative(x: SQ128x128): SQ128x128 | null;
|
|
113
|
+
/**
|
|
114
|
+
* Checks if two distributions are identical (same mean AND same variance).
|
|
115
|
+
*
|
|
116
|
+
* When f = g, d(x) = g(x) - f(x) = 0 everywhere, so:
|
|
117
|
+
* - Any point is a valid minimum
|
|
118
|
+
* - Required collateral = 0
|
|
119
|
+
*
|
|
120
|
+
* @param other - The other distribution to compare
|
|
121
|
+
* @returns True if the distributions are identical
|
|
122
|
+
*/
|
|
123
|
+
isIdentical(other: NormalDistribution): boolean;
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=normal-distribution.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normal-distribution.d.ts","sourceRoot":"","sources":["../../src/distributions/normal-distribution.ts"],"names":[],"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ASG;IACI,WAAW,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO;CAGvD"}
|
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normal distribution type for prediction market pricing.
|
|
3
|
+
*
|
|
4
|
+
* Represents a Gaussian distribution N(μ, σ²) with fixed-point arithmetic.
|
|
5
|
+
*
|
|
6
|
+
* ## Invariants
|
|
7
|
+
* - variance >= 0
|
|
8
|
+
* - sigma = sqrt(variance) (computed at construction)
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
import { INV_SQRT_2PI, ONE, SQ128x128, ZERO } from '../math/sq128';
|
|
13
|
+
/** Cached constant for sqrt computation */
|
|
14
|
+
const TWO = SQ128x128.fromNumber(2);
|
|
15
|
+
const EPSILON = SQ128x128.fromNumber(1e-15);
|
|
16
|
+
const MAX_SQRT_ITERATIONS = 50;
|
|
17
|
+
/**
|
|
18
|
+
* Performs a single Newton-Raphson iteration for sqrt.
|
|
19
|
+
*
|
|
20
|
+
* @returns The next guess, or null on arithmetic failure
|
|
21
|
+
*/
|
|
22
|
+
function sqrtIteration(x, guess) {
|
|
23
|
+
const quotient = x.div(guess);
|
|
24
|
+
if (!quotient) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const sum = guess.add(quotient);
|
|
28
|
+
if (!sum) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
return sum.div(TWO);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Checks if the sqrt iteration has converged.
|
|
35
|
+
*/
|
|
36
|
+
function sqrtConverged(current, next) {
|
|
37
|
+
const diff = next.sub(current);
|
|
38
|
+
if (!diff) {
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
return diff.abs().lt(EPSILON);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Computes an approximation of sqrt(x) using Newton-Raphson.
|
|
45
|
+
*
|
|
46
|
+
* @param x - The value to take the square root of
|
|
47
|
+
* @returns The square root, or null if x < 0
|
|
48
|
+
*/
|
|
49
|
+
function sqrt(x) {
|
|
50
|
+
if (x.isNegative()) {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
if (x.isZero()) {
|
|
54
|
+
return ZERO;
|
|
55
|
+
}
|
|
56
|
+
// Initial guess: x/2 or 1 if x < 2
|
|
57
|
+
let guess = x.gt(TWO) ? x.div(TWO) : ONE;
|
|
58
|
+
if (!guess) {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
for (let i = 0; i < MAX_SQRT_ITERATIONS; i++) {
|
|
62
|
+
const nextGuess = sqrtIteration(x, guess);
|
|
63
|
+
if (!nextGuess) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
if (sqrtConverged(guess, nextGuess)) {
|
|
67
|
+
return nextGuess;
|
|
68
|
+
}
|
|
69
|
+
guess = nextGuess;
|
|
70
|
+
}
|
|
71
|
+
return guess;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* A normal (Gaussian) distribution with fixed-point parameters.
|
|
75
|
+
*
|
|
76
|
+
* Immutable: all fields are readonly.
|
|
77
|
+
*/
|
|
78
|
+
export class NormalDistribution {
|
|
79
|
+
/** The mean (μ) of the distribution */
|
|
80
|
+
mean;
|
|
81
|
+
/** The variance (σ²) of the distribution */
|
|
82
|
+
variance;
|
|
83
|
+
/** The standard deviation (σ = √variance) */
|
|
84
|
+
sigma;
|
|
85
|
+
constructor(mean, variance, sigma) {
|
|
86
|
+
this.mean = mean;
|
|
87
|
+
this.variance = variance;
|
|
88
|
+
this.sigma = sigma;
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Creates a normal distribution, computing sigma from variance.
|
|
92
|
+
*
|
|
93
|
+
* @param mean - The mean of the distribution
|
|
94
|
+
* @param variance - The variance (must be >= 0)
|
|
95
|
+
* @returns The distribution, or null if variance < 0
|
|
96
|
+
*/
|
|
97
|
+
static create(mean, variance) {
|
|
98
|
+
if (variance.isNegative()) {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
const sigma = sqrt(variance);
|
|
102
|
+
if (!sigma) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
return new NormalDistribution(mean, variance, sigma);
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Creates a normal distribution with a precomputed sigma.
|
|
109
|
+
*
|
|
110
|
+
* Use this when sigma has already been computed (e.g., from contract state)
|
|
111
|
+
* to avoid redundant sqrt computation.
|
|
112
|
+
*
|
|
113
|
+
* @param mean - The mean
|
|
114
|
+
* @param variance - The variance (must be >= 0)
|
|
115
|
+
* @param sigma - The precomputed sigma (must be >= 0, and sigma² ≈ variance)
|
|
116
|
+
* @returns The distribution, or null if invalid
|
|
117
|
+
*/
|
|
118
|
+
static withSigma(mean, variance, sigma) {
|
|
119
|
+
if (variance.isNegative() || sigma.isNegative()) {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
// For zero variance, sigma must also be zero
|
|
123
|
+
if (variance.isZero() && !sigma.isZero()) {
|
|
124
|
+
return null;
|
|
125
|
+
}
|
|
126
|
+
return new NormalDistribution(mean, variance, sigma);
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Creates from a raw representation.
|
|
130
|
+
*
|
|
131
|
+
* @param raw - The raw representation
|
|
132
|
+
* @returns The distribution, or null if invalid
|
|
133
|
+
*/
|
|
134
|
+
static fromRaw(raw) {
|
|
135
|
+
const mean = SQ128x128.fromRaw(raw.mean);
|
|
136
|
+
const variance = SQ128x128.fromRaw(raw.variance);
|
|
137
|
+
const sigma = SQ128x128.fromRaw(raw.sigma);
|
|
138
|
+
// biome-ignore lint/complexity/useSimplifiedLogicExpression: readability is better with explicit null checks
|
|
139
|
+
if (!mean || !variance || !sigma) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
return NormalDistribution.withSigma(mean, variance, sigma);
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Converts to a raw representation for serialization.
|
|
146
|
+
*/
|
|
147
|
+
toRaw() {
|
|
148
|
+
return {
|
|
149
|
+
mean: this.mean.toRaw(),
|
|
150
|
+
variance: this.variance.toRaw(),
|
|
151
|
+
sigma: this.sigma.toRaw(),
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Returns true if this is a degenerate (point mass) distribution.
|
|
156
|
+
*
|
|
157
|
+
* A degenerate distribution has zero variance, representing
|
|
158
|
+
* a certain outcome at the mean value.
|
|
159
|
+
*/
|
|
160
|
+
isDegenerate() {
|
|
161
|
+
return this.variance.isZero();
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Returns the standard deviation (sigma).
|
|
165
|
+
*
|
|
166
|
+
* This is a convenience accessor; use `.sigma` for direct access.
|
|
167
|
+
*/
|
|
168
|
+
stdDev() {
|
|
169
|
+
return this.sigma;
|
|
170
|
+
}
|
|
171
|
+
// ==========================================================================
|
|
172
|
+
// PDF and Derivatives
|
|
173
|
+
// ==========================================================================
|
|
174
|
+
/**
|
|
175
|
+
* Computes the probability density function (PDF) at point x.
|
|
176
|
+
*
|
|
177
|
+
* φ(x; μ, σ) = (1/σ) * (1/√(2π)) * exp(-z²/2)
|
|
178
|
+
* where z = (x - μ) / σ
|
|
179
|
+
*
|
|
180
|
+
* For degenerate distributions (σ = 0), returns ZERO.
|
|
181
|
+
*
|
|
182
|
+
* @param x - The point at which to evaluate the PDF
|
|
183
|
+
* @returns The PDF value, or null if computation fails
|
|
184
|
+
*/
|
|
185
|
+
pdf(x) {
|
|
186
|
+
if (this.sigma.isZero()) {
|
|
187
|
+
return ZERO;
|
|
188
|
+
}
|
|
189
|
+
// z = (x - μ) / σ
|
|
190
|
+
const xMinusMu = x.sub(this.mean);
|
|
191
|
+
if (!xMinusMu) {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
const z = xMinusMu.div(this.sigma);
|
|
195
|
+
if (!z) {
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
// exp(-z²/2)
|
|
199
|
+
const expTerm = z.expNegHalfSquared();
|
|
200
|
+
if (!expTerm) {
|
|
201
|
+
return null;
|
|
202
|
+
}
|
|
203
|
+
// (1/σ) * (1/√(2π)) = INV_SQRT_2PI / σ
|
|
204
|
+
const coeff = INV_SQRT_2PI.div(this.sigma);
|
|
205
|
+
if (!coeff) {
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
return coeff.mul(expTerm);
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Computes the first derivative of the PDF at point x.
|
|
212
|
+
*
|
|
213
|
+
* φ'(x; μ, σ) = -((x - μ) / σ²) * φ(x; μ, σ)
|
|
214
|
+
*
|
|
215
|
+
* For degenerate distributions (σ = 0), returns ZERO.
|
|
216
|
+
*
|
|
217
|
+
* @param x - The point at which to evaluate the derivative
|
|
218
|
+
* @returns The derivative value, or null if computation fails
|
|
219
|
+
*/
|
|
220
|
+
pdfDerivative(x) {
|
|
221
|
+
if (this.sigma.isZero()) {
|
|
222
|
+
return ZERO;
|
|
223
|
+
}
|
|
224
|
+
const pdfValue = this.pdf(x);
|
|
225
|
+
if (!pdfValue || pdfValue.isZero()) {
|
|
226
|
+
return ZERO;
|
|
227
|
+
}
|
|
228
|
+
// (x - μ)
|
|
229
|
+
const xMinusMu = x.sub(this.mean);
|
|
230
|
+
if (!xMinusMu) {
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
// (x - μ) / σ²
|
|
234
|
+
const scaledDiff = xMinusMu.div(this.variance);
|
|
235
|
+
if (!scaledDiff) {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
// -((x - μ) / σ²) * φ(x)
|
|
239
|
+
const product = scaledDiff.mul(pdfValue);
|
|
240
|
+
if (!product) {
|
|
241
|
+
return null;
|
|
242
|
+
}
|
|
243
|
+
return product.neg();
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Computes the second derivative of the PDF at point x.
|
|
247
|
+
*
|
|
248
|
+
* φ''(x; μ, σ) = (((x - μ)² / σ⁴) - (1 / σ²)) * φ(x; μ, σ)
|
|
249
|
+
*
|
|
250
|
+
* For degenerate distributions (σ = 0), returns ZERO.
|
|
251
|
+
*
|
|
252
|
+
* @param x - The point at which to evaluate the second derivative
|
|
253
|
+
* @returns The second derivative value, or null if computation fails
|
|
254
|
+
*/
|
|
255
|
+
pdfSecondDerivative(x) {
|
|
256
|
+
if (this.sigma.isZero()) {
|
|
257
|
+
return ZERO;
|
|
258
|
+
}
|
|
259
|
+
const pdfValue = this.pdf(x);
|
|
260
|
+
if (!pdfValue || pdfValue.isZero()) {
|
|
261
|
+
return ZERO;
|
|
262
|
+
}
|
|
263
|
+
// (x - μ)
|
|
264
|
+
const xMinusMu = x.sub(this.mean);
|
|
265
|
+
if (!xMinusMu) {
|
|
266
|
+
return null;
|
|
267
|
+
}
|
|
268
|
+
// σ⁴ = variance²
|
|
269
|
+
const sigmaFourth = this.variance.mul(this.variance);
|
|
270
|
+
if (!sigmaFourth) {
|
|
271
|
+
return null;
|
|
272
|
+
}
|
|
273
|
+
// (x - μ)²
|
|
274
|
+
const xMinusMuSq = xMinusMu.pow2();
|
|
275
|
+
if (!xMinusMuSq) {
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
// (x - μ)² / σ⁴
|
|
279
|
+
const term1 = xMinusMuSq.div(sigmaFourth);
|
|
280
|
+
if (!term1) {
|
|
281
|
+
return null;
|
|
282
|
+
}
|
|
283
|
+
// 1 / σ²
|
|
284
|
+
const term2 = ONE.div(this.variance);
|
|
285
|
+
if (!term2) {
|
|
286
|
+
return null;
|
|
287
|
+
}
|
|
288
|
+
// ((x - μ)² / σ⁴) - (1 / σ²)
|
|
289
|
+
const factor = term1.sub(term2);
|
|
290
|
+
if (!factor) {
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
// factor * φ(x)
|
|
294
|
+
return factor.mul(pdfValue);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Checks if two distributions are identical (same mean AND same variance).
|
|
298
|
+
*
|
|
299
|
+
* When f = g, d(x) = g(x) - f(x) = 0 everywhere, so:
|
|
300
|
+
* - Any point is a valid minimum
|
|
301
|
+
* - Required collateral = 0
|
|
302
|
+
*
|
|
303
|
+
* @param other - The other distribution to compare
|
|
304
|
+
* @returns True if the distributions are identical
|
|
305
|
+
*/
|
|
306
|
+
isIdentical(other) {
|
|
307
|
+
return this.mean.eq(other.mean) && this.variance.eq(other.variance);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
//# sourceMappingURL=normal-distribution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normal-distribution.js","sourceRoot":"","sources":["../../src/distributions/normal-distribution.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,YAAY,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAYnE,2CAA2C;AAC3C,MAAM,GAAG,GAAc,SAAS,CAAC,UAAU,CAAC,CAAC,CAAc,CAAC;AAC5D,MAAM,OAAO,GAAc,SAAS,CAAC,UAAU,CAAC,KAAK,CAAc,CAAC;AACpE,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAE/B;;;;GAIG;AACH,SAAS,aAAa,CAAC,CAAY,EAAE,KAAgB;IACnD,MAAM,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC9B,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAChC,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,GAAG,CAAC,GAAG,CAAC,GAAG,C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CAAC;IAED;;;;;;;;;OASG;IACI,WAAW,CAAC,KAAyB;QAC1C,OAAO,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;IACtE,CAAC;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Raw representation of normal distribution sqrt hints.
|
|
3
|
+
*
|
|
4
|
+
* Matches Cairo `NormalSqrtHintsRaw` struct for Starknet serialization.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import type { SQ128x128Raw } from '../math/sq128-raw';
|
|
9
|
+
/**
|
|
10
|
+
* Precomputed sqrt hints for normal distribution operations.
|
|
11
|
+
*/
|
|
12
|
+
export interface NormalSqrtHintsRaw {
|
|
13
|
+
/** sqrt(2 * sigma * sqrt_pi) for L2 norm */
|
|
14
|
+
readonly l2_norm_denom: SQ128x128Raw;
|
|
15
|
+
/** sqrt(sigma * sqrt_pi) for backing checks */
|
|
16
|
+
readonly backing_denom: SQ128x128Raw;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=normal-sqrt-hints-raw.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normal-sqrt-hints-raw.d.ts","sourceRoot":"","sources":["../../src/distributions/normal-sqrt-hints-raw.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEtD;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,4CAA4C;IAE5C,QAAQ,CAAC,aAAa,EAAE,YAAY,CAAC;IACrC,+CAA+C;IAE/C,QAAQ,CAAC,aAAa,EAAE,YAAY,CAAC;CACtC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normal-sqrt-hints-raw.js","sourceRoot":"","sources":["../../src/distributions/normal-sqrt-hints-raw.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Effect-native error hierarchy for The Situation SDK.
|
|
3
|
+
*
|
|
4
|
+
* All errors extend `Data.TaggedError` so they work seamlessly with Effect's
|
|
5
|
+
* typed error channels.
|
|
6
|
+
*
|
|
7
|
+
* @module
|
|
8
|
+
*/
|
|
9
|
+
declare const InvalidInputError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
10
|
+
readonly _tag: "InvalidInputError";
|
|
11
|
+
} & Readonly<A>;
|
|
12
|
+
/**
|
|
13
|
+
* Input validation failed (e.g., negative variance, invalid address).
|
|
14
|
+
*/
|
|
15
|
+
export declare class InvalidInputError extends InvalidInputError_base<{
|
|
16
|
+
readonly message: string;
|
|
17
|
+
readonly field?: string;
|
|
18
|
+
}> {
|
|
19
|
+
}
|
|
20
|
+
declare const SolverFailedError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
21
|
+
readonly _tag: "SolverFailedError";
|
|
22
|
+
} & Readonly<A>;
|
|
23
|
+
/**
|
|
24
|
+
* Newton-Raphson or other numerical solver did not converge.
|
|
25
|
+
*/
|
|
26
|
+
export declare class SolverFailedError extends SolverFailedError_base<{
|
|
27
|
+
readonly message: string;
|
|
28
|
+
readonly iterations?: number;
|
|
29
|
+
}> {
|
|
30
|
+
}
|
|
31
|
+
declare const RpcError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
32
|
+
readonly _tag: "RpcError";
|
|
33
|
+
} & Readonly<A>;
|
|
34
|
+
/**
|
|
35
|
+
* Starknet RPC call failed.
|
|
36
|
+
*/
|
|
37
|
+
export declare class RpcError extends RpcError_base<{
|
|
38
|
+
readonly message: string;
|
|
39
|
+
readonly cause?: unknown;
|
|
40
|
+
}> {
|
|
41
|
+
}
|
|
42
|
+
declare const MissingDataError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
43
|
+
readonly _tag: "MissingDataError";
|
|
44
|
+
} & Readonly<A>;
|
|
45
|
+
/**
|
|
46
|
+
* Required data was not found or could not be parsed from an RPC response.
|
|
47
|
+
*/
|
|
48
|
+
export declare class MissingDataError extends MissingDataError_base<{
|
|
49
|
+
readonly message: string;
|
|
50
|
+
readonly field?: string;
|
|
51
|
+
}> {
|
|
52
|
+
}
|
|
53
|
+
declare const ExecutionError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
54
|
+
readonly _tag: "ExecutionError";
|
|
55
|
+
} & Readonly<A>;
|
|
56
|
+
/**
|
|
57
|
+
* Transaction or contract call execution failed.
|
|
58
|
+
*/
|
|
59
|
+
export declare class ExecutionError extends ExecutionError_base<{
|
|
60
|
+
readonly message: string;
|
|
61
|
+
readonly transactionHash?: string;
|
|
62
|
+
readonly cause?: unknown;
|
|
63
|
+
}> {
|
|
64
|
+
}
|
|
65
|
+
declare const NotConnectedError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
66
|
+
readonly _tag: "NotConnectedError";
|
|
67
|
+
} & Readonly<A>;
|
|
68
|
+
/**
|
|
69
|
+
* Operation requires a connected account but none is available.
|
|
70
|
+
*/
|
|
71
|
+
export declare class NotConnectedError extends NotConnectedError_base<{
|
|
72
|
+
readonly message: string;
|
|
73
|
+
}> {
|
|
74
|
+
}
|
|
75
|
+
declare const UnsupportedError_base: new <A extends Record<string, any> = {}>(args: import("effect/Types").Equals<A, {}> extends true ? void : { readonly [P in keyof A as P extends "_tag" ? never : P]: A[P]; }) => import("effect/Cause").YieldableError & {
|
|
76
|
+
readonly _tag: "UnsupportedError";
|
|
77
|
+
} & Readonly<A>;
|
|
78
|
+
/**
|
|
79
|
+
* Requested feature or operation is not supported.
|
|
80
|
+
*/
|
|
81
|
+
export declare class UnsupportedError extends UnsupportedError_base<{
|
|
82
|
+
readonly message: string;
|
|
83
|
+
}> {
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Union type covering all SDK errors for catch-all handling.
|
|
87
|
+
*/
|
|
88
|
+
export type SdkError = InvalidInputError | SolverFailedError | RpcError | MissingDataError | ExecutionError | NotConnectedError | UnsupportedError;
|
|
89
|
+
export {};
|
|
90
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;;;;AAIH;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,uBAAsC;IAC3E,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;CAAG;;;;AAEL;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,uBAAsC;IAC3E,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;CAC9B,CAAC;CAAG;;;;AAEL;;GAEG;AACH,qBAAa,QAAS,SAAQ,cAA6B;IACzD,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,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