@mark1russell7/rigor-statistics 0.1.8 → 0.1.9
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 +4 -0
- package/build/index.d.ts +25 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +78 -23
- package/build/index.js.map +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -71,6 +71,8 @@ To vary a conditional dimension, `sliceResponse` needs its parent at a level ins
|
|
|
71
71
|
|
|
72
72
|
The band of a curve is `value ± width × RMSE`, from the held-out error of the folds. On a log scale, the band is a ratio. The band has one width along the curve. It is the mean error of the model.
|
|
73
73
|
|
|
74
|
+
A measure with the field `range` keeps each view inside it, for example `[0, 1]` for a share. `sliceResponse` and `surfaceResponse` move `value`, `low` and `high` to the nearest end. Such a place has the field `clipped`, and the field `clipped` of the view counts these places. `predictResponse` gives the value that the model fitted, and a fit does not use the range. `parseResponseRecord` refuses a measured value outside the range.
|
|
75
|
+
|
|
74
76
|
The field `nearest` of each place tells how far the place is from a measurement. It goes from 0 to 1, and 0 means that a point was measured there. A viewer can fade the band away from the data. A table cell with the `fallback` value has `nearest` above 0.
|
|
75
77
|
|
|
76
78
|
### The error of one cell
|
|
@@ -124,6 +126,8 @@ The default expansion has one product for each pair of levels of two dimensions.
|
|
|
124
126
|
| `parseResponseRecord(value)` | The examination of unknown data. It gives the record, or one fault with a path for each error. |
|
|
125
127
|
| `predictResponse(model, inputs)`, `heldOutError(record, measure)` | The value of a model at one set of inputs, and the error of the folds of a measure. |
|
|
126
128
|
| `heldOutErrorAt(record, measure, ids)` | The held-out error of a chosen set of points, from the predictions of the option `outOfFold`. |
|
|
129
|
+
| `responseCells(record, vary, steps)` | The number of fitted places of a view, level axes included. It lets a caller bound the time of a view before the view starts. |
|
|
130
|
+
| `whenHolds(dimension, values)` | True when a place has the condition of a dimension. A dimension with no `when` is always present. |
|
|
127
131
|
| `sliceResponse(record, measure, options)`, `surfaceResponse(record, measure, options)` | A fitted curve over one dimension, or a fitted surface over two, with the matching measured points, the matching points with no value, a band and the distance to the nearest measurement. |
|
|
128
132
|
|
|
129
133
|
Each function throws a RangeError for an empty list, for a NaN and for a parameter out of its range. Thus a missing value cannot make a quiet NaN in a record.
|
package/build/index.d.ts
CHANGED
|
@@ -215,6 +215,11 @@ interface ResponseMeasure {
|
|
|
215
215
|
readonly unit: string;
|
|
216
216
|
/** The better direction of the value. The value `none` means that no direction is better. */
|
|
217
217
|
readonly direction: "higher" | "lower" | "none";
|
|
218
|
+
/**
|
|
219
|
+
* The low and the high end of the possible values, for example `[0, 1]` for a share. Each measured value is in this
|
|
220
|
+
* range. A view clips its fitted values to it, and a fit does not use it.
|
|
221
|
+
*/
|
|
222
|
+
readonly range?: readonly [number, number];
|
|
218
223
|
}
|
|
219
224
|
/** A declared reason that a measure is absent, for example infeasible, unsupported or out of budget. */
|
|
220
225
|
interface ResponseReason {
|
|
@@ -406,6 +411,8 @@ interface ResponseBand {
|
|
|
406
411
|
* count over the dimensions.
|
|
407
412
|
*/
|
|
408
413
|
readonly nearest: number;
|
|
414
|
+
/** This field is true when the measure has a `range` and the view moved `value`, `low` or `high` into it. */
|
|
415
|
+
readonly clipped?: true;
|
|
409
416
|
}
|
|
410
417
|
/** One place of a curve. */
|
|
411
418
|
interface ResponseCurvePoint extends ResponseBand {
|
|
@@ -440,6 +447,8 @@ interface ResponseSlice {
|
|
|
440
447
|
/** The points that match the held values and have no value of the measure, each with its reason. */
|
|
441
448
|
readonly absent: readonly ResponseAbsentPoint[];
|
|
442
449
|
readonly error: ResponseHeldOutError;
|
|
450
|
+
/** The number of places of `curve` with the field `clipped`. */
|
|
451
|
+
readonly clipped: number;
|
|
443
452
|
}
|
|
444
453
|
/** A measured point of a surface. */
|
|
445
454
|
interface ResponseSurfacePoint {
|
|
@@ -472,7 +481,11 @@ interface ResponseSurface {
|
|
|
472
481
|
/** The points that match the held values and have no value of the measure, each with its reason. */
|
|
473
482
|
readonly absent: readonly ResponseSurfaceAbsentPoint[];
|
|
474
483
|
readonly error: ResponseHeldOutError;
|
|
484
|
+
/** The number of places of `cells` with the field `clipped`. */
|
|
485
|
+
readonly clipped: number;
|
|
475
486
|
}
|
|
487
|
+
/** This function gives true when a place has the condition of a dimension. A dimension with no condition is present. */
|
|
488
|
+
export declare function whenHolds(dimension: ResponseDimension, values: Readonly<Record<string, unknown>>): boolean;
|
|
476
489
|
/**
|
|
477
490
|
* This function gives the value of a model at `inputs`, on the scale of the measure. The inputs have a value for each
|
|
478
491
|
* dimension that the model reads. An absent conditional dimension has `null`. A table model gives its `fallback` for a
|
|
@@ -525,6 +538,10 @@ export declare function heldOutErrorAt(record: ResponseRecord, measure: string,
|
|
|
525
538
|
* distance is on the log scale of the model, so the band is a ratio. The band has one width along all the curve. The
|
|
526
539
|
* band is the mean error of the model, and `nearest` tells how far the place is from a measurement.
|
|
527
540
|
*
|
|
541
|
+
* A measure with a `range` keeps each place inside it. The fields `value`, `low` and `high` move to the nearest end.
|
|
542
|
+
* The place then has the field `clipped`, and the field `clipped` of the view counts these places. The function
|
|
543
|
+
* `predictResponse` gives the value that the model fitted.
|
|
544
|
+
*
|
|
528
545
|
* The function throws a RangeError for an unknown measure or dimension, and for a held value that is not good for its
|
|
529
546
|
* dimension. It also throws for a dimension that is both varied and held, and for a bad option.
|
|
530
547
|
*/
|
|
@@ -536,6 +553,14 @@ export declare function sliceResponse(record: ResponseRecord, measure: string, o
|
|
|
536
553
|
* It throws when a conditional dimension varies with its parent, and when two varied dimensions need no common level.
|
|
537
554
|
*/
|
|
538
555
|
export declare function surfaceResponse(record: ResponseRecord, measure: string, options: ResponseSurfaceOptions): ResponseSurface;
|
|
556
|
+
/**
|
|
557
|
+
* This function gives the number of fitted places of a view before the view starts: the product of the lengths of its
|
|
558
|
+
* axes. A level axis counts its levels, and a continuous axis counts `steps`. The field `nearest` reads each point at
|
|
559
|
+
* each place, so the reads of a view are this count times the number of points. The default of `steps` is the default
|
|
560
|
+
* of a view. The function throws a RangeError for an unknown dimension, for one dimension named two times, and for a
|
|
561
|
+
* bad `steps`.
|
|
562
|
+
*/
|
|
563
|
+
export declare function responseCells(record: Pick<ResponseRecord, "dimensions">, vary: string | readonly [string, string], steps?: number): number;
|
|
539
564
|
/** The largest power of a factor. A larger power of a coordinate from -1 to 1 adds almost nothing to a model. */
|
|
540
565
|
export declare const RESPONSE_MAX_POWER = 8;
|
|
541
566
|
/** One fault of a record. */
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/describe.ts","../src/regression.ts","../src/bootstrap.ts","../src/ridge.ts","../src/response.ts","../src/response-parse.ts","../src/response-fit.ts","../src/tests.ts","../src/rank.ts","../src/discrete.ts","../src/compare.ts"],"mappings":";;;;;;KAOY;;wBAmBI,OAAO;wBAIP,KAAK;;;;;wBAgBL,GAAG;;;;;;;wBAgBH,eAAe,iCAAiC,WAAW,SAAQ;;wBAkBnE,SAAS,2BAA2B,WAAW,SAAQ;;;;;wBASvD,OAAO;;UAQN;WACN;WACA;;WAEA;WACA;;WAEA;WACA;;WAEA;WACA;;WAEA;;wBAGK,UAAU,4BAA4B;;;;;;UC3GrC;;WAEN;;UAGM;;WAEN;;WAEA;;;;;WAKA;;WAEA;;WAEA;;;;;;;;;;;wBAkBK,aAAa,mCAAmC,sBAAsB,UAAS,sBAA2B;UC/BzG;;WAEN;;WAEA;;WAEA;;WAEA,SAAS;;;;;;WAMT;;UAGM;;WAEN;WACA;WACA;WACA;WACA;;WAEA;;WAEA;;;;;;wBAOK,UAAU,GAAG,eAAe,KAAK,YAAY,iBAAiB,gBAAgB,UAAS,mBAAwB;;;;;;;;wBAsB/G,aAAa,GAAG,GAC9B,YAAY,KACZ,YAAY,KACZ,YAAY,YAAY,KAAK,YAAY,gBACzC,UAAS,mBACR;;;;;;wBAwBa,qBAAqB,8BAA8B,gCAAgC,UAAS,mBAAwB;;;;;;;wBAUpH,sB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A,qBAAqB;WACrB,mBAAmB;;WAEnB,mBAAmB;WACnB,iBAAiB;;;UAIX,uBAAuB;WAC7B,iBAAiB;WACjB,gBAAgB;;;UAIV;;WAEN;;WAEA;;WAEA;;WAEA;;WAEA;;WAEA;;;UAIM;;WAEN,OAAO,SAAS,eAAe;;WAE/B;;;;;WAKA;;WAEA;;;UAIM,6BAA6B;;WAEnC;;;UAIM,+BAA+B;;WAErC;;;;;;UAOM;WACN;WACA;WACA;;;;;;;WAOA;;;UAIM,2BAA2B;;WAEjC,IAAI;;;UAIE;WACN;;WAEA,IAAI;WACJ;WACA;;;UAIM;WACN;;WAEA,IAAI;;WAEJ;WACA;;;UAIM;WACN;WACA;;WAEA,MAAM,SAAS,eAAe;WAC9B,gBAAgB;WAChB,iBAAiB;;WAEjB,iBAAiB;WACjB,OAAO;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/describe.ts","../src/regression.ts","../src/bootstrap.ts","../src/ridge.ts","../src/response.ts","../src/response-parse.ts","../src/response-fit.ts","../src/tests.ts","../src/rank.ts","../src/discrete.ts","../src/compare.ts"],"mappings":";;;;;;KAOY;;wBAmBI,OAAO;wBAIP,KAAK;;;;;wBAgBL,GAAG;;;;;;;wBAgBH,eAAe,iCAAiC,WAAW,SAAQ;;wBAkBnE,SAAS,2BAA2B,WAAW,SAAQ;;;;;wBASvD,OAAO;;UAQN;WACN;WACA;;WAEA;WACA;;WAEA;WACA;;WAEA;WACA;;WAEA;;wBAGK,UAAU,4BAA4B;;;;;;UC3GrC;;WAEN;;UAGM;;WAEN;;WAEA;;;;;WAKA;;WAEA;;WAEA;;;;;;;;;;;wBAkBK,aAAa,mCAAmC,sBAAsB,UAAS,sBAA2B;UC/BzG;;WAEN;;WAEA;;WAEA;;WAEA,SAAS;;;;;;WAMT;;UAGM;;WAEN;WACA;WACA;WACA;WACA;;WAEA;;WAEA;;;;;;wBAOK,UAAU,GAAG,eAAe,KAAK,YAAY,iBAAiB,gBAAgB,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;wBASF,aAAa,2BAA2B,UAAS;WAA0B;IAAqC;UAW/G;;WAEN;;WAEA;;WAEA;;;UAIM;WACN;WACA;;WAEA;;WAEA;;UAGM;;WAEN;WACA;;WAEA;;WAEA;;WAEA;;WAEA,QAAQ;;WAER;;WAEA;;WAEA;WACA,cAAc;;WAEd;WACA,cAAc;;;;;;;;wBAST,cAAc,2BAA2B,UAAS,iBAAsB;;UA6CvE;WACN;WACA;;;wBASK,MAAM,oBAAoB;;UAQzB;WACN;WACA;WACA;;WAEA;;WAEA,UAAU;;;wBAIL,YAAY,oBAAoB,aAAa"}
|
package/build/index.js
CHANGED
|
@@ -717,6 +717,12 @@ function heldValues(name, record, vary, hold, needed) {
|
|
|
717
717
|
};
|
|
718
718
|
return Object.fromEntries(others.map((d) => [d.id, valueOf(d)]));
|
|
719
719
|
}
|
|
720
|
+
/** This function refuses a bad option `steps`. */
|
|
721
|
+
function checkSteps(name, steps) {
|
|
722
|
+
if (!Number.isSafeInteger(steps) || steps < 2) throw new RangeError(`${name}: steps is a whole number of 2 or more, not ${steps}.`);
|
|
723
|
+
}
|
|
724
|
+
/** This function gives a value inside a range. */
|
|
725
|
+
const clip = (value, [low, high]) => Math.min(high, Math.max(low, value));
|
|
720
726
|
/** This function gives the values of an axis: each level, or `steps` equal distances on the scale of the dimension. */
|
|
721
727
|
function axisValues(dimension, steps) {
|
|
722
728
|
if (dimension.kind !== "continuous") return dimension.levels;
|
|
@@ -739,7 +745,7 @@ function matches(dimension, value, held, tolerance) {
|
|
|
739
745
|
/** This function examines the request of a view, and it gives the parts that the two views share. */
|
|
740
746
|
function frameOf(name, record, measure, vary, options) {
|
|
741
747
|
const { hold = {}, steps = 33, tolerance = 0, width = 1 } = options;
|
|
742
|
-
|
|
748
|
+
checkSteps(name, steps);
|
|
743
749
|
if (!(Number.isFinite(tolerance) && tolerance >= 0)) throw new RangeError(`${name}: tolerance is a finite number of 0 or more, not ${tolerance}.`);
|
|
744
750
|
if (!(Number.isFinite(width) && width >= 0)) throw new RangeError(`${name}: width is a finite number of 0 or more, not ${width}.`);
|
|
745
751
|
const model = record.models.find((m) => m.measure === measure);
|
|
@@ -765,14 +771,25 @@ function frameOf(name, record, measure, vary, options) {
|
|
|
765
771
|
const missing = placed.filter((p) => typeof p.measures[measure] !== "number");
|
|
766
772
|
const error = heldOutError(record, measure);
|
|
767
773
|
const nearest = nearestOf(record.dimensions, record.points, measure);
|
|
774
|
+
const range = record.measures.find((m) => m.id === measure)?.range;
|
|
768
775
|
const band = (inputs) => {
|
|
769
776
|
const place = Object.fromEntries(record.dimensions.map((d) => [d.id, whenHolds(d, inputs) ? inputs[d.id] : null]));
|
|
770
777
|
const value = predictScaled(model, place);
|
|
771
|
-
|
|
778
|
+
const fitted = {
|
|
772
779
|
value: unscale(model, value),
|
|
773
780
|
low: unscale(model, value - width * error.rmse),
|
|
774
|
-
high: unscale(model, value + width * error.rmse)
|
|
775
|
-
|
|
781
|
+
high: unscale(model, value + width * error.rmse)
|
|
782
|
+
};
|
|
783
|
+
const inside = range === void 0 ? fitted : {
|
|
784
|
+
value: clip(fitted.value, range),
|
|
785
|
+
low: clip(fitted.low, range),
|
|
786
|
+
high: clip(fitted.high, range)
|
|
787
|
+
};
|
|
788
|
+
const moved = inside.value !== fitted.value || inside.low !== fitted.low || inside.high !== fitted.high;
|
|
789
|
+
return {
|
|
790
|
+
...inside,
|
|
791
|
+
nearest: nearest(place),
|
|
792
|
+
...moved ? { clipped: true } : {}
|
|
776
793
|
};
|
|
777
794
|
};
|
|
778
795
|
return {
|
|
@@ -812,23 +829,28 @@ const reasonOf = (point, measure) => point.absent !== void 0 && Object.hasOwn(po
|
|
|
812
829
|
* distance is on the log scale of the model, so the band is a ratio. The band has one width along all the curve. The
|
|
813
830
|
* band is the mean error of the model, and `nearest` tells how far the place is from a measurement.
|
|
814
831
|
*
|
|
832
|
+
* A measure with a `range` keeps each place inside it. The fields `value`, `low` and `high` move to the nearest end.
|
|
833
|
+
* The place then has the field `clipped`, and the field `clipped` of the view counts these places. The function
|
|
834
|
+
* `predictResponse` gives the value that the model fitted.
|
|
835
|
+
*
|
|
815
836
|
* The function throws a RangeError for an unknown measure or dimension, and for a held value that is not good for its
|
|
816
837
|
* dimension. It also throws for a dimension that is both varied and held, and for a bad option.
|
|
817
838
|
*/
|
|
818
839
|
function sliceResponse(record, measure, options) {
|
|
819
840
|
const { vary } = options;
|
|
820
841
|
const { held, axes, matched, missing, error, band } = frameOf("sliceResponse", record, measure, [vary], options);
|
|
842
|
+
const curve = axes[0].map((at) => ({
|
|
843
|
+
at,
|
|
844
|
+
...band({
|
|
845
|
+
...held,
|
|
846
|
+
[vary]: at
|
|
847
|
+
})
|
|
848
|
+
}));
|
|
821
849
|
return {
|
|
822
850
|
measure,
|
|
823
851
|
vary,
|
|
824
852
|
held,
|
|
825
|
-
curve
|
|
826
|
-
at,
|
|
827
|
-
...band({
|
|
828
|
-
...held,
|
|
829
|
-
[vary]: at
|
|
830
|
-
})
|
|
831
|
-
})),
|
|
853
|
+
curve,
|
|
832
854
|
points: matched.map((p) => ({
|
|
833
855
|
id: p.id,
|
|
834
856
|
at: p.values[vary],
|
|
@@ -841,7 +863,8 @@ function sliceResponse(record, measure, options) {
|
|
|
841
863
|
reason: reasonOf(p, measure),
|
|
842
864
|
...groupOf(p)
|
|
843
865
|
})),
|
|
844
|
-
error
|
|
866
|
+
error,
|
|
867
|
+
clipped: curve.filter((place) => place.clipped === true).length
|
|
845
868
|
};
|
|
846
869
|
}
|
|
847
870
|
/**
|
|
@@ -856,17 +879,18 @@ function surfaceResponse(record, measure, options) {
|
|
|
856
879
|
const { held, axes, matched, missing, error, band } = frameOf("surfaceResponse", record, measure, vary, options);
|
|
857
880
|
const x = axes[0];
|
|
858
881
|
const y = axes[1];
|
|
882
|
+
const cells = y.map((b) => x.map((a) => band({
|
|
883
|
+
...held,
|
|
884
|
+
[xId]: a,
|
|
885
|
+
[yId]: b
|
|
886
|
+
})));
|
|
859
887
|
return {
|
|
860
888
|
measure,
|
|
861
889
|
vary,
|
|
862
890
|
held,
|
|
863
891
|
x,
|
|
864
892
|
y,
|
|
865
|
-
cells
|
|
866
|
-
...held,
|
|
867
|
-
[xId]: a,
|
|
868
|
-
[yId]: b
|
|
869
|
-
}))),
|
|
893
|
+
cells,
|
|
870
894
|
points: matched.map((p) => ({
|
|
871
895
|
id: p.id,
|
|
872
896
|
at: [p.values[xId], p.values[yId]],
|
|
@@ -879,9 +903,27 @@ function surfaceResponse(record, measure, options) {
|
|
|
879
903
|
reason: reasonOf(p, measure),
|
|
880
904
|
...groupOf(p)
|
|
881
905
|
})),
|
|
882
|
-
error
|
|
906
|
+
error,
|
|
907
|
+
clipped: cells.flat().filter((place) => place.clipped === true).length
|
|
883
908
|
};
|
|
884
909
|
}
|
|
910
|
+
/**
|
|
911
|
+
* This function gives the number of fitted places of a view before the view starts: the product of the lengths of its
|
|
912
|
+
* axes. A level axis counts its levels, and a continuous axis counts `steps`. The field `nearest` reads each point at
|
|
913
|
+
* each place, so the reads of a view are this count times the number of points. The default of `steps` is the default
|
|
914
|
+
* of a view. The function throws a RangeError for an unknown dimension, for one dimension named two times, and for a
|
|
915
|
+
* bad `steps`.
|
|
916
|
+
*/
|
|
917
|
+
function responseCells(record, vary, steps = 33) {
|
|
918
|
+
checkSteps("responseCells", steps);
|
|
919
|
+
const ids = typeof vary === "string" ? [vary] : vary;
|
|
920
|
+
if (new Set(ids).size !== ids.length) throw new RangeError(`responseCells: the two varied dimensions are one dimension, "${ids[0]}".`);
|
|
921
|
+
return ids.reduce((count, id) => {
|
|
922
|
+
const dimension = record.dimensions.find((d) => d.id === id);
|
|
923
|
+
if (dimension === void 0) throw new RangeError(`responseCells: the record has no dimension "${id}".`);
|
|
924
|
+
return count * (dimension.kind === "continuous" ? steps : dimension.levels.length);
|
|
925
|
+
}, 1);
|
|
926
|
+
}
|
|
885
927
|
// src/response-parse.ts
|
|
886
928
|
/**
|
|
887
929
|
* The validator of the format `response-records/1`. The functions here read unknown data and write faults. Thus a page
|
|
@@ -985,9 +1027,7 @@ function checkDimension(value, path, faults) {
|
|
|
985
1027
|
need(!Object.hasOwn(object, "levels"), at(path, "levels"), "a continuous dimension has a range, not levels.", faults);
|
|
986
1028
|
need(!Object.hasOwn(object, "range") || !log || !isNumber(peek(object["range"], "0")) || peek(object["range"], "0") > 0, at(path, "range"), "a log dimension has a range above 0.", faults);
|
|
987
1029
|
need(Object.hasOwn(object, "range"), at(path, "range"), "this field is missing.", faults);
|
|
988
|
-
|
|
989
|
-
const good = Array.isArray(range) && range.length === 2 && isNumber(range[0]) && isNumber(range[1]) && range[0] < range[1];
|
|
990
|
-
if (Object.hasOwn(object, "range")) need(good, at(path, "range"), `this is a low and a high finite number, with low less than high, not ${shown(range)}.`, faults);
|
|
1030
|
+
if (Object.hasOwn(object, "range")) checkRange(object["range"], at(path, "range"), faults);
|
|
991
1031
|
} else if (kind === "ordinal" || kind === "categorical") {
|
|
992
1032
|
need(!Object.hasOwn(object, "range"), at(path, "range"), `a dimension of the kind ${kind} has levels, not a range.`, faults);
|
|
993
1033
|
need(kind === "ordinal" || !Object.hasOwn(object, "log"), at(path, "log"), "a categorical dimension has no log scale.", faults);
|
|
@@ -1021,6 +1061,10 @@ function checkWhen(value, path, dimensions, faults) {
|
|
|
1021
1061
|
if (!Array.isArray(known)) return;
|
|
1022
1062
|
levels.forEach((level, i) => need(known.includes(level), `${at(path, "levels")}[${i}]`, `the dimension ${shown(id)} has no level ${shown(level)}.`, faults));
|
|
1023
1063
|
}
|
|
1064
|
+
/** This function examines a range. */
|
|
1065
|
+
function checkRange(range, path, faults) {
|
|
1066
|
+
need(Array.isArray(range) && range.length === 2 && isNumber(range[0]) && isNumber(range[1]) && range[0] < range[1], path, `this is a low and a high finite number, with low less than high, not ${shown(range)}.`, faults);
|
|
1067
|
+
}
|
|
1024
1068
|
/** This function examines one measure. */
|
|
1025
1069
|
function checkMeasure(value, path, faults) {
|
|
1026
1070
|
const object = fields(value, path, [
|
|
@@ -1028,12 +1072,21 @@ function checkMeasure(value, path, faults) {
|
|
|
1028
1072
|
"label",
|
|
1029
1073
|
"unit",
|
|
1030
1074
|
"direction"
|
|
1031
|
-
], [], faults);
|
|
1075
|
+
], ["range"], faults);
|
|
1032
1076
|
if (object === void 0) return;
|
|
1033
1077
|
check(object, "id", path, isId, "text with one character or more", faults);
|
|
1034
1078
|
check(object, "label", path, isString, "text", faults);
|
|
1035
1079
|
check(object, "unit", path, isString, "text", faults);
|
|
1036
1080
|
check(object, "direction", path, (v) => v === "higher" || v === "lower" || v === "none", `"higher", "lower" or "none"`, faults);
|
|
1081
|
+
if (Object.hasOwn(object, "range")) checkRange(object["range"], at(path, "range"), faults);
|
|
1082
|
+
}
|
|
1083
|
+
/** This function refuses a measured value outside the range of its measure. */
|
|
1084
|
+
function checkMeasured(point, path, measures, faults) {
|
|
1085
|
+
for (const { id, range } of measures) {
|
|
1086
|
+
const value = peek(peek(point, "measures"), id);
|
|
1087
|
+
if (range === void 0 || typeof value !== "number") continue;
|
|
1088
|
+
need(value >= range[0] && value <= range[1], at(at(path, "measures"), id), `this value is outside the range of the measure, [${range[0]}, ${range[1]}].`, faults);
|
|
1089
|
+
}
|
|
1037
1090
|
}
|
|
1038
1091
|
/** This function examines one declared reason. */
|
|
1039
1092
|
function checkReason(value, path, faults) {
|
|
@@ -1125,6 +1178,8 @@ function responseDataFaults(value, required, optional) {
|
|
|
1125
1178
|
const points = list(object["points"], "points", 1, faults);
|
|
1126
1179
|
points.forEach((p, i) => checkPoint(p, `points[${i}]`, dimensions, measureIds, reasonIds, faults));
|
|
1127
1180
|
uniqueIds(points, "points", faults);
|
|
1181
|
+
if (faults.length > 0) return faults;
|
|
1182
|
+
points.forEach((p, i) => checkMeasured(p, `points[${i}]`, measures, faults));
|
|
1128
1183
|
return faults;
|
|
1129
1184
|
}
|
|
1130
1185
|
/** This function examines one input of a ridge model against the dimensions of the record. */
|
|
@@ -2327,6 +2382,6 @@ function calibration(forecasts) {
|
|
|
2327
2382
|
interval: wilson(hits, n)
|
|
2328
2383
|
}));
|
|
2329
2384
|
}
|
|
2330
|
-
export { KENDALL_EXACT, RESPONSE_LAMBDAS, RESPONSE_MAX_POWER, RESPONSE_MAX_TERMS, RESPONSE_RECORDS_SCHEMA, Z95, binomialInterval, bootstrap, bootstrapClusters, bootstrapLeastSquares, bootstrapMedian, bootstrapMedianRatio, bootstrapTwo, brier, calibration, compareRatios, fitResponse, heldOutError, heldOutErrorAt, holm, kendallTau, leastSquares, mean, median, medianInterval, negativeBinomialInterval, noiseFloor, noiseVerdict, pairedPermutation, parseResponseRecord, predictResponse, quantile, quantileSorted, ranks, ridgeSolve, sd, signTest, signTestPower, sliceResponse, sorted, spearman, summarize, surfaceResponse, wilson };
|
|
2385
|
+
export { KENDALL_EXACT, RESPONSE_LAMBDAS, RESPONSE_MAX_POWER, RESPONSE_MAX_TERMS, RESPONSE_RECORDS_SCHEMA, Z95, binomialInterval, bootstrap, bootstrapClusters, bootstrapLeastSquares, bootstrapMedian, bootstrapMedianRatio, bootstrapTwo, brier, calibration, compareRatios, fitResponse, heldOutError, heldOutErrorAt, holm, kendallTau, leastSquares, mean, median, medianInterval, negativeBinomialInterval, noiseFloor, noiseVerdict, pairedPermutation, parseResponseRecord, predictResponse, quantile, quantileSorted, ranks, responseCells, ridgeSolve, sd, signTest, signTestPower, sliceResponse, sorted, spearman, summarize, surfaceResponse, whenHolds, wilson };
|
|
2331
2386
|
|
|
2332
2387
|
//# sourceMappingURL=index.js.map
|