Skip to content

Commit

Permalink
fix(ava/insight): modify parameter names and algorithm infos
Browse files Browse the repository at this point in the history
  • Loading branch information
LAI-X authored and BBSQQ committed Oct 30, 2023
1 parent 88d0864 commit 1ad3aab
Show file tree
Hide file tree
Showing 15 changed files with 35 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { insightExtractor } from '../../../../src/insight/insights';
import { insightPatternsExtractor } from '../../../../src/insight/insights';

const data = [
{
Expand Down Expand Up @@ -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' }],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { insightExtractor } from '../../../../src/insight/insights';
import { insightPatternsExtractor } from '../../../../src/insight/insights';

const data = [
{ year: '1991', value: 0.3 },
Expand All @@ -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' }],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { insightExtractor } from '../../../../src/insight/insights';
import { insightPatternsExtractor } from '../../../../src/insight/insights';

const data = [
{ x: 1, y: 4.181 },
Expand Down Expand Up @@ -36,7 +36,7 @@ const data = [

describe('extract correlation insight', () => {
test('check correlation result', () => {
const result = insightExtractor({
const result = insightPatternsExtractor({
data,
dimensions: [],
measures: [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { insightExtractor } from '../../../../src/insight/insights';
import { insightPatternsExtractor } from '../../../../src/insight/insights';

const data = [
{
Expand Down Expand Up @@ -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' }],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { insightExtractor } from '../../../../src/insight/insights';
import { insightPatternsExtractor } from '../../../../src/insight/insights';

const data = [
{
Expand Down Expand Up @@ -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' }],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { insightExtractor } from '../../../../src/insight/insights';
import { insightPatternsExtractor } from '../../../../src/insight/insights';

const data = [
{ year: '1991', value: 3 },
Expand All @@ -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' }],
Expand Down
4 changes: 2 additions & 2 deletions packages/ava/__tests__/unit/insight/extractors/trend.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { insightExtractor } from '../../../../src/insight/insights';
import { insightPatternsExtractor } from '../../../../src/insight/insights';

const data = [
{ year: '1991', value: 3 },
Expand All @@ -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' }],
Expand Down
2 changes: 2 additions & 0 deletions packages/ava/src/insight/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
2 changes: 1 addition & 1 deletion packages/ava/src/insight/insights/checkers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
3 changes: 2 additions & 1 deletion packages/ava/src/insight/insights/extractors/changePoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand All @@ -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) {
Expand Down
8 changes: 6 additions & 2 deletions packages/ava/src/insight/insights/extractors/correlation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -42,7 +43,8 @@ export const getCorrelationInfo: GetPatternInfo<CorrelationInfo> = (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 [
{
Expand All @@ -53,6 +55,8 @@ export const getCorrelationInfo: GetPatternInfo<CorrelationInfo> = (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 } });
};
7 changes: 5 additions & 2 deletions packages/ava/src/insight/insights/extractors/trend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -47,7 +48,9 @@ export const getTrendInfo: GetPatternInfo<TrendInfo> = (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,
Expand Down
2 changes: 1 addition & 1 deletion packages/ava/src/insight/insights/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
6 changes: 3 additions & 3 deletions packages/ava/src/insight/pipeline/extract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -81,7 +81,7 @@ function extractPatternsFromSubject(
// Select only significant insights
filterInsight: true,
};
const extractedPatterns = insightExtractor({
const extractedPatterns = insightPatternsExtractor({
data,
dimensions,
measures,
Expand Down
2 changes: 1 addition & 1 deletion packages/ava/src/insight/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 1ad3aab

Please sign in to comment.