@nshiab/simple-data-analysis-core 2.0.9 → 2.1.0
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 +2795 -1139
- package/esm/class/SimpleTable.d.ts.map +1 -1
- package/esm/class/SimpleTable.js +2781 -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/llm.md +2106 -143
- 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 +2795 -1139
- package/script/class/SimpleTable.d.ts.map +1 -1
- package/script/class/SimpleTable.js +2781 -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
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { DOUBLE, INTEGER, VARCHAR } from "@duckdb/node-api";
|
|
2
|
+
import appendColumnBatches from "../helpers/appendColumnBatches.js";
|
|
3
|
+
import buildApproximateMutualReachabilityMst from "../helpers/buildApproximateMutualReachabilityMst.js";
|
|
4
|
+
import buildExactMutualReachabilityMst from "../helpers/buildExactMutualReachabilityMst.js";
|
|
5
|
+
import clusterHdbscan from "../helpers/clusterHdbscan.js";
|
|
6
|
+
import foldIdentifier from "../helpers/foldIdentifier.js";
|
|
7
|
+
import prepareNumericFeatures from "../helpers/prepareNumericFeatures.js";
|
|
8
|
+
import publishPreparedColumns from "../helpers/publishPreparedColumns.js";
|
|
9
|
+
import queueOp from "../helpers/queueOp.js";
|
|
10
|
+
import quoteIdentifier from "../helpers/quoteIdentifier.js";
|
|
11
|
+
export default function hdbscan(table, columns, newColumn, options = {}) {
|
|
12
|
+
const selected = typeof columns === "string" ? columns : [...columns];
|
|
13
|
+
const settings = structuredClone(options);
|
|
14
|
+
queueOp(table, {
|
|
15
|
+
kind: "barrier",
|
|
16
|
+
method: "hdbscan()",
|
|
17
|
+
parameters: { columns: selected, newColumn, options: settings },
|
|
18
|
+
execute: () => execute(table, selected, newColumn, settings),
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
async function execute(table, columns, newColumn, options) {
|
|
22
|
+
const { minClusterSize = 5, metric = "euclidean", allowSingleCluster = false, approximate = false, membershipScoreColumn, outlierScoreColumn, } = options;
|
|
23
|
+
const minSamples = options.minSamples ?? minClusterSize;
|
|
24
|
+
if (typeof newColumn !== "string") {
|
|
25
|
+
throw new Error("hdbscan() newColumn must be a string.");
|
|
26
|
+
}
|
|
27
|
+
if (!Number.isSafeInteger(minClusterSize) || minClusterSize < 2) {
|
|
28
|
+
throw new Error("hdbscan() minClusterSize must be a safe integer of at least 2.");
|
|
29
|
+
}
|
|
30
|
+
if (!Number.isSafeInteger(minSamples) || minSamples < 1) {
|
|
31
|
+
throw new Error("hdbscan() minSamples must be a safe integer of at least 1.");
|
|
32
|
+
}
|
|
33
|
+
if (!["euclidean", "cosine"].includes(metric)) {
|
|
34
|
+
throw new Error('hdbscan() metric must be "euclidean" or "cosine".');
|
|
35
|
+
}
|
|
36
|
+
if (typeof allowSingleCluster !== "boolean") {
|
|
37
|
+
throw new Error("hdbscan() allowSingleCluster must be a boolean.");
|
|
38
|
+
}
|
|
39
|
+
if (typeof approximate !== "boolean") {
|
|
40
|
+
throw new Error("hdbscan() approximate must be a boolean.");
|
|
41
|
+
}
|
|
42
|
+
if (membershipScoreColumn !== undefined &&
|
|
43
|
+
typeof membershipScoreColumn !== "string") {
|
|
44
|
+
throw new Error("hdbscan() membershipScoreColumn must be a string.");
|
|
45
|
+
}
|
|
46
|
+
if (outlierScoreColumn !== undefined &&
|
|
47
|
+
typeof outlierScoreColumn !== "string") {
|
|
48
|
+
throw new Error("hdbscan() outlierScoreColumn must be a string.");
|
|
49
|
+
}
|
|
50
|
+
const sourceColumns = Object.keys(await table.getTypes());
|
|
51
|
+
const outputNames = [newColumn, membershipScoreColumn, outlierScoreColumn]
|
|
52
|
+
.filter((name) => name !== undefined);
|
|
53
|
+
validateOutputNames(sourceColumns, outputNames);
|
|
54
|
+
const prepared = await prepareNumericFeatures(table, typeof columns === "string"
|
|
55
|
+
? { kind: "vector", column: columns }
|
|
56
|
+
: { kind: "scalars", columns }, { method: "hdbscan()" });
|
|
57
|
+
const connection = table.connection;
|
|
58
|
+
const suffix = crypto.randomUUID().replaceAll("-", "");
|
|
59
|
+
const name = (part) => `__sda_hdbscan_${suffix}_${part}`;
|
|
60
|
+
const names = {
|
|
61
|
+
rows: name("rows"),
|
|
62
|
+
neighbors: name("neighbors"),
|
|
63
|
+
search: name("search"),
|
|
64
|
+
hnsw: name("hnsw"),
|
|
65
|
+
candidates: name("candidates"),
|
|
66
|
+
coreDistances: name("core_distances"),
|
|
67
|
+
frontier: name("frontier"),
|
|
68
|
+
edges: name("edges"),
|
|
69
|
+
components: name("components"),
|
|
70
|
+
representatives: name("representatives"),
|
|
71
|
+
componentPairs: name("component_pairs"),
|
|
72
|
+
bridgeCandidates: name("bridge_candidates"),
|
|
73
|
+
mst: name("mst"),
|
|
74
|
+
result: name("result"),
|
|
75
|
+
};
|
|
76
|
+
try {
|
|
77
|
+
if (prepared.rowCount < 2) {
|
|
78
|
+
throw new Error(`hdbscan() requires at least 2 rows, but the input has ${prepared.rowCount}.`);
|
|
79
|
+
}
|
|
80
|
+
if (prepared.rowCount > 0x40000000) {
|
|
81
|
+
throw new Error("hdbscan() supports at most 1073741824 rows because its 2*n-1 hierarchy nodes use signed INTEGER identifiers.");
|
|
82
|
+
}
|
|
83
|
+
if (minSamples >= prepared.rowCount) {
|
|
84
|
+
const defaulted = options.minSamples === undefined
|
|
85
|
+
? " (defaulted from minClusterSize)"
|
|
86
|
+
: "";
|
|
87
|
+
throw new Error(`hdbscan() minSamples is ${minSamples}${defaulted}, but ${prepared.rowCount} rows provide at most ${prepared.rowCount - 1} other point${prepared.rowCount === 2 ? "" : "s"}. Set minSamples between 1 and ${prepared.rowCount - 1}, or provide at least ${minSamples + 1} rows.`);
|
|
88
|
+
}
|
|
89
|
+
if (minClusterSize > prepared.rowCount) {
|
|
90
|
+
throw new Error(`hdbscan() minClusterSize is ${minClusterSize}, but the input has ${prepared.rowCount} rows. Set minClusterSize between 2 and ${prepared.rowCount}, or provide more rows.`);
|
|
91
|
+
}
|
|
92
|
+
const q = quoteIdentifier;
|
|
93
|
+
await connection.run(`CREATE TEMP TABLE ${q(names.rows)} AS
|
|
94
|
+
SELECT ${q(prepared.rowIdColumn)}::INTEGER AS vertex,
|
|
95
|
+
${q(prepared.vectorColumn)} AS vec
|
|
96
|
+
FROM ${q(prepared.relation)}
|
|
97
|
+
ORDER BY ${q(prepared.rowIdColumn)}`);
|
|
98
|
+
if (approximate) {
|
|
99
|
+
await buildApproximateMutualReachabilityMst(connection, {
|
|
100
|
+
count: prepared.rowCount,
|
|
101
|
+
dimensions: prepared.dimensions,
|
|
102
|
+
minSamples,
|
|
103
|
+
}, { metric }, {
|
|
104
|
+
rows: names.rows,
|
|
105
|
+
neighbors: names.neighbors,
|
|
106
|
+
search: names.search,
|
|
107
|
+
hnsw: names.hnsw,
|
|
108
|
+
candidates: names.candidates,
|
|
109
|
+
coreDistances: names.coreDistances,
|
|
110
|
+
edges: names.edges,
|
|
111
|
+
components: names.components,
|
|
112
|
+
representatives: names.representatives,
|
|
113
|
+
componentPairs: names.componentPairs,
|
|
114
|
+
bridgeCandidates: names.bridgeCandidates,
|
|
115
|
+
mst: names.mst,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
await buildExactMutualReachabilityMst(connection, { count: prepared.rowCount, minSamples }, { metric }, {
|
|
120
|
+
rows: q(names.rows),
|
|
121
|
+
coreDistances: q(names.coreDistances),
|
|
122
|
+
frontier: q(names.frontier),
|
|
123
|
+
mst: q(names.mst),
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
const result = await clusterHdbscan(connection, q(names.mst), {
|
|
127
|
+
count: prepared.rowCount,
|
|
128
|
+
minClusterSize,
|
|
129
|
+
allowSingleCluster,
|
|
130
|
+
});
|
|
131
|
+
const labelColumn = "label";
|
|
132
|
+
const membershipColumn = "membership";
|
|
133
|
+
const gloshColumn = "glosh";
|
|
134
|
+
const resultColumns = [
|
|
135
|
+
"row_id INTEGER",
|
|
136
|
+
`${labelColumn} VARCHAR`,
|
|
137
|
+
membershipScoreColumn === undefined
|
|
138
|
+
? undefined
|
|
139
|
+
: `${membershipColumn} DOUBLE`,
|
|
140
|
+
outlierScoreColumn === undefined ? undefined : `${gloshColumn} DOUBLE`,
|
|
141
|
+
].filter((definition) => definition !== undefined);
|
|
142
|
+
await connection.run(`CREATE TEMP TABLE ${q(names.result)} (${resultColumns.join(",")})`);
|
|
143
|
+
const outputTypes = [
|
|
144
|
+
INTEGER,
|
|
145
|
+
VARCHAR,
|
|
146
|
+
...(membershipScoreColumn === undefined ? [] : [DOUBLE]),
|
|
147
|
+
...(outlierScoreColumn === undefined ? [] : [DOUBLE]),
|
|
148
|
+
];
|
|
149
|
+
await appendColumnBatches(connection, names.result, outputTypes, prepared.rowCount, (column, start, end) => {
|
|
150
|
+
if (column === 0) {
|
|
151
|
+
return Array.from({ length: end - start }, (_, offset) => start + offset);
|
|
152
|
+
}
|
|
153
|
+
if (column === 1) {
|
|
154
|
+
return Array.from(result.labels.subarray(start, end), (label) => label < 0 ? "noise" : `cluster-${label}`);
|
|
155
|
+
}
|
|
156
|
+
const membershipIndex = membershipScoreColumn === undefined ? -1 : 2;
|
|
157
|
+
return Array.from(column === membershipIndex
|
|
158
|
+
? result.probabilities.subarray(start, end)
|
|
159
|
+
: result.outlierScores.subarray(start, end));
|
|
160
|
+
});
|
|
161
|
+
const publicationOutputs = [{
|
|
162
|
+
name: newColumn,
|
|
163
|
+
expression: `r.${q(labelColumn)}`,
|
|
164
|
+
}];
|
|
165
|
+
if (membershipScoreColumn !== undefined) {
|
|
166
|
+
publicationOutputs.push({
|
|
167
|
+
name: membershipScoreColumn,
|
|
168
|
+
expression: `r.${q(membershipColumn)}`,
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
if (outlierScoreColumn !== undefined) {
|
|
172
|
+
publicationOutputs.push({
|
|
173
|
+
name: outlierScoreColumn,
|
|
174
|
+
expression: `r.${q(gloshColumn)}`,
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
await publishPreparedColumns(table, prepared, {
|
|
178
|
+
method: "hdbscan()",
|
|
179
|
+
parameters: { columns, newColumn, options },
|
|
180
|
+
result: { relation: names.result, rowIdColumn: "row_id" },
|
|
181
|
+
outputs: publicationOutputs,
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
finally {
|
|
185
|
+
for (const relation of Object.entries(names).reverse().flatMap(([key, value]) => key === "hnsw" ? [] : [value])) {
|
|
186
|
+
await connection.run(`DROP TABLE IF EXISTS ${quoteIdentifier(relation)}`);
|
|
187
|
+
}
|
|
188
|
+
await prepared.cleanup();
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
function validateOutputNames(sourceColumns, outputNames) {
|
|
192
|
+
const seen = new Map();
|
|
193
|
+
for (const name of outputNames) {
|
|
194
|
+
if (name.length === 0 || name.includes("\0")) {
|
|
195
|
+
throw new Error("hdbscan() output column names must be non-empty strings without null characters.");
|
|
196
|
+
}
|
|
197
|
+
const folded = foldIdentifier(name);
|
|
198
|
+
const source = sourceColumns.find((column) => foldIdentifier(column) === folded);
|
|
199
|
+
if (source !== undefined) {
|
|
200
|
+
throw new Error(`hdbscan() cannot create ${quoteIdentifier(name)} because that source column already exists. Remove it first or choose different output names.`);
|
|
201
|
+
}
|
|
202
|
+
const duplicate = seen.get(folded);
|
|
203
|
+
if (duplicate !== undefined) {
|
|
204
|
+
throw new Error(`hdbscan() output columns ${quoteIdentifier(duplicate)} and ${quoteIdentifier(name)} refer to the same column. Choose distinct output names.`);
|
|
205
|
+
}
|
|
206
|
+
seen.set(folded, name);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type SimpleTable from "../class/SimpleTable.js";
|
|
2
|
+
type Options = NonNullable<Parameters<SimpleTable["mahalanobis"]>[3]>;
|
|
3
|
+
export default function mahalanobis(table: SimpleTable, columns: string | string[], referencePoint: number[], newColumn: string, options?: Options): void;
|
|
4
|
+
export {};
|
|
5
|
+
//# sourceMappingURL=mahalanobis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mahalanobis.d.ts","sourceRoot":"","sources":["../../src/methods/mahalanobis.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AASvD,KAAK,OAAO,GAAG,WAAW,CAAC,UAAU,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAEtE,MAAM,CAAC,OAAO,UAAU,WAAW,CACjC,KAAK,EAAE,WAAW,EAClB,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,EAC1B,cAAc,EAAE,MAAM,EAAE,EACxB,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,OAAY,GACpB,IAAI,CAyBN"}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import computeCovariance from "../helpers/computeCovariance.js";
|
|
2
|
+
import computeMahalanobisDistances from "../helpers/computeMahalanobisDistances.js";
|
|
3
|
+
import foldIdentifier from "../helpers/foldIdentifier.js";
|
|
4
|
+
import prepareNumericFeatures from "../helpers/prepareNumericFeatures.js";
|
|
5
|
+
import publishPreparedColumns from "../helpers/publishPreparedColumns.js";
|
|
6
|
+
import queueOp from "../helpers/queueOp.js";
|
|
7
|
+
import quoteIdentifier from "../helpers/quoteIdentifier.js";
|
|
8
|
+
export default function mahalanobis(table, columns, referencePoint, newColumn, options = {}) {
|
|
9
|
+
if (!Array.isArray(referencePoint) || referencePoint.length === 0 ||
|
|
10
|
+
Array.from(referencePoint).some((value) => typeof value !== "number" || !Number.isFinite(value))) {
|
|
11
|
+
throw new Error("mahalanobis() referencePoint must be a nonempty array of finite numbers in feature-dimension order.");
|
|
12
|
+
}
|
|
13
|
+
const selected = typeof columns === "string" ? columns : [...columns];
|
|
14
|
+
const reference = [...referencePoint];
|
|
15
|
+
const settings = { ...options };
|
|
16
|
+
queueOp(table, {
|
|
17
|
+
kind: "barrier",
|
|
18
|
+
method: "mahalanobis()",
|
|
19
|
+
parameters: {
|
|
20
|
+
columns: selected,
|
|
21
|
+
referencePoint: reference,
|
|
22
|
+
newColumn,
|
|
23
|
+
options: settings,
|
|
24
|
+
},
|
|
25
|
+
execute: () => execute(table, selected, reference, newColumn, settings),
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
async function execute(table, columns, referencePoint, newColumn, options) {
|
|
29
|
+
const sourceColumns = Object.keys(await table.getTypes());
|
|
30
|
+
const outputNames = options.similarityScoreColumn === undefined
|
|
31
|
+
? [newColumn]
|
|
32
|
+
: [newColumn, options.similarityScoreColumn];
|
|
33
|
+
const seen = new Set();
|
|
34
|
+
for (const name of outputNames) {
|
|
35
|
+
if (typeof name !== "string" || name.length === 0 || name.includes("\0")) {
|
|
36
|
+
throw new Error("mahalanobis() output column names must be nonempty strings without null characters.");
|
|
37
|
+
}
|
|
38
|
+
const folded = foldIdentifier(name);
|
|
39
|
+
if (seen.has(folded)) {
|
|
40
|
+
throw new Error("mahalanobis() distance and similarity score columns must have different names (case-insensitive).");
|
|
41
|
+
}
|
|
42
|
+
seen.add(folded);
|
|
43
|
+
if (sourceColumns.some((column) => foldIdentifier(column) === folded)) {
|
|
44
|
+
throw new Error(`mahalanobis() cannot create ${quoteIdentifier(name)} because that column already exists. Remove it first or choose a different name.`);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
const prepared = await prepareNumericFeatures(table, typeof columns === "string"
|
|
48
|
+
? { kind: "vector", column: columns }
|
|
49
|
+
: { kind: "scalars", columns }, { method: "mahalanobis()" });
|
|
50
|
+
try {
|
|
51
|
+
if (referencePoint.length !== prepared.dimensions) {
|
|
52
|
+
throw new Error(`mahalanobis() referencePoint must contain ${prepared.dimensions} values in feature-dimension order; received ${referencePoint.length}.`);
|
|
53
|
+
}
|
|
54
|
+
const model = await computeCovariance(table.connection, {
|
|
55
|
+
relation: prepared.relation,
|
|
56
|
+
rowIdColumn: prepared.rowIdColumn,
|
|
57
|
+
vectorColumn: prepared.vectorColumn,
|
|
58
|
+
observations: prepared.rowCount,
|
|
59
|
+
dimensions: prepared.dimensions,
|
|
60
|
+
});
|
|
61
|
+
const distances = await computeMahalanobisDistances(table.connection, {
|
|
62
|
+
relation: prepared.relation,
|
|
63
|
+
rowIdColumn: prepared.rowIdColumn,
|
|
64
|
+
vectorColumn: prepared.vectorColumn,
|
|
65
|
+
}, model, referencePoint);
|
|
66
|
+
try {
|
|
67
|
+
const distance = `r.${quoteIdentifier(distances.distanceColumn)}`;
|
|
68
|
+
const outputs = [{ name: newColumn, expression: distance }];
|
|
69
|
+
if (options.similarityScoreColumn !== undefined) {
|
|
70
|
+
outputs.push({
|
|
71
|
+
name: options.similarityScoreColumn,
|
|
72
|
+
expression: `CASE WHEN max(${distance}) OVER () = 0 THEN 1::DOUBLE ELSE 1 - ${distance} / max(${distance}) OVER () END`,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
await publishPreparedColumns(table, prepared, {
|
|
76
|
+
method: "mahalanobis()",
|
|
77
|
+
parameters: { columns, referencePoint, newColumn, options },
|
|
78
|
+
result: {
|
|
79
|
+
relation: distances.relation,
|
|
80
|
+
rowIdColumn: distances.rowIdColumn,
|
|
81
|
+
},
|
|
82
|
+
outputs,
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
await distances.cleanup();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
await prepared.cleanup();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type GraphId } from "../helpers/prepareGraphStarts.js";
|
|
2
|
+
import type SimpleTable from "../class/SimpleTable.js";
|
|
3
|
+
type NeighborsOptions = {
|
|
4
|
+
direction?: "outgoing" | "incoming" | "both";
|
|
5
|
+
outputTable?: string | boolean;
|
|
6
|
+
};
|
|
7
|
+
export default function neighbors(simpleTable: SimpleTable, sourceColumn: string, targetColumn: string, startNodes: GraphId | GraphId[], options?: NeighborsOptions): SimpleTable;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=neighbors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"neighbors.d.ts","sourceRoot":"","sources":["../../src/methods/neighbors.ts"],"names":[],"mappings":"AAAA,OAA2B,EACzB,KAAK,OAAO,EAEb,MAAM,kCAAkC,CAAC;AAO1C,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAGvD,KAAK,gBAAgB,GAAG;IACtB,SAAS,CAAC,EAAE,UAAU,GAAG,UAAU,GAAG,MAAM,CAAC;IAC7C,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;CAChC,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,UAAU,EAAE,OAAO,GAAG,OAAO,EAAE,EAC/B,OAAO,GAAE,gBAAqB,GAC7B,WAAW,CAuEb"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import prepareGraphStarts from "../helpers/prepareGraphStarts.js";
|
|
2
|
+
import prepareGraphTraversal, { validateGraphStarts, } from "../helpers/prepareGraphTraversal.js";
|
|
3
|
+
import queueGraphResult from "../helpers/queueGraphResult.js";
|
|
4
|
+
import quoteIdentifier from "../helpers/quoteIdentifier.js";
|
|
5
|
+
export default function neighbors(simpleTable, sourceColumn, targetColumn, startNodes, options = {}) {
|
|
6
|
+
if (typeof sourceColumn !== "string") {
|
|
7
|
+
throw new TypeError("neighbors() sourceColumn must be a string.");
|
|
8
|
+
}
|
|
9
|
+
if (typeof targetColumn !== "string") {
|
|
10
|
+
throw new TypeError("neighbors() targetColumn must be a string.");
|
|
11
|
+
}
|
|
12
|
+
if (options === null || typeof options !== "object" || Array.isArray(options)) {
|
|
13
|
+
throw new TypeError("neighbors() options must be an object.");
|
|
14
|
+
}
|
|
15
|
+
if (options.direction !== undefined &&
|
|
16
|
+
!["outgoing", "incoming", "both"].includes(options.direction)) {
|
|
17
|
+
throw new TypeError('neighbors() options.direction must be "outgoing", "incoming", or "both".');
|
|
18
|
+
}
|
|
19
|
+
if (options.outputTable !== undefined &&
|
|
20
|
+
typeof options.outputTable !== "string" &&
|
|
21
|
+
typeof options.outputTable !== "boolean") {
|
|
22
|
+
throw new TypeError("neighbors() options.outputTable must be a string or boolean.");
|
|
23
|
+
}
|
|
24
|
+
const preparedStarts = prepareGraphStarts(startNodes, "neighbors()", "startNodes");
|
|
25
|
+
options = structuredClone(options);
|
|
26
|
+
const direction = options.direction ?? "outgoing";
|
|
27
|
+
const parameters = {
|
|
28
|
+
sourceColumn,
|
|
29
|
+
targetColumn,
|
|
30
|
+
startNodes: structuredClone(startNodes),
|
|
31
|
+
options,
|
|
32
|
+
};
|
|
33
|
+
return queueGraphResult(simpleTable, {
|
|
34
|
+
method: "neighbors()",
|
|
35
|
+
parameters,
|
|
36
|
+
outputTable: options.outputTable,
|
|
37
|
+
values: (schema) => {
|
|
38
|
+
validateStarts(schema, sourceColumn, targetColumn, preparedStarts);
|
|
39
|
+
return preparedStarts.values;
|
|
40
|
+
},
|
|
41
|
+
buildSelect: (input, schema) => neighborsSelect(input, schema, sourceColumn, targetColumn, preparedStarts, direction),
|
|
42
|
+
outputSchema: (schema) => {
|
|
43
|
+
const endpoints = validateStarts(schema, sourceColumn, targetColumn, preparedStarts);
|
|
44
|
+
return { start: endpoints.idType, node: endpoints.idType };
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
function validateStarts(schema, source, target, starts) {
|
|
49
|
+
return validateGraphStarts(schema, source, target, starts, "neighbors()", "startNodes");
|
|
50
|
+
}
|
|
51
|
+
function neighborsSelect(input, schema, source, target, starts, direction) {
|
|
52
|
+
const prepared = prepareGraphTraversal(input, schema, source, target, starts, "neighbors()", "startNodes");
|
|
53
|
+
const relations = prepared.relationNames([
|
|
54
|
+
"graph_starts",
|
|
55
|
+
"graph_edges",
|
|
56
|
+
"neighbor_matches",
|
|
57
|
+
]);
|
|
58
|
+
const startsRelation = relations.graph_starts;
|
|
59
|
+
const edgesRelation = relations.graph_edges;
|
|
60
|
+
const matchesRelation = relations.neighbor_matches;
|
|
61
|
+
return `WITH ${startsRelation}(${quoteIdentifier("start")}) AS (
|
|
62
|
+
VALUES ${prepared.startValues}
|
|
63
|
+
), ${edgesRelation} AS (
|
|
64
|
+
${prepared.edges(direction)}
|
|
65
|
+
), ${matchesRelation} AS (
|
|
66
|
+
SELECT ${quoteIdentifier("starts")}.${quoteIdentifier("start")},
|
|
67
|
+
${quoteIdentifier("edges")}.${quoteIdentifier("__to")} AS ${quoteIdentifier("node")},
|
|
68
|
+
${quoteIdentifier("edges")}.${quoteIdentifier("__from_key")} AS ${quoteIdentifier("__start_key")},
|
|
69
|
+
${quoteIdentifier("edges")}.${quoteIdentifier("__to_key")} AS ${quoteIdentifier("__node_key")}
|
|
70
|
+
FROM ${edgesRelation} AS ${quoteIdentifier("edges")}
|
|
71
|
+
INNER JOIN ${startsRelation} AS ${quoteIdentifier("starts")}
|
|
72
|
+
ON ${quoteIdentifier("edges")}.${quoteIdentifier("__from_key")} =
|
|
73
|
+
${prepared.key(`${quoteIdentifier("starts")}.${quoteIdentifier("start")}`)}
|
|
74
|
+
)
|
|
75
|
+
SELECT ${quoteIdentifier("start")}, ${quoteIdentifier("node")}
|
|
76
|
+
FROM (
|
|
77
|
+
SELECT DISTINCT ${quoteIdentifier("start")}, ${quoteIdentifier("node")}, ${quoteIdentifier("__start_key")}, ${quoteIdentifier("__node_key")}
|
|
78
|
+
FROM ${matchesRelation}
|
|
79
|
+
) AS ${quoteIdentifier("distinct_neighbors")}
|
|
80
|
+
ORDER BY ${quoteIdentifier("__start_key")}, ${quoteIdentifier("__node_key")}`;
|
|
81
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type SimpleTable from "../class/SimpleTable.js";
|
|
2
|
+
type Options = NonNullable<Parameters<SimpleTable["normalizeVector"]>[2]>;
|
|
3
|
+
export default function normalizeVector(table: SimpleTable, column: string, newColumn: string, options?: Options): void;
|
|
4
|
+
export {};
|
|
5
|
+
//# sourceMappingURL=normalizeVector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalizeVector.d.ts","sourceRoot":"","sources":["../../src/methods/normalizeVector.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAOvD,KAAK,OAAO,GAAG,WAAW,CAAC,UAAU,CAAC,WAAW,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAE1E,MAAM,CAAC,OAAO,UAAU,eAAe,CACrC,KAAK,EAAE,WAAW,EAClB,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,MAAM,EACjB,OAAO,GAAE,OAAY,GACpB,IAAI,CAiBN"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import foldIdentifier from "../helpers/foldIdentifier.js";
|
|
2
|
+
import prepareNumericFeatures from "../helpers/prepareNumericFeatures.js";
|
|
3
|
+
import publishPreparedColumns from "../helpers/publishPreparedColumns.js";
|
|
4
|
+
import queueOp from "../helpers/queueOp.js";
|
|
5
|
+
import quoteIdentifier from "../helpers/quoteIdentifier.js";
|
|
6
|
+
export default function normalizeVector(table, column, newColumn, options = {}) {
|
|
7
|
+
if (options.normalization !== undefined &&
|
|
8
|
+
options.normalization !== "dimensionMinMax" &&
|
|
9
|
+
options.normalization !== "rowL2") {
|
|
10
|
+
throw new Error('normalizeVector() options.normalization must be "dimensionMinMax" or "rowL2".');
|
|
11
|
+
}
|
|
12
|
+
const settings = structuredClone(options);
|
|
13
|
+
queueOp(table, {
|
|
14
|
+
kind: "barrier",
|
|
15
|
+
method: "normalizeVector()",
|
|
16
|
+
parameters: { column, newColumn, options: settings },
|
|
17
|
+
execute: () => execute(table, column, newColumn, settings),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
async function execute(table, column, newColumn, options) {
|
|
21
|
+
const normalization = options.normalization ?? "dimensionMinMax";
|
|
22
|
+
const overwrite = foldIdentifier(column) === foldIdentifier(newColumn);
|
|
23
|
+
if (!overwrite) {
|
|
24
|
+
const sourceColumns = Object.keys(await table.getTypes());
|
|
25
|
+
if (sourceColumns.some((name) => foldIdentifier(name) === foldIdentifier(newColumn))) {
|
|
26
|
+
throw new Error(`normalizeVector() cannot create ${quoteIdentifier(newColumn)} because that column already exists. Remove it first or choose a different name.`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const prepared = await prepareNumericFeatures(table, { kind: "vector", column }, { method: "normalizeVector()" });
|
|
30
|
+
const connection = table.connection;
|
|
31
|
+
const q = quoteIdentifier;
|
|
32
|
+
const suffix = crypto.randomUUID().replaceAll("-", "");
|
|
33
|
+
const statsName = `__sda_normalize_vector_${suffix}_stats`;
|
|
34
|
+
const resultName = `__sda_normalize_vector_${suffix}_result`;
|
|
35
|
+
const dimension = q(`__sda_dimension_${suffix}`);
|
|
36
|
+
const minimum = q(`__sda_min_${suffix}`);
|
|
37
|
+
const maximum = q(`__sda_max_${suffix}`);
|
|
38
|
+
const normalized = `__sda_normalized_${suffix}`;
|
|
39
|
+
try {
|
|
40
|
+
if (prepared.rowCount === 0) {
|
|
41
|
+
throw new Error("normalizeVector() requires at least one row; the dataset is empty.");
|
|
42
|
+
}
|
|
43
|
+
const sourceColumn = prepared.sourceColumns.find((name) => foldIdentifier(name) === foldIdentifier(column));
|
|
44
|
+
if (normalization === "rowL2") {
|
|
45
|
+
// Scale before squaring so extreme finite magnitudes do not overflow
|
|
46
|
+
// or underflow the norm. A zero vector stays zero.
|
|
47
|
+
await connection.run(`CREATE TEMP TABLE ${q(resultName)} AS
|
|
48
|
+
WITH magnitudes AS (
|
|
49
|
+
SELECT ${q(prepared.rowIdColumn)}, ${q(prepared.vectorColumn)} AS vec,
|
|
50
|
+
list_max(list_transform(${q(prepared.vectorColumn)}, value -> abs(value))) AS magnitude
|
|
51
|
+
FROM ${q(prepared.relation)}
|
|
52
|
+
), scaled AS (
|
|
53
|
+
SELECT *, list_transform(vec, value -> value / nullif(magnitude, 0)) AS unit_scale
|
|
54
|
+
FROM magnitudes
|
|
55
|
+
), norms AS (
|
|
56
|
+
SELECT *, sqrt(list_sum(list_transform(unit_scale, value -> value * value))) AS norm
|
|
57
|
+
FROM scaled
|
|
58
|
+
)
|
|
59
|
+
SELECT ${q(prepared.rowIdColumn)},
|
|
60
|
+
(CASE WHEN magnitude = 0 THEN vec::DOUBLE[]
|
|
61
|
+
ELSE list_transform(unit_scale, value -> value / norm)
|
|
62
|
+
END)::DOUBLE[${prepared.dimensions}] AS ${q(normalized)}
|
|
63
|
+
FROM norms`);
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
await connection.run(`CREATE TEMP TABLE ${q(statsName)} AS
|
|
67
|
+
SELECT ordinal::BIGINT AS ${dimension}, min(value)::DOUBLE AS ${minimum},
|
|
68
|
+
max(value)::DOUBLE AS ${maximum}
|
|
69
|
+
FROM ${q(prepared.relation)} p,
|
|
70
|
+
UNNEST(p.${q(prepared.vectorColumn)}::DOUBLE[]) WITH ORDINALITY AS values(value, ordinal)
|
|
71
|
+
GROUP BY ordinal`);
|
|
72
|
+
const invalidStats = Number((await connection.runAndReadAll(`SELECT count(*) FROM ${q(statsName)}
|
|
73
|
+
WHERE NOT isfinite(${minimum}) OR NOT isfinite(${maximum})`)).getRowsJS()[0][0]);
|
|
74
|
+
if (invalidStats > 0) {
|
|
75
|
+
throw new Error(`normalizeVector() found ${invalidStats} dimension${invalidStats === 1 ? "" : "s"} with non-finite aggregate values after conversion to DOUBLE.`);
|
|
76
|
+
}
|
|
77
|
+
const constantDimensions = (await connection.runAndReadAll(`SELECT ${dimension} FROM ${q(statsName)}
|
|
78
|
+
WHERE ${minimum} = ${maximum} ORDER BY ${dimension}`)).getRowsJS().map((row) => Number(row[0]));
|
|
79
|
+
if (constantDimensions.length > 0) {
|
|
80
|
+
throw new Error(`normalizeVector() cannot scale constant dimension${constantDimensions.length === 1 ? "" : "s"} ${constantDimensions.join(", ")} in column ${q(sourceColumn)} because the range is zero. Remove ${constantDimensions.length === 1
|
|
81
|
+
? "that dimension"
|
|
82
|
+
: "those dimensions"} before normalizing. Conversion to DOUBLE can also collapse distinct large integers or decimals at its precision limit.`);
|
|
83
|
+
}
|
|
84
|
+
const value = `p.${q(prepared.vectorColumn)}[s.${dimension}]`;
|
|
85
|
+
const min = `s.${minimum}`;
|
|
86
|
+
const max = `s.${maximum}`;
|
|
87
|
+
// Dividing both sides by the larger magnitude when a range crosses zero
|
|
88
|
+
// avoids overflowing max - min for extreme finite DOUBLE values.
|
|
89
|
+
const scaled = `CASE
|
|
90
|
+
WHEN ${min} < 0 AND ${max} > 0 AND -${min} >= ${max}
|
|
91
|
+
THEN ((${value} / -${min}) + 1.0) / ((${max} / -${min}) + 1.0)
|
|
92
|
+
WHEN ${min} < 0 AND ${max} > 0
|
|
93
|
+
THEN ((${value} / ${max}) + (-${min} / ${max})) /
|
|
94
|
+
(1.0 + (-${min} / ${max}))
|
|
95
|
+
ELSE (${value} - ${min}) / (${max} - ${min})
|
|
96
|
+
END`;
|
|
97
|
+
await connection.run(`CREATE TEMP TABLE ${q(resultName)} AS
|
|
98
|
+
SELECT p.${q(prepared.rowIdColumn)},
|
|
99
|
+
list(${scaled} ORDER BY s.${dimension})::DOUBLE[${prepared.dimensions}]
|
|
100
|
+
AS ${q(normalized)}
|
|
101
|
+
FROM ${q(prepared.relation)} p CROSS JOIN ${q(statsName)} s
|
|
102
|
+
GROUP BY p.${q(prepared.rowIdColumn)}`);
|
|
103
|
+
}
|
|
104
|
+
const invalidResults = Number((await connection.runAndReadAll(`SELECT count(*) FROM ${q(resultName)}
|
|
105
|
+
WHERE ${q(normalized)} IS NULL
|
|
106
|
+
OR list_count(${q(normalized)}) != ${prepared.dimensions}
|
|
107
|
+
OR NOT list_bool_and(list_transform(${q(normalized)}, value -> isfinite(value)))
|
|
108
|
+
OR list_min(${q(normalized)}) < ${normalization === "rowL2" ? -1 : 0}
|
|
109
|
+
OR list_max(${q(normalized)}) > 1`)).getRowsJS()[0][0]);
|
|
110
|
+
if (invalidResults > 0) {
|
|
111
|
+
throw new Error(`normalizeVector() produced non-finite or out-of-range values for ${invalidResults} row${invalidResults === 1 ? "" : "s"}. Rescale the source values before normalizing.`);
|
|
112
|
+
}
|
|
113
|
+
await publishPreparedColumns(table, prepared, {
|
|
114
|
+
method: "normalizeVector()",
|
|
115
|
+
parameters: { column, newColumn, options },
|
|
116
|
+
result: {
|
|
117
|
+
relation: resultName,
|
|
118
|
+
rowIdColumn: prepared.rowIdColumn,
|
|
119
|
+
},
|
|
120
|
+
outputs: [{
|
|
121
|
+
name: overwrite ? sourceColumn : newColumn,
|
|
122
|
+
expression: `r.${q(normalized)}`,
|
|
123
|
+
replace: overwrite ? sourceColumn : undefined,
|
|
124
|
+
}],
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
finally {
|
|
128
|
+
await connection.run(`DROP TABLE IF EXISTS ${q(resultName)}`);
|
|
129
|
+
await connection.run(`DROP TABLE IF EXISTS ${q(statsName)}`);
|
|
130
|
+
await prepared.cleanup();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type SimpleTable from "../class/SimpleTable.js";
|
|
2
|
+
import type { GraphId } from "../helpers/prepareGraphStarts.js";
|
|
3
|
+
import { type GraphTemporalOptions } from "../helpers/prepareGraphTemporalSql.js";
|
|
4
|
+
import type { GraphDirection } from "../helpers/prepareGraphTraversal.js";
|
|
5
|
+
type PathsOptions = GraphTemporalOptions & {
|
|
6
|
+
direction?: GraphDirection;
|
|
7
|
+
outputTable?: string | boolean;
|
|
8
|
+
weight?: string;
|
|
9
|
+
};
|
|
10
|
+
export default function paths(simpleTable: SimpleTable, sourceColumn: string, targetColumn: string, edgeId: string, start: GraphId, end: GraphId, options?: PathsOptions): SimpleTable;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=paths.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"paths.d.ts","sourceRoot":"","sources":["../../src/methods/paths.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AASvD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAgC,EAC9B,KAAK,oBAAoB,EAG1B,MAAM,uCAAuC,CAAC;AAC/C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAM1E,KAAK,YAAY,GAAG,oBAAoB,GAAG;IACzC,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,KAAK,CAC3B,WAAW,EAAE,WAAW,EACxB,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,MAAM,EACpB,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,OAAO,EACZ,OAAO,GAAE,YAAiB,GACzB,WAAW,CA+Gb"}
|