@formant/ava 3.4.1-formant
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 +72 -0
- package/dist/ava.min.js +1 -0
- package/esm/advisor/advise-pipeline/advicesForChart.js +68 -0
- package/esm/advisor/advise-pipeline/data-to-advices.js +241 -0
- package/esm/advisor/advise-pipeline/index.js +1 -0
- package/esm/advisor/advise-pipeline/spec-mapping.js +500 -0
- package/esm/advisor/advisor.js +35 -0
- package/esm/advisor/constants.js +13 -0
- package/esm/advisor/index.js +2 -0
- package/esm/advisor/lint-pipeline/check-rules.js +43 -0
- package/esm/advisor/lint-pipeline/getChartType.js +109 -0
- package/esm/advisor/lint-pipeline/index.js +0 -0
- package/esm/advisor/lint-pipeline/lintRules.js +32 -0
- package/esm/advisor/ruler/index.js +74 -0
- package/esm/advisor/ruler/rules/aggregation-single-row.js +21 -0
- package/esm/advisor/ruler/rules/all-can-be-table.js +17 -0
- package/esm/advisor/ruler/rules/bar-series-qty.js +36 -0
- package/esm/advisor/ruler/rules/bar-without-axis-min.js +41 -0
- package/esm/advisor/ruler/rules/constants.js +6 -0
- package/esm/advisor/ruler/rules/data-check.js +40 -0
- package/esm/advisor/ruler/rules/data-field-qty.js +26 -0
- package/esm/advisor/ruler/rules/diff-pie-sector.js +33 -0
- package/esm/advisor/ruler/rules/index.js +68 -0
- package/esm/advisor/ruler/rules/landscape-or-portrait.js +40 -0
- package/esm/advisor/ruler/rules/limit-series.js +47 -0
- package/esm/advisor/ruler/rules/line-field-time-ordinal.js +25 -0
- package/esm/advisor/ruler/rules/no-redundant-field.js +32 -0
- package/esm/advisor/ruler/rules/nominal-enum-combinatorial.js +54 -0
- package/esm/advisor/ruler/rules/purpose-check.js +27 -0
- package/esm/advisor/ruler/rules/series-qty-limit.js +34 -0
- package/esm/advisor/ruler/rules/x-axis-line-fading.js +41 -0
- package/esm/advisor/ruler/types.js +1 -0
- package/esm/advisor/ruler/utils.js +54 -0
- package/esm/advisor/types.js +1 -0
- package/esm/advisor/utils/clone.js +32 -0
- package/esm/advisor/utils/compare.js +14 -0
- package/esm/advisor/utils/computeScore.js +25 -0
- package/esm/advisor/utils/deep-mix.js +76 -0
- package/esm/advisor/utils/hasSubset.js +3 -0
- package/esm/advisor/utils/index.js +8 -0
- package/esm/advisor/utils/inferDataType.js +70 -0
- package/esm/advisor/utils/intersects.js +3 -0
- package/esm/advisor/utils/isNil.js +4 -0
- package/esm/ckb/base.js +1310 -0
- package/esm/ckb/ckb.js +55 -0
- package/esm/ckb/constants.js +197 -0
- package/esm/ckb/i18n/index.js +23 -0
- package/esm/ckb/i18n/types.js +1 -0
- package/esm/ckb/i18n/zh-CN.js +525 -0
- package/esm/ckb/index.js +14 -0
- package/esm/ckb/types.js +1 -0
- package/esm/common/types.js +1 -0
- package/esm/data/analysis/field/index.js +336 -0
- package/esm/data/analysis/field/types.js +1 -0
- package/esm/data/analysis/graph/index.js +170 -0
- package/esm/data/analysis/graph/types.js +1 -0
- package/esm/data/analysis/index.js +1 -0
- package/esm/data/analysis/types.js +1 -0
- package/esm/data/dataset/field/baseFrame.js +76 -0
- package/esm/data/dataset/field/dataFrame.js +556 -0
- package/esm/data/dataset/field/index.js +3 -0
- package/esm/data/dataset/field/series.js +149 -0
- package/esm/data/dataset/field/types.js +1 -0
- package/esm/data/dataset/field/utils.js +58 -0
- package/esm/data/dataset/graph/index.js +186 -0
- package/esm/data/dataset/graph/types.js +1 -0
- package/esm/data/dataset/graph/utils.js +15 -0
- package/esm/data/dataset/index.js +1 -0
- package/esm/data/dataset/types.js +1 -0
- package/esm/data/index.js +5 -0
- package/esm/data/statistics/IQR.js +49 -0
- package/esm/data/statistics/base.js +248 -0
- package/esm/data/statistics/bayesian.js +25 -0
- package/esm/data/statistics/buishand-u.js +19 -0
- package/esm/data/statistics/caches.js +28 -0
- package/esm/data/statistics/cdf.js +25 -0
- package/esm/data/statistics/constants.js +12 -0
- package/esm/data/statistics/index.js +7 -0
- package/esm/data/statistics/lowess.js +80 -0
- package/esm/data/statistics/mannkendall-test.js +50 -0
- package/esm/data/statistics/maxabs.js +9 -0
- package/esm/data/statistics/pcorrtest.js +76 -0
- package/esm/data/statistics/pettitt-test.js +33 -0
- package/esm/data/statistics/quantile.js +56 -0
- package/esm/data/statistics/types.js +1 -0
- package/esm/data/statistics/vector.js +67 -0
- package/esm/data/statistics/window.js +55 -0
- package/esm/data/types.js +2 -0
- package/esm/data/utils/common.js +58 -0
- package/esm/data/utils/index.js +5 -0
- package/esm/data/utils/isType/constants.js +24 -0
- package/esm/data/utils/isType/index.js +2 -0
- package/esm/data/utils/isType/isDateString.js +104 -0
- package/esm/data/utils/isType/isType.js +78 -0
- package/esm/index.js +11 -0
- package/esm/insight/algorithms/base/compare.js +40 -0
- package/esm/insight/algorithms/categoryOutlier.js +4 -0
- package/esm/insight/algorithms/changePoint.js +10 -0
- package/esm/insight/algorithms/index.js +3 -0
- package/esm/insight/algorithms/trendDirection.js +4 -0
- package/esm/insight/chart/constants.js +25 -0
- package/esm/insight/chart/generator/homogeneous.js +70 -0
- package/esm/insight/chart/generator/index.js +2 -0
- package/esm/insight/chart/generator/insights.js +16 -0
- package/esm/insight/chart/index.js +4 -0
- package/esm/insight/chart/strategy/augmentedMarks/categoryOutlier.js +30 -0
- package/esm/insight/chart/strategy/augmentedMarks/changePoint.js +42 -0
- package/esm/insight/chart/strategy/augmentedMarks/correlation.js +6 -0
- package/esm/insight/chart/strategy/augmentedMarks/homogeneous.js +5 -0
- package/esm/insight/chart/strategy/augmentedMarks/index.js +8 -0
- package/esm/insight/chart/strategy/augmentedMarks/lowVariance.js +23 -0
- package/esm/insight/chart/strategy/augmentedMarks/majority.js +5 -0
- package/esm/insight/chart/strategy/augmentedMarks/timeSeriesOutlier.js +82 -0
- package/esm/insight/chart/strategy/augmentedMarks/trend.js +26 -0
- package/esm/insight/chart/strategy/chart.js +45 -0
- package/esm/insight/chart/strategy/commonMarks/areaMark.js +12 -0
- package/esm/insight/chart/strategy/commonMarks/index.js +5 -0
- package/esm/insight/chart/strategy/commonMarks/intervalMark.js +14 -0
- package/esm/insight/chart/strategy/commonMarks/lineMark.js +34 -0
- package/esm/insight/chart/strategy/commonMarks/pointMark.js +17 -0
- package/esm/insight/chart/strategy/commonMarks/textMark.js +28 -0
- package/esm/insight/chart/strategy/index.js +4 -0
- package/esm/insight/chart/strategy/viewSpec.js +16 -0
- package/esm/insight/chart/types.js +1 -0
- package/esm/insight/chart/utils.js +4 -0
- package/esm/insight/constant.js +21 -0
- package/esm/insight/index.js +5 -0
- package/esm/insight/insights/checkers.js +97 -0
- package/esm/insight/insights/extractors/categoryOutlier.js +90 -0
- package/esm/insight/insights/extractors/changePoint.js +55 -0
- package/esm/insight/insights/extractors/correlation.js +38 -0
- package/esm/insight/insights/extractors/homogeneous.js +98 -0
- package/esm/insight/insights/extractors/lowVariance.js +49 -0
- package/esm/insight/insights/extractors/majority.js +66 -0
- package/esm/insight/insights/extractors/timeSeriesOutlier.js +61 -0
- package/esm/insight/insights/extractors/trend.js +49 -0
- package/esm/insight/insights/index.js +28 -0
- package/esm/insight/insights/util.js +77 -0
- package/esm/insight/narrative/factory.js +22 -0
- package/esm/insight/narrative/index.js +14 -0
- package/esm/insight/narrative/strategy/base.js +6 -0
- package/esm/insight/narrative/strategy/categoryOutlier.js +74 -0
- package/esm/insight/narrative/strategy/changePoint.js +52 -0
- package/esm/insight/narrative/strategy/commonness.js +45 -0
- package/esm/insight/narrative/strategy/correlation.js +51 -0
- package/esm/insight/narrative/strategy/exception.js +70 -0
- package/esm/insight/narrative/strategy/helpers.js +25 -0
- package/esm/insight/narrative/strategy/index.js +13 -0
- package/esm/insight/narrative/strategy/lowVariance.js +48 -0
- package/esm/insight/narrative/strategy/majority.js +62 -0
- package/esm/insight/narrative/strategy/timeSeriesOutlier.js +92 -0
- package/esm/insight/narrative/strategy/trend.js +57 -0
- package/esm/insight/pipeline/extract.js +236 -0
- package/esm/insight/pipeline/index.js +11 -0
- package/esm/insight/pipeline/insight.js +81 -0
- package/esm/insight/pipeline/preprocess.js +33 -0
- package/esm/insight/pipeline/specificInsight.js +71 -0
- package/esm/insight/pipeline/util.js +14 -0
- package/esm/insight/pipeline/visualize.js +41 -0
- package/esm/insight/types.js +1 -0
- package/esm/insight/utils/aggregate.js +87 -0
- package/esm/insight/utils/common.js +35 -0
- package/esm/ntv/generate/generateTextSpec.js +157 -0
- package/esm/ntv/generate/index.js +5 -0
- package/esm/ntv/generate/types.js +1 -0
- package/esm/ntv/generate/utils.js +86 -0
- package/esm/ntv/index.js +4 -0
- package/esm/ntv/schema/common.js +1 -0
- package/esm/ntv/schema/index.js +4 -0
- package/esm/ntv/schema/paragraph.js +1 -0
- package/esm/ntv/schema/phrase.js +52 -0
- package/esm/ntv/schema/structure.js +1 -0
- package/esm/ntv/types.js +1 -0
- package/esm/ntv/utils/index.js +1 -0
- package/esm/ntv/utils/isSpecType.js +58 -0
- package/esm/utils/arr2map.js +7 -0
- package/esm/utils/dataFormat.js +32 -0
- package/esm/utils/index.js +3 -0
- package/esm/utils/isType.js +14 -0
- package/lib/advisor/advise-pipeline/advicesForChart.d.ts +13 -0
- package/lib/advisor/advise-pipeline/advicesForChart.js +73 -0
- package/lib/advisor/advise-pipeline/data-to-advices.d.ts +22 -0
- package/lib/advisor/advise-pipeline/data-to-advices.js +245 -0
- package/lib/advisor/advise-pipeline/index.d.ts +1 -0
- package/lib/advisor/advise-pipeline/index.js +5 -0
- package/lib/advisor/advise-pipeline/spec-mapping.d.ts +14 -0
- package/lib/advisor/advise-pipeline/spec-mapping.js +504 -0
- package/lib/advisor/advisor.d.ts +18 -0
- package/lib/advisor/advisor.js +38 -0
- package/lib/advisor/constants.d.ts +1 -0
- package/lib/advisor/constants.js +16 -0
- package/lib/advisor/index.d.ts +2 -0
- package/lib/advisor/index.js +7 -0
- package/lib/advisor/lint-pipeline/check-rules.d.ts +4 -0
- package/lib/advisor/lint-pipeline/check-rules.js +47 -0
- package/lib/advisor/lint-pipeline/getChartType.d.ts +7 -0
- package/lib/advisor/lint-pipeline/getChartType.js +113 -0
- package/lib/advisor/lint-pipeline/index.d.ts +0 -0
- package/lib/advisor/lint-pipeline/index.js +0 -0
- package/lib/advisor/lint-pipeline/lintRules.d.ts +5 -0
- package/lib/advisor/lint-pipeline/lintRules.js +36 -0
- package/lib/advisor/ruler/index.d.ts +21 -0
- package/lib/advisor/ruler/index.js +80 -0
- package/lib/advisor/ruler/rules/aggregation-single-row.d.ts +2 -0
- package/lib/advisor/ruler/rules/aggregation-single-row.js +24 -0
- package/lib/advisor/ruler/rules/all-can-be-table.d.ts +2 -0
- package/lib/advisor/ruler/rules/all-can-be-table.js +20 -0
- package/lib/advisor/ruler/rules/bar-series-qty.d.ts +2 -0
- package/lib/advisor/ruler/rules/bar-series-qty.js +39 -0
- package/lib/advisor/ruler/rules/bar-without-axis-min.d.ts +2 -0
- package/lib/advisor/ruler/rules/bar-without-axis-min.js +44 -0
- package/lib/advisor/ruler/rules/constants.d.ts +6 -0
- package/lib/advisor/ruler/rules/constants.js +9 -0
- package/lib/advisor/ruler/rules/data-check.d.ts +2 -0
- package/lib/advisor/ruler/rules/data-check.js +43 -0
- package/lib/advisor/ruler/rules/data-field-qty.d.ts +2 -0
- package/lib/advisor/ruler/rules/data-field-qty.js +29 -0
- package/lib/advisor/ruler/rules/diff-pie-sector.d.ts +2 -0
- package/lib/advisor/ruler/rules/diff-pie-sector.js +36 -0
- package/lib/advisor/ruler/rules/index.d.ts +19 -0
- package/lib/advisor/ruler/rules/index.js +71 -0
- package/lib/advisor/ruler/rules/landscape-or-portrait.d.ts +2 -0
- package/lib/advisor/ruler/rules/landscape-or-portrait.js +43 -0
- package/lib/advisor/ruler/rules/limit-series.d.ts +2 -0
- package/lib/advisor/ruler/rules/limit-series.js +50 -0
- package/lib/advisor/ruler/rules/line-field-time-ordinal.d.ts +2 -0
- package/lib/advisor/ruler/rules/line-field-time-ordinal.js +28 -0
- package/lib/advisor/ruler/rules/no-redundant-field.d.ts +2 -0
- package/lib/advisor/ruler/rules/no-redundant-field.js +35 -0
- package/lib/advisor/ruler/rules/nominal-enum-combinatorial.d.ts +2 -0
- package/lib/advisor/ruler/rules/nominal-enum-combinatorial.js +57 -0
- package/lib/advisor/ruler/rules/purpose-check.d.ts +2 -0
- package/lib/advisor/ruler/rules/purpose-check.js +30 -0
- package/lib/advisor/ruler/rules/series-qty-limit.d.ts +2 -0
- package/lib/advisor/ruler/rules/series-qty-limit.js +37 -0
- package/lib/advisor/ruler/rules/x-axis-line-fading.d.ts +2 -0
- package/lib/advisor/ruler/rules/x-axis-line-fading.js +44 -0
- package/lib/advisor/ruler/types.d.ts +125 -0
- package/lib/advisor/ruler/types.js +2 -0
- package/lib/advisor/ruler/utils.d.ts +10 -0
- package/lib/advisor/ruler/utils.js +61 -0
- package/lib/advisor/types.d.ts +218 -0
- package/lib/advisor/types.js +4 -0
- package/lib/advisor/utils/clone.d.ts +2 -0
- package/lib/advisor/utils/clone.js +34 -0
- package/lib/advisor/utils/compare.d.ts +3 -0
- package/lib/advisor/utils/compare.js +17 -0
- package/lib/advisor/utils/computeScore.d.ts +7 -0
- package/lib/advisor/utils/computeScore.js +27 -0
- package/lib/advisor/utils/deep-mix.d.ts +2 -0
- package/lib/advisor/utils/deep-mix.js +78 -0
- package/lib/advisor/utils/hasSubset.d.ts +1 -0
- package/lib/advisor/utils/hasSubset.js +7 -0
- package/lib/advisor/utils/index.d.ts +5 -0
- package/lib/advisor/utils/index.js +19 -0
- package/lib/advisor/utils/inferDataType.d.ts +6 -0
- package/lib/advisor/utils/inferDataType.js +75 -0
- package/lib/advisor/utils/intersects.d.ts +1 -0
- package/lib/advisor/utils/intersects.js +7 -0
- package/lib/advisor/utils/isNil.d.ts +2 -0
- package/lib/advisor/utils/isNil.js +6 -0
- package/lib/ckb/base.d.ts +2 -0
- package/lib/ckb/base.js +1313 -0
- package/lib/ckb/ckb.d.ts +8 -0
- package/lib/ckb/ckb.js +59 -0
- package/lib/ckb/constants.d.ts +79 -0
- package/lib/ckb/constants.js +200 -0
- package/lib/ckb/i18n/index.d.ts +10 -0
- package/lib/ckb/i18n/index.js +27 -0
- package/lib/ckb/i18n/types.d.ts +52 -0
- package/lib/ckb/i18n/types.js +2 -0
- package/lib/ckb/i18n/zh-CN.d.ts +7 -0
- package/lib/ckb/i18n/zh-CN.js +528 -0
- package/lib/ckb/index.d.ts +4 -0
- package/lib/ckb/index.js +20 -0
- package/lib/ckb/types.d.ts +185 -0
- package/lib/ckb/types.js +2 -0
- package/lib/common/types.d.ts +14 -0
- package/lib/common/types.js +2 -0
- package/lib/data/analysis/field/index.d.ts +79 -0
- package/lib/data/analysis/field/index.js +355 -0
- package/lib/data/analysis/field/types.d.ts +99 -0
- package/lib/data/analysis/field/types.js +2 -0
- package/lib/data/analysis/graph/index.d.ts +28 -0
- package/lib/data/analysis/graph/index.js +178 -0
- package/lib/data/analysis/graph/types.d.ts +62 -0
- package/lib/data/analysis/graph/types.js +2 -0
- package/lib/data/analysis/index.d.ts +1 -0
- package/lib/data/analysis/index.js +5 -0
- package/lib/data/analysis/types.d.ts +1 -0
- package/lib/data/analysis/types.js +2 -0
- package/lib/data/dataset/field/baseFrame.d.ts +30 -0
- package/lib/data/dataset/field/baseFrame.js +78 -0
- package/lib/data/dataset/field/dataFrame.d.ts +35 -0
- package/lib/data/dataset/field/dataFrame.js +558 -0
- package/lib/data/dataset/field/index.d.ts +3 -0
- package/lib/data/dataset/field/index.js +8 -0
- package/lib/data/dataset/field/series.d.ts +18 -0
- package/lib/data/dataset/field/series.js +151 -0
- package/lib/data/dataset/field/types.d.ts +54 -0
- package/lib/data/dataset/field/types.js +2 -0
- package/lib/data/dataset/field/utils.d.ts +13 -0
- package/lib/data/dataset/field/utils.js +68 -0
- package/lib/data/dataset/graph/index.d.ts +18 -0
- package/lib/data/dataset/graph/index.js +188 -0
- package/lib/data/dataset/graph/types.d.ts +35 -0
- package/lib/data/dataset/graph/types.js +2 -0
- package/lib/data/dataset/graph/utils.d.ts +1 -0
- package/lib/data/dataset/graph/utils.js +19 -0
- package/lib/data/dataset/index.d.ts +1 -0
- package/lib/data/dataset/index.js +4 -0
- package/lib/data/dataset/types.d.ts +1 -0
- package/lib/data/dataset/types.js +4 -0
- package/lib/data/index.d.ts +5 -0
- package/lib/data/index.js +8 -0
- package/lib/data/statistics/IQR.d.ts +21 -0
- package/lib/data/statistics/IQR.js +53 -0
- package/lib/data/statistics/base.d.ts +106 -0
- package/lib/data/statistics/base.js +271 -0
- package/lib/data/statistics/bayesian.d.ts +5 -0
- package/lib/data/statistics/bayesian.js +30 -0
- package/lib/data/statistics/buishand-u.d.ts +7 -0
- package/lib/data/statistics/buishand-u.js +23 -0
- package/lib/data/statistics/caches.d.ts +13 -0
- package/lib/data/statistics/caches.js +33 -0
- package/lib/data/statistics/cdf.d.ts +7 -0
- package/lib/data/statistics/cdf.js +29 -0
- package/lib/data/statistics/constants.d.ts +5 -0
- package/lib/data/statistics/constants.js +15 -0
- package/lib/data/statistics/index.d.ts +7 -0
- package/lib/data/statistics/index.js +14 -0
- package/lib/data/statistics/lowess.d.ts +10 -0
- package/lib/data/statistics/lowess.js +87 -0
- package/lib/data/statistics/mannkendall-test.d.ts +15 -0
- package/lib/data/statistics/mannkendall-test.js +54 -0
- package/lib/data/statistics/maxabs.d.ts +5 -0
- package/lib/data/statistics/maxabs.js +13 -0
- package/lib/data/statistics/pcorrtest.d.ts +3 -0
- package/lib/data/statistics/pcorrtest.js +80 -0
- package/lib/data/statistics/pettitt-test.d.ts +9 -0
- package/lib/data/statistics/pettitt-test.js +38 -0
- package/lib/data/statistics/quantile.d.ts +16 -0
- package/lib/data/statistics/quantile.js +61 -0
- package/lib/data/statistics/types.d.ts +70 -0
- package/lib/data/statistics/types.js +2 -0
- package/lib/data/statistics/vector.d.ts +15 -0
- package/lib/data/statistics/vector.js +78 -0
- package/lib/data/statistics/window.d.ts +12 -0
- package/lib/data/statistics/window.js +60 -0
- package/lib/data/types.d.ts +2 -0
- package/lib/data/types.js +5 -0
- package/lib/data/utils/common.d.ts +26 -0
- package/lib/data/utils/common.js +67 -0
- package/lib/data/utils/index.d.ts +2 -0
- package/lib/data/utils/index.js +8 -0
- package/lib/data/utils/isType/constants.d.ts +15 -0
- package/lib/data/utils/isType/constants.js +27 -0
- package/lib/data/utils/isType/index.d.ts +2 -0
- package/lib/data/utils/isType/index.js +5 -0
- package/lib/data/utils/isType/isDateString.d.ts +18 -0
- package/lib/data/utils/isType/isDateString.js +111 -0
- package/lib/data/utils/isType/isType.d.ts +13 -0
- package/lib/data/utils/isType/isType.js +94 -0
- package/lib/index.d.ts +10 -0
- package/lib/index.js +75 -0
- package/lib/insight/algorithms/base/compare.d.ts +14 -0
- package/lib/insight/algorithms/base/compare.js +45 -0
- package/lib/insight/algorithms/categoryOutlier.d.ts +4 -0
- package/lib/insight/algorithms/categoryOutlier.js +7 -0
- package/lib/insight/algorithms/changePoint.d.ts +10 -0
- package/lib/insight/algorithms/changePoint.js +13 -0
- package/lib/insight/algorithms/index.d.ts +3 -0
- package/lib/insight/algorithms/index.js +6 -0
- package/lib/insight/algorithms/trendDirection.d.ts +4 -0
- package/lib/insight/algorithms/trendDirection.js +7 -0
- package/lib/insight/chart/constants.d.ts +13 -0
- package/lib/insight/chart/constants.js +28 -0
- package/lib/insight/chart/generator/homogeneous.d.ts +3 -0
- package/lib/insight/chart/generator/homogeneous.js +75 -0
- package/lib/insight/chart/generator/index.d.ts +2 -0
- package/lib/insight/chart/generator/index.js +5 -0
- package/lib/insight/chart/generator/insights.d.ts +3 -0
- package/lib/insight/chart/generator/insights.js +20 -0
- package/lib/insight/chart/index.d.ts +4 -0
- package/lib/insight/chart/index.js +7 -0
- package/lib/insight/chart/strategy/augmentedMarks/categoryOutlier.d.ts +5 -0
- package/lib/insight/chart/strategy/augmentedMarks/categoryOutlier.js +35 -0
- package/lib/insight/chart/strategy/augmentedMarks/changePoint.d.ts +5 -0
- package/lib/insight/chart/strategy/augmentedMarks/changePoint.js +47 -0
- package/lib/insight/chart/strategy/augmentedMarks/correlation.d.ts +3 -0
- package/lib/insight/chart/strategy/augmentedMarks/correlation.js +10 -0
- package/lib/insight/chart/strategy/augmentedMarks/homogeneous.d.ts +3 -0
- package/lib/insight/chart/strategy/augmentedMarks/homogeneous.js +9 -0
- package/lib/insight/chart/strategy/augmentedMarks/index.d.ts +8 -0
- package/lib/insight/chart/strategy/augmentedMarks/index.js +24 -0
- package/lib/insight/chart/strategy/augmentedMarks/lowVariance.d.ts +5 -0
- package/lib/insight/chart/strategy/augmentedMarks/lowVariance.js +28 -0
- package/lib/insight/chart/strategy/augmentedMarks/majority.d.ts +3 -0
- package/lib/insight/chart/strategy/augmentedMarks/majority.js +9 -0
- package/lib/insight/chart/strategy/augmentedMarks/timeSeriesOutlier.d.ts +5 -0
- package/lib/insight/chart/strategy/augmentedMarks/timeSeriesOutlier.js +87 -0
- package/lib/insight/chart/strategy/augmentedMarks/trend.d.ts +5 -0
- package/lib/insight/chart/strategy/augmentedMarks/trend.js +31 -0
- package/lib/insight/chart/strategy/chart.d.ts +7 -0
- package/lib/insight/chart/strategy/chart.js +49 -0
- package/lib/insight/chart/strategy/commonMarks/areaMark.d.ts +3 -0
- package/lib/insight/chart/strategy/commonMarks/areaMark.js +16 -0
- package/lib/insight/chart/strategy/commonMarks/index.d.ts +5 -0
- package/lib/insight/chart/strategy/commonMarks/index.js +13 -0
- package/lib/insight/chart/strategy/commonMarks/intervalMark.d.ts +5 -0
- package/lib/insight/chart/strategy/commonMarks/intervalMark.js +18 -0
- package/lib/insight/chart/strategy/commonMarks/lineMark.d.ts +3 -0
- package/lib/insight/chart/strategy/commonMarks/lineMark.js +38 -0
- package/lib/insight/chart/strategy/commonMarks/pointMark.d.ts +5 -0
- package/lib/insight/chart/strategy/commonMarks/pointMark.js +21 -0
- package/lib/insight/chart/strategy/commonMarks/textMark.d.ts +5 -0
- package/lib/insight/chart/strategy/commonMarks/textMark.js +32 -0
- package/lib/insight/chart/strategy/index.d.ts +4 -0
- package/lib/insight/chart/strategy/index.js +10 -0
- package/lib/insight/chart/strategy/viewSpec.d.ts +3 -0
- package/lib/insight/chart/strategy/viewSpec.js +20 -0
- package/lib/insight/chart/types.d.ts +60 -0
- package/lib/insight/chart/types.js +2 -0
- package/lib/insight/chart/utils.d.ts +3 -0
- package/lib/insight/chart/utils.js +8 -0
- package/lib/insight/constant.d.ts +12 -0
- package/lib/insight/constant.js +24 -0
- package/lib/insight/index.d.ts +6 -0
- package/lib/insight/index.js +13 -0
- package/lib/insight/insights/checkers.d.ts +16 -0
- package/lib/insight/insights/checkers.js +107 -0
- package/lib/insight/insights/extractors/categoryOutlier.d.ts +12 -0
- package/lib/insight/insights/extractors/categoryOutlier.js +95 -0
- package/lib/insight/insights/extractors/changePoint.d.ts +8 -0
- package/lib/insight/insights/extractors/changePoint.js +60 -0
- package/lib/insight/insights/extractors/correlation.d.ts +9 -0
- package/lib/insight/insights/extractors/correlation.js +43 -0
- package/lib/insight/insights/extractors/homogeneous.d.ts +4 -0
- package/lib/insight/insights/extractors/homogeneous.js +103 -0
- package/lib/insight/insights/extractors/lowVariance.d.ts +8 -0
- package/lib/insight/insights/extractors/lowVariance.js +54 -0
- package/lib/insight/insights/extractors/majority.d.ts +10 -0
- package/lib/insight/insights/extractors/majority.js +71 -0
- package/lib/insight/insights/extractors/timeSeriesOutlier.d.ts +2 -0
- package/lib/insight/insights/extractors/timeSeriesOutlier.js +65 -0
- package/lib/insight/insights/extractors/trend.d.ts +9 -0
- package/lib/insight/insights/extractors/trend.js +54 -0
- package/lib/insight/insights/index.d.ts +12 -0
- package/lib/insight/insights/index.js +32 -0
- package/lib/insight/insights/util.d.ts +13 -0
- package/lib/insight/insights/util.js +87 -0
- package/lib/insight/narrative/factory.d.ts +6 -0
- package/lib/insight/narrative/factory.js +25 -0
- package/lib/insight/narrative/index.d.ts +3 -0
- package/lib/insight/narrative/index.js +18 -0
- package/lib/insight/narrative/strategy/base.d.ts +9 -0
- package/lib/insight/narrative/strategy/base.js +9 -0
- package/lib/insight/narrative/strategy/categoryOutlier.d.ts +9 -0
- package/lib/insight/narrative/strategy/categoryOutlier.js +76 -0
- package/lib/insight/narrative/strategy/changePoint.d.ts +8 -0
- package/lib/insight/narrative/strategy/changePoint.js +54 -0
- package/lib/insight/narrative/strategy/commonness.d.ts +9 -0
- package/lib/insight/narrative/strategy/commonness.js +47 -0
- package/lib/insight/narrative/strategy/correlation.d.ts +8 -0
- package/lib/insight/narrative/strategy/correlation.js +53 -0
- package/lib/insight/narrative/strategy/exception.d.ts +10 -0
- package/lib/insight/narrative/strategy/exception.js +72 -0
- package/lib/insight/narrative/strategy/helpers.d.ts +5 -0
- package/lib/insight/narrative/strategy/helpers.js +31 -0
- package/lib/insight/narrative/strategy/index.d.ts +9 -0
- package/lib/insight/narrative/strategy/index.js +28 -0
- package/lib/insight/narrative/strategy/lowVariance.d.ts +8 -0
- package/lib/insight/narrative/strategy/lowVariance.js +50 -0
- package/lib/insight/narrative/strategy/majority.d.ts +8 -0
- package/lib/insight/narrative/strategy/majority.js +64 -0
- package/lib/insight/narrative/strategy/timeSeriesOutlier.d.ts +8 -0
- package/lib/insight/narrative/strategy/timeSeriesOutlier.js +94 -0
- package/lib/insight/narrative/strategy/trend.d.ts +8 -0
- package/lib/insight/narrative/strategy/trend.js +59 -0
- package/lib/insight/pipeline/extract.d.ts +13 -0
- package/lib/insight/pipeline/extract.js +243 -0
- package/lib/insight/pipeline/index.d.ts +2 -0
- package/lib/insight/pipeline/index.js +15 -0
- package/lib/insight/pipeline/insight.d.ts +10 -0
- package/lib/insight/pipeline/insight.js +86 -0
- package/lib/insight/pipeline/preprocess.d.ts +6 -0
- package/lib/insight/pipeline/preprocess.js +39 -0
- package/lib/insight/pipeline/specificInsight.d.ts +11 -0
- package/lib/insight/pipeline/specificInsight.js +79 -0
- package/lib/insight/pipeline/util.d.ts +5 -0
- package/lib/insight/pipeline/util.js +20 -0
- package/lib/insight/pipeline/visualize.d.ts +3 -0
- package/lib/insight/pipeline/visualize.js +46 -0
- package/lib/insight/types.d.ts +238 -0
- package/lib/insight/types.js +2 -0
- package/lib/insight/utils/aggregate.d.ts +7 -0
- package/lib/insight/utils/aggregate.js +93 -0
- package/lib/insight/utils/common.d.ts +3 -0
- package/lib/insight/utils/common.js +41 -0
- package/lib/ntv/generate/generateTextSpec.d.ts +9 -0
- package/lib/ntv/generate/generateTextSpec.js +160 -0
- package/lib/ntv/generate/index.d.ts +2 -0
- package/lib/ntv/generate/index.js +12 -0
- package/lib/ntv/generate/types.d.ts +58 -0
- package/lib/ntv/generate/types.js +2 -0
- package/lib/ntv/generate/utils.d.ts +29 -0
- package/lib/ntv/generate/utils.js +96 -0
- package/lib/ntv/index.d.ts +4 -0
- package/lib/ntv/index.js +10 -0
- package/lib/ntv/schema/common.d.ts +17 -0
- package/lib/ntv/schema/common.js +2 -0
- package/lib/ntv/schema/index.d.ts +4 -0
- package/lib/ntv/schema/index.js +7 -0
- package/lib/ntv/schema/paragraph.d.ts +34 -0
- package/lib/ntv/schema/paragraph.js +2 -0
- package/lib/ntv/schema/phrase.d.ts +70 -0
- package/lib/ntv/schema/phrase.js +55 -0
- package/lib/ntv/schema/structure.d.ts +18 -0
- package/lib/ntv/schema/structure.js +2 -0
- package/lib/ntv/types.d.ts +2 -0
- package/lib/ntv/types.js +2 -0
- package/lib/ntv/utils/index.d.ts +1 -0
- package/lib/ntv/utils/index.js +4 -0
- package/lib/ntv/utils/isSpecType.d.ts +17 -0
- package/lib/ntv/utils/isSpecType.js +76 -0
- package/lib/utils/arr2map.d.ts +1 -0
- package/lib/utils/arr2map.js +11 -0
- package/lib/utils/dataFormat.d.ts +11 -0
- package/lib/utils/dataFormat.js +35 -0
- package/lib/utils/index.d.ts +3 -0
- package/lib/utils/index.js +8 -0
- package/lib/utils/isType.d.ts +4 -0
- package/lib/utils/isType.js +21 -0
- package/package.json +88 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.lowess = exports.weightedLinearRegression = exports.bisquareWeightFunction = exports.tricubeWeightFunction = void 0;
|
|
4
|
+
var lodash_1 = require("lodash");
|
|
5
|
+
var utils_1 = require("../utils");
|
|
6
|
+
var base_1 = require("./base");
|
|
7
|
+
var constants_1 = require("./constants");
|
|
8
|
+
var vector_1 = require("./vector");
|
|
9
|
+
var tricubeWeightFunction = function (x) {
|
|
10
|
+
if (!(0, lodash_1.isNumber)(x) || Math.abs(x) >= 1)
|
|
11
|
+
return 0;
|
|
12
|
+
return Math.pow((1 - Math.pow(Math.abs(x), 3)), 3);
|
|
13
|
+
};
|
|
14
|
+
exports.tricubeWeightFunction = tricubeWeightFunction;
|
|
15
|
+
var bisquareWeightFunction = function (x) {
|
|
16
|
+
if (!(0, lodash_1.isNumber)(x) || Math.abs(x) >= 1)
|
|
17
|
+
return 0;
|
|
18
|
+
return Math.pow((1 - Math.pow(x, 2)), 2);
|
|
19
|
+
};
|
|
20
|
+
exports.bisquareWeightFunction = bisquareWeightFunction;
|
|
21
|
+
var weightedLinearRegression = function (x, y, w) {
|
|
22
|
+
/** dimension: 2*n */
|
|
23
|
+
var xt = [(0, utils_1.nOnes)(x.length), x];
|
|
24
|
+
/** dimension: n*2 */
|
|
25
|
+
var xMatrix = (0, vector_1.matrixTranspose)(xt);
|
|
26
|
+
/** dimension: n*1 */
|
|
27
|
+
var yMatrix = (0, vector_1.matrixTranspose)([y]);
|
|
28
|
+
/** diagonal matrix with w as the main diagonal */
|
|
29
|
+
var wMatrix = (0, vector_1.constructDiagonalMatrix)(w);
|
|
30
|
+
/**
|
|
31
|
+
* (X^(T)wX)^(-1)
|
|
32
|
+
* - 2*n, n*n, n*2 => 2*2
|
|
33
|
+
* */
|
|
34
|
+
var factor = (0, vector_1.inverseSecondOrderMatrix)((0, vector_1.multiMatrixMultiply)([xt, wMatrix, xMatrix]));
|
|
35
|
+
/**
|
|
36
|
+
* (X^(T)wX)^(-1) X^(T)wY
|
|
37
|
+
* - 2*2, 2*n, n*1 => 2*1
|
|
38
|
+
* */
|
|
39
|
+
return (0, vector_1.multiMatrixMultiply)([factor, xt, wMatrix, yMatrix]);
|
|
40
|
+
};
|
|
41
|
+
exports.weightedLinearRegression = weightedLinearRegression;
|
|
42
|
+
/**
|
|
43
|
+
* Locally weighted regression
|
|
44
|
+
* - General idea: perform weighted linear regression on localized subsets of the data point by point to calculate fitted value.
|
|
45
|
+
* - Reference: William S. Cleveland. Robust Locally Weighted Regression and Smoothing Scatterplots. Journal of the American Statistical Association. 1979. Vol. 74(368):829-836.
|
|
46
|
+
* */
|
|
47
|
+
var lowess = function (x, y, options) {
|
|
48
|
+
var xLength = x.length;
|
|
49
|
+
var mergeOptions = (0, lodash_1.mergeWith)(constants_1.DEFAULT_LOWESS_OPTIONS, options, function (defaultValue, inputValue) {
|
|
50
|
+
return inputValue !== null && inputValue !== void 0 ? inputValue : defaultValue;
|
|
51
|
+
});
|
|
52
|
+
// length of subset
|
|
53
|
+
var r = Math.ceil(xLength * mergeOptions.f);
|
|
54
|
+
// for each i, hi be the distance from xi to the rth nearest neighbor of xi
|
|
55
|
+
var h = x.map(function (xi) {
|
|
56
|
+
// rth smallest number among |xi - xj|, for j = 1, ..., n
|
|
57
|
+
return x.map(function (xj) { return Math.abs(xi - xj); }).sort(function (a, b) { return a - b; })[r];
|
|
58
|
+
});
|
|
59
|
+
// weight, n*n
|
|
60
|
+
var w = x.map(function (xi, i) {
|
|
61
|
+
// wk(xi) = weightFunc((xk - xi)/hi), for k = 1, ..., n
|
|
62
|
+
return x.map(function (xk) { return (0, exports.tricubeWeightFunction)((xk - xi) / h[i]); });
|
|
63
|
+
});
|
|
64
|
+
var robustCoefficient = (0, utils_1.nOnes)(xLength);
|
|
65
|
+
/** fitted values */
|
|
66
|
+
var yFit = (0, utils_1.nZeros)(xLength);
|
|
67
|
+
var _loop_1 = function (iter) {
|
|
68
|
+
for (var i = 0; i < xLength; i += 1) {
|
|
69
|
+
var robustWeight = w[i].map(function (wik, k) { return wik * robustCoefficient[k]; });
|
|
70
|
+
var beta = (0, exports.weightedLinearRegression)(x, y, robustWeight);
|
|
71
|
+
yFit[i] = beta[0][0] + beta[1][0] * x[i];
|
|
72
|
+
}
|
|
73
|
+
var residuals = (0, vector_1.vectorSubtract)(y, yFit);
|
|
74
|
+
/** median of |residuals| */
|
|
75
|
+
var s = (0, base_1.median)(residuals.map(function (res) { return Math.abs(res); }));
|
|
76
|
+
residuals.forEach(function (res, i) {
|
|
77
|
+
robustCoefficient[i] = (0, exports.bisquareWeightFunction)(res / (6 * s));
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
for (var iter = 0; iter < mergeOptions.nSteps; iter += 1) {
|
|
81
|
+
_loop_1(iter);
|
|
82
|
+
}
|
|
83
|
+
return {
|
|
84
|
+
y: yFit,
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
exports.lowess = lowess;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { TrendType } from '../../insight/types';
|
|
2
|
+
/**
|
|
3
|
+
* http://vsp.pnnl.gov/help/Vsample/Design_Trend_Mann_Kendall.htm
|
|
4
|
+
the Mann-Kendall (MK) test is to statistically assess if there
|
|
5
|
+
is a monotonic upward or downward trend of the variable of
|
|
6
|
+
interest over time.
|
|
7
|
+
使用 Mann-Kendall 单调趋势检验判断趋势是否有方向性(上升/下降)
|
|
8
|
+
* @param data
|
|
9
|
+
* @param alpha
|
|
10
|
+
*/
|
|
11
|
+
export declare function mkTest(data: number[], alpha?: number): {
|
|
12
|
+
trend: TrendType;
|
|
13
|
+
pValue: number;
|
|
14
|
+
zScore: number;
|
|
15
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mkTest = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var lodash_1 = require("lodash");
|
|
6
|
+
var common_1 = require("../../insight/utils/common");
|
|
7
|
+
var __1 = require("..");
|
|
8
|
+
/**
|
|
9
|
+
* http://vsp.pnnl.gov/help/Vsample/Design_Trend_Mann_Kendall.htm
|
|
10
|
+
the Mann-Kendall (MK) test is to statistically assess if there
|
|
11
|
+
is a monotonic upward or downward trend of the variable of
|
|
12
|
+
interest over time.
|
|
13
|
+
使用 Mann-Kendall 单调趋势检验判断趋势是否有方向性(上升/下降)
|
|
14
|
+
* @param data
|
|
15
|
+
* @param alpha
|
|
16
|
+
*/
|
|
17
|
+
function mkTest(data, alpha) {
|
|
18
|
+
if (alpha === void 0) { alpha = 0.05; }
|
|
19
|
+
var length = data === null || data === void 0 ? void 0 : data.length;
|
|
20
|
+
var S = 0;
|
|
21
|
+
for (var k = 0; k < length - 1; k += 1) {
|
|
22
|
+
for (var j = k + 1; j < length; j += 1) {
|
|
23
|
+
S += (0, common_1.sign)(data[j] - data[k]);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
var _a = tslib_1.__read((0, common_1.unique)(data), 2), uniqArr = _a[0], uniqCount = _a[1];
|
|
27
|
+
var uniqLength = uniqArr.length;
|
|
28
|
+
var varS = (length * (length - 1) * (2 * length + 5) -
|
|
29
|
+
(uniqLength === length ? 0 : (0, lodash_1.sumBy)(uniqCount, function (c) { return c * (c - 1) * (2 * c + 5); }))) /
|
|
30
|
+
18;
|
|
31
|
+
var zScore = 0;
|
|
32
|
+
if (S > 0) {
|
|
33
|
+
zScore = (S - 1) / Math.sqrt(varS);
|
|
34
|
+
}
|
|
35
|
+
else if (S < 0) {
|
|
36
|
+
zScore = (S + 1) / Math.sqrt(varS);
|
|
37
|
+
}
|
|
38
|
+
// calculate the p_value
|
|
39
|
+
var pValue = 2 * (1 - (0, __1.cdf)(Math.abs(zScore), 0, 1));
|
|
40
|
+
var h = Math.abs(zScore) > (0, __1.normalDistributionQuantile)(1 - alpha / 2, 0, 1);
|
|
41
|
+
var trend = 'no trend';
|
|
42
|
+
if (zScore < 0 && h) {
|
|
43
|
+
trend = 'decreasing';
|
|
44
|
+
}
|
|
45
|
+
else if (zScore > 0 && h) {
|
|
46
|
+
trend = 'increasing';
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
trend: trend,
|
|
50
|
+
pValue: pValue,
|
|
51
|
+
zScore: zScore,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
exports.mkTest = mkTest;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.maxabs = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
/**
|
|
6
|
+
* Returns the maximum absolute value of array
|
|
7
|
+
* @param x input array
|
|
8
|
+
* */
|
|
9
|
+
var maxabs = function (x) {
|
|
10
|
+
var absoluteX = x.map(function (value) { return Math.abs(value); });
|
|
11
|
+
return Math.max.apply(Math, tslib_1.__spreadArray([], tslib_1.__read(absoluteX), false));
|
|
12
|
+
};
|
|
13
|
+
exports.maxabs = maxabs;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pcorrtest = void 0;
|
|
4
|
+
var lodash_1 = require("lodash");
|
|
5
|
+
var base_1 = require("./base");
|
|
6
|
+
var constants_1 = require("./constants");
|
|
7
|
+
var quantile_1 = require("./quantile");
|
|
8
|
+
/** Perform a Pearson product-moment correlation test between paired samples */
|
|
9
|
+
var pcorrtest = function (x, y, options) {
|
|
10
|
+
if (x.length !== y.length) {
|
|
11
|
+
// eslint-disable-next-line no-console
|
|
12
|
+
console.error('invalid arguments: First and second arguments must be arrays having the same length');
|
|
13
|
+
return {
|
|
14
|
+
pcorr: null,
|
|
15
|
+
rejected: false,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
var _a = (0, lodash_1.mergeWith)(constants_1.DEFAULT_PCORRTEST_OPTIONS, options, function (defaultValue, inputValue) {
|
|
19
|
+
return inputValue !== null && inputValue !== void 0 ? inputValue : defaultValue;
|
|
20
|
+
}), alpha = _a.alpha, alternative = _a.alternative, rho = _a.rho;
|
|
21
|
+
/** pearson correlation coefficient */
|
|
22
|
+
var pcorr = (0, base_1.pearson)(x, y);
|
|
23
|
+
/** statistic to be tested */
|
|
24
|
+
var statistic;
|
|
25
|
+
var threshold;
|
|
26
|
+
/** whether to reject null hypothesis */
|
|
27
|
+
var rejected = false;
|
|
28
|
+
if (rho !== 0) {
|
|
29
|
+
/**
|
|
30
|
+
* - if rho is provided, it needs to be corrected by Fisher's z transform so that it satisfies the normal distribution
|
|
31
|
+
* - https://en.wikipedia.org/wiki/Fisher_transformation
|
|
32
|
+
* */
|
|
33
|
+
var z = 0.5 * Math.log((1 + pcorr) / (1 - pcorr));
|
|
34
|
+
/** mean of z */
|
|
35
|
+
var meanZ = 0.5 * Math.log((1 + rho) / (1 - rho));
|
|
36
|
+
/** standard error of z */
|
|
37
|
+
var sigmaZ = 1 / Math.sqrt(x.length - 3);
|
|
38
|
+
statistic = (z - meanZ) / sigmaZ;
|
|
39
|
+
if (alternative === 'greater') {
|
|
40
|
+
threshold = (0, quantile_1.normalDistributionQuantile)(1 - alpha);
|
|
41
|
+
if (statistic >= threshold)
|
|
42
|
+
rejected = true;
|
|
43
|
+
}
|
|
44
|
+
else if (alternative === 'less') {
|
|
45
|
+
threshold = (0, quantile_1.normalDistributionQuantile)(alpha);
|
|
46
|
+
if (statistic <= threshold)
|
|
47
|
+
rejected = true;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
threshold = (0, quantile_1.normalDistributionQuantile)(1 - alpha / 2);
|
|
51
|
+
if (Math.abs(statistic) >= threshold)
|
|
52
|
+
rejected = true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
// obey the t distribution under the null hypothesis, t~t(n-2)
|
|
57
|
+
var degree = x.length - 2;
|
|
58
|
+
statistic = (pcorr * Math.sqrt(degree)) / Math.sqrt(1 - Math.pow(pcorr, 2));
|
|
59
|
+
if (alternative === 'greater') {
|
|
60
|
+
threshold = (0, quantile_1.tDistributionQuantile)(1 - alpha, degree);
|
|
61
|
+
if (statistic >= threshold)
|
|
62
|
+
rejected = true;
|
|
63
|
+
}
|
|
64
|
+
else if (alternative === 'less') {
|
|
65
|
+
threshold = (0, quantile_1.tDistributionQuantile)(alpha, degree);
|
|
66
|
+
if (statistic <= threshold)
|
|
67
|
+
rejected = true;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
threshold = (0, quantile_1.tDistributionQuantile)(1 - alpha / 2, degree);
|
|
71
|
+
if (Math.abs(statistic) >= threshold)
|
|
72
|
+
rejected = true;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return {
|
|
76
|
+
rejected: rejected,
|
|
77
|
+
pcorr: pcorr,
|
|
78
|
+
};
|
|
79
|
+
};
|
|
80
|
+
exports.pcorrtest = pcorrtest;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ChangePointItem } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Pettitt's (1979) method is a rank-based nonparametric test for abrupt changes in a time series.
|
|
4
|
+
* */
|
|
5
|
+
export declare function pettittTest(data: number[]): ChangePointItem;
|
|
6
|
+
/**
|
|
7
|
+
* p-value calc in Pettitt
|
|
8
|
+
*/
|
|
9
|
+
export declare function calcPValue(data: number[], index: number): number;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calcPValue = exports.pettittTest = void 0;
|
|
4
|
+
var lodash_1 = require("lodash");
|
|
5
|
+
var common_1 = require("../../insight/utils/common");
|
|
6
|
+
/**
|
|
7
|
+
* Pettitt's (1979) method is a rank-based nonparametric test for abrupt changes in a time series.
|
|
8
|
+
* */
|
|
9
|
+
function pettittTest(data) {
|
|
10
|
+
var n = data === null || data === void 0 ? void 0 : data.length;
|
|
11
|
+
var rankArr = (0, common_1.rank)(data);
|
|
12
|
+
var Umax = 0;
|
|
13
|
+
var UmaxIndex = -1;
|
|
14
|
+
for (var k = 0; k < n; k += 1) {
|
|
15
|
+
var U = Math.abs(2 * (0, lodash_1.sumBy)(rankArr.slice(0, k)) - k * (n + 1));
|
|
16
|
+
if (U > Umax) {
|
|
17
|
+
Umax = U;
|
|
18
|
+
UmaxIndex = k;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
var pvalue = 2 * Math.exp((-6 * Math.pow(Umax, 2)) / (Math.pow(n, 2) + Math.pow(n, 3)));
|
|
22
|
+
return {
|
|
23
|
+
index: UmaxIndex,
|
|
24
|
+
significance: 1 - pvalue,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
exports.pettittTest = pettittTest;
|
|
28
|
+
/**
|
|
29
|
+
* p-value calc in Pettitt
|
|
30
|
+
*/
|
|
31
|
+
function calcPValue(data, index) {
|
|
32
|
+
var n = data === null || data === void 0 ? void 0 : data.length;
|
|
33
|
+
var rankArr = (0, common_1.rank)(data);
|
|
34
|
+
var U = Math.abs(2 * (0, lodash_1.sumBy)(rankArr.slice(0, index)) - index * (n + 1));
|
|
35
|
+
var pvalue = 2 * Math.exp((-6 * Math.pow(U, 2)) / (Math.pow(n, 2) + Math.pow(n, 3)));
|
|
36
|
+
return pvalue;
|
|
37
|
+
}
|
|
38
|
+
exports.calcPValue = calcPValue;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normal distribution quantile function
|
|
3
|
+
* - Reference to equation 26.2.23 in https://personal.math.ubc.ca/~cbm/aands/abramowitz_and_stegun.pdf
|
|
4
|
+
* - If F(x) is the cumulative distribution function of a normal distribution N(mu, sigma), F(x) = p, quantile(p, mu, sigma) = x.
|
|
5
|
+
* - The value range of p is [0, 1]. If p > 1 or p < 0, return NaN.
|
|
6
|
+
* @param p input value
|
|
7
|
+
* @param mu mean
|
|
8
|
+
* @param sigma standard deviation
|
|
9
|
+
* */
|
|
10
|
+
export declare const normalDistributionQuantile: (p: number, mu?: number, sigma?: number) => number;
|
|
11
|
+
/**
|
|
12
|
+
* student's t distribution quantile function
|
|
13
|
+
* @param p probability
|
|
14
|
+
* @param v degree of freedom
|
|
15
|
+
*/
|
|
16
|
+
export declare const tDistributionQuantile: (p: number, d?: number) => number;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.tDistributionQuantile = exports.normalDistributionQuantile = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Normal distribution quantile function
|
|
6
|
+
* - Reference to equation 26.2.23 in https://personal.math.ubc.ca/~cbm/aands/abramowitz_and_stegun.pdf
|
|
7
|
+
* - If F(x) is the cumulative distribution function of a normal distribution N(mu, sigma), F(x) = p, quantile(p, mu, sigma) = x.
|
|
8
|
+
* - The value range of p is [0, 1]. If p > 1 or p < 0, return NaN.
|
|
9
|
+
* @param p input value
|
|
10
|
+
* @param mu mean
|
|
11
|
+
* @param sigma standard deviation
|
|
12
|
+
* */
|
|
13
|
+
var normalDistributionQuantile = function (p, mu, sigma) {
|
|
14
|
+
if (mu === void 0) { mu = 0; }
|
|
15
|
+
if (sigma === void 0) { sigma = 1; }
|
|
16
|
+
if (p > 1 || p < 0 || sigma < 0)
|
|
17
|
+
return NaN;
|
|
18
|
+
// formula requires that p is no more than 0.5
|
|
19
|
+
var adjustedP = p <= 0.5 ? p : 1 - p;
|
|
20
|
+
var t = Math.sqrt(-2 * Math.log(adjustedP));
|
|
21
|
+
/**
|
|
22
|
+
* Q(qXp) + F(qXp) = 1
|
|
23
|
+
* - use approximate elementary functional algorithm, error less than 4.5e-4
|
|
24
|
+
* @todo add document explaining the derivation process
|
|
25
|
+
* */
|
|
26
|
+
var qXp = t - (2.515517 + 0.802853 * t + 0.010328 * Math.pow(t, 2)) / (1 + 1.432788 * t + 0.189269 * Math.pow(t, 2) + 0.001308 * Math.pow(t, 3));
|
|
27
|
+
// quantile of standard normal distribution
|
|
28
|
+
var normalXp = p <= 0.5 ? -1 * qXp : qXp;
|
|
29
|
+
// transfer to quantile of normal distribution N(mu, sigma)
|
|
30
|
+
var Xp = sigma * normalXp + mu;
|
|
31
|
+
return Xp;
|
|
32
|
+
};
|
|
33
|
+
exports.normalDistributionQuantile = normalDistributionQuantile;
|
|
34
|
+
/**
|
|
35
|
+
* student's t distribution quantile function
|
|
36
|
+
* @param p probability
|
|
37
|
+
* @param v degree of freedom
|
|
38
|
+
*/
|
|
39
|
+
var tDistributionQuantile = function (p, d) {
|
|
40
|
+
if (d === void 0) { d = 1; }
|
|
41
|
+
if (p > 1 || p < 0 || d <= 0)
|
|
42
|
+
return NaN;
|
|
43
|
+
// when the degree of freedom is 1, the t distribution is the same as a standard Cauchy distribution
|
|
44
|
+
// reference to equation 35 in http://www.homepages.ucl.ac.uk/~ucahwts/lgsnotes/JCF_Student.pdf
|
|
45
|
+
if (d === 1)
|
|
46
|
+
return -Math.cos(Math.PI * p) / Math.sin(Math.PI * p);
|
|
47
|
+
// reference to equation 36 in http://www.homepages.ucl.ac.uk/~ucahwts/lgsnotes/JCF_Student.pdf
|
|
48
|
+
if (d === 2)
|
|
49
|
+
return (2 * p - 1) / Math.sqrt(2 * p * (1 - p));
|
|
50
|
+
// Q(x) = p, Q(x) + F(x) = 1, F(x) is standard normal distribution CDF
|
|
51
|
+
var prop = p > 0.5 ? p : 1 - p;
|
|
52
|
+
var x = (0, exports.normalDistributionQuantile)(prop);
|
|
53
|
+
var g1 = (Math.pow(x, 3) + x) / 4;
|
|
54
|
+
var g2 = (5 * Math.pow(x, 5) + 16 * Math.pow(x, 3) + 3 * x) / 96;
|
|
55
|
+
var g3 = (3 * Math.pow(x, 7) + 19 * Math.pow(x, 5) + 17 * Math.pow(x, 3) - 15 * x) / 384;
|
|
56
|
+
var g4 = (79 * Math.pow(x, 9) + 776 * Math.pow(x, 7) + 1482 * Math.pow(x, 5) - 1920 * Math.pow(x, 3) - 945 * x) / 92160;
|
|
57
|
+
// Cornish–Fisher expansions
|
|
58
|
+
// reference to equation 26.7.5 in https://personal.math.ubc.ca/~cbm/aands/abramowitz_and_stegun.pdf
|
|
59
|
+
return (p > 0.5 ? 1 : -1) * (x + g1 / d + g2 / Math.pow(d, 2) + g3 / Math.pow(d, 3) + g4 / Math.pow(d, 4));
|
|
60
|
+
};
|
|
61
|
+
exports.tDistributionQuantile = tDistributionQuantile;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* function options of LOWESS method
|
|
3
|
+
*/
|
|
4
|
+
export type LowessOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* Proportion of points for local regression which influence smoothing at each value; default: 2/3
|
|
7
|
+
* */
|
|
8
|
+
f?: number;
|
|
9
|
+
/**
|
|
10
|
+
* Number of iterations for local regression (fewer iterations translates to faster function execution; default: 3)
|
|
11
|
+
* */
|
|
12
|
+
nSteps?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Nonnegative parameter which may be used to reduce the number of computations.
|
|
15
|
+
* Perform a local regression at intervals of delta data points.
|
|
16
|
+
* */
|
|
17
|
+
delta?: number;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* LOWESS output
|
|
21
|
+
*/
|
|
22
|
+
export type LowessOutput = {
|
|
23
|
+
/** Fitted values */
|
|
24
|
+
y: number[];
|
|
25
|
+
};
|
|
26
|
+
export type PCorrTestParameter = {
|
|
27
|
+
/**
|
|
28
|
+
* Significance level (default: 0.05).
|
|
29
|
+
*/
|
|
30
|
+
alpha?: number;
|
|
31
|
+
/**
|
|
32
|
+
* Alternative hypothesis (`two-sided`, `less`, or `greater`; default: 'two-sided').
|
|
33
|
+
*/
|
|
34
|
+
alternative?: 'two-sided' | 'less' | 'greater';
|
|
35
|
+
/**
|
|
36
|
+
* Correlation under H0 (default: 0.0).
|
|
37
|
+
* To test whether the correlation coefficient is equal to some other value than 0.
|
|
38
|
+
*/
|
|
39
|
+
rho?: number;
|
|
40
|
+
};
|
|
41
|
+
export type PCorrTestOutput = {
|
|
42
|
+
/**
|
|
43
|
+
* whether to reject null hypothesis
|
|
44
|
+
* */
|
|
45
|
+
rejected: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* pearson correlation coefficient
|
|
48
|
+
* */
|
|
49
|
+
pcorr: number;
|
|
50
|
+
/**
|
|
51
|
+
* used significance level
|
|
52
|
+
* */
|
|
53
|
+
alpha?: number;
|
|
54
|
+
/**
|
|
55
|
+
* statistic to be tested
|
|
56
|
+
* */
|
|
57
|
+
statistic?: number;
|
|
58
|
+
/**
|
|
59
|
+
* used alternative hypothesis (`two-sided`, `less` or `greater`).
|
|
60
|
+
* */
|
|
61
|
+
alternative?: string;
|
|
62
|
+
/**
|
|
63
|
+
* assumed correlation under H0 (equal to the supplied `rho` option).
|
|
64
|
+
* */
|
|
65
|
+
nullValue?: number;
|
|
66
|
+
};
|
|
67
|
+
export type ChangePointItem = {
|
|
68
|
+
index: number;
|
|
69
|
+
significance: number;
|
|
70
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/** operation of vector or matrix */
|
|
2
|
+
export declare const vectorAdd: (x: number[], y: number[]) => number[];
|
|
3
|
+
export declare const vectorSubtract: (x: number[], y: number[]) => number[];
|
|
4
|
+
export declare const vectorInnerProduct: (x: number[], y: number[]) => number;
|
|
5
|
+
export declare const matrixTranspose: (x: number[][]) => any[];
|
|
6
|
+
export declare const matrixMultiply: (x: number[][], y: number[][]) => number[][];
|
|
7
|
+
export declare const multiMatrixMultiply: (matrixSet: number[][][]) => number[][];
|
|
8
|
+
/**
|
|
9
|
+
* Constructs a diagonal matrix where the values of the main diagonal are the values of the given vector
|
|
10
|
+
*/
|
|
11
|
+
export declare const constructDiagonalMatrix: (diagonalVector: number[]) => any[][];
|
|
12
|
+
/**
|
|
13
|
+
* Calculate the inverse matrix for second order matrix
|
|
14
|
+
* */
|
|
15
|
+
export declare const inverseSecondOrderMatrix: (matrix: number[][]) => number[][];
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.inverseSecondOrderMatrix = exports.constructDiagonalMatrix = exports.multiMatrixMultiply = exports.matrixMultiply = exports.matrixTranspose = exports.vectorInnerProduct = exports.vectorSubtract = exports.vectorAdd = void 0;
|
|
4
|
+
/** operation of vector or matrix */
|
|
5
|
+
var vectorAdd = function (x, y) {
|
|
6
|
+
if (x.length !== y.length)
|
|
7
|
+
return null;
|
|
8
|
+
return x.map(function (xi, i) { return xi + y[i]; });
|
|
9
|
+
};
|
|
10
|
+
exports.vectorAdd = vectorAdd;
|
|
11
|
+
var vectorSubtract = function (x, y) {
|
|
12
|
+
if (x.length !== y.length)
|
|
13
|
+
return null;
|
|
14
|
+
return x.map(function (xi, i) { return xi - y[i]; });
|
|
15
|
+
};
|
|
16
|
+
exports.vectorSubtract = vectorSubtract;
|
|
17
|
+
var vectorInnerProduct = function (x, y) {
|
|
18
|
+
if (x.length !== y.length)
|
|
19
|
+
return null;
|
|
20
|
+
var result = 0;
|
|
21
|
+
x.forEach(function (xi, i) {
|
|
22
|
+
result += xi * y[i];
|
|
23
|
+
});
|
|
24
|
+
return result;
|
|
25
|
+
};
|
|
26
|
+
exports.vectorInnerProduct = vectorInnerProduct;
|
|
27
|
+
var matrixTranspose = function (x) {
|
|
28
|
+
var result = [];
|
|
29
|
+
var _loop_1 = function (j) {
|
|
30
|
+
result.push(x.map(function (xi) { return xi[j]; }));
|
|
31
|
+
};
|
|
32
|
+
for (var j = 0; j < x[0].length; j += 1) {
|
|
33
|
+
_loop_1(j);
|
|
34
|
+
}
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
exports.matrixTranspose = matrixTranspose;
|
|
38
|
+
var matrixMultiply = function (x, y) {
|
|
39
|
+
var _a;
|
|
40
|
+
if (((_a = x[0]) === null || _a === void 0 ? void 0 : _a.length) !== y.length)
|
|
41
|
+
return null;
|
|
42
|
+
var result = [];
|
|
43
|
+
var yT = (0, exports.matrixTranspose)(y);
|
|
44
|
+
x.forEach(function (xi) { return result.push(yT.map(function (yj) { return (0, exports.vectorInnerProduct)(xi, yj); })); });
|
|
45
|
+
return result;
|
|
46
|
+
};
|
|
47
|
+
exports.matrixMultiply = matrixMultiply;
|
|
48
|
+
var multiMatrixMultiply = function (matrixSet) {
|
|
49
|
+
var result = matrixSet[0];
|
|
50
|
+
for (var i = 1; i < matrixSet.length; i += 1) {
|
|
51
|
+
result = (0, exports.matrixMultiply)(result, matrixSet[i]);
|
|
52
|
+
}
|
|
53
|
+
return result;
|
|
54
|
+
};
|
|
55
|
+
exports.multiMatrixMultiply = multiMatrixMultiply;
|
|
56
|
+
/**
|
|
57
|
+
* Constructs a diagonal matrix where the values of the main diagonal are the values of the given vector
|
|
58
|
+
*/
|
|
59
|
+
var constructDiagonalMatrix = function (diagonalVector) {
|
|
60
|
+
return diagonalVector.map(function (diagonalValue, i) {
|
|
61
|
+
// ith row
|
|
62
|
+
var row = Array(diagonalVector.length).fill(0);
|
|
63
|
+
row[i] = diagonalValue;
|
|
64
|
+
return row;
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
exports.constructDiagonalMatrix = constructDiagonalMatrix;
|
|
68
|
+
/**
|
|
69
|
+
* Calculate the inverse matrix for second order matrix
|
|
70
|
+
* */
|
|
71
|
+
var inverseSecondOrderMatrix = function (matrix) {
|
|
72
|
+
var determinant = matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0];
|
|
73
|
+
return [
|
|
74
|
+
[matrix[1][1] / determinant, -matrix[0][1] / determinant],
|
|
75
|
+
[-matrix[1][0] / determinant, matrix[0][0] / determinant],
|
|
76
|
+
];
|
|
77
|
+
};
|
|
78
|
+
exports.inverseSecondOrderMatrix = inverseSecondOrderMatrix;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ChangePointItem } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Window-based change point detection
|
|
4
|
+
*/
|
|
5
|
+
export declare function windowBasedMean(data: number[], params?: {
|
|
6
|
+
windowSize?: number;
|
|
7
|
+
significanceLimit?: number;
|
|
8
|
+
}): ChangePointItem[];
|
|
9
|
+
/**
|
|
10
|
+
* Window-based change point test
|
|
11
|
+
*/
|
|
12
|
+
export declare function calcPValue(data: number[], index: number, window?: number): number;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calcPValue = exports.windowBasedMean = void 0;
|
|
4
|
+
var lodash_1 = require("lodash");
|
|
5
|
+
var constant_1 = require("../../insight/constant");
|
|
6
|
+
var util_1 = require("../../insight/insights/util");
|
|
7
|
+
var DEFAULT_WINDOW_SIZE = 4;
|
|
8
|
+
/**
|
|
9
|
+
* Window-based change point detection
|
|
10
|
+
*/
|
|
11
|
+
function windowBasedMean(data, params) {
|
|
12
|
+
var len = data === null || data === void 0 ? void 0 : data.length;
|
|
13
|
+
var K = (params === null || params === void 0 ? void 0 : params.windowSize) || DEFAULT_WINDOW_SIZE;
|
|
14
|
+
if (len <= 2 * K + 3)
|
|
15
|
+
return [];
|
|
16
|
+
var significanceLimit = (params === null || params === void 0 ? void 0 : params.significanceLimit) || constant_1.SIGNIFICANCE_BENCHMARK;
|
|
17
|
+
var diff = Array(len).fill(0);
|
|
18
|
+
for (var i = K; i <= len - K; i += 1) {
|
|
19
|
+
var meanLeft = (0, lodash_1.mean)(data.slice(i - K, i));
|
|
20
|
+
var meanRight = (0, lodash_1.mean)(data.slice(i, i + K));
|
|
21
|
+
diff[i] = Math.abs(meanLeft - meanRight);
|
|
22
|
+
}
|
|
23
|
+
var differences = diff.slice(K, len - K + 1);
|
|
24
|
+
var sorted = differences.sort(function (a, b) { return b - a; });
|
|
25
|
+
var result = [];
|
|
26
|
+
var _loop_1 = function (i) {
|
|
27
|
+
var difference = sorted[i];
|
|
28
|
+
var index = diff.findIndex(function (item) { return item === difference; });
|
|
29
|
+
var significance = 1 - (0, util_1.calculatePValue)(differences, difference);
|
|
30
|
+
if (significance >= significanceLimit) {
|
|
31
|
+
result.push({
|
|
32
|
+
index: index,
|
|
33
|
+
significance: significance,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
for (var i = 0; i < sorted.length; i += 1) {
|
|
38
|
+
_loop_1(i);
|
|
39
|
+
}
|
|
40
|
+
return result;
|
|
41
|
+
}
|
|
42
|
+
exports.windowBasedMean = windowBasedMean;
|
|
43
|
+
/**
|
|
44
|
+
* Window-based change point test
|
|
45
|
+
*/
|
|
46
|
+
function calcPValue(data, index, window) {
|
|
47
|
+
var len = data === null || data === void 0 ? void 0 : data.length;
|
|
48
|
+
var K = window || DEFAULT_WINDOW_SIZE;
|
|
49
|
+
if (len <= 2 * K + 3)
|
|
50
|
+
return 0;
|
|
51
|
+
var diff = Array(len).fill(0);
|
|
52
|
+
for (var i = K; i <= len - K; i += 1) {
|
|
53
|
+
var meanLeft = (0, lodash_1.mean)(data.slice(i - K, i));
|
|
54
|
+
var meanRight = (0, lodash_1.mean)(data.slice(i, i + K));
|
|
55
|
+
diff[i] = Math.abs(meanLeft - meanRight);
|
|
56
|
+
}
|
|
57
|
+
var p = (0, util_1.calculatePValue)(diff.slice(K, len - K + 1), diff[index]);
|
|
58
|
+
return p;
|
|
59
|
+
}
|
|
60
|
+
exports.calcPValue = calcPValue;
|