Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions front_end/src/utils/math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,20 @@ export function unscaleNominalLocation(x: number, scaling: Scaling) {
*/
export function getCdfAt(x: number, cdf: number[], scaling: Scaling) {
const location = unscaleNominalLocation(x, scaling);
const floatIndex = location * (cdf.length - 1);
if (floatIndex <= 0) {
if (location <= 0) {
return cdf.at(0);
}
if (floatIndex >= 1) {
if (location >= 1) {
return cdf.at(-1);
}
return cdf.at(Math.round(floatIndex));
const floatIndex = location * (cdf.length - 1);
// linear interpolation
const lowerIndex = Math.floor(floatIndex);
const upperIndex = Math.ceil(floatIndex);
const weight = floatIndex - lowerIndex;
/* eslint-disable @typescript-eslint/no-non-null-assertion */
return cdf[lowerIndex]! * (1 - weight) + cdf[upperIndex]! * weight;
/* eslint-enable @typescript-eslint/no-non-null-assertion */
}

/**
Expand Down
10 changes: 3 additions & 7 deletions front_end/src/utils/questions/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,15 +135,11 @@ export function getContinuousGroupScaling(
range_min: rangeMinPoints.length > 0 ? Math.min(...rangeMinPoints) : null,
// set zero_point to null if any are linearly scaled
zero_point:
zeroPoints.length > 0 && !zeroPoints.some((p) => p !== null)
? Math.min(...zeroPoints)
: null,
zeroPoints.length === questions.length ? Math.min(...zeroPoints) : null,
};
// we can have mixes of log and linear scaled options
// which leads to a derived zero point inside the range which is invalid
// so just ignore the log scaling in this case
// if zero_point ends up lying within the range, remove the scaling
if (
scaling.zero_point !== null &&
!isNil(scaling.zero_point) &&
!isNil(scaling.range_min) &&
!isNil(scaling.range_max) &&
scaling.range_min <= scaling.zero_point &&
Expand Down