Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix math.min / max for array size more than 10^7 #1427

Merged
merged 1 commit into from
May 13, 2022
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
3 changes: 2 additions & 1 deletion apps/dashboard/src/fairness/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
IMetricRequest,
IMetricResponse
} from "@responsible-ai/core-ui";
import _ from "lodash";

export const supportedBinaryClassificationPerformanceKeys = [
"accuracy_score",
Expand Down Expand Up @@ -65,7 +66,7 @@ export function generateRandomMetrics(
request: IMetricRequest,
abortSignal?: AbortSignal
): Promise<IMetricResponse> {
const binSize = Math.max(...request.binVector);
const binSize = _.max(request.binVector) || 0;
const bins: number[] = new Array(binSize + 1)
.fill(0)
.map(() => Math.random() / 3 + 0.33);
Expand Down
16 changes: 8 additions & 8 deletions libs/core-ui/src/lib/util/JointDataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ export class JointDataset {
};
if (args.metadata.modelType === ModelTypes.Regression) {
this.metaDict[JointDataset.PredictedYLabel].featureRange = {
max: Math.max(...args.predictedY),
min: Math.min(...args.predictedY),
max: _.max(args.predictedY) || 0,
min: _.min(args.predictedY) || 0,
rangeType: RangeTypes.Numeric
};
}
Expand Down Expand Up @@ -223,8 +223,8 @@ export class JointDataset {
abbridgedLabel: label,
category: ColumnCategories.Outcome,
featureRange: {
max: Math.max(...projection),
min: Math.min(...projection),
max: _.max(projection) || 0,
min: _.min(projection) || 0,
rangeType: RangeTypes.Numeric
},
isCategorical: false,
Expand Down Expand Up @@ -257,8 +257,8 @@ export class JointDataset {
};
if (args.metadata.modelType === ModelTypes.Regression) {
this.metaDict[JointDataset.TrueYLabel].featureRange = {
max: Math.max(...args.trueY),
min: Math.min(...args.trueY),
max: _.max(args.trueY) || 0,
min: _.min(args.trueY) || 0,
rangeType: RangeTypes.Numeric
};
}
Expand All @@ -278,8 +278,8 @@ export class JointDataset {
abbridgedLabel: localization.Interpret.Columns.error,
category: ColumnCategories.Outcome,
featureRange: {
max: Math.max(...regressionErrorArray),
min: Math.min(...regressionErrorArray),
max: _.max(regressionErrorArray) || 0,
min: _.min(regressionErrorArray) || 0,
rangeType: RangeTypes.Numeric
},
isCategorical: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

import { SeriesOptionsType } from "highcharts";
import _ from "lodash";

import { IGlobalSeries } from "../Highchart/FeatureImportanceBar";
import { IHighchartsConfig } from "../Highchart/IHighchartsConfig";
Expand Down Expand Up @@ -31,7 +32,7 @@ export function getFeatureImportanceBoxOptions(
const y = base.concat(
...sortArray.map((index) => series.unsortedIndividualY?.[index] || [])
);
const curMin = Math.min(...y);
const curMin = _.min(y) || 0;
yAxisMin = Math.min(yAxisMin, curMin);
boxTempData.push({
color: FabricStyles.fabricColorPalette[series.colorIndex],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { interpolateHcl as d3interpolateHcl } from "d3-interpolate";
import { scaleLinear as d3scaleLinear } from "d3-scale";
import { select } from "d3-selection";
import { linkVertical as d3linkVertical } from "d3-shape";
import _ from "lodash";
import {
getTheme,
IProcessedStyleSet,
Expand Down Expand Up @@ -261,12 +262,12 @@ export class TreeViewRenderer extends React.PureComponent<
);
const x = rootDescendants.map((d) => d.x);
const y = rootDescendants.map((d) => d.y);
const minX = Math.min(Math.min(...x) - 40, pathMin);
const minX = Math.min((_.min(x) || 0) - 40, pathMin);
//100:tooltip width
const maxX = Math.max(Math.max(...x) + 40 + 100, pathMax);
const minY = Math.min(...y) - 40;
const maxX = Math.max((_.max(x) || 0) + 40 + 100, pathMax);
const minY = (_.min(y) || 0) - 40;
//40:tooltip height
const maxY = Math.max(...y) + 40 + 40;
const maxY = (_.max(y) || 0) + 40 + 40;
const containerStyles = mergeStyles({
transform: `translate(${-minX}px, ${-minY}px)`
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ export class Beehive extends React.PureComponent<
const featureArray =
data.testDataset.dataset?.map((row: number[]) => row[featureIndex]) ||
[];
const min = Math.min(...featureArray);
const max = Math.max(...featureArray);
const min = _.min(featureArray) || 0;
const max = _.max(featureArray) || 0;
const range = max - min;
return (value: string | number): number => {
return range !== 0 && typeof value === "number"
Expand Down
4 changes: 2 additions & 2 deletions libs/mlchartlib/src/lib/components/ModelMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ export class ModelMetadata {
}
const featureVector = testData.map((row) => row[featureIndex]);
return {
max: Math.max(...featureVector),
min: Math.min(...featureVector),
max: _.max(featureVector) || 0,
min: _.min(featureVector) || 0,
rangeType: featureVector.every((val) => Number.isInteger(val))
? RangeTypes.Integer
: RangeTypes.Numeric
Expand Down