@lapxo/obligations 0.4.0 → 0.4.1
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 +32 -2
- package/TARGET.bound +78 -30
- package/dist/measures/capacity.d.ts +302 -0
- package/dist/measures/capacity.js +168 -0
- package/dist/measures/coincidence.d.ts +111 -0
- package/dist/measures/coincidence.js +81 -0
- package/dist/measures/error-events.js +23 -4
- package/dist/measures/fitting.d.ts +1 -1
- package/dist/measures/index.d.ts +6 -0
- package/dist/measures/index.js +3 -0
- package/dist/measures/unanimity-fit.d.ts +156 -0
- package/dist/measures/unanimity-fit.js +133 -0
- package/docs/img/cell.svg +28 -0
- package/docs/img/logo-fork.svg +6 -0
- package/docs/img/logo.svg +6 -0
- package/docs/img/price.svg +28 -0
- package/docs/img/thermometer.svg +28 -0
- package/docs/img/withdrawal.svg +28 -0
- package/docs/learn/in-phase.md +46 -0
- package/docs/learn/price.md +52 -0
- package/docs/learn/signature.md +50 -0
- package/docs/learn/thermometer.md +58 -0
- package/docs/learn/withdrawal.md +51 -0
- package/docs/measures.md +48 -0
- package/docs/paper.md +233 -0
- package/docs/reference.md +495 -0
- package/package.json +1 -1
- package/receipts.bound +113 -70
- package/samples/measures/capacity.json +71 -0
- package/samples/measures/coincidence.json +624 -0
- package/samples/measures/decisions.json +66 -0
- package/samples/measures/unanimity-fit.json +166 -0
- package/samples/no/installed-artifact.json +14 -2
- package/samples/yes/installed-artifact.json +32 -5
- package/vectors/measures/capacity.cli.json +97 -0
- package/vectors/measures/coincidence.cli.json +97 -0
- package/vectors/measures/decisions.cli.json +97 -0
- package/vectors/measures/descent.cli.json +19 -70
- package/vectors/measures/implementation.json +82 -0
- package/vectors/measures/installed-artifact.cli.json +28 -8
- package/vectors/measures/m3.cli.json +19 -70
- package/vectors/measures/observations.cli.json +19 -70
- package/vectors/measures/spectrum.cli.json +18 -69
- package/vectors/measures/unanimity-fit.cli.json +97 -0
- package/vectors/measures/unanimity.cli.json +19 -70
- package/samples/measures/m3-reader.mjs +0 -732
- package/samples/measures/reader.mjs +0 -424
|
@@ -1,424 +0,0 @@
|
|
|
1
|
-
// work/obligations-0.4.0/repository/dist/measures/error-events.js
|
|
2
|
-
function errorMatrix(rows, policy, requested) {
|
|
3
|
-
if (!Number.isSafeInteger(policy.minCells) || policy.minCells < 2)
|
|
4
|
-
throw new Error("REFUSE\xB7measure invalid minimum cells");
|
|
5
|
-
const cells = /* @__PURE__ */ new Map();
|
|
6
|
-
for (const row of rows) {
|
|
7
|
-
if (!row.event || !row.origin || row.error !== 0 && row.error !== 1)
|
|
8
|
-
throw new Error("REFUSE\xB7measure invalid error event");
|
|
9
|
-
const at = cells.get(row.event) ?? /* @__PURE__ */ new Map();
|
|
10
|
-
if (at.has(row.origin) && at.get(row.origin) !== row.error)
|
|
11
|
-
throw new Error("REFUSE\xB7measure conflicting error event");
|
|
12
|
-
at.set(row.origin, row.error);
|
|
13
|
-
cells.set(row.event, at);
|
|
14
|
-
}
|
|
15
|
-
const origins = [...new Set(requested ?? rows.map((row) => row.origin))].sort();
|
|
16
|
-
if (origins.some((origin) => !origin))
|
|
17
|
-
throw new Error("REFUSE\xB7measure invalid origin");
|
|
18
|
-
const events = [...cells.keys()].filter((event) => origins.some((origin) => cells.get(event).has(origin))).sort();
|
|
19
|
-
if (events.length < policy.minCells || !origins.length)
|
|
20
|
-
return { status: "unmeasured", cause: "insufficient observed events" };
|
|
21
|
-
if (events.some((event) => origins.some((origin) => !cells.get(event).has(origin))))
|
|
22
|
-
return { status: "unmeasured", cause: "incomplete shared event observations" };
|
|
23
|
-
return { status: "measured", origins, events, matrix: events.map((event) => origins.map((origin) => cells.get(event).get(origin))) };
|
|
24
|
-
}
|
|
25
|
-
function covariance(reading) {
|
|
26
|
-
if (reading.status === "unmeasured")
|
|
27
|
-
return reading;
|
|
28
|
-
const n = reading.events.length, m = reading.origins.length;
|
|
29
|
-
if (!n || !m || reading.matrix.length !== n || reading.matrix.some((row) => row.length !== m || row.some((x) => x !== 0 && x !== 1)) || new Set(reading.events).size !== n || new Set(reading.origins).size !== m)
|
|
30
|
-
throw new Error("REFUSE\xB7measure invalid error matrix");
|
|
31
|
-
const mean = reading.origins.map((_, i) => reading.matrix.reduce((sum, row) => sum + row[i], 0) / n);
|
|
32
|
-
const matrix = Array.from({ length: m }, (_, i) => Array.from({ length: m }, (_2, j) => reading.matrix.reduce((sum, row) => sum + (row[i] - mean[i]) * (row[j] - mean[j]), 0) / n));
|
|
33
|
-
return { ...reading, matrix };
|
|
34
|
-
}
|
|
35
|
-
var errorCovariance = (rows, policy) => covariance(errorMatrix(rows, policy));
|
|
36
|
-
function participationRatio(reading) {
|
|
37
|
-
if (reading.status === "unmeasured")
|
|
38
|
-
return reading;
|
|
39
|
-
const trace = reading.matrix.reduce((sum, row, i) => sum + row[i], 0);
|
|
40
|
-
const square = reading.matrix.reduce((sum, row) => sum + row.reduce((n, value) => n + value * value, 0), 0);
|
|
41
|
-
if (square === 0)
|
|
42
|
-
return { status: "unmeasured", cause: "zero observed variation; dependence unidentified" };
|
|
43
|
-
return { status: "measured", value: trace * trace / square };
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// work/obligations-0.4.0/repository/dist/measures/spectrum.js
|
|
47
|
-
var refuse = (cause) => {
|
|
48
|
-
throw new Error("REFUSE\xB7measure " + cause);
|
|
49
|
-
};
|
|
50
|
-
function spectrum(reading, policy) {
|
|
51
|
-
if (reading.status === "unmeasured")
|
|
52
|
-
return reading;
|
|
53
|
-
if (!Number.isFinite(policy.absolute) || policy.absolute <= 0 || !Number.isFinite(policy.relative) || policy.relative < 0 || !Number.isSafeInteger(policy.maxRotations) || policy.maxRotations < 1)
|
|
54
|
-
refuse("invalid numerical policy");
|
|
55
|
-
const n = reading.origins.length, original = reading.matrix;
|
|
56
|
-
if (!n || original.length !== n || original.some((row) => row.length !== n || row.some((x) => !Number.isFinite(x))))
|
|
57
|
-
refuse("invalid covariance matrix");
|
|
58
|
-
const scale = Math.max(...original.flat().map(Math.abs)), tolerance = policy.absolute + policy.relative * scale;
|
|
59
|
-
for (let i = 0; i < n; i++)
|
|
60
|
-
for (let j = 0; j < n; j++)
|
|
61
|
-
if (original[i][j] !== original[j][i])
|
|
62
|
-
refuse("nonsymmetric covariance");
|
|
63
|
-
const a = original.map((row) => [...row]), v = Array.from({ length: n }, (_, i) => Array.from({ length: n }, (_2, j) => i === j ? 1 : 0));
|
|
64
|
-
for (let step = 0; step < policy.maxRotations; step++) {
|
|
65
|
-
let p = 0, q = 0, largest = 0;
|
|
66
|
-
for (let i = 0; i < n; i++)
|
|
67
|
-
for (let j = i + 1; j < n; j++)
|
|
68
|
-
if (Math.abs(a[i][j]) > largest) {
|
|
69
|
-
largest = Math.abs(a[i][j]);
|
|
70
|
-
p = i;
|
|
71
|
-
q = j;
|
|
72
|
-
}
|
|
73
|
-
if (largest <= tolerance)
|
|
74
|
-
break;
|
|
75
|
-
const theta = 0.5 * Math.atan2(2 * a[p][q], a[q][q] - a[p][p]), c = Math.cos(theta), s = Math.sin(theta);
|
|
76
|
-
const pp = a[p][p], qq = a[q][q], pq = a[p][q];
|
|
77
|
-
for (let k = 0; k < n; k++)
|
|
78
|
-
if (k !== p && k !== q) {
|
|
79
|
-
const x = a[k][p], y = a[k][q];
|
|
80
|
-
a[k][p] = a[p][k] = c * x - s * y;
|
|
81
|
-
a[k][q] = a[q][k] = s * x + c * y;
|
|
82
|
-
}
|
|
83
|
-
a[p][p] = c * c * pp - 2 * s * c * pq + s * s * qq;
|
|
84
|
-
a[q][q] = s * s * pp + 2 * s * c * pq + c * c * qq;
|
|
85
|
-
a[p][q] = a[q][p] = 0;
|
|
86
|
-
for (let k = 0; k < n; k++) {
|
|
87
|
-
const x = v[k][p], y = v[k][q];
|
|
88
|
-
v[k][p] = c * x - s * y;
|
|
89
|
-
v[k][q] = s * x + c * y;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
const order = Array.from({ length: n }, (_, i) => i).sort((i, j) => a[j][j] - a[i][i] || i - j);
|
|
93
|
-
const raw = order.map((i) => a[i][i]);
|
|
94
|
-
if (raw.some((x) => x < -tolerance))
|
|
95
|
-
refuse("covariance is not positive semidefinite");
|
|
96
|
-
const values = raw.map((x) => Math.max(0, x)), vectors = order.map((i) => v.map((row) => row[i]));
|
|
97
|
-
const residual = Math.max(...vectors.map((vector, i) => Math.hypot(...original.map((row, j) => row.reduce((sum, x, k) => sum + x * vector[k], 0) - values[i] * vector[j]))));
|
|
98
|
-
if (residual > n * tolerance)
|
|
99
|
-
return { status: "unmeasured", cause: "eigensolver did not converge within declared budget" };
|
|
100
|
-
return { status: "measured", origins: reading.origins, values, vectors, tolerance, residual };
|
|
101
|
-
}
|
|
102
|
-
function commonMass(reading) {
|
|
103
|
-
if (reading.status === "unmeasured")
|
|
104
|
-
return reading;
|
|
105
|
-
const total = reading.values.reduce((sum, x) => sum + x, 0);
|
|
106
|
-
return total <= reading.tolerance ? { status: "unmeasured", cause: "no resolved variation" } : { status: "measured", value: reading.values[0] / total };
|
|
107
|
-
}
|
|
108
|
-
function loadings(reading) {
|
|
109
|
-
if (reading.status === "unmeasured")
|
|
110
|
-
return reading;
|
|
111
|
-
if (reading.values[0] <= reading.tolerance || reading.values.length > 1 && reading.values[0] - reading.values[1] <= 2 * reading.tolerance)
|
|
112
|
-
return { status: "unmeasured", cause: "top eigenspace is unresolved or repeated" };
|
|
113
|
-
return { status: "measured", origins: reading.origins, values: reading.vectors[0].map(Math.abs) };
|
|
114
|
-
}
|
|
115
|
-
function commonMassOf(reading, origins, tau) {
|
|
116
|
-
if (reading.status === "unmeasured")
|
|
117
|
-
return reading;
|
|
118
|
-
if (!Number.isFinite(tau) || tau <= 0 || tau > 1)
|
|
119
|
-
refuse("invalid spectral threshold");
|
|
120
|
-
const selected = [...new Set(origins)].map((origin) => reading.origins.indexOf(origin));
|
|
121
|
-
if (!selected.length || selected.some((i) => i < 0))
|
|
122
|
-
return { status: "unmeasured", cause: "subset not observed" };
|
|
123
|
-
const energy = reading.values.map((value, k) => value * selected.reduce((sum, i) => sum + reading.vectors[k][i] ** 2, 0));
|
|
124
|
-
const total = energy.reduce((sum, x) => sum + x, 0);
|
|
125
|
-
if (total <= reading.tolerance)
|
|
126
|
-
return { status: "unmeasured", cause: "no resolved subset variation" };
|
|
127
|
-
const cutoff = tau * reading.values[0];
|
|
128
|
-
if (reading.values.some((value) => Math.abs(value - cutoff) <= 2 * reading.tolerance) && tau !== 1)
|
|
129
|
-
return { status: "unmeasured", cause: "spectral threshold unresolved at tolerance" };
|
|
130
|
-
const common = energy.reduce((sum, x, k) => sum + (reading.values[k] >= cutoff - 2 * reading.tolerance ? x : 0), 0);
|
|
131
|
-
return { status: "measured", value: common / total };
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// work/obligations-0.4.0/repository/dist/measures/model.js
|
|
135
|
-
function valid({ c, p, n }) {
|
|
136
|
-
if (!Number.isFinite(c) || c < 0 || c > 1 || !Number.isFinite(p) || p < 0 || p > 1 || !Number.isSafeInteger(n) || n < 2)
|
|
137
|
-
throw new Error("REFUSE\xB7measure invalid unanimity model");
|
|
138
|
-
}
|
|
139
|
-
function logSum(a, b) {
|
|
140
|
-
const high = Math.max(a, b);
|
|
141
|
-
return high === -Infinity ? high : high + Math.log(Math.exp(a - high) + Math.exp(b - high));
|
|
142
|
-
}
|
|
143
|
-
function unanimityFloor(model, k) {
|
|
144
|
-
valid(model);
|
|
145
|
-
if (!Number.isSafeInteger(k) || k < 1)
|
|
146
|
-
throw new Error("REFUSE\xB7measure invalid witness count");
|
|
147
|
-
const { c, p, n } = model;
|
|
148
|
-
if (c === 1 || p === 1)
|
|
149
|
-
return { status: "measured", value: 1 };
|
|
150
|
-
if (p === 0)
|
|
151
|
-
return { status: "measured", value: c };
|
|
152
|
-
const logPrivate = Math.log1p(-c) + k * Math.log(p) + (1 - k) * Math.log(n - 1);
|
|
153
|
-
const logA = logSum(c === 0 ? -Infinity : Math.log(c), logPrivate), logB = Math.log1p(-c) + k * Math.log1p(-p);
|
|
154
|
-
const odds = logA - logB;
|
|
155
|
-
const value = odds >= 0 ? 1 / (1 + Math.exp(-odds)) : Math.exp(odds) / (1 + Math.exp(odds));
|
|
156
|
-
return { status: "measured", value };
|
|
157
|
-
}
|
|
158
|
-
function unanimityThreshold(model, searchLimit) {
|
|
159
|
-
valid(model);
|
|
160
|
-
if (!Number.isSafeInteger(searchLimit) || searchLimit < 1)
|
|
161
|
-
throw new Error("REFUSE\xB7measure invalid search budget");
|
|
162
|
-
const { c, p, n } = model, q = p / (n - 1), coefficient = 1 - p - q;
|
|
163
|
-
if (c === 1 || p === 0 || p === 1 || coefficient <= 0)
|
|
164
|
-
return { status: "measured", value: 1 };
|
|
165
|
-
if (c === 0)
|
|
166
|
-
return { status: "unmeasured", cause: "no finite nondecreasing threshold for this model" };
|
|
167
|
-
const right = Math.log(p) + Math.log(c), base = Math.log(coefficient) + Math.log1p(-c) + Math.log(n - 1);
|
|
168
|
-
for (let k = 1; k <= searchLimit; k++)
|
|
169
|
-
if (base + k * Math.log(q) <= right)
|
|
170
|
-
return { status: "measured", value: k };
|
|
171
|
-
return { status: "unmeasured", cause: "threshold outside declared search budget" };
|
|
172
|
-
}
|
|
173
|
-
function descentCount(graph, cell) {
|
|
174
|
-
const nodes = /* @__PURE__ */ new Map();
|
|
175
|
-
for (const node of graph) {
|
|
176
|
-
if (!node.scope || nodes.has(node.scope))
|
|
177
|
-
throw new Error("REFUSE\xB7measure duplicate or absent graph scope");
|
|
178
|
-
nodes.set(node.scope, [...new Set(node.restsOn)]);
|
|
179
|
-
}
|
|
180
|
-
if (!nodes.has(cell) || [...nodes.values()].some((parents) => parents.some((parent) => !nodes.has(parent))))
|
|
181
|
-
return { status: "unmeasured", cause: "incomplete declared descent graph" };
|
|
182
|
-
const seen = /* @__PURE__ */ new Map(), visiting = /* @__PURE__ */ new Set();
|
|
183
|
-
function reaches(scope) {
|
|
184
|
-
if (visiting.has(scope))
|
|
185
|
-
throw new Error("REFUSE\xB7measure cyclic descent at " + scope);
|
|
186
|
-
if (seen.has(scope))
|
|
187
|
-
return seen.get(scope);
|
|
188
|
-
visiting.add(scope);
|
|
189
|
-
let result = false;
|
|
190
|
-
for (const parent of nodes.get(scope)) {
|
|
191
|
-
const nested = reaches(parent);
|
|
192
|
-
result = result || parent === cell || nested;
|
|
193
|
-
}
|
|
194
|
-
visiting.delete(scope);
|
|
195
|
-
seen.set(scope, result);
|
|
196
|
-
return result;
|
|
197
|
-
}
|
|
198
|
-
let count = 0;
|
|
199
|
-
for (const scope of nodes.keys())
|
|
200
|
-
if (reaches(scope) && scope !== cell)
|
|
201
|
-
count++;
|
|
202
|
-
return { status: "measured", value: count };
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
// work/obligations-0.4.0/repository/dist/measures/experiments.js
|
|
206
|
-
function stream(policy) {
|
|
207
|
-
if (!Number.isInteger(policy.seed) || policy.seed <= 0 || policy.seed > 4294967295 || !Number.isSafeInteger(policy.trials) || policy.trials < 1)
|
|
208
|
-
throw new Error("REFUSE\xB7experiment invalid seed or trial count");
|
|
209
|
-
let x = policy.seed >>> 0;
|
|
210
|
-
return () => {
|
|
211
|
-
x ^= x << 13;
|
|
212
|
-
x ^= x >>> 17;
|
|
213
|
-
x ^= x << 5;
|
|
214
|
-
return (x >>> 0) / 4294967296;
|
|
215
|
-
};
|
|
216
|
-
}
|
|
217
|
-
var rate = (events, falseEvents) => ({ events, falseEvents, rate: events ? falseEvents / events : "unmeasured" });
|
|
218
|
-
var wrong = (random, n, bias = 0) => random() < bias ? 1 : 1 + Math.floor(random() * (n - 1));
|
|
219
|
-
function dissentExperiment(model, k, policy) {
|
|
220
|
-
unanimityFloor(model, k);
|
|
221
|
-
const random = stream(policy);
|
|
222
|
-
let unanimous = 0, unanimousFalse = 0, majority = 0, majorityFalse = 0;
|
|
223
|
-
for (let trial = 0; trial < policy.trials; trial++) {
|
|
224
|
-
const common = random() < model.c;
|
|
225
|
-
const counts = /* @__PURE__ */ new Map();
|
|
226
|
-
for (let i = 0; i < k; i++) {
|
|
227
|
-
const value = common ? 1 : random() < model.p ? wrong(random, model.n) : 0;
|
|
228
|
-
counts.set(value, (counts.get(value) ?? 0) + 1);
|
|
229
|
-
}
|
|
230
|
-
for (const [value, count] of counts) {
|
|
231
|
-
if (count === k) {
|
|
232
|
-
unanimous++;
|
|
233
|
-
if (value !== 0)
|
|
234
|
-
unanimousFalse++;
|
|
235
|
-
} else if (count > k / 2) {
|
|
236
|
-
majority++;
|
|
237
|
-
if (value !== 0)
|
|
238
|
-
majorityFalse++;
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
return { unanimity: rate(unanimous, unanimousFalse), majorityWithDissent: rate(majority, majorityFalse) };
|
|
243
|
-
}
|
|
244
|
-
function interestExperiment(model, bias, shared, policy) {
|
|
245
|
-
unanimityFloor(model, 2);
|
|
246
|
-
if (!Number.isFinite(bias) || bias < 0 || bias > 1)
|
|
247
|
-
throw new Error("REFUSE\xB7experiment invalid interest bias");
|
|
248
|
-
const random = stream(policy);
|
|
249
|
-
let agreed = 0, falseAgreed = 0;
|
|
250
|
-
for (let trial = 0; trial < policy.trials; trial++) {
|
|
251
|
-
const common = random() < model.c;
|
|
252
|
-
const a = common ? 1 : random() < model.p ? wrong(random, model.n, bias) : 0;
|
|
253
|
-
const b = common ? 1 : random() < model.p ? wrong(random, model.n, shared ? bias : 0) : 0;
|
|
254
|
-
if (a === b) {
|
|
255
|
-
agreed++;
|
|
256
|
-
if (a !== 0)
|
|
257
|
-
falseAgreed++;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
return rate(agreed, falseAgreed);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
// work/obligations-0.4.0/repository/dist/lattice/errors.js
|
|
264
|
-
var UnitError = class _UnitError extends Error {
|
|
265
|
-
code;
|
|
266
|
-
detail;
|
|
267
|
-
constructor(code, message, detail = {}) {
|
|
268
|
-
super(message);
|
|
269
|
-
this.name = "UnitError";
|
|
270
|
-
this.code = code;
|
|
271
|
-
this.detail = Object.freeze({ ...detail });
|
|
272
|
-
Object.setPrototypeOf(this, _UnitError.prototype);
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
|
|
276
|
-
// work/obligations-0.4.0/repository/dist/lattice/order.js
|
|
277
|
-
function build(levels, join, meet) {
|
|
278
|
-
const n = levels.length;
|
|
279
|
-
for (let i = 0; i < n; i++) {
|
|
280
|
-
if (levels.indexOf(levels[i]) !== i) {
|
|
281
|
-
throw new UnitError("DUPLICATE_LEVEL", `the level \`${levels[i]}\` is declared twice`, {
|
|
282
|
-
level: levels[i]
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
const index = new Map(levels.map((l, i) => [l, i]));
|
|
287
|
-
const leq = (a, b) => join[a][b] === b;
|
|
288
|
-
const total = levels.every((_, i) => levels.every((__, j) => join[i][j] === i || join[i][j] === j));
|
|
289
|
-
let simple = true;
|
|
290
|
-
for (let x = 0; x < n && simple; x++) {
|
|
291
|
-
for (let y = 0; y < n && simple; y++) {
|
|
292
|
-
for (let z = 0; z < n; z++) {
|
|
293
|
-
if (meet[x][join[y][z]] !== join[meet[x][y]][meet[x][z]]) {
|
|
294
|
-
simple = false;
|
|
295
|
-
break;
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
const all = [...levels.keys()];
|
|
301
|
-
const bottomIx = all.find((i) => all.every((j) => leq(i, j))) ?? 0;
|
|
302
|
-
const topIx = all.find((i) => all.every((j) => leq(j, i))) ?? n - 1;
|
|
303
|
-
const joinIrr = all.filter((j) => j !== bottomIx && all.filter((x) => x !== j && leq(x, j)).reduce((acc, x) => join[acc][x], bottomIx) !== j);
|
|
304
|
-
const meetIrr = all.filter((m) => m !== topIx && all.filter((x) => x !== m && leq(m, x)).reduce((acc, x) => meet[acc][x], topIx) !== m);
|
|
305
|
-
const seen = /* @__PURE__ */ new Set();
|
|
306
|
-
const allDebits = [];
|
|
307
|
-
for (const x of [...joinIrr, ...meetIrr]) {
|
|
308
|
-
if (!seen.has(x)) {
|
|
309
|
-
seen.add(x);
|
|
310
|
-
allDebits.push(x);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
return {
|
|
314
|
-
levels,
|
|
315
|
-
isLadder: total,
|
|
316
|
-
isSimple: simple,
|
|
317
|
-
bottomIx,
|
|
318
|
-
topIx,
|
|
319
|
-
bottom: levels[bottomIx],
|
|
320
|
-
top: levels[topIx],
|
|
321
|
-
leq,
|
|
322
|
-
higher: (a, b) => join[a][b],
|
|
323
|
-
lower: (a, b) => meet[a][b],
|
|
324
|
-
rank(level) {
|
|
325
|
-
const r = index.get(level);
|
|
326
|
-
if (r === void 0) {
|
|
327
|
-
throw new UnitError("UNKNOWN_LEVEL", `no level \`${level}\` in this scale`, {
|
|
328
|
-
level,
|
|
329
|
-
levels
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
return r;
|
|
333
|
-
},
|
|
334
|
-
stateOf(floor, ceiling) {
|
|
335
|
-
if (!leq(floor, ceiling))
|
|
336
|
-
return "CONFLICT";
|
|
337
|
-
if (floor !== bottomIx)
|
|
338
|
-
return "REQUIRED";
|
|
339
|
-
if (ceiling !== topIx)
|
|
340
|
-
return "FORBIDDEN";
|
|
341
|
-
return "FREE";
|
|
342
|
-
},
|
|
343
|
-
joins: () => joinIrr.slice(),
|
|
344
|
-
limits: () => meetIrr.slice(),
|
|
345
|
-
debits: () => allDebits.slice(),
|
|
346
|
-
intervalHeight(lo, hi) {
|
|
347
|
-
if (!leq(lo, hi))
|
|
348
|
-
return null;
|
|
349
|
-
const inside = all.filter((x) => leq(lo, x) && leq(x, hi));
|
|
350
|
-
const covers = (x) => inside.filter((y) => y !== x && leq(x, y) && !inside.some((z) => z !== x && z !== y && leq(x, z) && leq(z, y)));
|
|
351
|
-
const long = /* @__PURE__ */ new Map([[lo, 0]]);
|
|
352
|
-
const short = /* @__PURE__ */ new Map([[lo, 0]]);
|
|
353
|
-
const walk = [...inside].sort((a, b) => inside.filter((z) => leq(z, a)).length - inside.filter((z) => leq(z, b)).length);
|
|
354
|
-
for (const x of walk) {
|
|
355
|
-
const lx = long.get(x);
|
|
356
|
-
const sx = short.get(x);
|
|
357
|
-
if (lx === void 0 || sx === void 0)
|
|
358
|
-
continue;
|
|
359
|
-
for (const y of covers(x)) {
|
|
360
|
-
long.set(y, Math.max(long.get(y) ?? lx + 1, lx + 1));
|
|
361
|
-
short.set(y, Math.min(short.get(y) ?? sx + 1, sx + 1));
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
const l = long.get(hi);
|
|
365
|
-
return l !== void 0 && l === short.get(hi) ? l : null;
|
|
366
|
-
}
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
function chain(levels) {
|
|
370
|
-
if (!Array.isArray(levels) || levels.length === 0) {
|
|
371
|
-
throw new UnitError("EMPTY_CHAIN", "a chain needs at least one level");
|
|
372
|
-
}
|
|
373
|
-
const n = levels.length;
|
|
374
|
-
const grid = (f) => [...Array(n)].map((_, i) => [...Array(n)].map((__, j) => f(i, j)));
|
|
375
|
-
return build(levels, grid(Math.max), grid(Math.min));
|
|
376
|
-
}
|
|
377
|
-
|
|
378
|
-
// work/obligations-0.4.0/repository/dist/debit/unit.js
|
|
379
|
-
function unit(subject, bounds) {
|
|
380
|
-
return { subject, floor: bounds.floor, ceiling: bounds.ceiling };
|
|
381
|
-
}
|
|
382
|
-
function state(c, u) {
|
|
383
|
-
return c.stateOf(c.rank(u.floor), c.rank(u.ceiling));
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
// work/obligations-0.4.0/quartet-reader.mjs
|
|
387
|
-
function evaluate(sample) {
|
|
388
|
-
const scale = chain(["off", "on"]), cells = [unit("free", { floor: "off", ceiling: "on" }), unit("required", { floor: "on", ceiling: "on" }), unit("forbidden", { floor: "off", ceiling: "off" }), unit("conflict", { floor: "on", ceiling: "off" })];
|
|
389
|
-
const before = JSON.stringify(cells), states = cells.map((cell) => state(scale, cell));
|
|
390
|
-
cells.forEach(Object.freeze);
|
|
391
|
-
let result;
|
|
392
|
-
switch (sample.group) {
|
|
393
|
-
case "observations":
|
|
394
|
-
result = errorCovariance(sample.rows, sample.policy);
|
|
395
|
-
break;
|
|
396
|
-
case "spectrum": {
|
|
397
|
-
const cov = sample.matrix ? { status: "measured", origins: sample.origins, events: [], matrix: sample.matrix } : errorCovariance(sample.rows, sample.observationPolicy);
|
|
398
|
-
const eigen = spectrum(cov, sample.policy);
|
|
399
|
-
result = { rank: sample.matrix ? "unmeasured" : participationRatio(cov), commonMass: commonMass(eigen), loadings: loadings(eigen), subset: commonMassOf(eigen, sample.origins, sample.tau), state: states[0] };
|
|
400
|
-
break;
|
|
401
|
-
}
|
|
402
|
-
case "unanimity": {
|
|
403
|
-
const sequence = [1, 2, 3].map((k) => unanimityFloor(sample.model, k));
|
|
404
|
-
if (sample.claim === "monotone-from-one" && sequence[1].value < sequence[0].value) throw Error("REFUSE\xB7measure T1 monotonicity counterexample " + JSON.stringify({ sequence, threshold: unanimityThreshold(sample.model, sample.searchLimit) }));
|
|
405
|
-
result = { F: unanimityFloor(sample.model, sample.k), threshold: unanimityThreshold(sample.model, sample.searchLimit), dissent: dissentExperiment(sample.model, sample.k, sample.experiment), interest: interestExperiment(sample.model, sample.bias, sample.shared, sample.experiment), sequence };
|
|
406
|
-
break;
|
|
407
|
-
}
|
|
408
|
-
case "descent":
|
|
409
|
-
result = descentCount(sample.graph, sample.cell);
|
|
410
|
-
break;
|
|
411
|
-
default:
|
|
412
|
-
throw Error("REFUSE\xB7measure unknown quartet");
|
|
413
|
-
}
|
|
414
|
-
if (JSON.stringify(cells) !== before || JSON.stringify(cells.map((cell) => state(scale, cell))) !== JSON.stringify(states)) throw Error("REFUSE\xB7measure algebra state changed");
|
|
415
|
-
return { result, states };
|
|
416
|
-
}
|
|
417
|
-
function observe(bytes) {
|
|
418
|
-
const sample = JSON.parse(new TextDecoder().decode(bytes));
|
|
419
|
-
return [{ scope: "measurement/" + sample.group + "/" + sample.place, role: "writes", measure: "result", bound: { kind: "enumerated", values: [JSON.stringify(evaluate(sample))] } }];
|
|
420
|
-
}
|
|
421
|
-
export {
|
|
422
|
-
evaluate,
|
|
423
|
-
observe
|
|
424
|
-
};
|