@nshiab/simple-data-analysis-core 2.0.9 → 2.1.1
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/esm/class/SDAError.d.ts +6 -6
- package/esm/class/SDAError.js +6 -6
- package/esm/class/Simple.d.ts +9 -9
- package/esm/class/Simple.js +9 -9
- package/esm/class/SimpleDB.d.ts +80 -76
- package/esm/class/SimpleDB.d.ts.map +1 -1
- package/esm/class/SimpleDB.js +80 -76
- package/esm/class/SimpleTable.d.ts +2806 -1139
- package/esm/class/SimpleTable.d.ts.map +1 -1
- package/esm/class/SimpleTable.js +2792 -1149
- package/esm/helpers/buildApproximateMutualReachabilityMst.d.ts +45 -0
- package/esm/helpers/buildApproximateMutualReachabilityMst.d.ts.map +1 -0
- package/esm/helpers/buildApproximateMutualReachabilityMst.js +212 -0
- package/esm/helpers/buildChronologicalGraphComponentsSql.d.ts +14 -0
- package/esm/helpers/buildChronologicalGraphComponentsSql.d.ts.map +1 -0
- package/esm/helpers/buildChronologicalGraphComponentsSql.js +167 -0
- package/esm/helpers/buildExactMutualReachabilityMst.d.ts +28 -0
- package/esm/helpers/buildExactMutualReachabilityMst.d.ts.map +1 -0
- package/esm/helpers/buildExactMutualReachabilityMst.js +97 -0
- package/esm/helpers/buildGraphTemporalCostStateSql.d.ts +12 -0
- package/esm/helpers/buildGraphTemporalCostStateSql.d.ts.map +1 -0
- package/esm/helpers/buildGraphTemporalCostStateSql.js +86 -0
- package/esm/helpers/buildGraphTemporalReachabilitySql.d.ts +13 -0
- package/esm/helpers/buildGraphTemporalReachabilitySql.d.ts.map +1 -0
- package/esm/helpers/buildGraphTemporalReachabilitySql.js +70 -0
- package/esm/helpers/buildSparseMutualReachabilityMst.d.ts +10 -0
- package/esm/helpers/buildSparseMutualReachabilityMst.d.ts.map +1 -0
- package/esm/helpers/buildSparseMutualReachabilityMst.js +47 -0
- package/esm/helpers/buildUmapGraph.d.ts +2 -5
- package/esm/helpers/buildUmapGraph.d.ts.map +1 -1
- package/esm/helpers/buildUmapGraph.js +6 -100
- package/esm/helpers/buildVectorNeighbors.d.ts +45 -0
- package/esm/helpers/buildVectorNeighbors.d.ts.map +1 -0
- package/esm/helpers/buildVectorNeighbors.js +170 -0
- package/esm/helpers/buildWeakGraphComponentsSql.d.ts +3 -0
- package/esm/helpers/buildWeakGraphComponentsSql.d.ts.map +1 -0
- package/esm/helpers/buildWeakGraphComponentsSql.js +32 -0
- package/esm/helpers/camelCase.d.ts +7 -5
- package/esm/helpers/camelCase.d.ts.map +1 -1
- package/esm/helpers/camelCase.js +7 -5
- package/esm/helpers/capitalize.d.ts +6 -4
- package/esm/helpers/capitalize.d.ts.map +1 -1
- package/esm/helpers/capitalize.js +6 -4
- package/esm/helpers/clusterHdbscan.d.ts +18 -0
- package/esm/helpers/clusterHdbscan.d.ts.map +1 -0
- package/esm/helpers/clusterHdbscan.js +342 -0
- package/esm/helpers/computeCovariance.d.ts +16 -0
- package/esm/helpers/computeCovariance.d.ts.map +1 -0
- package/esm/helpers/computeCovariance.js +99 -0
- package/esm/helpers/computeMahalanobisDistances.d.ts +14 -0
- package/esm/helpers/computeMahalanobisDistances.d.ts.map +1 -0
- package/esm/helpers/computeMahalanobisDistances.js +87 -0
- package/esm/helpers/createDirectory.d.ts +4 -3
- package/esm/helpers/createDirectory.d.ts.map +1 -1
- package/esm/helpers/createDirectory.js +4 -3
- package/esm/helpers/dataToArrays.d.ts +6 -4
- package/esm/helpers/dataToArrays.d.ts.map +1 -1
- package/esm/helpers/dataToArrays.js +6 -4
- package/esm/helpers/extractTypes.d.ts +1 -1
- package/esm/helpers/extractTypes.js +4 -9
- package/esm/helpers/factorCovariance.d.ts +17 -0
- package/esm/helpers/factorCovariance.d.ts.map +1 -0
- package/esm/helpers/factorCovariance.js +189 -0
- package/esm/helpers/findGeoColumn.d.ts +6 -4
- package/esm/helpers/findGeoColumn.d.ts.map +1 -1
- package/esm/helpers/findGeoColumn.js +6 -4
- package/esm/helpers/findGeoColumnFromSchema.d.ts +8 -5
- package/esm/helpers/findGeoColumnFromSchema.d.ts.map +1 -1
- package/esm/helpers/findGeoColumnFromSchema.js +8 -5
- package/esm/helpers/formatDate.d.ts +12 -6
- package/esm/helpers/formatDate.d.ts.map +1 -1
- package/esm/helpers/formatDate.js +12 -6
- package/esm/helpers/formatMissingTables.d.ts +8 -5
- package/esm/helpers/formatMissingTables.d.ts.map +1 -1
- package/esm/helpers/formatMissingTables.js +8 -5
- package/esm/helpers/formatNumber.d.ts +19 -10
- package/esm/helpers/formatNumber.d.ts.map +1 -1
- package/esm/helpers/formatNumber.js +32 -17
- package/esm/helpers/getGraphEdgeIdColumn.d.ts +9 -0
- package/esm/helpers/getGraphEdgeIdColumn.d.ts.map +1 -0
- package/esm/helpers/getGraphEdgeIdColumn.js +25 -0
- package/esm/helpers/getGraphEndpointColumns.d.ts +11 -0
- package/esm/helpers/getGraphEndpointColumns.d.ts.map +1 -0
- package/esm/helpers/getGraphEndpointColumns.js +160 -0
- package/esm/helpers/getGraphWeightColumn.d.ts +10 -0
- package/esm/helpers/getGraphWeightColumn.d.ts.map +1 -0
- package/esm/helpers/getGraphWeightColumn.js +40 -0
- package/esm/helpers/graphRouteResultSchema.d.ts +4 -0
- package/esm/helpers/graphRouteResultSchema.d.ts.map +1 -0
- package/esm/helpers/graphRouteResultSchema.js +12 -0
- package/esm/helpers/graphRouteResultSelect.d.ts +4 -0
- package/esm/helpers/graphRouteResultSelect.d.ts.map +1 -0
- package/esm/helpers/graphRouteResultSelect.js +22 -0
- package/esm/helpers/hasGeometryColumn.d.ts +4 -3
- package/esm/helpers/hasGeometryColumn.d.ts.map +1 -1
- package/esm/helpers/hasGeometryColumn.js +4 -3
- package/esm/helpers/inspectGraphConnectivity.d.ts +10 -0
- package/esm/helpers/inspectGraphConnectivity.d.ts.map +1 -0
- package/esm/helpers/inspectGraphConnectivity.js +55 -0
- package/esm/helpers/mergeOptions.d.ts +24 -13
- package/esm/helpers/mergeOptions.d.ts.map +1 -1
- package/esm/helpers/mergeOptions.js +24 -13
- package/esm/helpers/parseValue.d.ts +6 -4
- package/esm/helpers/parseValue.d.ts.map +1 -1
- package/esm/helpers/parseValue.js +6 -4
- package/esm/helpers/prepareGraphRouteSql.d.ts +31 -0
- package/esm/helpers/prepareGraphRouteSql.d.ts.map +1 -0
- package/esm/helpers/prepareGraphRouteSql.js +86 -0
- package/esm/helpers/prepareGraphStarts.d.ts +9 -0
- package/esm/helpers/prepareGraphStarts.d.ts.map +1 -0
- package/esm/helpers/prepareGraphStarts.js +68 -0
- package/esm/helpers/prepareGraphTemporalSql.d.ts +28 -0
- package/esm/helpers/prepareGraphTemporalSql.d.ts.map +1 -0
- package/esm/helpers/prepareGraphTemporalSql.js +154 -0
- package/esm/helpers/prepareGraphTraversal.d.ts +19 -0
- package/esm/helpers/prepareGraphTraversal.d.ts.map +1 -0
- package/esm/helpers/prepareGraphTraversal.js +79 -0
- package/esm/helpers/prepareNumericFeatures.d.ts +41 -0
- package/esm/helpers/prepareNumericFeatures.d.ts.map +1 -0
- package/esm/helpers/prepareNumericFeatures.js +210 -0
- package/esm/helpers/prettyDuration.d.ts +14 -8
- package/esm/helpers/prettyDuration.d.ts.map +1 -1
- package/esm/helpers/prettyDuration.js +14 -8
- package/esm/helpers/printTable.d.ts +18 -13
- package/esm/helpers/printTable.d.ts.map +1 -1
- package/esm/helpers/printTable.js +18 -13
- package/esm/helpers/publishPreparedColumns.d.ts +37 -0
- package/esm/helpers/publishPreparedColumns.d.ts.map +1 -0
- package/esm/helpers/publishPreparedColumns.js +113 -0
- package/esm/helpers/queryDB.d.ts +24 -13
- package/esm/helpers/queryDB.d.ts.map +1 -1
- package/esm/helpers/queryDB.js +24 -13
- package/esm/helpers/queueAsyncBarrier.d.ts +12 -7
- package/esm/helpers/queueAsyncBarrier.d.ts.map +1 -1
- package/esm/helpers/queueAsyncBarrier.js +12 -7
- package/esm/helpers/queueGraphResult.d.ts +18 -0
- package/esm/helpers/queueGraphResult.d.ts.map +1 -0
- package/esm/helpers/queueGraphResult.js +39 -0
- package/esm/helpers/quoteIdentifier.d.ts +4 -3
- package/esm/helpers/quoteIdentifier.d.ts.map +1 -1
- package/esm/helpers/quoteIdentifier.js +4 -3
- package/esm/helpers/quoteQualifiedIdentifier.d.ts +6 -4
- package/esm/helpers/quoteQualifiedIdentifier.d.ts.map +1 -1
- package/esm/helpers/quoteQualifiedIdentifier.js +6 -4
- package/esm/helpers/runQuery.d.ts.map +1 -1
- package/esm/helpers/runQuery.js +17 -3
- package/esm/helpers/selectFuzzyReplacements.d.ts +11 -0
- package/esm/helpers/selectFuzzyReplacements.d.ts.map +1 -0
- package/esm/helpers/selectFuzzyReplacements.js +124 -0
- package/esm/helpers/stabilizeCosineVectors.d.ts +14 -0
- package/esm/helpers/stabilizeCosineVectors.d.ts.map +1 -0
- package/esm/helpers/stabilizeCosineVectors.js +34 -0
- package/esm/helpers/stringToArray.d.ts +4 -3
- package/esm/helpers/stringToArray.d.ts.map +1 -1
- package/esm/helpers/stringToArray.js +4 -3
- package/esm/helpers/updateColumnsWithJS.d.ts +12 -6
- package/esm/helpers/updateColumnsWithJS.d.ts.map +1 -1
- package/esm/helpers/updateColumnsWithJS.js +12 -6
- package/esm/helpers/validateGraphRouteResultSchema.d.ts +4 -0
- package/esm/helpers/validateGraphRouteResultSchema.d.ts.map +1 -0
- package/esm/helpers/validateGraphRouteResultSchema.js +13 -0
- package/esm/helpers/validateGraphTemporalEvents.d.ts +7 -0
- package/esm/helpers/validateGraphTemporalEvents.d.ts.map +1 -0
- package/esm/helpers/validateGraphTemporalEvents.js +47 -0
- package/esm/helpers/validateNumericalAnalysis.d.ts +10 -6
- package/esm/helpers/validateNumericalAnalysis.d.ts.map +1 -1
- package/esm/helpers/validateNumericalAnalysis.js +10 -6
- package/esm/helpers/validateVectorRowIds.d.ts +4 -0
- package/esm/helpers/validateVectorRowIds.d.ts.map +1 -0
- package/esm/helpers/validateVectorRowIds.js +16 -0
- package/esm/helpers/vectorDistanceExpression.d.ts +6 -0
- package/esm/helpers/vectorDistanceExpression.d.ts.map +1 -0
- package/esm/helpers/vectorDistanceExpression.js +11 -0
- package/esm/helpers/wrapString.d.ts +10 -7
- package/esm/helpers/wrapString.d.ts.map +1 -1
- package/esm/helpers/wrapString.js +10 -7
- package/esm/methods/addId.d.ts +5 -0
- package/esm/methods/addId.d.ts.map +1 -0
- package/esm/methods/addId.js +38 -0
- package/esm/methods/commonNeighbors.d.ts +10 -0
- package/esm/methods/commonNeighbors.d.ts.map +1 -0
- package/esm/methods/commonNeighbors.js +101 -0
- package/esm/methods/connectedComponents.d.ts +9 -0
- package/esm/methods/connectedComponents.d.ts.map +1 -0
- package/esm/methods/connectedComponents.js +147 -0
- package/esm/methods/degree.d.ts +9 -0
- package/esm/methods/degree.d.ts.map +1 -0
- package/esm/methods/degree.js +135 -0
- package/esm/methods/distances.d.ts +12 -0
- package/esm/methods/distances.d.ts.map +1 -0
- package/esm/methods/distances.js +164 -0
- package/esm/methods/findCycles.d.ts +12 -0
- package/esm/methods/findCycles.d.ts.map +1 -0
- package/esm/methods/findCycles.js +330 -0
- package/esm/methods/fuzzyClean.d.ts.map +1 -1
- package/esm/methods/fuzzyClean.js +17 -136
- package/esm/methods/fuzzyJoin.js +70 -16
- package/esm/methods/getTypes.d.ts +1 -1
- package/esm/methods/hdbscan.d.ts +5 -0
- package/esm/methods/hdbscan.d.ts.map +1 -0
- package/esm/methods/hdbscan.js +208 -0
- package/esm/methods/mahalanobis.d.ts +5 -0
- package/esm/methods/mahalanobis.d.ts.map +1 -0
- package/esm/methods/mahalanobis.js +92 -0
- package/esm/methods/neighbors.d.ts +9 -0
- package/esm/methods/neighbors.d.ts.map +1 -0
- package/esm/methods/neighbors.js +81 -0
- package/esm/methods/normalizeVector.d.ts +5 -0
- package/esm/methods/normalizeVector.d.ts.map +1 -0
- package/esm/methods/normalizeVector.js +132 -0
- package/esm/methods/paths.d.ts +12 -0
- package/esm/methods/paths.d.ts.map +1 -0
- package/esm/methods/paths.js +287 -0
- package/esm/methods/reachable.d.ts +11 -0
- package/esm/methods/reachable.d.ts.map +1 -0
- package/esm/methods/reachable.js +131 -0
- package/esm/methods/rowToVector.d.ts +5 -0
- package/esm/methods/rowToVector.d.ts.map +1 -0
- package/esm/methods/rowToVector.js +77 -0
- package/esm/methods/shortestPath.d.ts +12 -0
- package/esm/methods/shortestPath.d.ts.map +1 -0
- package/esm/methods/shortestPath.js +337 -0
- package/esm/methods/topologicalSort.d.ts +7 -0
- package/esm/methods/topologicalSort.d.ts.map +1 -0
- package/esm/methods/topologicalSort.js +164 -0
- package/esm/methods/trim.d.ts +1 -1
- package/esm/methods/trim.d.ts.map +1 -1
- package/esm/methods/trim.js +17 -8
- package/llm.md +2146 -173
- package/llms.txt +1 -1
- package/package.json +1 -1
- package/script/class/SDAError.d.ts +6 -6
- package/script/class/SDAError.js +6 -6
- package/script/class/Simple.d.ts +9 -9
- package/script/class/Simple.js +9 -9
- package/script/class/SimpleDB.d.ts +80 -76
- package/script/class/SimpleDB.d.ts.map +1 -1
- package/script/class/SimpleDB.js +80 -76
- package/script/class/SimpleTable.d.ts +2806 -1139
- package/script/class/SimpleTable.d.ts.map +1 -1
- package/script/class/SimpleTable.js +2792 -1149
- package/script/helpers/buildApproximateMutualReachabilityMst.d.ts +45 -0
- package/script/helpers/buildApproximateMutualReachabilityMst.d.ts.map +1 -0
- package/script/helpers/buildApproximateMutualReachabilityMst.js +219 -0
- package/script/helpers/buildChronologicalGraphComponentsSql.d.ts +14 -0
- package/script/helpers/buildChronologicalGraphComponentsSql.d.ts.map +1 -0
- package/script/helpers/buildChronologicalGraphComponentsSql.js +174 -0
- package/script/helpers/buildExactMutualReachabilityMst.d.ts +28 -0
- package/script/helpers/buildExactMutualReachabilityMst.d.ts.map +1 -0
- package/script/helpers/buildExactMutualReachabilityMst.js +103 -0
- package/script/helpers/buildGraphTemporalCostStateSql.d.ts +12 -0
- package/script/helpers/buildGraphTemporalCostStateSql.d.ts.map +1 -0
- package/script/helpers/buildGraphTemporalCostStateSql.js +92 -0
- package/script/helpers/buildGraphTemporalReachabilitySql.d.ts +13 -0
- package/script/helpers/buildGraphTemporalReachabilitySql.d.ts.map +1 -0
- package/script/helpers/buildGraphTemporalReachabilitySql.js +76 -0
- package/script/helpers/buildSparseMutualReachabilityMst.d.ts +10 -0
- package/script/helpers/buildSparseMutualReachabilityMst.d.ts.map +1 -0
- package/script/helpers/buildSparseMutualReachabilityMst.js +50 -0
- package/script/helpers/buildUmapGraph.d.ts +2 -5
- package/script/helpers/buildUmapGraph.d.ts.map +1 -1
- package/script/helpers/buildUmapGraph.js +6 -100
- package/script/helpers/buildVectorNeighbors.d.ts +45 -0
- package/script/helpers/buildVectorNeighbors.d.ts.map +1 -0
- package/script/helpers/buildVectorNeighbors.js +176 -0
- package/script/helpers/buildWeakGraphComponentsSql.d.ts +3 -0
- package/script/helpers/buildWeakGraphComponentsSql.d.ts.map +1 -0
- package/script/helpers/buildWeakGraphComponentsSql.js +38 -0
- package/script/helpers/camelCase.d.ts +7 -5
- package/script/helpers/camelCase.d.ts.map +1 -1
- package/script/helpers/camelCase.js +7 -5
- package/script/helpers/capitalize.d.ts +6 -4
- package/script/helpers/capitalize.d.ts.map +1 -1
- package/script/helpers/capitalize.js +6 -4
- package/script/helpers/clusterHdbscan.d.ts +18 -0
- package/script/helpers/clusterHdbscan.d.ts.map +1 -0
- package/script/helpers/clusterHdbscan.js +346 -0
- package/script/helpers/computeCovariance.d.ts +16 -0
- package/script/helpers/computeCovariance.d.ts.map +1 -0
- package/script/helpers/computeCovariance.js +105 -0
- package/script/helpers/computeMahalanobisDistances.d.ts +14 -0
- package/script/helpers/computeMahalanobisDistances.d.ts.map +1 -0
- package/script/helpers/computeMahalanobisDistances.js +93 -0
- package/script/helpers/createDirectory.d.ts +4 -3
- package/script/helpers/createDirectory.d.ts.map +1 -1
- package/script/helpers/createDirectory.js +4 -3
- package/script/helpers/dataToArrays.d.ts +6 -4
- package/script/helpers/dataToArrays.d.ts.map +1 -1
- package/script/helpers/dataToArrays.js +6 -4
- package/script/helpers/extractTypes.d.ts +1 -1
- package/script/helpers/extractTypes.js +4 -9
- package/script/helpers/factorCovariance.d.ts +17 -0
- package/script/helpers/factorCovariance.d.ts.map +1 -0
- package/script/helpers/factorCovariance.js +194 -0
- package/script/helpers/findGeoColumn.d.ts +6 -4
- package/script/helpers/findGeoColumn.d.ts.map +1 -1
- package/script/helpers/findGeoColumn.js +6 -4
- package/script/helpers/findGeoColumnFromSchema.d.ts +8 -5
- package/script/helpers/findGeoColumnFromSchema.d.ts.map +1 -1
- package/script/helpers/findGeoColumnFromSchema.js +8 -5
- package/script/helpers/formatDate.d.ts +12 -6
- package/script/helpers/formatDate.d.ts.map +1 -1
- package/script/helpers/formatDate.js +12 -6
- package/script/helpers/formatMissingTables.d.ts +8 -5
- package/script/helpers/formatMissingTables.d.ts.map +1 -1
- package/script/helpers/formatMissingTables.js +8 -5
- package/script/helpers/formatNumber.d.ts +19 -10
- package/script/helpers/formatNumber.d.ts.map +1 -1
- package/script/helpers/formatNumber.js +32 -17
- package/script/helpers/getGraphEdgeIdColumn.d.ts +9 -0
- package/script/helpers/getGraphEdgeIdColumn.d.ts.map +1 -0
- package/script/helpers/getGraphEdgeIdColumn.js +31 -0
- package/script/helpers/getGraphEndpointColumns.d.ts +11 -0
- package/script/helpers/getGraphEndpointColumns.d.ts.map +1 -0
- package/script/helpers/getGraphEndpointColumns.js +166 -0
- package/script/helpers/getGraphWeightColumn.d.ts +10 -0
- package/script/helpers/getGraphWeightColumn.d.ts.map +1 -0
- package/script/helpers/getGraphWeightColumn.js +46 -0
- package/script/helpers/graphRouteResultSchema.d.ts +4 -0
- package/script/helpers/graphRouteResultSchema.d.ts.map +1 -0
- package/script/helpers/graphRouteResultSchema.js +18 -0
- package/script/helpers/graphRouteResultSelect.d.ts +4 -0
- package/script/helpers/graphRouteResultSelect.d.ts.map +1 -0
- package/script/helpers/graphRouteResultSelect.js +28 -0
- package/script/helpers/hasGeometryColumn.d.ts +4 -3
- package/script/helpers/hasGeometryColumn.d.ts.map +1 -1
- package/script/helpers/hasGeometryColumn.js +4 -3
- package/script/helpers/inspectGraphConnectivity.d.ts +10 -0
- package/script/helpers/inspectGraphConnectivity.d.ts.map +1 -0
- package/script/helpers/inspectGraphConnectivity.js +58 -0
- package/script/helpers/mergeOptions.d.ts +24 -13
- package/script/helpers/mergeOptions.d.ts.map +1 -1
- package/script/helpers/mergeOptions.js +24 -13
- package/script/helpers/parseValue.d.ts +6 -4
- package/script/helpers/parseValue.d.ts.map +1 -1
- package/script/helpers/parseValue.js +6 -4
- package/script/helpers/prepareGraphRouteSql.d.ts +31 -0
- package/script/helpers/prepareGraphRouteSql.d.ts.map +1 -0
- package/script/helpers/prepareGraphRouteSql.js +127 -0
- package/script/helpers/prepareGraphStarts.d.ts +9 -0
- package/script/helpers/prepareGraphStarts.d.ts.map +1 -0
- package/script/helpers/prepareGraphStarts.js +71 -0
- package/script/helpers/prepareGraphTemporalSql.d.ts +28 -0
- package/script/helpers/prepareGraphTemporalSql.d.ts.map +1 -0
- package/script/helpers/prepareGraphTemporalSql.js +161 -0
- package/script/helpers/prepareGraphTraversal.d.ts +19 -0
- package/script/helpers/prepareGraphTraversal.d.ts.map +1 -0
- package/script/helpers/prepareGraphTraversal.js +87 -0
- package/script/helpers/prepareNumericFeatures.d.ts +41 -0
- package/script/helpers/prepareNumericFeatures.d.ts.map +1 -0
- package/script/helpers/prepareNumericFeatures.js +217 -0
- package/script/helpers/prettyDuration.d.ts +14 -8
- package/script/helpers/prettyDuration.d.ts.map +1 -1
- package/script/helpers/prettyDuration.js +14 -8
- package/script/helpers/printTable.d.ts +18 -13
- package/script/helpers/printTable.d.ts.map +1 -1
- package/script/helpers/printTable.js +18 -13
- package/script/helpers/publishPreparedColumns.d.ts +37 -0
- package/script/helpers/publishPreparedColumns.d.ts.map +1 -0
- package/script/helpers/publishPreparedColumns.js +119 -0
- package/script/helpers/queryDB.d.ts +24 -13
- package/script/helpers/queryDB.d.ts.map +1 -1
- package/script/helpers/queryDB.js +24 -13
- package/script/helpers/queueAsyncBarrier.d.ts +12 -7
- package/script/helpers/queueAsyncBarrier.d.ts.map +1 -1
- package/script/helpers/queueAsyncBarrier.js +12 -7
- package/script/helpers/queueGraphResult.d.ts +18 -0
- package/script/helpers/queueGraphResult.d.ts.map +1 -0
- package/script/helpers/queueGraphResult.js +45 -0
- package/script/helpers/quoteIdentifier.d.ts +4 -3
- package/script/helpers/quoteIdentifier.d.ts.map +1 -1
- package/script/helpers/quoteIdentifier.js +4 -3
- package/script/helpers/quoteQualifiedIdentifier.d.ts +6 -4
- package/script/helpers/quoteQualifiedIdentifier.d.ts.map +1 -1
- package/script/helpers/quoteQualifiedIdentifier.js +6 -4
- package/script/helpers/runQuery.d.ts.map +1 -1
- package/script/helpers/runQuery.js +17 -3
- package/script/helpers/selectFuzzyReplacements.d.ts +11 -0
- package/script/helpers/selectFuzzyReplacements.d.ts.map +1 -0
- package/script/helpers/selectFuzzyReplacements.js +127 -0
- package/script/helpers/stabilizeCosineVectors.d.ts +14 -0
- package/script/helpers/stabilizeCosineVectors.d.ts.map +1 -0
- package/script/helpers/stabilizeCosineVectors.js +40 -0
- package/script/helpers/stringToArray.d.ts +4 -3
- package/script/helpers/stringToArray.d.ts.map +1 -1
- package/script/helpers/stringToArray.js +4 -3
- package/script/helpers/updateColumnsWithJS.d.ts +12 -6
- package/script/helpers/updateColumnsWithJS.d.ts.map +1 -1
- package/script/helpers/updateColumnsWithJS.js +12 -6
- package/script/helpers/validateGraphRouteResultSchema.d.ts +4 -0
- package/script/helpers/validateGraphRouteResultSchema.d.ts.map +1 -0
- package/script/helpers/validateGraphRouteResultSchema.js +19 -0
- package/script/helpers/validateGraphTemporalEvents.d.ts +7 -0
- package/script/helpers/validateGraphTemporalEvents.d.ts.map +1 -0
- package/script/helpers/validateGraphTemporalEvents.js +53 -0
- package/script/helpers/validateNumericalAnalysis.d.ts +10 -6
- package/script/helpers/validateNumericalAnalysis.d.ts.map +1 -1
- package/script/helpers/validateNumericalAnalysis.js +10 -6
- package/script/helpers/validateVectorRowIds.d.ts +4 -0
- package/script/helpers/validateVectorRowIds.d.ts.map +1 -0
- package/script/helpers/validateVectorRowIds.js +19 -0
- package/script/helpers/vectorDistanceExpression.d.ts +6 -0
- package/script/helpers/vectorDistanceExpression.d.ts.map +1 -0
- package/script/helpers/vectorDistanceExpression.js +14 -0
- package/script/helpers/wrapString.d.ts +10 -7
- package/script/helpers/wrapString.d.ts.map +1 -1
- package/script/helpers/wrapString.js +10 -7
- package/script/methods/addId.d.ts +5 -0
- package/script/methods/addId.d.ts.map +1 -0
- package/script/methods/addId.js +44 -0
- package/script/methods/commonNeighbors.d.ts +10 -0
- package/script/methods/commonNeighbors.d.ts.map +1 -0
- package/script/methods/commonNeighbors.js +140 -0
- package/script/methods/connectedComponents.d.ts +9 -0
- package/script/methods/connectedComponents.d.ts.map +1 -0
- package/script/methods/connectedComponents.js +186 -0
- package/script/methods/degree.d.ts +9 -0
- package/script/methods/degree.d.ts.map +1 -0
- package/script/methods/degree.js +141 -0
- package/script/methods/distances.d.ts +12 -0
- package/script/methods/distances.d.ts.map +1 -0
- package/script/methods/distances.js +203 -0
- package/script/methods/findCycles.d.ts +12 -0
- package/script/methods/findCycles.d.ts.map +1 -0
- package/script/methods/findCycles.js +369 -0
- package/script/methods/fuzzyClean.d.ts.map +1 -1
- package/script/methods/fuzzyClean.js +17 -136
- package/script/methods/fuzzyJoin.js +70 -16
- package/script/methods/getTypes.d.ts +1 -1
- package/script/methods/hdbscan.d.ts +5 -0
- package/script/methods/hdbscan.d.ts.map +1 -0
- package/script/methods/hdbscan.js +214 -0
- package/script/methods/mahalanobis.d.ts +5 -0
- package/script/methods/mahalanobis.d.ts.map +1 -0
- package/script/methods/mahalanobis.js +98 -0
- package/script/methods/neighbors.d.ts +9 -0
- package/script/methods/neighbors.d.ts.map +1 -0
- package/script/methods/neighbors.js +120 -0
- package/script/methods/normalizeVector.d.ts +5 -0
- package/script/methods/normalizeVector.d.ts.map +1 -0
- package/script/methods/normalizeVector.js +138 -0
- package/script/methods/paths.d.ts +12 -0
- package/script/methods/paths.d.ts.map +1 -0
- package/script/methods/paths.js +326 -0
- package/script/methods/reachable.d.ts +11 -0
- package/script/methods/reachable.d.ts.map +1 -0
- package/script/methods/reachable.js +170 -0
- package/script/methods/rowToVector.d.ts +5 -0
- package/script/methods/rowToVector.d.ts.map +1 -0
- package/script/methods/rowToVector.js +83 -0
- package/script/methods/shortestPath.d.ts +12 -0
- package/script/methods/shortestPath.d.ts.map +1 -0
- package/script/methods/shortestPath.js +376 -0
- package/script/methods/topologicalSort.d.ts +7 -0
- package/script/methods/topologicalSort.d.ts.map +1 -0
- package/script/methods/topologicalSort.js +170 -0
- package/script/methods/trim.d.ts +1 -1
- package/script/methods/trim.d.ts.map +1 -1
- package/script/methods/trim.js +17 -8
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { ARRAY, DOUBLE } from "@duckdb/node-api";
|
|
2
|
+
import { covarianceWhitening } from "./factorCovariance.js";
|
|
3
|
+
import quoteIdentifier from "./quoteIdentifier.js";
|
|
4
|
+
/** Evaluates bulk distances in DuckDB; the caller owns the returned scratch table. */
|
|
5
|
+
export default async function computeMahalanobisDistances(connection, input, model, referencePoint) {
|
|
6
|
+
const { dimensions, means, origins, meanOffsets } = model;
|
|
7
|
+
if ([means, origins, meanOffsets].some((values) => values.length !== dimensions)) {
|
|
8
|
+
throw new Error("The covariance centroid has the wrong dimensions.");
|
|
9
|
+
}
|
|
10
|
+
const vectorLiteral = (values) => {
|
|
11
|
+
if (values.some((value) => !Number.isFinite(value))) {
|
|
12
|
+
throw new Error("Mahalanobis centering requires finite coefficients.");
|
|
13
|
+
}
|
|
14
|
+
return `[${values.join(",")}]::DOUBLE[${dimensions}]`;
|
|
15
|
+
};
|
|
16
|
+
const originSql = vectorLiteral(origins);
|
|
17
|
+
const offsetSql = vectorLiteral(meanOffsets);
|
|
18
|
+
if (referencePoint !== undefined &&
|
|
19
|
+
(referencePoint.length !== dimensions ||
|
|
20
|
+
referencePoint.some((value) => !Number.isFinite(value)))) {
|
|
21
|
+
throw new Error("Mahalanobis reference point must contain one finite number per dimension.");
|
|
22
|
+
}
|
|
23
|
+
// Direct subtraction retains exact matches and tiny reference offsets that
|
|
24
|
+
// would be lost by subtracting the centroid from both points separately.
|
|
25
|
+
const centeredValue = referencePoint === undefined
|
|
26
|
+
? `(value - array_extract(${originSql}, dimension)) - array_extract(${offsetSql}, dimension)`
|
|
27
|
+
: `value - array_extract(${vectorLiteral(Float64Array.from(referencePoint))}, dimension)`;
|
|
28
|
+
const whitening = covarianceWhitening(model);
|
|
29
|
+
const suffix = crypto.randomUUID().replaceAll("-", "");
|
|
30
|
+
const relation = `__sda_mahalanobis_distances_${suffix}`;
|
|
31
|
+
const weights = `__sda_mahalanobis_weights_${suffix}`;
|
|
32
|
+
const rowIdColumn = "row_id";
|
|
33
|
+
const distanceColumn = "distance";
|
|
34
|
+
const cleanup = async () => {
|
|
35
|
+
await connection.run(`DROP TABLE IF EXISTS ${quoteIdentifier(relation)}`);
|
|
36
|
+
};
|
|
37
|
+
try {
|
|
38
|
+
await connection.run(`CREATE TEMP TABLE ${quoteIdentifier(weights)}
|
|
39
|
+
(weight DOUBLE[${dimensions}])`);
|
|
40
|
+
const appender = await connection.createAppender(weights);
|
|
41
|
+
try {
|
|
42
|
+
// Only O(d²) summary state crosses this boundary, one O(d) row at a time.
|
|
43
|
+
// Binding a native table avoids parsing a matrix-sized SQL literal and
|
|
44
|
+
// repeatedly evaluating it inside a per-observation lambda.
|
|
45
|
+
for (let row = 0; row < dimensions; row++) {
|
|
46
|
+
appender.appendArray(Array.from(whitening.subarray(row * dimensions, (row + 1) * dimensions)), ARRAY(DOUBLE, dimensions));
|
|
47
|
+
appender.endRow();
|
|
48
|
+
}
|
|
49
|
+
appender.flushSync();
|
|
50
|
+
}
|
|
51
|
+
finally {
|
|
52
|
+
appender.closeSync();
|
|
53
|
+
}
|
|
54
|
+
// Center once per observation. The cross product is consumed by a grouped
|
|
55
|
+
// aggregate: O(n d²) arithmetic, O(n d) centered storage, O(d²) coefficients,
|
|
56
|
+
// and O(n) aggregate/output state. Source vectors never enter JavaScript.
|
|
57
|
+
await connection.run(`CREATE TEMP TABLE ${quoteIdentifier(relation)} AS
|
|
58
|
+
WITH centered AS MATERIALIZED (
|
|
59
|
+
SELECT ${quoteIdentifier(input.rowIdColumn)} AS row_id,
|
|
60
|
+
list_transform(${quoteIdentifier(input.vectorColumn)},
|
|
61
|
+
(value, dimension) -> ${centeredValue})::DOUBLE[${dimensions}] AS vector
|
|
62
|
+
FROM ${quoteIdentifier(input.relation)}
|
|
63
|
+
), components AS MATERIALIZED (
|
|
64
|
+
SELECT row_id, abs(array_inner_product(weight, vector)) AS component
|
|
65
|
+
FROM centered CROSS JOIN ${quoteIdentifier(weights)}
|
|
66
|
+
), magnitudes AS (
|
|
67
|
+
SELECT row_id, max(component) AS magnitude FROM components GROUP BY row_id
|
|
68
|
+
)
|
|
69
|
+
SELECT row_id, CASE WHEN magnitude = 0 THEN 0::DOUBLE
|
|
70
|
+
ELSE magnitude * sqrt(sum(pow(component / magnitude, 2))) END AS distance
|
|
71
|
+
FROM components JOIN magnitudes USING (row_id)
|
|
72
|
+
GROUP BY row_id, magnitude`);
|
|
73
|
+
const invalid = Number((await connection.runAndReadAll(`SELECT count(*) FROM ${quoteIdentifier(relation)}
|
|
74
|
+
WHERE distance IS NULL OR NOT isfinite(distance)`)).getRowsJS()[0][0]);
|
|
75
|
+
if (invalid > 0) {
|
|
76
|
+
throw new Error(`Mahalanobis distance produced ${invalid} non-finite results. Rescale features or remove numerically unstable dimensions.`);
|
|
77
|
+
}
|
|
78
|
+
return { relation, rowIdColumn, distanceColumn, cleanup };
|
|
79
|
+
}
|
|
80
|
+
catch (error) {
|
|
81
|
+
await cleanup();
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
await connection.run(`DROP TABLE IF EXISTS ${quoteIdentifier(weights)}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
* Creates missing directories in an output path, including parent directories.
|
|
3
3
|
* Non-hidden path segments containing a dot are treated as filenames and omitted.
|
|
4
4
|
*
|
|
5
|
-
* @param path - An output file path or a directory path without dotted segments.
|
|
6
|
-
* @returns Nothing. Existing directories are left unchanged.
|
|
7
|
-
*
|
|
8
5
|
* @example
|
|
9
6
|
* ```ts
|
|
10
7
|
* import { createDirectory } from "@nshiab/simple-data-analysis-core/helpers";
|
|
11
8
|
* createDirectory("output/tables/results.csv"); // Creates output/tables.
|
|
12
9
|
* ```
|
|
10
|
+
*
|
|
11
|
+
* @param path - An output file path or a directory path without dotted segments.
|
|
12
|
+
*
|
|
13
|
+
* @returns Nothing. Existing directories are left unchanged.
|
|
13
14
|
*/
|
|
14
15
|
export default function createDirectory(path: string): void;
|
|
15
16
|
//# sourceMappingURL=createDirectory.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDirectory.d.ts","sourceRoot":"","sources":["../../src/helpers/createDirectory.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"createDirectory.d.ts","sourceRoot":"","sources":["../../src/helpers/createDirectory.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,OAAO,UAAU,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAS1D"}
|
|
@@ -3,14 +3,15 @@ import { existsSync, mkdirSync } from "node:fs";
|
|
|
3
3
|
* Creates missing directories in an output path, including parent directories.
|
|
4
4
|
* Non-hidden path segments containing a dot are treated as filenames and omitted.
|
|
5
5
|
*
|
|
6
|
-
* @param path - An output file path or a directory path without dotted segments.
|
|
7
|
-
* @returns Nothing. Existing directories are left unchanged.
|
|
8
|
-
*
|
|
9
6
|
* @example
|
|
10
7
|
* ```ts
|
|
11
8
|
* import { createDirectory } from "@nshiab/simple-data-analysis-core/helpers";
|
|
12
9
|
* createDirectory("output/tables/results.csv"); // Creates output/tables.
|
|
13
10
|
* ```
|
|
11
|
+
*
|
|
12
|
+
* @param path - An output file path or a directory path without dotted segments.
|
|
13
|
+
*
|
|
14
|
+
* @returns Nothing. Existing directories are left unchanged.
|
|
14
15
|
*/
|
|
15
16
|
export default function createDirectory(path) {
|
|
16
17
|
path = path
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Transforms an array of objects into an object of arrays. This function is the inverse of `arraysToData` and is useful for converting data from a row-based format to a columnar format.
|
|
3
3
|
*
|
|
4
|
-
* @param data An array of objects. Each object is expected to have the same set of keys.
|
|
5
|
-
*
|
|
6
|
-
* @returns An object where each key maps to an array of values, effectively representing the data in a columnar format.
|
|
7
|
-
*
|
|
8
4
|
* @example
|
|
9
5
|
* ```ts
|
|
10
6
|
* // Basic usage with a simple dataset
|
|
@@ -24,6 +20,7 @@
|
|
|
24
20
|
* // city: ['New York', 'London', 'Paris']
|
|
25
21
|
* // }
|
|
26
22
|
* ```
|
|
23
|
+
*
|
|
27
24
|
* @example
|
|
28
25
|
* ```ts
|
|
29
26
|
* // Preparing data for statistical analysis
|
|
@@ -43,6 +40,11 @@
|
|
|
43
40
|
* // humidity: [60, 65, 55]
|
|
44
41
|
* // }
|
|
45
42
|
* ```
|
|
43
|
+
*
|
|
44
|
+
* @param data An array of objects. Each object is expected to have the same set of keys.
|
|
45
|
+
*
|
|
46
|
+
* @returns An object where each key maps to an array of values, effectively representing the data in a columnar format.
|
|
47
|
+
*
|
|
46
48
|
* @category Formatting
|
|
47
49
|
*/
|
|
48
50
|
export default function dataToArrays<T extends Record<string, unknown>>(data: T[]): {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataToArrays.d.ts","sourceRoot":"","sources":["../../src/helpers/dataToArrays.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"dataToArrays.d.ts","sourceRoot":"","sources":["../../src/helpers/dataToArrays.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgDG;AAEH,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EACpE,IAAI,EAAE,CAAC,EAAE,GACR;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE;CAAE,CAU5B"}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Transforms an array of objects into an object of arrays. This function is the inverse of `arraysToData` and is useful for converting data from a row-based format to a columnar format.
|
|
3
3
|
*
|
|
4
|
-
* @param data An array of objects. Each object is expected to have the same set of keys.
|
|
5
|
-
*
|
|
6
|
-
* @returns An object where each key maps to an array of values, effectively representing the data in a columnar format.
|
|
7
|
-
*
|
|
8
4
|
* @example
|
|
9
5
|
* ```ts
|
|
10
6
|
* // Basic usage with a simple dataset
|
|
@@ -24,6 +20,7 @@
|
|
|
24
20
|
* // city: ['New York', 'London', 'Paris']
|
|
25
21
|
* // }
|
|
26
22
|
* ```
|
|
23
|
+
*
|
|
27
24
|
* @example
|
|
28
25
|
* ```ts
|
|
29
26
|
* // Preparing data for statistical analysis
|
|
@@ -43,6 +40,11 @@
|
|
|
43
40
|
* // humidity: [60, 65, 55]
|
|
44
41
|
* // }
|
|
45
42
|
* ```
|
|
43
|
+
*
|
|
44
|
+
* @param data An array of objects. Each object is expected to have the same set of keys.
|
|
45
|
+
*
|
|
46
|
+
* @returns An object where each key maps to an array of values, effectively representing the data in a columnar format.
|
|
47
|
+
*
|
|
46
48
|
* @category Formatting
|
|
47
49
|
*/
|
|
48
50
|
export default function dataToArrays(data) {
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
export default function extractTypes(types) {
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
typesObj[t.column_name] = t.column_type;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
return typesObj;
|
|
2
|
+
const rows = (types ?? []);
|
|
3
|
+
// Define own properties so valid names such as __proto__ do not invoke
|
|
4
|
+
// Object.prototype setters in Node.js.
|
|
5
|
+
return Object.fromEntries(rows.filter((row) => row.column_name).map((row) => [row.column_name, row.column_type]));
|
|
11
6
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type CovarianceFactor = {
|
|
2
|
+
dimensions: number;
|
|
3
|
+
covariance: Float64Array;
|
|
4
|
+
scales: Float64Array;
|
|
5
|
+
cholesky: Float64Array;
|
|
6
|
+
reciprocalCondition: number;
|
|
7
|
+
};
|
|
8
|
+
/** Factors a sample covariance matrix for stable repeated linear solves. */
|
|
9
|
+
export declare function factorCovariance(covarianceInput: ArrayLike<number>, dimensions: number): CovarianceFactor;
|
|
10
|
+
/** Solves covariance * x = rightHandSide through the scaled Cholesky factor. */
|
|
11
|
+
export declare function solveCovariance(factor: CovarianceFactor, rightHandSide: ArrayLike<number>): Float64Array;
|
|
12
|
+
/**
|
|
13
|
+
* Returns the lower-triangular transform whose squared norm is Mahalanobis
|
|
14
|
+
* squared distance. This inverts only the Cholesky factor, never covariance.
|
|
15
|
+
*/
|
|
16
|
+
export declare function covarianceWhitening(factor: CovarianceFactor): Float64Array;
|
|
17
|
+
//# sourceMappingURL=factorCovariance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"factorCovariance.d.ts","sourceRoot":"","sources":["../../src/helpers/factorCovariance.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,gBAAgB,GAAG;IAC7B,UAAU,EAAE,MAAM,CAAC;IACnB,UAAU,EAAE,YAAY,CAAC;IACzB,MAAM,EAAE,YAAY,CAAC;IACrB,QAAQ,EAAE,YAAY,CAAC;IACvB,mBAAmB,EAAE,MAAM,CAAC;CAC7B,CAAC;AAkGF,4EAA4E;AAC5E,wBAAgB,gBAAgB,CAC9B,eAAe,EAAE,SAAS,CAAC,MAAM,CAAC,EAClC,UAAU,EAAE,MAAM,GACjB,gBAAgB,CAoGlB;AAED,gFAAgF;AAChF,wBAAgB,eAAe,CAC7B,MAAM,EAAE,gBAAgB,EACxB,aAAa,EAAE,SAAS,CAAC,MAAM,CAAC,GAC/B,YAAY,CAsBd;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,gBAAgB,GACvB,YAAY,CA2Bd"}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
const instabilityMultiplier = 64;
|
|
2
|
+
function singularCovariance(reason) {
|
|
3
|
+
return new Error(`Covariance is singular or numerically unstable (${reason}). Constant columns, linearly dependent features, or too few observations are common causes. Remove redundant features or provide more observations.`);
|
|
4
|
+
}
|
|
5
|
+
function scaleCovarianceEntry(value, leftScale, rightScale) {
|
|
6
|
+
// Divide by the larger scale first. For a valid covariance, Cauchy-Schwarz
|
|
7
|
+
// bounds |value| by their product, so this avoids intermediate overflow when
|
|
8
|
+
// two otherwise equivalent features use radically different units.
|
|
9
|
+
return leftScale >= rightScale
|
|
10
|
+
? value / leftScale / rightScale
|
|
11
|
+
: value / rightScale / leftScale;
|
|
12
|
+
}
|
|
13
|
+
function solveCorrelation(cholesky, dimensions, rightHandSide) {
|
|
14
|
+
const solution = new Float64Array(dimensions);
|
|
15
|
+
for (let row = 0; row < dimensions; row++) {
|
|
16
|
+
let value = rightHandSide[row];
|
|
17
|
+
for (let column = 0; column < row; column++) {
|
|
18
|
+
value -= cholesky[row * dimensions + column] * solution[column];
|
|
19
|
+
}
|
|
20
|
+
solution[row] = value / cholesky[row * dimensions + row];
|
|
21
|
+
}
|
|
22
|
+
for (let row = dimensions - 1; row >= 0; row--) {
|
|
23
|
+
let value = solution[row];
|
|
24
|
+
for (let column = row + 1; column < dimensions; column++) {
|
|
25
|
+
value -= cholesky[column * dimensions + row] * solution[column];
|
|
26
|
+
}
|
|
27
|
+
solution[row] = value / cholesky[row * dimensions + row];
|
|
28
|
+
}
|
|
29
|
+
return solution;
|
|
30
|
+
}
|
|
31
|
+
// Hager's estimator avoids forming the inverse merely to decide whether the
|
|
32
|
+
// correlation-scaled covariance is safe to solve. Scaling first makes this
|
|
33
|
+
// rank decision invariant to a change of units in any feature.
|
|
34
|
+
function estimateInverseOneNorm(cholesky, dimensions) {
|
|
35
|
+
let vector = new Float64Array(dimensions).fill(1 / dimensions);
|
|
36
|
+
let estimate = 0;
|
|
37
|
+
let previousIndex = -1;
|
|
38
|
+
for (let iteration = 0; iteration < 8; iteration++) {
|
|
39
|
+
const solved = solveCorrelation(cholesky, dimensions, vector);
|
|
40
|
+
estimate = Math.max(estimate, solved.reduce((sum, value) => sum + Math.abs(value), 0));
|
|
41
|
+
const signs = solved.map((value) => value < 0 ? -1 : 1);
|
|
42
|
+
const dual = solveCorrelation(cholesky, dimensions, signs);
|
|
43
|
+
let index = 0;
|
|
44
|
+
for (let i = 1; i < dimensions; i++) {
|
|
45
|
+
if (Math.abs(dual[i]) > Math.abs(dual[index]))
|
|
46
|
+
index = i;
|
|
47
|
+
}
|
|
48
|
+
const directional = dual.reduce((sum, value, i) => sum + value * vector[i], 0);
|
|
49
|
+
if (Math.abs(dual[index]) <= directional || index === previousIndex)
|
|
50
|
+
break;
|
|
51
|
+
vector = new Float64Array(dimensions);
|
|
52
|
+
vector[index] = 1;
|
|
53
|
+
previousIndex = index;
|
|
54
|
+
}
|
|
55
|
+
// The all-positive initial vector can be an eigenvector that causes Hager's
|
|
56
|
+
// iteration to stop at the *smallest* inverse eigenvalue (for example an
|
|
57
|
+
// equicorrelation matrix). Higham's alternating, increasing-magnitude probe
|
|
58
|
+
// prevents that failure; normalize by its 1-norm to retain a lower estimate.
|
|
59
|
+
// Reference: https://www.netlib.org/lapack/double/dlacon.f (final stage).
|
|
60
|
+
const alternating = Float64Array.from({ length: dimensions }, (_, i) => (i % 2 === 0 ? 1 : -1) * (1 + i / Math.max(1, dimensions - 1)));
|
|
61
|
+
const alternatingNorm = alternating.reduce((sum, value) => sum + Math.abs(value), 0);
|
|
62
|
+
const solved = solveCorrelation(cholesky, dimensions, alternating);
|
|
63
|
+
estimate = Math.max(estimate, solved.reduce((sum, value) => sum + Math.abs(value), 0) / alternatingNorm);
|
|
64
|
+
return estimate;
|
|
65
|
+
}
|
|
66
|
+
/** Factors a sample covariance matrix for stable repeated linear solves. */
|
|
67
|
+
export function factorCovariance(covarianceInput, dimensions) {
|
|
68
|
+
if (!Number.isSafeInteger(dimensions) || dimensions < 1) {
|
|
69
|
+
throw new Error("Covariance dimensions must be a positive safe integer.");
|
|
70
|
+
}
|
|
71
|
+
if (covarianceInput.length !== dimensions * dimensions) {
|
|
72
|
+
throw new Error(`Expected ${dimensions * dimensions} covariance values, received ${covarianceInput.length}.`);
|
|
73
|
+
}
|
|
74
|
+
const covariance = Float64Array.from(covarianceInput);
|
|
75
|
+
const scales = new Float64Array(dimensions);
|
|
76
|
+
for (let dimension = 0; dimension < dimensions; dimension++) {
|
|
77
|
+
const variance = covariance[dimension * dimensions + dimension];
|
|
78
|
+
if (!Number.isFinite(variance) || variance <= 0) {
|
|
79
|
+
throw singularCovariance(`feature ${dimension + 1} has non-positive or non-finite sample variance`);
|
|
80
|
+
}
|
|
81
|
+
scales[dimension] = Math.sqrt(variance);
|
|
82
|
+
}
|
|
83
|
+
const correlation = new Float64Array(dimensions * dimensions);
|
|
84
|
+
let correlationOneNorm = 0;
|
|
85
|
+
for (let column = 0; column < dimensions; column++) {
|
|
86
|
+
let columnSum = 0;
|
|
87
|
+
for (let row = 0; row < dimensions; row++) {
|
|
88
|
+
const left = covariance[row * dimensions + column];
|
|
89
|
+
const right = covariance[column * dimensions + row];
|
|
90
|
+
if (!Number.isFinite(left) || !Number.isFinite(right)) {
|
|
91
|
+
throw singularCovariance("the sample covariance contains non-finite values");
|
|
92
|
+
}
|
|
93
|
+
const value = row === column ? 1 : scaleCovarianceEntry(left, scales[row], scales[column]) / 2 + scaleCovarianceEntry(right, scales[row], scales[column]) / 2;
|
|
94
|
+
if (!Number.isFinite(value)) {
|
|
95
|
+
throw singularCovariance("correlation scaling produced a non-finite value");
|
|
96
|
+
}
|
|
97
|
+
correlation[row * dimensions + column] = value;
|
|
98
|
+
columnSum += Math.abs(value);
|
|
99
|
+
}
|
|
100
|
+
correlationOneNorm = Math.max(correlationOneNorm, columnSum);
|
|
101
|
+
}
|
|
102
|
+
const cholesky = new Float64Array(dimensions * dimensions);
|
|
103
|
+
for (let row = 0; row < dimensions; row++) {
|
|
104
|
+
for (let column = 0; column <= row; column++) {
|
|
105
|
+
let value = correlation[row * dimensions + column];
|
|
106
|
+
for (let k = 0; k < column; k++) {
|
|
107
|
+
value -= cholesky[row * dimensions + k] *
|
|
108
|
+
cholesky[column * dimensions + k];
|
|
109
|
+
}
|
|
110
|
+
if (row === column) {
|
|
111
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
112
|
+
throw singularCovariance(`correlation-scaled Cholesky pivot ${row + 1} is not positive`);
|
|
113
|
+
}
|
|
114
|
+
cholesky[row * dimensions + column] = Math.sqrt(value);
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
cholesky[row * dimensions + column] = value /
|
|
118
|
+
cholesky[column * dimensions + column];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const inverseOneNorm = estimateInverseOneNorm(cholesky, dimensions);
|
|
123
|
+
const reciprocalCondition = 1 / (correlationOneNorm * inverseOneNorm);
|
|
124
|
+
// This is the usual dimension-scaled floating-point rank tolerance, with a
|
|
125
|
+
// modest safety factor for covariance aggregation and subsequent row solves.
|
|
126
|
+
const tolerance = instabilityMultiplier * dimensions * Number.EPSILON;
|
|
127
|
+
if (!Number.isFinite(reciprocalCondition) || reciprocalCondition <= tolerance) {
|
|
128
|
+
throw singularCovariance(`estimated reciprocal condition ${reciprocalCondition} is at or below ${tolerance}`);
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
dimensions,
|
|
132
|
+
covariance,
|
|
133
|
+
scales,
|
|
134
|
+
cholesky,
|
|
135
|
+
reciprocalCondition,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/** Solves covariance * x = rightHandSide through the scaled Cholesky factor. */
|
|
139
|
+
export function solveCovariance(factor, rightHandSide) {
|
|
140
|
+
const { dimensions, scales, cholesky } = factor;
|
|
141
|
+
if (rightHandSide.length !== dimensions) {
|
|
142
|
+
throw new Error(`Expected a right-hand side with ${dimensions} values, received ${rightHandSide.length}.`);
|
|
143
|
+
}
|
|
144
|
+
const scaled = new Float64Array(dimensions);
|
|
145
|
+
for (let i = 0; i < dimensions; i++) {
|
|
146
|
+
if (!Number.isFinite(rightHandSide[i])) {
|
|
147
|
+
throw new Error("The covariance solve requires finite values.");
|
|
148
|
+
}
|
|
149
|
+
scaled[i] = rightHandSide[i] / scales[i];
|
|
150
|
+
}
|
|
151
|
+
const solution = solveCorrelation(cholesky, dimensions, scaled);
|
|
152
|
+
for (let i = 0; i < dimensions; i++) {
|
|
153
|
+
solution[i] /= scales[i];
|
|
154
|
+
if (!Number.isFinite(solution[i])) {
|
|
155
|
+
throw singularCovariance("the linear solve produced a non-finite value");
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return solution;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Returns the lower-triangular transform whose squared norm is Mahalanobis
|
|
162
|
+
* squared distance. This inverts only the Cholesky factor, never covariance.
|
|
163
|
+
*/
|
|
164
|
+
export function covarianceWhitening(factor) {
|
|
165
|
+
const { dimensions, scales, cholesky } = factor;
|
|
166
|
+
const whitening = new Float64Array(dimensions * dimensions);
|
|
167
|
+
// Invert the triangular correlation factor first, then apply feature units.
|
|
168
|
+
// Keeping units out of the recurrence avoids repeated underflow/rounding of
|
|
169
|
+
// the same coefficient, and visits only the nonzero triangle.
|
|
170
|
+
for (let column = 0; column < dimensions; column++) {
|
|
171
|
+
for (let row = column; row < dimensions; row++) {
|
|
172
|
+
let value = row === column ? 1 : 0;
|
|
173
|
+
for (let k = column; k < row; k++) {
|
|
174
|
+
value -= cholesky[row * dimensions + k] *
|
|
175
|
+
whitening[k * dimensions + column];
|
|
176
|
+
}
|
|
177
|
+
whitening[row * dimensions + column] = value /
|
|
178
|
+
cholesky[row * dimensions + row];
|
|
179
|
+
}
|
|
180
|
+
for (let row = column; row < dimensions; row++) {
|
|
181
|
+
const index = row * dimensions + column;
|
|
182
|
+
whitening[index] /= scales[column];
|
|
183
|
+
if (!Number.isFinite(whitening[index])) {
|
|
184
|
+
throw singularCovariance("the whitening transform produced a non-finite value");
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
return whitening;
|
|
189
|
+
}
|
|
@@ -2,14 +2,16 @@ import type SimpleTable from "../class/SimpleTable.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* Returns the only geometry column in a table.
|
|
4
4
|
*
|
|
5
|
-
* @param simpleTable - The table to inspect.
|
|
6
|
-
* @param method - The SDA method requesting a geometry column.
|
|
7
|
-
* @returns A promise resolving to the name of the only geometry column.
|
|
8
|
-
*
|
|
9
5
|
* @example
|
|
10
6
|
* ```ts
|
|
11
7
|
* const column = await findGeoColumn(table, "getGeoData()");
|
|
12
8
|
* ```
|
|
9
|
+
*
|
|
10
|
+
* @param simpleTable - The table to inspect.
|
|
11
|
+
*
|
|
12
|
+
* @param method - The SDA method requesting a geometry column.
|
|
13
|
+
*
|
|
14
|
+
* @returns A promise resolving to the name of the only geometry column.
|
|
13
15
|
*/
|
|
14
16
|
export default function findGeoColumn(simpleTable: SimpleTable, method: string): Promise<string>;
|
|
15
17
|
//# sourceMappingURL=findGeoColumn.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findGeoColumn.d.ts","sourceRoot":"","sources":["../../src/helpers/findGeoColumn.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAEvD
|
|
1
|
+
{"version":3,"file":"findGeoColumn.d.ts","sourceRoot":"","sources":["../../src/helpers/findGeoColumn.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAEvD;;;;;;;;;;;;;GAaG;AACH,wBAA8B,aAAa,CACzC,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,MAAM,CAAC,CAMjB"}
|
|
@@ -2,14 +2,16 @@ import findGeoColumnFromSchema from "./findGeoColumnFromSchema.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* Returns the only geometry column in a table.
|
|
4
4
|
*
|
|
5
|
-
* @param simpleTable - The table to inspect.
|
|
6
|
-
* @param method - The SDA method requesting a geometry column.
|
|
7
|
-
* @returns A promise resolving to the name of the only geometry column.
|
|
8
|
-
*
|
|
9
5
|
* @example
|
|
10
6
|
* ```ts
|
|
11
7
|
* const column = await findGeoColumn(table, "getGeoData()");
|
|
12
8
|
* ```
|
|
9
|
+
*
|
|
10
|
+
* @param simpleTable - The table to inspect.
|
|
11
|
+
*
|
|
12
|
+
* @param method - The SDA method requesting a geometry column.
|
|
13
|
+
*
|
|
14
|
+
* @returns A promise resolving to the name of the only geometry column.
|
|
13
15
|
*/
|
|
14
16
|
export default async function findGeoColumn(simpleTable, method) {
|
|
15
17
|
return findGeoColumnFromSchema(await simpleTable.getTypes(), method, simpleTable.name);
|
|
@@ -2,11 +2,6 @@ import type { TableSchema } from "./pendingOps.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* Returns the only geometry column in a table schema.
|
|
4
4
|
*
|
|
5
|
-
* @param types - The table schema to inspect.
|
|
6
|
-
* @param method - The SDA method requesting a geometry column.
|
|
7
|
-
* @param tableName - The name of the table represented by the schema.
|
|
8
|
-
* @returns The name of the only geometry column.
|
|
9
|
-
*
|
|
10
5
|
* @example
|
|
11
6
|
* ```ts
|
|
12
7
|
* const column = findGeoColumnFromSchema(
|
|
@@ -15,6 +10,14 @@ import type { TableSchema } from "./pendingOps.js";
|
|
|
15
10
|
* "places",
|
|
16
11
|
* );
|
|
17
12
|
* ```
|
|
13
|
+
*
|
|
14
|
+
* @param types - The table schema to inspect.
|
|
15
|
+
*
|
|
16
|
+
* @param method - The SDA method requesting a geometry column.
|
|
17
|
+
*
|
|
18
|
+
* @param tableName - The name of the table represented by the schema.
|
|
19
|
+
*
|
|
20
|
+
* @returns The name of the only geometry column.
|
|
18
21
|
*/
|
|
19
22
|
export default function findGeoColumnFromSchema(types: TableSchema, method: string, tableName: string): string;
|
|
20
23
|
//# sourceMappingURL=findGeoColumnFromSchema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findGeoColumnFromSchema.d.ts","sourceRoot":"","sources":["../../src/helpers/findGeoColumnFromSchema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD
|
|
1
|
+
{"version":3,"file":"findGeoColumnFromSchema.d.ts","sourceRoot":"","sources":["../../src/helpers/findGeoColumnFromSchema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,OAAO,UAAU,uBAAuB,CAC7C,KAAK,EAAE,WAAW,EAClB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,GAChB,MAAM,CAoBR"}
|
|
@@ -2,11 +2,6 @@ import quoteIdentifier from "./quoteIdentifier.js";
|
|
|
2
2
|
/**
|
|
3
3
|
* Returns the only geometry column in a table schema.
|
|
4
4
|
*
|
|
5
|
-
* @param types - The table schema to inspect.
|
|
6
|
-
* @param method - The SDA method requesting a geometry column.
|
|
7
|
-
* @param tableName - The name of the table represented by the schema.
|
|
8
|
-
* @returns The name of the only geometry column.
|
|
9
|
-
*
|
|
10
5
|
* @example
|
|
11
6
|
* ```ts
|
|
12
7
|
* const column = findGeoColumnFromSchema(
|
|
@@ -15,6 +10,14 @@ import quoteIdentifier from "./quoteIdentifier.js";
|
|
|
15
10
|
* "places",
|
|
16
11
|
* );
|
|
17
12
|
* ```
|
|
13
|
+
*
|
|
14
|
+
* @param types - The table schema to inspect.
|
|
15
|
+
*
|
|
16
|
+
* @param method - The SDA method requesting a geometry column.
|
|
17
|
+
*
|
|
18
|
+
* @param tableName - The name of the table represented by the schema.
|
|
19
|
+
*
|
|
20
|
+
* @returns The name of the only geometry column.
|
|
18
21
|
*/
|
|
19
22
|
export default function findGeoColumnFromSchema(types, method, tableName) {
|
|
20
23
|
const geometryColumns = Object.keys(types).filter((column) => types[column].toLowerCase().includes("geometry")).sort();
|
|
@@ -2,12 +2,6 @@
|
|
|
2
2
|
* Formats a `Date` object into a human-readable string using only the format
|
|
3
3
|
* strings actually used in the project.
|
|
4
4
|
*
|
|
5
|
-
* @param date - The `Date` object to format.
|
|
6
|
-
* @param format - The format string to use. Only `"Month DD, YYYY, at HH:MM period"` and `"Month DD"` are supported.
|
|
7
|
-
* @param options - Optional settings.
|
|
8
|
-
* @param options.utc - If `true`, format the date in UTC instead of local time. Defaults to `false`.
|
|
9
|
-
* @returns The formatted date string.
|
|
10
|
-
*
|
|
11
5
|
* @example
|
|
12
6
|
* ```ts
|
|
13
7
|
* // Format a date with time (local time).
|
|
@@ -15,18 +9,30 @@
|
|
|
15
9
|
* const formatted = formatDate(date, "Month DD, YYYY, at HH:MM period");
|
|
16
10
|
* console.log(formatted); // "January 1, 2023, at 1:35 a.m."
|
|
17
11
|
* ```
|
|
12
|
+
*
|
|
18
13
|
* @example
|
|
19
14
|
* ```ts
|
|
20
15
|
* // Format a date as month and day only (UTC).
|
|
21
16
|
* const formatted = formatDate(new Date("2023-01-01"), "Month DD", { utc: true });
|
|
22
17
|
* console.log(formatted); // "January 1"
|
|
23
18
|
* ```
|
|
19
|
+
*
|
|
24
20
|
* @example
|
|
25
21
|
* ```ts
|
|
26
22
|
* // Minutes of ":00" are omitted.
|
|
27
23
|
* const formatted = formatDate(new Date("2023-01-01T01:00:00"), "Month DD, YYYY, at HH:MM period", { utc: true });
|
|
28
24
|
* console.log(formatted); // "January 1, 2023, at 1 a.m."
|
|
29
25
|
* ```
|
|
26
|
+
*
|
|
27
|
+
* @param date - The `Date` object to format.
|
|
28
|
+
*
|
|
29
|
+
* @param format - The format string to use. Only `"Month DD, YYYY, at HH:MM period"` and `"Month DD"` are supported.
|
|
30
|
+
*
|
|
31
|
+
* @param options - Optional settings.
|
|
32
|
+
*
|
|
33
|
+
* @param options.utc - If `true`, format the date in UTC instead of local time. Defaults to `false`.
|
|
34
|
+
*
|
|
35
|
+
* @returns The formatted date string.
|
|
30
36
|
*/
|
|
31
37
|
export default function formatDate(date: Date, format: "Month DD, YYYY, at HH:MM period" | "Month DD", options?: {
|
|
32
38
|
utc?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formatDate.d.ts","sourceRoot":"","sources":["../../src/helpers/formatDate.ts"],"names":[],"mappings":"AAeA
|
|
1
|
+
{"version":3,"file":"formatDate.d.ts","sourceRoot":"","sources":["../../src/helpers/formatDate.ts"],"names":[],"mappings":"AAeA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAChC,IAAI,EAAE,IAAI,EACV,MAAM,EAAE,iCAAiC,GAAG,UAAU,EACtD,OAAO,GAAE;IAAE,GAAG,CAAC,EAAE,OAAO,CAAA;CAAO,GAC9B,MAAM,CA2BR"}
|
|
@@ -16,12 +16,6 @@ const MONTHS = [
|
|
|
16
16
|
* Formats a `Date` object into a human-readable string using only the format
|
|
17
17
|
* strings actually used in the project.
|
|
18
18
|
*
|
|
19
|
-
* @param date - The `Date` object to format.
|
|
20
|
-
* @param format - The format string to use. Only `"Month DD, YYYY, at HH:MM period"` and `"Month DD"` are supported.
|
|
21
|
-
* @param options - Optional settings.
|
|
22
|
-
* @param options.utc - If `true`, format the date in UTC instead of local time. Defaults to `false`.
|
|
23
|
-
* @returns The formatted date string.
|
|
24
|
-
*
|
|
25
19
|
* @example
|
|
26
20
|
* ```ts
|
|
27
21
|
* // Format a date with time (local time).
|
|
@@ -29,18 +23,30 @@ const MONTHS = [
|
|
|
29
23
|
* const formatted = formatDate(date, "Month DD, YYYY, at HH:MM period");
|
|
30
24
|
* console.log(formatted); // "January 1, 2023, at 1:35 a.m."
|
|
31
25
|
* ```
|
|
26
|
+
*
|
|
32
27
|
* @example
|
|
33
28
|
* ```ts
|
|
34
29
|
* // Format a date as month and day only (UTC).
|
|
35
30
|
* const formatted = formatDate(new Date("2023-01-01"), "Month DD", { utc: true });
|
|
36
31
|
* console.log(formatted); // "January 1"
|
|
37
32
|
* ```
|
|
33
|
+
*
|
|
38
34
|
* @example
|
|
39
35
|
* ```ts
|
|
40
36
|
* // Minutes of ":00" are omitted.
|
|
41
37
|
* const formatted = formatDate(new Date("2023-01-01T01:00:00"), "Month DD, YYYY, at HH:MM period", { utc: true });
|
|
42
38
|
* console.log(formatted); // "January 1, 2023, at 1 a.m."
|
|
43
39
|
* ```
|
|
40
|
+
*
|
|
41
|
+
* @param date - The `Date` object to format.
|
|
42
|
+
*
|
|
43
|
+
* @param format - The format string to use. Only `"Month DD, YYYY, at HH:MM period"` and `"Month DD"` are supported.
|
|
44
|
+
*
|
|
45
|
+
* @param options - Optional settings.
|
|
46
|
+
*
|
|
47
|
+
* @param options.utc - If `true`, format the date in UTC instead of local time. Defaults to `false`.
|
|
48
|
+
*
|
|
49
|
+
* @returns The formatted date string.
|
|
44
50
|
*/
|
|
45
51
|
export default function formatDate(date, format, options = {}) {
|
|
46
52
|
const getFullYear = options.utc ? date.getUTCFullYear : date.getFullYear;
|