#include #include #include #include #include #include "../Utils/bitSet.hpp" #include #include "undirectedGraph.hpp" #include "outlierScore.hpp" #include "cluster.hpp" #include "hdbscanConstraint.hpp" namespace hdbscanStar { class hdbscanAlgorithm { public: /// /// Calculates the core distances for each point in the data set, given some value for k. /// /// A vector of vectors where index [i][j] indicates the jth attribute /// of data point i Each point's core distance will be it's distance to /// the kth nearest neighbor An array of core distances static std::vector calculateCoreDistances(std::vector> distances, int k); static undirectedGraph constructMst(std::vector> distances, std::vector coreDistances, bool selfEdges); /// /// Propagates constraint satisfaction, stability, and lowest child death level from each child /// cluster to each parent cluster in the tree. This method must be called before calling /// findProminentClusters() or calculateOutlierScores(). /// /// A list of Clusters forming a cluster tree /// true if there are any clusters with infinite stability, false otherwise static void computeHierarchyAndClusterTree(undirectedGraph* mst, int minClusterSize, std::vector constraints, std::vector>& hierarchy, std::vector& pointNoiseLevels, std::vector& pointLastClusters, std::vector& clusters); static std::vector findProminentClusters(std::vector& clusters, std::vector>& hierarchy, int numPoints); static std::vector findMembershipScore(std::vector clusterids, std::vector coreDistances); static bool propagateTree(std::vector& sclusters); /// /// Produces the outlier score for each point in the data set, and returns a sorted list of /// outlier scores. propagateTree() must be called before calling this method. /// /// A list of Clusters forming a cluster tree which has already been /// propagated A double[] with the levels at which each /// point became noise An int[] with the last label each /// point had before becoming noise An array of core /// distances for each data point An List of OutlierScores, sorted in /// descending order static std::vector calculateOutlierScores(std::vector& clusters, std::vector& pointNoiseLevels, std::vector& pointLastClusters, std::vector coreDistances); /// /// Removes the set of points from their parent Cluster, and creates a new Cluster, provided the /// clusterId is not 0 (noise). /// /// The set of points to be in the new Cluster /// An array of cluster labels, which will be modified /// The parent Cluster of the new Cluster being created /// The label of the new Cluster /// The edge weight at which to remove the points from their previous /// Cluster The new Cluster, or null if the clusterId was 0 static cluster* createNewCluster(std::set& points, std::vector& clusterLabels, cluster* parentCluster, int clusterLabel, double edgeWeight); /// /// Calculates the number of constraints satisfied by the new clusters and virtual children of /// the parents of the new clusters. /// /// Labels of new clusters /// An List of clusters /// An List of constraints /// An array of current cluster labels for points static void calculateNumConstraintsSatisfied(std::set& newClusterLabels, std::vector& clusters, std::vector& constraints, std::vector& clusterLabels); }; } // namespace hdbscanStar