@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,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = buildWeakGraphComponentsSql;
|
|
7
|
+
const quoteIdentifier_js_1 = __importDefault(require("./quoteIdentifier.js"));
|
|
8
|
+
/** Builds weak component labels and zero-based IDs from bidirectional edges. */
|
|
9
|
+
function buildWeakGraphComponentsSql(edges, nodes, labels, roots) {
|
|
10
|
+
const q = quoteIdentifier_js_1.default;
|
|
11
|
+
return `${labels}(
|
|
12
|
+
${q("node")}, ${q("__node_key")}, ${q("__root_key")}
|
|
13
|
+
) USING KEY(${q("__node_key")}) AS (
|
|
14
|
+
SELECT ${q("node")}, ${q("__key")}, ${q("__key")}
|
|
15
|
+
FROM ${nodes}
|
|
16
|
+
UNION
|
|
17
|
+
SELECT ${q("edges")}.${q("__to")},
|
|
18
|
+
${q("edges")}.${q("__to_key")},
|
|
19
|
+
MIN(${q("reached")}.${q("__root_key")})
|
|
20
|
+
FROM ${labels} AS ${q("reached")}
|
|
21
|
+
INNER JOIN ${edges} AS ${q("edges")}
|
|
22
|
+
ON ${q("reached")}.${q("__node_key")} =
|
|
23
|
+
${q("edges")}.${q("__from_key")}
|
|
24
|
+
INNER JOIN recurring.${labels} AS ${q("best")}
|
|
25
|
+
ON ${q("edges")}.${q("__to_key")} =
|
|
26
|
+
${q("best")}.${q("__node_key")}
|
|
27
|
+
GROUP BY ${q("edges")}.${q("__to")},
|
|
28
|
+
${q("edges")}.${q("__to_key")}, ${q("best")}.${q("__root_key")}
|
|
29
|
+
HAVING MIN(${q("reached")}.${q("__root_key")}) <
|
|
30
|
+
${q("best")}.${q("__root_key")}
|
|
31
|
+
), ${roots} AS (
|
|
32
|
+
SELECT ${q("__root_key")},
|
|
33
|
+
CAST(row_number() OVER (ORDER BY ${q("__root_key")}) - 1 AS BIGINT)
|
|
34
|
+
AS ${q("componentId")}
|
|
35
|
+
FROM (SELECT DISTINCT ${q("__root_key")} FROM ${labels})
|
|
36
|
+
AS ${q("distinct_roots")}
|
|
37
|
+
)`;
|
|
38
|
+
}
|
|
@@ -2,29 +2,31 @@
|
|
|
2
2
|
* Converts a string into camelCase. This is useful for creating variable
|
|
3
3
|
* names or object keys from human-readable text.
|
|
4
4
|
*
|
|
5
|
-
* @param input - The string to convert to camelCase. It can contain spaces,
|
|
6
|
-
* punctuation, and mixed casing.
|
|
7
|
-
*
|
|
8
|
-
* @returns The camelCased version of the input string.
|
|
9
|
-
*
|
|
10
5
|
* @example
|
|
11
6
|
* ```ts
|
|
12
7
|
* // Basic conversion
|
|
13
8
|
* const result1 = camelCase("hello world");
|
|
14
9
|
* console.log(result1); // "helloWorld"
|
|
15
10
|
* ```
|
|
11
|
+
*
|
|
16
12
|
* @example
|
|
17
13
|
* ```ts
|
|
18
14
|
* // With punctuation and mixed case
|
|
19
15
|
* const result2 = camelCase(" --Some@Thing is- happening-- ");
|
|
20
16
|
* console.log(result2); // "someThingIsHappening"
|
|
21
17
|
* ```
|
|
18
|
+
*
|
|
22
19
|
* @example
|
|
23
20
|
* ```ts
|
|
24
21
|
* // With a single word
|
|
25
22
|
* const result3 = camelCase("Journalism");
|
|
26
23
|
* console.log(result3); // "journalism"
|
|
27
24
|
* ```
|
|
25
|
+
*
|
|
26
|
+
* @param input - The string to convert to camelCase. It can contain spaces,
|
|
27
|
+
* punctuation, and mixed casing.
|
|
28
|
+
*
|
|
29
|
+
* @returns The camelCased version of the input string.
|
|
28
30
|
*/
|
|
29
31
|
export default function camelCase(input: string): string;
|
|
30
32
|
//# sourceMappingURL=camelCase.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"camelCase.d.ts","sourceRoot":"","sources":["../../src/helpers/camelCase.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"camelCase.d.ts","sourceRoot":"","sources":["../../src/helpers/camelCase.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAiBvD"}
|
|
@@ -9,29 +9,31 @@ const capitalize_js_1 = __importDefault(require("./capitalize.js"));
|
|
|
9
9
|
* Converts a string into camelCase. This is useful for creating variable
|
|
10
10
|
* names or object keys from human-readable text.
|
|
11
11
|
*
|
|
12
|
-
* @param input - The string to convert to camelCase. It can contain spaces,
|
|
13
|
-
* punctuation, and mixed casing.
|
|
14
|
-
*
|
|
15
|
-
* @returns The camelCased version of the input string.
|
|
16
|
-
*
|
|
17
12
|
* @example
|
|
18
13
|
* ```ts
|
|
19
14
|
* // Basic conversion
|
|
20
15
|
* const result1 = camelCase("hello world");
|
|
21
16
|
* console.log(result1); // "helloWorld"
|
|
22
17
|
* ```
|
|
18
|
+
*
|
|
23
19
|
* @example
|
|
24
20
|
* ```ts
|
|
25
21
|
* // With punctuation and mixed case
|
|
26
22
|
* const result2 = camelCase(" --Some@Thing is- happening-- ");
|
|
27
23
|
* console.log(result2); // "someThingIsHappening"
|
|
28
24
|
* ```
|
|
25
|
+
*
|
|
29
26
|
* @example
|
|
30
27
|
* ```ts
|
|
31
28
|
* // With a single word
|
|
32
29
|
* const result3 = camelCase("Journalism");
|
|
33
30
|
* console.log(result3); // "journalism"
|
|
34
31
|
* ```
|
|
32
|
+
*
|
|
33
|
+
* @param input - The string to convert to camelCase. It can contain spaces,
|
|
34
|
+
* punctuation, and mixed casing.
|
|
35
|
+
*
|
|
36
|
+
* @returns The camelCased version of the input string.
|
|
35
37
|
*/
|
|
36
38
|
function camelCase(input) {
|
|
37
39
|
const words = input
|
|
@@ -1,28 +1,30 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Capitalizes the first letter of a given string.
|
|
3
3
|
*
|
|
4
|
-
* @param string - The string to be capitalized.
|
|
5
|
-
*
|
|
6
|
-
* @returns A new string with the first letter in uppercase.
|
|
7
|
-
*
|
|
8
4
|
* @example
|
|
9
5
|
* ```ts
|
|
10
6
|
* // Basic usage
|
|
11
7
|
* const capitalized = capitalize("hello world");
|
|
12
8
|
* console.log(capitalized); // "Hello world"
|
|
13
9
|
* ```
|
|
10
|
+
*
|
|
14
11
|
* @example
|
|
15
12
|
* ```ts
|
|
16
13
|
* // With an already capitalized string
|
|
17
14
|
* const alreadyCapitalized = capitalize("Journalism");
|
|
18
15
|
* console.log(alreadyCapitalized); // "Journalism"
|
|
19
16
|
* ```
|
|
17
|
+
*
|
|
20
18
|
* @example
|
|
21
19
|
* ```ts
|
|
22
20
|
* // With a single character
|
|
23
21
|
* const singleChar = capitalize("a");
|
|
24
22
|
* console.log(singleChar); // "A"
|
|
25
23
|
* ```
|
|
24
|
+
*
|
|
25
|
+
* @param string - The string to be capitalized.
|
|
26
|
+
*
|
|
27
|
+
* @returns A new string with the first letter in uppercase.
|
|
26
28
|
*/
|
|
27
29
|
export default function capitalize(string: string): string;
|
|
28
30
|
//# sourceMappingURL=capitalize.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capitalize.d.ts","sourceRoot":"","sources":["../../src/helpers/capitalize.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"capitalize.d.ts","sourceRoot":"","sources":["../../src/helpers/capitalize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAMzD"}
|
|
@@ -4,28 +4,30 @@ exports.default = capitalize;
|
|
|
4
4
|
/**
|
|
5
5
|
* Capitalizes the first letter of a given string.
|
|
6
6
|
*
|
|
7
|
-
* @param string - The string to be capitalized.
|
|
8
|
-
*
|
|
9
|
-
* @returns A new string with the first letter in uppercase.
|
|
10
|
-
*
|
|
11
7
|
* @example
|
|
12
8
|
* ```ts
|
|
13
9
|
* // Basic usage
|
|
14
10
|
* const capitalized = capitalize("hello world");
|
|
15
11
|
* console.log(capitalized); // "Hello world"
|
|
16
12
|
* ```
|
|
13
|
+
*
|
|
17
14
|
* @example
|
|
18
15
|
* ```ts
|
|
19
16
|
* // With an already capitalized string
|
|
20
17
|
* const alreadyCapitalized = capitalize("Journalism");
|
|
21
18
|
* console.log(alreadyCapitalized); // "Journalism"
|
|
22
19
|
* ```
|
|
20
|
+
*
|
|
23
21
|
* @example
|
|
24
22
|
* ```ts
|
|
25
23
|
* // With a single character
|
|
26
24
|
* const singleChar = capitalize("a");
|
|
27
25
|
* console.log(singleChar); // "A"
|
|
28
26
|
* ```
|
|
27
|
+
*
|
|
28
|
+
* @param string - The string to be capitalized.
|
|
29
|
+
*
|
|
30
|
+
* @returns A new string with the first letter in uppercase.
|
|
29
31
|
*/
|
|
30
32
|
function capitalize(string) {
|
|
31
33
|
if (string.length === 0) {
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { DuckDBConnection } from "@duckdb/node-api";
|
|
2
|
+
/**
|
|
3
|
+
* Build the condensed hierarchy, select EOM clusters, and calculate point
|
|
4
|
+
* outputs from an HDBSCAN mutual-reachability MST. Only O(n) graph/hierarchy
|
|
5
|
+
* state crosses from DuckDB; source vectors remain native.
|
|
6
|
+
*/
|
|
7
|
+
export default function clusterHdbscan(connection: DuckDBConnection, mst: string, options: {
|
|
8
|
+
count: number;
|
|
9
|
+
minClusterSize: number;
|
|
10
|
+
allowSingleCluster: boolean;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
labels: Int32Array;
|
|
13
|
+
probabilities: Float64Array;
|
|
14
|
+
outlierScores: Float64Array;
|
|
15
|
+
}>;
|
|
16
|
+
/** Match a C float accumulator, including rounding after every addition. */
|
|
17
|
+
export declare function accumulateFloat32(values: number[]): number;
|
|
18
|
+
//# sourceMappingURL=clusterHdbscan.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clusterHdbscan.d.ts","sourceRoot":"","sources":["../../src/helpers/clusterHdbscan.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAWzD;;;;GAIG;AACH,wBAA8B,cAAc,CAC1C,UAAU,EAAE,gBAAgB,EAC5B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE;IACP,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,kBAAkB,EAAE,OAAO,CAAC;CAC7B,GACA,OAAO,CAAC;IACT,MAAM,EAAE,UAAU,CAAC;IACnB,aAAa,EAAE,YAAY,CAAC;IAC5B,aAAa,EAAE,YAAY,CAAC;CAC7B,CAAC,CAcD;AA4YD,4EAA4E;AAC5E,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAI1D"}
|
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = clusterHdbscan;
|
|
4
|
+
exports.accumulateFloat32 = accumulateFloat32;
|
|
5
|
+
/**
|
|
6
|
+
* Build the condensed hierarchy, select EOM clusters, and calculate point
|
|
7
|
+
* outputs from an HDBSCAN mutual-reachability MST. Only O(n) graph/hierarchy
|
|
8
|
+
* state crosses from DuckDB; source vectors remain native.
|
|
9
|
+
*/
|
|
10
|
+
async function clusterHdbscan(connection, mst, options) {
|
|
11
|
+
// Leaves and internal nodes share the signed Int32 hierarchy namespace.
|
|
12
|
+
if (!Number.isSafeInteger(options.count) || options.count < 2 ||
|
|
13
|
+
options.count > 0x40000000) {
|
|
14
|
+
throw new Error("HDBSCAN hierarchy requires between 2 and 1073741824 rows so all 2*n-1 node identifiers fit signed INTEGER state.");
|
|
15
|
+
}
|
|
16
|
+
const edges = await readMst(connection, mst, options.count);
|
|
17
|
+
const linkage = buildSingleLinkage(edges, options.count);
|
|
18
|
+
const tree = condenseTree(linkage, options.count, options.minClusterSize);
|
|
19
|
+
return selectClusters(tree, options.count, options.allowSingleCluster);
|
|
20
|
+
}
|
|
21
|
+
async function readMst(connection, mst, count) {
|
|
22
|
+
const edges = [];
|
|
23
|
+
const result = await connection.stream(`SELECT source,target,distance FROM ${mst}`);
|
|
24
|
+
while (true) {
|
|
25
|
+
const chunk = await result.fetchChunk();
|
|
26
|
+
if (!chunk || chunk.rowCount === 0)
|
|
27
|
+
break;
|
|
28
|
+
const sources = chunk.getColumnVector(0);
|
|
29
|
+
const targets = chunk.getColumnVector(1);
|
|
30
|
+
const distances = chunk.getColumnVector(2);
|
|
31
|
+
for (let row = 0; row < chunk.rowCount; row++) {
|
|
32
|
+
const rawSource = sources.getItem(row);
|
|
33
|
+
const rawTarget = targets.getItem(row);
|
|
34
|
+
const rawDistance = distances.getItem(row);
|
|
35
|
+
if (rawSource === null || rawSource === undefined ||
|
|
36
|
+
rawTarget === null || rawTarget === undefined ||
|
|
37
|
+
rawDistance === null || rawDistance === undefined) {
|
|
38
|
+
throw new Error("HDBSCAN mutual-reachability MST contains an invalid edge.");
|
|
39
|
+
}
|
|
40
|
+
const source = Number(rawSource);
|
|
41
|
+
const target = Number(rawTarget);
|
|
42
|
+
const distance = Number(rawDistance);
|
|
43
|
+
if (!Number.isSafeInteger(source) || source < 0 || source >= count ||
|
|
44
|
+
!Number.isSafeInteger(target) || target < 0 || target >= count ||
|
|
45
|
+
source === target || !Number.isFinite(distance) || distance < 0) {
|
|
46
|
+
throw new Error("HDBSCAN mutual-reachability MST contains an invalid edge.");
|
|
47
|
+
}
|
|
48
|
+
edges.push({ source, target, distance });
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
if (edges.length !== count - 1) {
|
|
52
|
+
throw new Error(`HDBSCAN mutual-reachability MST returned ${edges.length} edges; ${count - 1} were required.`);
|
|
53
|
+
}
|
|
54
|
+
return edges;
|
|
55
|
+
}
|
|
56
|
+
function buildSingleLinkage(edges, count) {
|
|
57
|
+
edges.sort((a, b) => a.distance - b.distance ||
|
|
58
|
+
Math.min(a.source, a.target) - Math.min(b.source, b.target) ||
|
|
59
|
+
Math.max(a.source, a.target) - Math.max(b.source, b.target));
|
|
60
|
+
const parent = new Int32Array(count);
|
|
61
|
+
const size = new Int32Array(count).fill(1);
|
|
62
|
+
const node = new Int32Array(count);
|
|
63
|
+
for (let vertex = 0; vertex < count; vertex++) {
|
|
64
|
+
parent[vertex] = vertex;
|
|
65
|
+
node[vertex] = vertex;
|
|
66
|
+
}
|
|
67
|
+
const find = (start) => {
|
|
68
|
+
let root = start;
|
|
69
|
+
while (parent[root] !== root)
|
|
70
|
+
root = parent[root];
|
|
71
|
+
let current = start;
|
|
72
|
+
while (parent[current] !== current) {
|
|
73
|
+
const next = parent[current];
|
|
74
|
+
parent[current] = root;
|
|
75
|
+
current = next;
|
|
76
|
+
}
|
|
77
|
+
return root;
|
|
78
|
+
};
|
|
79
|
+
const linkage = [];
|
|
80
|
+
for (const edge of edges) {
|
|
81
|
+
let leftRoot = find(edge.source);
|
|
82
|
+
let rightRoot = find(edge.target);
|
|
83
|
+
if (leftRoot === rightRoot) {
|
|
84
|
+
throw new Error("HDBSCAN mutual-reachability edges do not form a tree.");
|
|
85
|
+
}
|
|
86
|
+
const combinedNode = count + linkage.length;
|
|
87
|
+
const combinedSize = size[leftRoot] + size[rightRoot];
|
|
88
|
+
linkage.push({
|
|
89
|
+
left: node[leftRoot],
|
|
90
|
+
right: node[rightRoot],
|
|
91
|
+
distance: edge.distance,
|
|
92
|
+
size: combinedSize,
|
|
93
|
+
});
|
|
94
|
+
if (size[leftRoot] < size[rightRoot]) {
|
|
95
|
+
[leftRoot, rightRoot] = [rightRoot, leftRoot];
|
|
96
|
+
}
|
|
97
|
+
parent[rightRoot] = leftRoot;
|
|
98
|
+
size[leftRoot] = combinedSize;
|
|
99
|
+
node[leftRoot] = combinedNode;
|
|
100
|
+
}
|
|
101
|
+
if (linkage.length !== count - 1 || linkage.at(-1)?.size !== count) {
|
|
102
|
+
throw new Error("HDBSCAN mutual-reachability edges do not form one connected tree.");
|
|
103
|
+
}
|
|
104
|
+
return linkage;
|
|
105
|
+
}
|
|
106
|
+
function condenseTree(hierarchy, count, minClusterSize) {
|
|
107
|
+
const root = 2 * count - 2;
|
|
108
|
+
const relabel = new Int32Array(root + 1).fill(-1);
|
|
109
|
+
relabel[root] = count;
|
|
110
|
+
let nextLabel = count + 1;
|
|
111
|
+
const ignored = new Uint8Array(root + 1);
|
|
112
|
+
const result = [];
|
|
113
|
+
for (const current of breadthFirstHierarchy(hierarchy, count, root)) {
|
|
114
|
+
if (ignored[current] || current < count)
|
|
115
|
+
continue;
|
|
116
|
+
const split = hierarchy[current - count];
|
|
117
|
+
const lambda = split.distance > 0 ? 1 / split.distance : Infinity;
|
|
118
|
+
const leftSize = split.left >= count
|
|
119
|
+
? hierarchy[split.left - count].size
|
|
120
|
+
: 1;
|
|
121
|
+
const rightSize = split.right >= count
|
|
122
|
+
? hierarchy[split.right - count].size
|
|
123
|
+
: 1;
|
|
124
|
+
if (leftSize >= minClusterSize && rightSize >= minClusterSize) {
|
|
125
|
+
relabel[split.left] = nextLabel++;
|
|
126
|
+
result.push({
|
|
127
|
+
parent: relabel[current],
|
|
128
|
+
child: relabel[split.left],
|
|
129
|
+
lambda,
|
|
130
|
+
childSize: leftSize,
|
|
131
|
+
});
|
|
132
|
+
relabel[split.right] = nextLabel++;
|
|
133
|
+
result.push({
|
|
134
|
+
parent: relabel[current],
|
|
135
|
+
child: relabel[split.right],
|
|
136
|
+
lambda,
|
|
137
|
+
childSize: rightSize,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
else if (leftSize < minClusterSize && rightSize < minClusterSize) {
|
|
141
|
+
appendRunt(hierarchy, count, split.left, relabel[current], lambda, ignored, result);
|
|
142
|
+
appendRunt(hierarchy, count, split.right, relabel[current], lambda, ignored, result);
|
|
143
|
+
}
|
|
144
|
+
else if (leftSize < minClusterSize) {
|
|
145
|
+
relabel[split.right] = relabel[current];
|
|
146
|
+
appendRunt(hierarchy, count, split.left, relabel[current], lambda, ignored, result);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
relabel[split.left] = relabel[current];
|
|
150
|
+
appendRunt(hierarchy, count, split.right, relabel[current], lambda, ignored, result);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
if (result.length === 0) {
|
|
154
|
+
throw new Error("HDBSCAN condensed hierarchy is empty.");
|
|
155
|
+
}
|
|
156
|
+
return result;
|
|
157
|
+
}
|
|
158
|
+
function appendRunt(hierarchy, count, root, parent, lambda, ignored, result) {
|
|
159
|
+
for (const node of breadthFirstHierarchy(hierarchy, count, root)) {
|
|
160
|
+
if (node < count) {
|
|
161
|
+
result.push({ parent, child: node, lambda, childSize: 1 });
|
|
162
|
+
}
|
|
163
|
+
ignored[node] = 1;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function breadthFirstHierarchy(hierarchy, count, root) {
|
|
167
|
+
const result = [];
|
|
168
|
+
let level = [root];
|
|
169
|
+
while (level.length > 0) {
|
|
170
|
+
for (const node of level)
|
|
171
|
+
result.push(node);
|
|
172
|
+
const next = [];
|
|
173
|
+
for (const node of level) {
|
|
174
|
+
if (node < count)
|
|
175
|
+
continue;
|
|
176
|
+
const split = hierarchy[node - count];
|
|
177
|
+
next.push(split.left, split.right);
|
|
178
|
+
}
|
|
179
|
+
level = next;
|
|
180
|
+
}
|
|
181
|
+
return result;
|
|
182
|
+
}
|
|
183
|
+
function selectClusters(tree, count, allowSingleCluster) {
|
|
184
|
+
let root = Number.MAX_SAFE_INTEGER;
|
|
185
|
+
let maximumParent = -1;
|
|
186
|
+
for (const edge of tree) {
|
|
187
|
+
if (edge.parent < root)
|
|
188
|
+
root = edge.parent;
|
|
189
|
+
if (edge.parent > maximumParent)
|
|
190
|
+
maximumParent = edge.parent;
|
|
191
|
+
}
|
|
192
|
+
if (root !== count) {
|
|
193
|
+
throw new Error("HDBSCAN condensed hierarchy has an invalid root.");
|
|
194
|
+
}
|
|
195
|
+
const births = new Float64Array(maximumParent + 1).fill(NaN);
|
|
196
|
+
for (const edge of tree) {
|
|
197
|
+
if (Number.isNaN(births[edge.child]))
|
|
198
|
+
births[edge.child] = edge.lambda;
|
|
199
|
+
else
|
|
200
|
+
births[edge.child] = Math.min(births[edge.child], edge.lambda);
|
|
201
|
+
}
|
|
202
|
+
births[root] = 0;
|
|
203
|
+
const stability = new Map();
|
|
204
|
+
for (let cluster = root; cluster <= maximumParent; cluster++) {
|
|
205
|
+
stability.set(cluster, 0);
|
|
206
|
+
}
|
|
207
|
+
for (const edge of tree) {
|
|
208
|
+
stability.set(edge.parent, stability.get(edge.parent) +
|
|
209
|
+
(edge.lambda - births[edge.parent]) * edge.childSize);
|
|
210
|
+
}
|
|
211
|
+
const clusterEdges = tree.filter(({ childSize }) => childSize > 1);
|
|
212
|
+
const nodeList = [...stability.keys()].sort((a, b) => b - a);
|
|
213
|
+
if (!allowSingleCluster)
|
|
214
|
+
nodeList.pop();
|
|
215
|
+
const preferred = new Map();
|
|
216
|
+
const children = new Map();
|
|
217
|
+
for (const edge of clusterEdges) {
|
|
218
|
+
const values = children.get(edge.parent) ?? [];
|
|
219
|
+
values.push(edge.child);
|
|
220
|
+
children.set(edge.parent, values);
|
|
221
|
+
}
|
|
222
|
+
for (const cluster of nodeList) {
|
|
223
|
+
const childClusters = children.get(cluster) ?? [];
|
|
224
|
+
// hdbscan 0.8.44 stores this otherwise-double reduction in a C float.
|
|
225
|
+
const subtreeStability = accumulateFloat32(childClusters.map((child) => stability.get(child)));
|
|
226
|
+
if (subtreeStability > stability.get(cluster)) {
|
|
227
|
+
stability.set(cluster, subtreeStability);
|
|
228
|
+
preferred.set(cluster, false);
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
preferred.set(cluster, true);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const clusters = [];
|
|
235
|
+
const pending = [root];
|
|
236
|
+
while (pending.length > 0) {
|
|
237
|
+
const cluster = pending.pop();
|
|
238
|
+
if ((cluster !== root || allowSingleCluster) && preferred.get(cluster)) {
|
|
239
|
+
clusters.push(cluster);
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
const childClusters = children.get(cluster) ?? [];
|
|
243
|
+
for (let index = childClusters.length - 1; index >= 0; index--) {
|
|
244
|
+
pending.push(childClusters[index]);
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
clusters.sort((a, b) => a - b);
|
|
248
|
+
const labelsByCluster = new Map(clusters.map((cluster, label) => [cluster, label]));
|
|
249
|
+
const pointEdges = new Array(count);
|
|
250
|
+
const parentByCluster = new Map();
|
|
251
|
+
for (const edge of tree) {
|
|
252
|
+
if (edge.child < count)
|
|
253
|
+
pointEdges[edge.child] = edge;
|
|
254
|
+
else
|
|
255
|
+
parentByCluster.set(edge.child, edge.parent);
|
|
256
|
+
}
|
|
257
|
+
for (let point = 0; point < count; point++) {
|
|
258
|
+
if (pointEdges[point] === undefined) {
|
|
259
|
+
throw new Error("HDBSCAN condensed hierarchy omitted an input row.");
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
const labels = new Int32Array(count).fill(-1);
|
|
263
|
+
const selectedAncestor = new Int32Array(maximumParent + 1).fill(-1);
|
|
264
|
+
for (let cluster = root; cluster <= maximumParent; cluster++) {
|
|
265
|
+
if (labelsByCluster.has(cluster)) {
|
|
266
|
+
selectedAncestor[cluster] = cluster;
|
|
267
|
+
continue;
|
|
268
|
+
}
|
|
269
|
+
const parent = parentByCluster.get(cluster);
|
|
270
|
+
if (parent !== undefined) {
|
|
271
|
+
selectedAncestor[cluster] = selectedAncestor[parent];
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
let rootExit = 0;
|
|
275
|
+
for (const edge of tree) {
|
|
276
|
+
if (edge.parent === root && edge.lambda > rootExit)
|
|
277
|
+
rootExit = edge.lambda;
|
|
278
|
+
}
|
|
279
|
+
for (let point = 0; point < count; point++) {
|
|
280
|
+
const pointEdge = pointEdges[point];
|
|
281
|
+
const cluster = selectedAncestor[pointEdge.parent];
|
|
282
|
+
if (cluster < 0)
|
|
283
|
+
continue;
|
|
284
|
+
if (cluster === root &&
|
|
285
|
+
!(clusters.length === 1 && allowSingleCluster &&
|
|
286
|
+
pointEdge.lambda >= rootExit))
|
|
287
|
+
continue;
|
|
288
|
+
labels[point] = labelsByCluster.get(cluster);
|
|
289
|
+
}
|
|
290
|
+
const deaths = directMaximumLambdas(tree, maximumParent);
|
|
291
|
+
const probabilities = new Float64Array(count);
|
|
292
|
+
for (let point = 0; point < count; point++) {
|
|
293
|
+
const label = labels[point];
|
|
294
|
+
if (label < 0)
|
|
295
|
+
continue;
|
|
296
|
+
const cluster = clusters[label];
|
|
297
|
+
const maximum = deaths[cluster];
|
|
298
|
+
const lambda = pointEdges[point].lambda;
|
|
299
|
+
probabilities[point] = maximum === 0 || !Number.isFinite(lambda)
|
|
300
|
+
? 1
|
|
301
|
+
: Math.min(lambda, maximum) / maximum;
|
|
302
|
+
}
|
|
303
|
+
// hdbscan 0.8.44 propagates maximum density through the condensed tree in
|
|
304
|
+
// reverse edge order, so each parent sees maxima already resolved below it.
|
|
305
|
+
for (let index = tree.length - 1; index >= 0; index--) {
|
|
306
|
+
const edge = tree[index];
|
|
307
|
+
if (deaths[edge.child] > deaths[edge.parent]) {
|
|
308
|
+
deaths[edge.parent] = deaths[edge.child];
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
const outlierScores = new Float64Array(count);
|
|
312
|
+
for (let point = 0; point < count; point++) {
|
|
313
|
+
const edge = pointEdges[point];
|
|
314
|
+
const maximum = deaths[edge.parent];
|
|
315
|
+
if (maximum === 0 || !Number.isFinite(edge.lambda)) {
|
|
316
|
+
outlierScores[point] = 0;
|
|
317
|
+
}
|
|
318
|
+
else if (!Number.isFinite(maximum)) {
|
|
319
|
+
// hdbscan 0.8.44 returns NaN for (Infinity - finite) / Infinity.
|
|
320
|
+
// Use the finite perturbation limit so public outputs remain finite.
|
|
321
|
+
outlierScores[point] = 1;
|
|
322
|
+
}
|
|
323
|
+
else {
|
|
324
|
+
outlierScores[point] = (maximum - edge.lambda) / maximum;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
if (probabilities.some((value) => !Number.isFinite(value)) ||
|
|
328
|
+
outlierScores.some((value) => !Number.isFinite(value))) {
|
|
329
|
+
throw new Error("HDBSCAN produced non-finite point scores.");
|
|
330
|
+
}
|
|
331
|
+
return { labels, probabilities, outlierScores };
|
|
332
|
+
}
|
|
333
|
+
/** Match a C float accumulator, including rounding after every addition. */
|
|
334
|
+
function accumulateFloat32(values) {
|
|
335
|
+
let total = 0;
|
|
336
|
+
for (const value of values)
|
|
337
|
+
total = Math.fround(total + value);
|
|
338
|
+
return total;
|
|
339
|
+
}
|
|
340
|
+
function directMaximumLambdas(tree, maximumParent) {
|
|
341
|
+
const deaths = new Float64Array(maximumParent + 1);
|
|
342
|
+
for (const edge of tree) {
|
|
343
|
+
deaths[edge.parent] = Math.max(deaths[edge.parent], edge.lambda);
|
|
344
|
+
}
|
|
345
|
+
return deaths;
|
|
346
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { DuckDBConnection } from "@duckdb/node-api";
|
|
2
|
+
import { type CovarianceFactor } from "./factorCovariance.js";
|
|
3
|
+
export type CovarianceModel = CovarianceFactor & {
|
|
4
|
+
means: Float64Array;
|
|
5
|
+
origins: Float64Array;
|
|
6
|
+
meanOffsets: Float64Array;
|
|
7
|
+
observations: number;
|
|
8
|
+
};
|
|
9
|
+
export default function computeCovariance(connection: DuckDBConnection, input: {
|
|
10
|
+
relation: string;
|
|
11
|
+
rowIdColumn: string;
|
|
12
|
+
vectorColumn: string;
|
|
13
|
+
observations: number;
|
|
14
|
+
dimensions: number;
|
|
15
|
+
}): Promise<CovarianceModel>;
|
|
16
|
+
//# sourceMappingURL=computeCovariance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"computeCovariance.d.ts","sourceRoot":"","sources":["../../src/helpers/computeCovariance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AAEzD,OAAO,EAAE,KAAK,gBAAgB,EAAoB,MAAM,uBAAuB,CAAC;AAEhF,MAAM,MAAM,eAAe,GAAG,gBAAgB,GAAG;IAC/C,KAAK,EAAE,YAAY,CAAC;IACpB,OAAO,EAAE,YAAY,CAAC;IACtB,WAAW,EAAE,YAAY,CAAC;IAC1B,YAAY,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,wBAA8B,iBAAiB,CAC7C,UAAU,EAAE,gBAAgB,EAC5B,KAAK,EAAE;IACL,QAAQ,EAAE,MAAM,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;CACpB,GACA,OAAO,CAAC,eAAe,CAAC,CAmH1B"}
|