From 1ad3aabd22a7c286be99cfa17b2a3dca0e0b3a81 Mon Sep 17 00:00:00 2001 From: "laixingui.lxg" Date: Fri, 27 Oct 2023 19:40:26 +0800 Subject: [PATCH] fix(ava/insight): modify parameter names and algorithm infos --- .../unit/insight/extractors/category-outlier.test.ts | 4 ++-- .../unit/insight/extractors/change-point.test.ts | 4 ++-- .../__tests__/unit/insight/extractors/correlation.test.ts | 4 ++-- .../unit/insight/extractors/low-variance.test.ts | 4 ++-- .../__tests__/unit/insight/extractors/majority.test.ts | 4 ++-- .../unit/insight/extractors/time-series-outlier.test.ts | 4 ++-- .../ava/__tests__/unit/insight/extractors/trend.test.ts | 4 ++-- packages/ava/src/insight/constant.ts | 2 ++ packages/ava/src/insight/insights/checkers.ts | 2 +- .../ava/src/insight/insights/extractors/changePoint.ts | 3 ++- .../ava/src/insight/insights/extractors/correlation.ts | 8 ++++++-- packages/ava/src/insight/insights/extractors/trend.ts | 7 +++++-- packages/ava/src/insight/insights/index.ts | 2 +- packages/ava/src/insight/pipeline/extract.ts | 6 +++--- packages/ava/src/insight/types.ts | 2 +- 15 files changed, 35 insertions(+), 25 deletions(-) diff --git a/packages/ava/__tests__/unit/insight/extractors/category-outlier.test.ts b/packages/ava/__tests__/unit/insight/extractors/category-outlier.test.ts index 14a02910..ffad7ce6 100644 --- a/packages/ava/__tests__/unit/insight/extractors/category-outlier.test.ts +++ b/packages/ava/__tests__/unit/insight/extractors/category-outlier.test.ts @@ -1,4 +1,4 @@ -import { insightExtractor } from '../../../../src/insight/insights'; +import { insightPatternsExtractor } from '../../../../src/insight/insights'; const data = [ { @@ -37,7 +37,7 @@ const data = [ describe('extract category-outlier insight', () => { test('check outliers result', () => { - const result = insightExtractor({ + const result = insightPatternsExtractor({ data, dimensions: ['type'], measures: [{ fieldName: 'sales', method: 'SUM' }], diff --git a/packages/ava/__tests__/unit/insight/extractors/change-point.test.ts b/packages/ava/__tests__/unit/insight/extractors/change-point.test.ts index 2e2013bf..970b3abf 100644 --- a/packages/ava/__tests__/unit/insight/extractors/change-point.test.ts +++ b/packages/ava/__tests__/unit/insight/extractors/change-point.test.ts @@ -1,4 +1,4 @@ -import { insightExtractor } from '../../../../src/insight/insights'; +import { insightPatternsExtractor } from '../../../../src/insight/insights'; const data = [ { year: '1991', value: 0.3 }, @@ -14,7 +14,7 @@ const data = [ describe('extract change-point insight', () => { test('check change-point result', () => { - const result = insightExtractor({ + const result = insightPatternsExtractor({ data, dimensions: ['year'], measures: [{ fieldName: 'value', method: 'SUM' }], diff --git a/packages/ava/__tests__/unit/insight/extractors/correlation.test.ts b/packages/ava/__tests__/unit/insight/extractors/correlation.test.ts index 8263da41..f4fda913 100644 --- a/packages/ava/__tests__/unit/insight/extractors/correlation.test.ts +++ b/packages/ava/__tests__/unit/insight/extractors/correlation.test.ts @@ -1,4 +1,4 @@ -import { insightExtractor } from '../../../../src/insight/insights'; +import { insightPatternsExtractor } from '../../../../src/insight/insights'; const data = [ { x: 1, y: 4.181 }, @@ -36,7 +36,7 @@ const data = [ describe('extract correlation insight', () => { test('check correlation result', () => { - const result = insightExtractor({ + const result = insightPatternsExtractor({ data, dimensions: [], measures: [ diff --git a/packages/ava/__tests__/unit/insight/extractors/low-variance.test.ts b/packages/ava/__tests__/unit/insight/extractors/low-variance.test.ts index 7e4a3055..75a64ebf 100644 --- a/packages/ava/__tests__/unit/insight/extractors/low-variance.test.ts +++ b/packages/ava/__tests__/unit/insight/extractors/low-variance.test.ts @@ -1,4 +1,4 @@ -import { insightExtractor } from '../../../../src/insight/insights'; +import { insightPatternsExtractor } from '../../../../src/insight/insights'; const data = [ { @@ -37,7 +37,7 @@ const data = [ describe('extract low-variance insight', () => { test('check low-variance result', () => { - const result = insightExtractor({ + const result = insightPatternsExtractor({ data, dimensions: ['type'], measures: [{ fieldName: 'sales', method: 'SUM' }], diff --git a/packages/ava/__tests__/unit/insight/extractors/majority.test.ts b/packages/ava/__tests__/unit/insight/extractors/majority.test.ts index 4dc7dca2..011c1ed4 100644 --- a/packages/ava/__tests__/unit/insight/extractors/majority.test.ts +++ b/packages/ava/__tests__/unit/insight/extractors/majority.test.ts @@ -1,4 +1,4 @@ -import { insightExtractor } from '../../../../src/insight/insights'; +import { insightPatternsExtractor } from '../../../../src/insight/insights'; const data = [ { @@ -37,7 +37,7 @@ const data = [ describe('extract majority insight', () => { test('check majority result', () => { - const result = insightExtractor({ + const result = insightPatternsExtractor({ data, dimensions: ['type'], measures: [{ fieldName: 'sales', method: 'SUM' }], diff --git a/packages/ava/__tests__/unit/insight/extractors/time-series-outlier.test.ts b/packages/ava/__tests__/unit/insight/extractors/time-series-outlier.test.ts index bb7df6d6..a491c522 100644 --- a/packages/ava/__tests__/unit/insight/extractors/time-series-outlier.test.ts +++ b/packages/ava/__tests__/unit/insight/extractors/time-series-outlier.test.ts @@ -1,4 +1,4 @@ -import { insightExtractor } from '../../../../src/insight/insights'; +import { insightPatternsExtractor } from '../../../../src/insight/insights'; const data = [ { year: '1991', value: 3 }, @@ -14,7 +14,7 @@ const data = [ describe('extract time-series-outlier insight', () => { test('check outliers result', () => { - const result = insightExtractor({ + const result = insightPatternsExtractor({ data, dimensions: ['year'], measures: [{ fieldName: 'value', method: 'SUM' }], diff --git a/packages/ava/__tests__/unit/insight/extractors/trend.test.ts b/packages/ava/__tests__/unit/insight/extractors/trend.test.ts index 7137d82c..60c991c0 100644 --- a/packages/ava/__tests__/unit/insight/extractors/trend.test.ts +++ b/packages/ava/__tests__/unit/insight/extractors/trend.test.ts @@ -1,4 +1,4 @@ -import { insightExtractor } from '../../../../src/insight/insights'; +import { insightPatternsExtractor } from '../../../../src/insight/insights'; const data = [ { year: '1991', value: 3 }, @@ -14,7 +14,7 @@ const data = [ describe('extract trend insight', () => { test('check trend result', () => { - const result = insightExtractor({ + const result = insightPatternsExtractor({ data, dimensions: ['year'], measures: [{ fieldName: 'value', method: 'SUM' }], diff --git a/packages/ava/src/insight/constant.ts b/packages/ava/src/insight/constant.ts index 2c557cbe..714dc2eb 100644 --- a/packages/ava/src/insight/constant.ts +++ b/packages/ava/src/insight/constant.ts @@ -28,3 +28,5 @@ export const HOMOGENEOUS_PATTERN_TYPES = ['commonness', 'exception'] as const; export const VERIFICATION_FAILURE_INFO = 'The input does not meet the requirements.'; export const NO_PATTERN_INFO = 'No insights were found at the specified significance threshold.'; + +export const CHANGE_POINT_SIGNIFICANCE_BENCHMARK = 0.15; diff --git a/packages/ava/src/insight/insights/checkers.ts b/packages/ava/src/insight/insights/checkers.ts index 1aa9e5ce..6259c4a0 100644 --- a/packages/ava/src/insight/insights/checkers.ts +++ b/packages/ava/src/insight/insights/checkers.ts @@ -90,7 +90,7 @@ export const correlationChecker: ExtractorChecker = ({ data, subjectInfo, fieldP !fieldPropsMap[measures[0].fieldName].levelOfMeasurements?.includes('Continuous') || !fieldPropsMap[measures[1].fieldName].levelOfMeasurements?.includes('Continuous') ) - return 'Level of measure is not continuous. '; + return 'Level of measurement is not continuous. '; return true; }; diff --git a/packages/ava/src/insight/insights/extractors/changePoint.ts b/packages/ava/src/insight/insights/extractors/changePoint.ts index f0c130a0..0629875d 100644 --- a/packages/ava/src/insight/insights/extractors/changePoint.ts +++ b/packages/ava/src/insight/insights/extractors/changePoint.ts @@ -2,6 +2,7 @@ import { get, isString } from 'lodash'; import { changePoint } from '../../algorithms'; import { getAlgorithmCommonInput, getNonSignificantInsight, preValidation } from '../util'; +import { CHANGE_POINT_SIGNIFICANCE_BENCHMARK } from '../../constant'; import type { ChangePointInfo, CommonParameter, GetPatternInfo } from '../../types'; @@ -15,7 +16,7 @@ export const findChangePoints = (series: number[], changePointsParameter: Common const changePointsResult: ChangePointItem[] = []; // significanceBenchmark is equivalent to the confidence interval in hypothesis testing - const significanceBenchmark = 1 - (changePointsParameter?.significance ?? 0.15); + const significanceBenchmark = 1 - (changePointsParameter?.threshold ?? CHANGE_POINT_SIGNIFICANCE_BENCHMARK); results.forEach((item) => { // item.significance is similar to confidence interval if (item?.index >= 0 && item?.significance >= significanceBenchmark) { diff --git a/packages/ava/src/insight/insights/extractors/correlation.ts b/packages/ava/src/insight/insights/extractors/correlation.ts index 65fcc3dd..74169b90 100644 --- a/packages/ava/src/insight/insights/extractors/correlation.ts +++ b/packages/ava/src/insight/insights/extractors/correlation.ts @@ -4,6 +4,7 @@ import { pcorrtest } from '../../../data'; import { PCorrTestParameter } from '../../../data/statistics/types'; import { CorrelationInfo, GetPatternInfo } from '../../types'; import { getNonSignificantInsight, preValidation } from '../util'; +import { DEFAULT_PCORRTEST_OPTIONS } from '../../../data/statistics/constants'; type CorrelationResult = { significance: number; @@ -42,7 +43,8 @@ export const getCorrelationInfo: GetPatternInfo = (props) => { const yField = measures[1].fieldName; const x = data.map((item) => item?.[xField] as number); const y = data.map((item) => item?.[yField] as number); - const result = findCorrelation(x, y, options?.algorithmParameter?.correlation); + const correlationParameter = options?.algorithmParameter?.correlation; + const result = findCorrelation(x, y, correlationParameter); if (result) { return [ { @@ -53,6 +55,8 @@ export const getCorrelationInfo: GetPatternInfo = (props) => { }, ]; } - const info = 'The Pearson product-moment correlation test does not pass at the specified significance (alpha).'; + const info = `The Pearson product-moment correlation test does not pass at the specified significance level ${ + correlationParameter?.alpha ?? DEFAULT_PCORRTEST_OPTIONS.alpha + }.`; return getNonSignificantInsight({ insightType, infoType: 'noInsight', customInfo: { info } }); }; diff --git a/packages/ava/src/insight/insights/extractors/trend.ts b/packages/ava/src/insight/insights/extractors/trend.ts index 721cd1f3..e8a86ebb 100644 --- a/packages/ava/src/insight/insights/extractors/trend.ts +++ b/packages/ava/src/insight/insights/extractors/trend.ts @@ -4,6 +4,7 @@ import { get, isString } from 'lodash'; import { CommonParameter, GetPatternInfo, TrendInfo } from '../../types'; import { trendDirection } from '../../algorithms'; import { getAlgorithmCommonInput, getNonSignificantInsight, preValidation } from '../util'; +import { SIGNIFICANCE_LEVEL } from '../../constant'; type TrendResult = { significance: number; @@ -12,7 +13,7 @@ type TrendResult = { }; export function findTimeSeriesTrend(series: number[], trendParameter: CommonParameter): TrendResult { - const significance = trendParameter?.significance ?? 0.05; + const significance = trendParameter?.threshold ?? SIGNIFICANCE_LEVEL; const testResult = trendDirection.mkTest(series, significance); const { pValue, trend } = testResult; @@ -47,7 +48,9 @@ export const getTrendInfo: GetPatternInfo = (props) => { ...(result.trend === 'no trend' ? { significantInsight: false, - info: 'The Mann-Kendall (MK) test does not pass at the specified significance (alpha).', + info: `The Mann-Kendall (MK) test does not pass at the specified significance level ${ + trendParameter?.threshold ?? SIGNIFICANCE_LEVEL + }.`, } : { significantInsight: true, diff --git a/packages/ava/src/insight/insights/index.ts b/packages/ava/src/insight/insights/index.ts index fdb9aef4..ff4ba3bf 100644 --- a/packages/ava/src/insight/insights/index.ts +++ b/packages/ava/src/insight/insights/index.ts @@ -21,7 +21,7 @@ export const extractorMap = { correlation: getCorrelationInfo, }; -export const insightExtractor = (props: InsightExtractorProps): PatternInfo[] => { +export const insightPatternsExtractor = (props: InsightExtractorProps): PatternInfo[] => { const { insightType = 'trend', options } = props; const { filterInsight = false } = options || {}; const extractor = extractorMap[insightType]; diff --git a/packages/ava/src/insight/pipeline/extract.ts b/packages/ava/src/insight/pipeline/extract.ts index 3b85e25c..bdb8a8ac 100644 --- a/packages/ava/src/insight/pipeline/extract.ts +++ b/packages/ava/src/insight/pipeline/extract.ts @@ -2,7 +2,7 @@ import { groupBy, uniq, flatten, isString } from 'lodash'; import Heap from 'heap-js'; import { PATTERN_TYPES, InsightScoreBenchmark, ImpactScoreWeight } from '../constant'; -import { insightExtractor, ExtractorCheckers } from '../insights'; +import { insightPatternsExtractor, ExtractorCheckers } from '../insights'; import { aggregate } from '../utils/aggregate'; import { extractHomogeneousPatternsForMeasures, @@ -71,7 +71,7 @@ function extractPatternsFromSubject( if (insightExtractorChecker) { if (isString(insightExtractorChecker({ data, subjectInfo, fieldPropsMap }))) isValid = false; } - if (isValid && insightExtractor) { + if (isValid && insightPatternsExtractor) { const { algorithmParameter, dataProcessInfo } = options || {}; const extractorOptions: InsightExtractorOptions = { algorithmParameter, @@ -81,7 +81,7 @@ function extractPatternsFromSubject( // Select only significant insights filterInsight: true, }; - const extractedPatterns = insightExtractor({ + const extractedPatterns = insightPatternsExtractor({ data, dimensions, measures, diff --git a/packages/ava/src/insight/types.ts b/packages/ava/src/insight/types.ts index 64d57f50..217d6cd0 100644 --- a/packages/ava/src/insight/types.ts +++ b/packages/ava/src/insight/types.ts @@ -142,7 +142,7 @@ export type OutlierParameter = { export type CommonParameter = { /** Significance level (alpha) in hypothesis testing */ - significance?: number; + threshold?: number; }; /** Key parameters in the algorithm for extracting insights */