@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,248 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Statistical methods used internally by ava.
|
|
3
|
+
*/
|
|
4
|
+
import { __read, __spreadArray } from "tslib";
|
|
5
|
+
import { assert } from '../utils';
|
|
6
|
+
import * as cache from './caches';
|
|
7
|
+
/**
|
|
8
|
+
* Get the minimum of the array.
|
|
9
|
+
* @param value - The array to process
|
|
10
|
+
*/
|
|
11
|
+
export function min(value) {
|
|
12
|
+
var cachedValue = cache.get(value, 'min');
|
|
13
|
+
if (cachedValue !== undefined)
|
|
14
|
+
return cachedValue;
|
|
15
|
+
return cache.set(value, 'min', Math.min.apply(Math, __spreadArray([], __read(value), false)));
|
|
16
|
+
}
|
|
17
|
+
function getMinIndex(value) {
|
|
18
|
+
var min = value[0];
|
|
19
|
+
var idx = 0;
|
|
20
|
+
for (var i = 0; i < value.length; i += 1) {
|
|
21
|
+
if (value[i] < min) {
|
|
22
|
+
idx = i;
|
|
23
|
+
min = value[i];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return idx;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Get the minimum index of the array.
|
|
30
|
+
* @param value - The array to process
|
|
31
|
+
*/
|
|
32
|
+
export function minIndex(value) {
|
|
33
|
+
var cachedValue = cache.get(value, 'minIndex');
|
|
34
|
+
if (cachedValue !== undefined)
|
|
35
|
+
return cachedValue;
|
|
36
|
+
return cache.set(value, 'minIndex', getMinIndex(value));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Get the maximum of the array.
|
|
40
|
+
* @param value - The array to process
|
|
41
|
+
*/
|
|
42
|
+
export function max(value) {
|
|
43
|
+
var cachedValue = cache.get(value, 'max');
|
|
44
|
+
if (cachedValue !== undefined)
|
|
45
|
+
return cachedValue;
|
|
46
|
+
return cache.set(value, 'max', Math.max.apply(Math, __spreadArray([], __read(value), false)));
|
|
47
|
+
}
|
|
48
|
+
function getMaxIndex(value) {
|
|
49
|
+
var max = value[0];
|
|
50
|
+
var idx = 0;
|
|
51
|
+
for (var i = 0; i < value.length; i += 1) {
|
|
52
|
+
if (value[i] > max) {
|
|
53
|
+
idx = i;
|
|
54
|
+
max = value[i];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return idx;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get the maximum index of the array.
|
|
61
|
+
* @param value - The array to process
|
|
62
|
+
*/
|
|
63
|
+
export function maxIndex(value) {
|
|
64
|
+
var cachedValue = cache.get(value, 'maxIndex');
|
|
65
|
+
if (cachedValue !== undefined)
|
|
66
|
+
return cachedValue;
|
|
67
|
+
return cache.set(value, 'maxIndex', getMaxIndex(value));
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Calculate the sum of the array.
|
|
71
|
+
* @param value - The array to process
|
|
72
|
+
*/
|
|
73
|
+
export function sum(value) {
|
|
74
|
+
var cachedValue = cache.get(value, 'sum');
|
|
75
|
+
if (cachedValue !== undefined)
|
|
76
|
+
return cachedValue;
|
|
77
|
+
return cache.set(value, 'sum', value.reduce(function (prev, current) { return current + prev; }, 0));
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Calculate the mean of the array.
|
|
81
|
+
* @param value - The array to process
|
|
82
|
+
|
|
83
|
+
*/
|
|
84
|
+
export function mean(value) {
|
|
85
|
+
return sum(value) / value.length;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Calculate the geometricMean of the array.
|
|
89
|
+
* @param value - The array to process
|
|
90
|
+
*/
|
|
91
|
+
export function geometricMean(value) {
|
|
92
|
+
assert(value.some(function (item) { return item > 0; }), 'Each item in value must greater than 0.');
|
|
93
|
+
var cachedValue = cache.get(value, 'geometricMean');
|
|
94
|
+
if (cachedValue !== undefined)
|
|
95
|
+
return cachedValue;
|
|
96
|
+
return cache.set(value, 'geometricMean', Math.pow(value.reduce(function (prev, curr) { return prev * curr; }, 1), (1 / value.length)));
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Calculate the harmonic mean of the array.
|
|
100
|
+
* @param value - The array to process
|
|
101
|
+
*/
|
|
102
|
+
export function harmonicMean(value) {
|
|
103
|
+
var base = Math.pow(2, 16);
|
|
104
|
+
var cachedValue = cache.get(value, 'harmonicMean');
|
|
105
|
+
if (cachedValue !== undefined)
|
|
106
|
+
return cachedValue;
|
|
107
|
+
return cache.set(value, 'harmonicMean', (base * value.length) / value.reduce(function (prev, curr) { return base / curr + prev; }, 0));
|
|
108
|
+
}
|
|
109
|
+
function sort(value) {
|
|
110
|
+
return value.sort(function (l, r) { return (l > r ? 1 : -1); });
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Calculate the median of the array.
|
|
114
|
+
* @param value - The array to process
|
|
115
|
+
*/
|
|
116
|
+
export function median(value, sorted) {
|
|
117
|
+
if (sorted === void 0) { sorted = false; }
|
|
118
|
+
var length = value.length;
|
|
119
|
+
var newArray = sorted ? value : sort(value);
|
|
120
|
+
if (length % 2 === 1)
|
|
121
|
+
return newArray[(length - 1) / 2];
|
|
122
|
+
return (newArray[length / 2 - 1] + newArray[length / 2]) / 2;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* Calculate the quartile of the array.
|
|
126
|
+
* @param value - The array to process
|
|
127
|
+
* @param sorted - Whether it is sorted
|
|
128
|
+
*/
|
|
129
|
+
export function quartile(value, sorted) {
|
|
130
|
+
if (sorted === void 0) { sorted = false; }
|
|
131
|
+
assert(value.length >= 3, 'The length of value cannot be less than 3.');
|
|
132
|
+
var length = value.length;
|
|
133
|
+
var newArray = sorted ? value : sort(value);
|
|
134
|
+
var Q2 = median(newArray, true);
|
|
135
|
+
var Q1;
|
|
136
|
+
var Q3;
|
|
137
|
+
if (length % 2 === 1) {
|
|
138
|
+
Q1 = median(newArray.slice(0, (length - 1) / 2), true);
|
|
139
|
+
Q3 = median(newArray.slice((length + 1) / 2), true);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
Q1 = median(newArray.slice(0, length / 2), true);
|
|
143
|
+
Q3 = median(newArray.slice(length / 2), true);
|
|
144
|
+
}
|
|
145
|
+
return [Q1, Q2, Q3];
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Calculate the quantile of the array.
|
|
149
|
+
* @param value - The array to process
|
|
150
|
+
* @param percent - percent
|
|
151
|
+
* @param sorted - Whether it is sorted
|
|
152
|
+
*/
|
|
153
|
+
export function quantile(value, percent, sorted) {
|
|
154
|
+
if (sorted === void 0) { sorted = false; }
|
|
155
|
+
assert(percent > 0 && percent < 100, 'The percent cannot be between (0, 100).');
|
|
156
|
+
var newArray = sorted ? value : sort(value);
|
|
157
|
+
var index = Math.ceil((value.length * percent) / 100) - 1;
|
|
158
|
+
return newArray[index];
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Calculate the variance of the array.
|
|
162
|
+
* @param value - The array to process
|
|
163
|
+
*/
|
|
164
|
+
export function variance(value) {
|
|
165
|
+
var m = mean(value);
|
|
166
|
+
var cachedValue = cache.get(value, 'variance');
|
|
167
|
+
if (cachedValue !== undefined)
|
|
168
|
+
return cachedValue;
|
|
169
|
+
return cache.set(value, 'variance', value.reduce(function (prev, curr) { return prev + Math.pow((curr - m), 2); }, 0) / value.length);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Calculate the standard deviation of the array.
|
|
173
|
+
* @param value - The array to process
|
|
174
|
+
*/
|
|
175
|
+
export function standardDeviation(value) {
|
|
176
|
+
return Math.sqrt(variance(value));
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Calculate the coefficient of variance of the array.
|
|
180
|
+
* @param value - The array to process
|
|
181
|
+
*/
|
|
182
|
+
export function coefficientOfVariance(value) {
|
|
183
|
+
var stdev = standardDeviation(value);
|
|
184
|
+
var arrayMean = mean(value);
|
|
185
|
+
return stdev / arrayMean;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Calculate the covariance of the array.
|
|
189
|
+
* @param x - variable x
|
|
190
|
+
* @param y - variable y
|
|
191
|
+
*/
|
|
192
|
+
export function covariance(x, y) {
|
|
193
|
+
assert(x.length === y.length, 'The x and y must has same length.');
|
|
194
|
+
var exy = mean(x.map(function (item, i) { return item * y[i]; }));
|
|
195
|
+
return exy - mean(x) * mean(y);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Calculate the pearson correlation coefficient of two value.
|
|
199
|
+
* @param x - variable x
|
|
200
|
+
* @param y - variable y
|
|
201
|
+
*/
|
|
202
|
+
export function pearson(x, y) {
|
|
203
|
+
var cov = covariance(x, y);
|
|
204
|
+
var dx = standardDeviation(x);
|
|
205
|
+
var dy = standardDeviation(y);
|
|
206
|
+
return cov / (dx * dy);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Calculate the counts of valid value in the array.
|
|
210
|
+
* @param value - The array to process
|
|
211
|
+
*/
|
|
212
|
+
export function valid(value) {
|
|
213
|
+
var count = 0;
|
|
214
|
+
for (var i = 0; i < value.length; i += 1) {
|
|
215
|
+
if (value[i])
|
|
216
|
+
count += 1;
|
|
217
|
+
}
|
|
218
|
+
return count;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Calculate the counts of missing value in the array.
|
|
222
|
+
* @param value - The array to process
|
|
223
|
+
*/
|
|
224
|
+
export function missing(value) {
|
|
225
|
+
return value.length - valid(value);
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Calculate the counts of each distinct value in the array.
|
|
229
|
+
* @param value - The array to process
|
|
230
|
+
*/
|
|
231
|
+
export function valueMap(value) {
|
|
232
|
+
var data = {};
|
|
233
|
+
value.forEach(function (v) {
|
|
234
|
+
var vStr = "".concat(v);
|
|
235
|
+
if (data[vStr])
|
|
236
|
+
data[vStr] += 1;
|
|
237
|
+
else
|
|
238
|
+
data[vStr] = 1;
|
|
239
|
+
});
|
|
240
|
+
return data;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Calculate the counts of distinct value in the array.
|
|
244
|
+
* @param value - The array to process
|
|
245
|
+
*/
|
|
246
|
+
export function distinct(value) {
|
|
247
|
+
return Object.keys(valueMap(value)).length;
|
|
248
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import BayesianChangePoint from 'bayesian-changepoint';
|
|
2
|
+
import { calcPValue } from './pettitt-test';
|
|
3
|
+
function breakpointVerifier(next, prev) {
|
|
4
|
+
if (Math.abs(next.data - prev.data) >= 1) {
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Bayesian Online Changepoint Detection
|
|
11
|
+
*/
|
|
12
|
+
export function bayesian(series) {
|
|
13
|
+
if (series === void 0) { series = []; }
|
|
14
|
+
var detection = new BayesianChangePoint({
|
|
15
|
+
breakpointVerifier: breakpointVerifier,
|
|
16
|
+
chunkSize: series.length,
|
|
17
|
+
iteratee: function (t) { return t; },
|
|
18
|
+
});
|
|
19
|
+
detection.exec(series);
|
|
20
|
+
var result = detection.breakPoints().map(function (breakPoint) { return ({
|
|
21
|
+
index: breakPoint.index,
|
|
22
|
+
significance: 1 - calcPValue(series, breakPoint.index),
|
|
23
|
+
}); });
|
|
24
|
+
return result;
|
|
25
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { sumBy, sum, mean } from 'lodash';
|
|
2
|
+
import { maxabs } from '..';
|
|
3
|
+
import { calcPValue } from './window';
|
|
4
|
+
/**
|
|
5
|
+
* Buishad U statistics test
|
|
6
|
+
*/
|
|
7
|
+
export function buishandUTest(data) {
|
|
8
|
+
var n = data === null || data === void 0 ? void 0 : data.length;
|
|
9
|
+
var meanValue = mean(data);
|
|
10
|
+
var Sk = data.map(function (_, index) { return sum(data.slice(0, index + 1)) - meanValue * (index + 1); });
|
|
11
|
+
var U = sumBy(Sk.slice(0, n - 1), function (item) { return Math.pow(item, 2); }) / (n * (n + 1));
|
|
12
|
+
var Smax = maxabs(Sk);
|
|
13
|
+
var maxIndex = Sk.findIndex(function (item) { return item === Smax; });
|
|
14
|
+
return {
|
|
15
|
+
uValue: U,
|
|
16
|
+
index: maxIndex,
|
|
17
|
+
significance: 1 - calcPValue(data, maxIndex),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cache some statistics results to improve performance.
|
|
3
|
+
*/
|
|
4
|
+
var CACHES = new WeakMap();
|
|
5
|
+
/**
|
|
6
|
+
* Cache the value for target and key.
|
|
7
|
+
* @param target - target
|
|
8
|
+
* @param key - key
|
|
9
|
+
* @param value - value
|
|
10
|
+
*/
|
|
11
|
+
export function set(target, key, value) {
|
|
12
|
+
if (!CACHES.get(target)) {
|
|
13
|
+
CACHES.set(target, new Map());
|
|
14
|
+
}
|
|
15
|
+
CACHES.get(target).set(key, value);
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Get the cached value for target and key.
|
|
20
|
+
* @param target - target
|
|
21
|
+
* @param key - key
|
|
22
|
+
*/
|
|
23
|
+
export function get(target, key) {
|
|
24
|
+
var cache = CACHES.get(target);
|
|
25
|
+
if (!cache)
|
|
26
|
+
return undefined;
|
|
27
|
+
return cache.get(key);
|
|
28
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { isNil } from 'lodash';
|
|
2
|
+
/**
|
|
3
|
+
* Evaluates the cumulative distribution function (CDF) for a normal distribution at a value x
|
|
4
|
+
* - Reference to equation 26.2.17 in https://personal.math.ubc.ca/~cbm/aands/abramowitz_and_stegun.pdf
|
|
5
|
+
* @param mu mean
|
|
6
|
+
* @param sigma standard deviation
|
|
7
|
+
* */
|
|
8
|
+
export var cdf = function (x, mu, sigma) {
|
|
9
|
+
if (mu === void 0) { mu = 0; }
|
|
10
|
+
if (sigma === void 0) { sigma = 1; }
|
|
11
|
+
if (sigma < 0 || [x, mu, sigma].some(function (value) { return isNil(value); }))
|
|
12
|
+
return NaN;
|
|
13
|
+
// transfer to standard normal distribution
|
|
14
|
+
var normalX = Math.abs((x - mu) / sigma);
|
|
15
|
+
/** probability density function of the standard normal distribution */
|
|
16
|
+
var Zx = (1 / Math.sqrt(2 * Math.PI)) * Math.exp((-1 * Math.pow(normalX, 2)) / 2);
|
|
17
|
+
/**
|
|
18
|
+
* - use approximate elementary functional algorithm, error less than 4.5e-4
|
|
19
|
+
* @todo add document explaining the derivation process
|
|
20
|
+
* */
|
|
21
|
+
var t = 1 / (1 + 0.33267 * normalX);
|
|
22
|
+
// error less than 1e-5
|
|
23
|
+
var Px = 1 - Zx * (0.4361836 * t - 0.1201676 * Math.pow(t, 2) + 0.937298 * Math.pow(t, 3));
|
|
24
|
+
return x > mu ? Px : 1 - Px;
|
|
25
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { isNumber, mergeWith } from 'lodash';
|
|
2
|
+
import { nOnes, nZeros } from '../utils';
|
|
3
|
+
import { median } from './base';
|
|
4
|
+
import { DEFAULT_LOWESS_OPTIONS } from './constants';
|
|
5
|
+
import { constructDiagonalMatrix, inverseSecondOrderMatrix, matrixTranspose, multiMatrixMultiply, vectorSubtract, } from './vector';
|
|
6
|
+
export var tricubeWeightFunction = function (x) {
|
|
7
|
+
if (!isNumber(x) || Math.abs(x) >= 1)
|
|
8
|
+
return 0;
|
|
9
|
+
return Math.pow((1 - Math.pow(Math.abs(x), 3)), 3);
|
|
10
|
+
};
|
|
11
|
+
export var bisquareWeightFunction = function (x) {
|
|
12
|
+
if (!isNumber(x) || Math.abs(x) >= 1)
|
|
13
|
+
return 0;
|
|
14
|
+
return Math.pow((1 - Math.pow(x, 2)), 2);
|
|
15
|
+
};
|
|
16
|
+
export var weightedLinearRegression = function (x, y, w) {
|
|
17
|
+
/** dimension: 2*n */
|
|
18
|
+
var xt = [nOnes(x.length), x];
|
|
19
|
+
/** dimension: n*2 */
|
|
20
|
+
var xMatrix = matrixTranspose(xt);
|
|
21
|
+
/** dimension: n*1 */
|
|
22
|
+
var yMatrix = matrixTranspose([y]);
|
|
23
|
+
/** diagonal matrix with w as the main diagonal */
|
|
24
|
+
var wMatrix = constructDiagonalMatrix(w);
|
|
25
|
+
/**
|
|
26
|
+
* (X^(T)wX)^(-1)
|
|
27
|
+
* - 2*n, n*n, n*2 => 2*2
|
|
28
|
+
* */
|
|
29
|
+
var factor = inverseSecondOrderMatrix(multiMatrixMultiply([xt, wMatrix, xMatrix]));
|
|
30
|
+
/**
|
|
31
|
+
* (X^(T)wX)^(-1) X^(T)wY
|
|
32
|
+
* - 2*2, 2*n, n*1 => 2*1
|
|
33
|
+
* */
|
|
34
|
+
return multiMatrixMultiply([factor, xt, wMatrix, yMatrix]);
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Locally weighted regression
|
|
38
|
+
* - General idea: perform weighted linear regression on localized subsets of the data point by point to calculate fitted value.
|
|
39
|
+
* - Reference: William S. Cleveland. Robust Locally Weighted Regression and Smoothing Scatterplots. Journal of the American Statistical Association. 1979. Vol. 74(368):829-836.
|
|
40
|
+
* */
|
|
41
|
+
export var lowess = function (x, y, options) {
|
|
42
|
+
var xLength = x.length;
|
|
43
|
+
var mergeOptions = mergeWith(DEFAULT_LOWESS_OPTIONS, options, function (defaultValue, inputValue) {
|
|
44
|
+
return inputValue !== null && inputValue !== void 0 ? inputValue : defaultValue;
|
|
45
|
+
});
|
|
46
|
+
// length of subset
|
|
47
|
+
var r = Math.ceil(xLength * mergeOptions.f);
|
|
48
|
+
// for each i, hi be the distance from xi to the rth nearest neighbor of xi
|
|
49
|
+
var h = x.map(function (xi) {
|
|
50
|
+
// rth smallest number among |xi - xj|, for j = 1, ..., n
|
|
51
|
+
return x.map(function (xj) { return Math.abs(xi - xj); }).sort(function (a, b) { return a - b; })[r];
|
|
52
|
+
});
|
|
53
|
+
// weight, n*n
|
|
54
|
+
var w = x.map(function (xi, i) {
|
|
55
|
+
// wk(xi) = weightFunc((xk - xi)/hi), for k = 1, ..., n
|
|
56
|
+
return x.map(function (xk) { return tricubeWeightFunction((xk - xi) / h[i]); });
|
|
57
|
+
});
|
|
58
|
+
var robustCoefficient = nOnes(xLength);
|
|
59
|
+
/** fitted values */
|
|
60
|
+
var yFit = nZeros(xLength);
|
|
61
|
+
var _loop_1 = function (iter) {
|
|
62
|
+
for (var i = 0; i < xLength; i += 1) {
|
|
63
|
+
var robustWeight = w[i].map(function (wik, k) { return wik * robustCoefficient[k]; });
|
|
64
|
+
var beta = weightedLinearRegression(x, y, robustWeight);
|
|
65
|
+
yFit[i] = beta[0][0] + beta[1][0] * x[i];
|
|
66
|
+
}
|
|
67
|
+
var residuals = vectorSubtract(y, yFit);
|
|
68
|
+
/** median of |residuals| */
|
|
69
|
+
var s = median(residuals.map(function (res) { return Math.abs(res); }));
|
|
70
|
+
residuals.forEach(function (res, i) {
|
|
71
|
+
robustCoefficient[i] = bisquareWeightFunction(res / (6 * s));
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
for (var iter = 0; iter < mergeOptions.nSteps; iter += 1) {
|
|
75
|
+
_loop_1(iter);
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
y: yFit,
|
|
79
|
+
};
|
|
80
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { __read } from "tslib";
|
|
2
|
+
import { sumBy } from 'lodash';
|
|
3
|
+
import { sign, unique } from '../../insight/utils/common';
|
|
4
|
+
import { normalDistributionQuantile, cdf } from '..';
|
|
5
|
+
/**
|
|
6
|
+
* http://vsp.pnnl.gov/help/Vsample/Design_Trend_Mann_Kendall.htm
|
|
7
|
+
the Mann-Kendall (MK) test is to statistically assess if there
|
|
8
|
+
is a monotonic upward or downward trend of the variable of
|
|
9
|
+
interest over time.
|
|
10
|
+
使用 Mann-Kendall 单调趋势检验判断趋势是否有方向性(上升/下降)
|
|
11
|
+
* @param data
|
|
12
|
+
* @param alpha
|
|
13
|
+
*/
|
|
14
|
+
export function mkTest(data, alpha) {
|
|
15
|
+
if (alpha === void 0) { alpha = 0.05; }
|
|
16
|
+
var length = data === null || data === void 0 ? void 0 : data.length;
|
|
17
|
+
var S = 0;
|
|
18
|
+
for (var k = 0; k < length - 1; k += 1) {
|
|
19
|
+
for (var j = k + 1; j < length; j += 1) {
|
|
20
|
+
S += sign(data[j] - data[k]);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
var _a = __read(unique(data), 2), uniqArr = _a[0], uniqCount = _a[1];
|
|
24
|
+
var uniqLength = uniqArr.length;
|
|
25
|
+
var varS = (length * (length - 1) * (2 * length + 5) -
|
|
26
|
+
(uniqLength === length ? 0 : sumBy(uniqCount, function (c) { return c * (c - 1) * (2 * c + 5); }))) /
|
|
27
|
+
18;
|
|
28
|
+
var zScore = 0;
|
|
29
|
+
if (S > 0) {
|
|
30
|
+
zScore = (S - 1) / Math.sqrt(varS);
|
|
31
|
+
}
|
|
32
|
+
else if (S < 0) {
|
|
33
|
+
zScore = (S + 1) / Math.sqrt(varS);
|
|
34
|
+
}
|
|
35
|
+
// calculate the p_value
|
|
36
|
+
var pValue = 2 * (1 - cdf(Math.abs(zScore), 0, 1));
|
|
37
|
+
var h = Math.abs(zScore) > normalDistributionQuantile(1 - alpha / 2, 0, 1);
|
|
38
|
+
var trend = 'no trend';
|
|
39
|
+
if (zScore < 0 && h) {
|
|
40
|
+
trend = 'decreasing';
|
|
41
|
+
}
|
|
42
|
+
else if (zScore > 0 && h) {
|
|
43
|
+
trend = 'increasing';
|
|
44
|
+
}
|
|
45
|
+
return {
|
|
46
|
+
trend: trend,
|
|
47
|
+
pValue: pValue,
|
|
48
|
+
zScore: zScore,
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { __read, __spreadArray } from "tslib";
|
|
2
|
+
/**
|
|
3
|
+
* Returns the maximum absolute value of array
|
|
4
|
+
* @param x input array
|
|
5
|
+
* */
|
|
6
|
+
export var maxabs = function (x) {
|
|
7
|
+
var absoluteX = x.map(function (value) { return Math.abs(value); });
|
|
8
|
+
return Math.max.apply(Math, __spreadArray([], __read(absoluteX), false));
|
|
9
|
+
};
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { mergeWith } from 'lodash';
|
|
2
|
+
import { pearson } from './base';
|
|
3
|
+
import { DEFAULT_PCORRTEST_OPTIONS } from './constants';
|
|
4
|
+
import { normalDistributionQuantile, tDistributionQuantile } from './quantile';
|
|
5
|
+
/** Perform a Pearson product-moment correlation test between paired samples */
|
|
6
|
+
export var pcorrtest = function (x, y, options) {
|
|
7
|
+
if (x.length !== y.length) {
|
|
8
|
+
// eslint-disable-next-line no-console
|
|
9
|
+
console.error('invalid arguments: First and second arguments must be arrays having the same length');
|
|
10
|
+
return {
|
|
11
|
+
pcorr: null,
|
|
12
|
+
rejected: false,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
var _a = mergeWith(DEFAULT_PCORRTEST_OPTIONS, options, function (defaultValue, inputValue) {
|
|
16
|
+
return inputValue !== null && inputValue !== void 0 ? inputValue : defaultValue;
|
|
17
|
+
}), alpha = _a.alpha, alternative = _a.alternative, rho = _a.rho;
|
|
18
|
+
/** pearson correlation coefficient */
|
|
19
|
+
var pcorr = pearson(x, y);
|
|
20
|
+
/** statistic to be tested */
|
|
21
|
+
var statistic;
|
|
22
|
+
var threshold;
|
|
23
|
+
/** whether to reject null hypothesis */
|
|
24
|
+
var rejected = false;
|
|
25
|
+
if (rho !== 0) {
|
|
26
|
+
/**
|
|
27
|
+
* - if rho is provided, it needs to be corrected by Fisher's z transform so that it satisfies the normal distribution
|
|
28
|
+
* - https://en.wikipedia.org/wiki/Fisher_transformation
|
|
29
|
+
* */
|
|
30
|
+
var z = 0.5 * Math.log((1 + pcorr) / (1 - pcorr));
|
|
31
|
+
/** mean of z */
|
|
32
|
+
var meanZ = 0.5 * Math.log((1 + rho) / (1 - rho));
|
|
33
|
+
/** standard error of z */
|
|
34
|
+
var sigmaZ = 1 / Math.sqrt(x.length - 3);
|
|
35
|
+
statistic = (z - meanZ) / sigmaZ;
|
|
36
|
+
if (alternative === 'greater') {
|
|
37
|
+
threshold = normalDistributionQuantile(1 - alpha);
|
|
38
|
+
if (statistic >= threshold)
|
|
39
|
+
rejected = true;
|
|
40
|
+
}
|
|
41
|
+
else if (alternative === 'less') {
|
|
42
|
+
threshold = normalDistributionQuantile(alpha);
|
|
43
|
+
if (statistic <= threshold)
|
|
44
|
+
rejected = true;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
threshold = normalDistributionQuantile(1 - alpha / 2);
|
|
48
|
+
if (Math.abs(statistic) >= threshold)
|
|
49
|
+
rejected = true;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
// obey the t distribution under the null hypothesis, t~t(n-2)
|
|
54
|
+
var degree = x.length - 2;
|
|
55
|
+
statistic = (pcorr * Math.sqrt(degree)) / Math.sqrt(1 - Math.pow(pcorr, 2));
|
|
56
|
+
if (alternative === 'greater') {
|
|
57
|
+
threshold = tDistributionQuantile(1 - alpha, degree);
|
|
58
|
+
if (statistic >= threshold)
|
|
59
|
+
rejected = true;
|
|
60
|
+
}
|
|
61
|
+
else if (alternative === 'less') {
|
|
62
|
+
threshold = tDistributionQuantile(alpha, degree);
|
|
63
|
+
if (statistic <= threshold)
|
|
64
|
+
rejected = true;
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
threshold = tDistributionQuantile(1 - alpha / 2, degree);
|
|
68
|
+
if (Math.abs(statistic) >= threshold)
|
|
69
|
+
rejected = true;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
rejected: rejected,
|
|
74
|
+
pcorr: pcorr,
|
|
75
|
+
};
|
|
76
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { sumBy } from 'lodash';
|
|
2
|
+
import { rank } from '../../insight/utils/common';
|
|
3
|
+
/**
|
|
4
|
+
* Pettitt's (1979) method is a rank-based nonparametric test for abrupt changes in a time series.
|
|
5
|
+
* */
|
|
6
|
+
export function pettittTest(data) {
|
|
7
|
+
var n = data === null || data === void 0 ? void 0 : data.length;
|
|
8
|
+
var rankArr = rank(data);
|
|
9
|
+
var Umax = 0;
|
|
10
|
+
var UmaxIndex = -1;
|
|
11
|
+
for (var k = 0; k < n; k += 1) {
|
|
12
|
+
var U = Math.abs(2 * sumBy(rankArr.slice(0, k)) - k * (n + 1));
|
|
13
|
+
if (U > Umax) {
|
|
14
|
+
Umax = U;
|
|
15
|
+
UmaxIndex = k;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
var pvalue = 2 * Math.exp((-6 * Math.pow(Umax, 2)) / (Math.pow(n, 2) + Math.pow(n, 3)));
|
|
19
|
+
return {
|
|
20
|
+
index: UmaxIndex,
|
|
21
|
+
significance: 1 - pvalue,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* p-value calc in Pettitt
|
|
26
|
+
*/
|
|
27
|
+
export function calcPValue(data, index) {
|
|
28
|
+
var n = data === null || data === void 0 ? void 0 : data.length;
|
|
29
|
+
var rankArr = rank(data);
|
|
30
|
+
var U = Math.abs(2 * sumBy(rankArr.slice(0, index)) - index * (n + 1));
|
|
31
|
+
var pvalue = 2 * Math.exp((-6 * Math.pow(U, 2)) / (Math.pow(n, 2) + Math.pow(n, 3)));
|
|
32
|
+
return pvalue;
|
|
33
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
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 var normalDistributionQuantile = function (p, mu, sigma) {
|
|
11
|
+
if (mu === void 0) { mu = 0; }
|
|
12
|
+
if (sigma === void 0) { sigma = 1; }
|
|
13
|
+
if (p > 1 || p < 0 || sigma < 0)
|
|
14
|
+
return NaN;
|
|
15
|
+
// formula requires that p is no more than 0.5
|
|
16
|
+
var adjustedP = p <= 0.5 ? p : 1 - p;
|
|
17
|
+
var t = Math.sqrt(-2 * Math.log(adjustedP));
|
|
18
|
+
/**
|
|
19
|
+
* Q(qXp) + F(qXp) = 1
|
|
20
|
+
* - use approximate elementary functional algorithm, error less than 4.5e-4
|
|
21
|
+
* @todo add document explaining the derivation process
|
|
22
|
+
* */
|
|
23
|
+
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));
|
|
24
|
+
// quantile of standard normal distribution
|
|
25
|
+
var normalXp = p <= 0.5 ? -1 * qXp : qXp;
|
|
26
|
+
// transfer to quantile of normal distribution N(mu, sigma)
|
|
27
|
+
var Xp = sigma * normalXp + mu;
|
|
28
|
+
return Xp;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* student's t distribution quantile function
|
|
32
|
+
* @param p probability
|
|
33
|
+
* @param v degree of freedom
|
|
34
|
+
*/
|
|
35
|
+
export var tDistributionQuantile = function (p, d) {
|
|
36
|
+
if (d === void 0) { d = 1; }
|
|
37
|
+
if (p > 1 || p < 0 || d <= 0)
|
|
38
|
+
return NaN;
|
|
39
|
+
// when the degree of freedom is 1, the t distribution is the same as a standard Cauchy distribution
|
|
40
|
+
// reference to equation 35 in http://www.homepages.ucl.ac.uk/~ucahwts/lgsnotes/JCF_Student.pdf
|
|
41
|
+
if (d === 1)
|
|
42
|
+
return -Math.cos(Math.PI * p) / Math.sin(Math.PI * p);
|
|
43
|
+
// reference to equation 36 in http://www.homepages.ucl.ac.uk/~ucahwts/lgsnotes/JCF_Student.pdf
|
|
44
|
+
if (d === 2)
|
|
45
|
+
return (2 * p - 1) / Math.sqrt(2 * p * (1 - p));
|
|
46
|
+
// Q(x) = p, Q(x) + F(x) = 1, F(x) is standard normal distribution CDF
|
|
47
|
+
var prop = p > 0.5 ? p : 1 - p;
|
|
48
|
+
var x = normalDistributionQuantile(prop);
|
|
49
|
+
var g1 = (Math.pow(x, 3) + x) / 4;
|
|
50
|
+
var g2 = (5 * Math.pow(x, 5) + 16 * Math.pow(x, 3) + 3 * x) / 96;
|
|
51
|
+
var g3 = (3 * Math.pow(x, 7) + 19 * Math.pow(x, 5) + 17 * Math.pow(x, 3) - 15 * x) / 384;
|
|
52
|
+
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;
|
|
53
|
+
// Cornish–Fisher expansions
|
|
54
|
+
// reference to equation 26.7.5 in https://personal.math.ubc.ca/~cbm/aands/abramowitz_and_stegun.pdf
|
|
55
|
+
return (p > 0.5 ? 1 : -1) * (x + g1 / d + g2 / Math.pow(d, 2) + g3 / Math.pow(d, 3) + g4 / Math.pow(d, 4));
|
|
56
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|