Skip to content

HMath.MachineLearning.Clustering

Module index · Numerical conventions

Description

Dense, finite-budget clustering. Distances are Euclidean, labels zero based; DBSCAN noise is -1. OPTICS preserves undefined reachability as Nothing. Affinity propagation uses Frey & Dueck's responsibility/availability updates (Science 2007, doi:10.1126/science.1136800), with explicit damping.

On this page

API Purpose
ClusterModel Fitted cluster centroids as cluster-by-feature observations; prediction assigns new queries to the learned centers.
clusterCenters Cluster centroids as cluster-by-feature rows.
predictClusters Assign each row to its closest squared-Euclidean center; ties use the first center.
kMeans Seeded random-center Lloyd iteration; residual is total center displacement.
kMeansPlusPlus D-squared k-means++ initialization followed by Lloyd center updates.
miniBatchKMeans Online center updates with per-cluster counts and seeded shuffled batches.
kMedoids PAM exhaustive medoid swaps.
GaussianMixture Fitted component probabilities,mean vectors,and covariance matrices in shared component order.
mixtureWeights Gaussian-mixture component probabilities in component order.
mixtureMeans Component mean vectors, matching mixtureWeights order.
mixtureCovariances One feature-by-feature covariance matrix per Gaussian component.
fitGaussianMixture Full-covariance EM initialized by k-means++; positive ridge is added at each covariance update.
mixtureResponsibilities Compute normalized posterior component probabilities with log-sum-exp stabilization.
dbscan Density expansion using a positive Euclidean radius; minimumPoints includes the observation itself.
optics OPTICS (Ankerst et al., SIGMOD 1999): ordered point index, core distance, reachability distance.
extractOPTICS Extract DBSCAN-style labels at epsilon from a checked OPTICS ordering; noise is -1.
meanShift Gaussian-kernel mean shift from every training point; modes within bandwidth/2 are merged.
Linkage Single, complete, average Euclidean distance or Ward variance-increase linkage.
Single Declaration and type contract below.
Complete Declaration and type contract below.
Average Declaration and type contract below.
Ward Declaration and type contract below.
Merge One hierarchical-clustering merge, retaining child IDs,linkage distance,and merged observation count.
Merge Declaration and type contract below.
leftCluster Left child cluster ID in a hierarchical merge.
rightCluster Right child cluster ID in a hierarchical merge.
mergeDistance Linkage distance at which the two child clusters merge.
mergedSize Number of original observations in the merged cluster.
hierarchical Agglomerate the closest active clusters to produce all n-1 linkage rows.
cutHierarchy Validate the entire hierarchy and return k cluster labels in original observation order.
spectralClustering Cluster row-normalized leading eigenvectors of the normalized Gaussian affinity matrix.
affinityPropagation The preference is the common diagonal similarity; damping is in [0.5,1).

Documentation

ClusterModel

data ClusterModel Source #

Fitted cluster centroids as cluster-by-feature observations; prediction assigns new queries to the learned centers.

clusterCenters

clusterCenters :: ClusterModel -> Dataset Source #

Cluster centroids as cluster-by-feature rows.

predictClusters

predictClusters :: ClusterModel -> Dataset -> Either MathError [Int] Source #

Assign each row to its closest squared-Euclidean center; ties use the first center.

kMeans

kMeans :: MLConfig -> Int -> Dataset -> Either MathError (Fit ClusterModel) Source #

Seeded random-center Lloyd iteration; residual is total center displacement.

kMeansPlusPlus

kMeansPlusPlus :: MLConfig -> Int -> Dataset -> Either MathError (Fit ClusterModel) Source #

D-squared k-means++ initialization followed by Lloyd center updates.

miniBatchKMeans

miniBatchKMeans :: MLConfig -> Int -> Int -> Dataset -> Either MathError (Fit ClusterModel) Source #

Online center updates with per-cluster counts and seeded shuffled batches. One outer iteration consumes batchSize observations, cycling shuffled data.

kMedoids

kMedoids :: MLConfig -> Int -> Dataset -> Either MathError (Fit [Int]) Source #

PAM exhaustive medoid swaps. Return original row indices; residual is the objective decrease.

GaussianMixture

data GaussianMixture Source #

Fitted component probabilities,mean vectors,and covariance matrices in shared component order.

mixtureWeights

mixtureWeights :: GaussianMixture -> [Double] Source #

Gaussian-mixture component probabilities in component order.

mixtureMeans

mixtureMeans :: GaussianMixture -> Dataset Source #

Component mean vectors, matching mixtureWeights order.

mixtureCovariances

mixtureCovariances :: GaussianMixture -> [Dataset] Source #

One feature-by-feature covariance matrix per Gaussian component.

fitGaussianMixture

fitGaussianMixture :: MLConfig -> Int -> Double -> Dataset -> Either MathError (Fit GaussianMixture) Source #

Full-covariance EM initialized by k-means++; positive ridge is added at each covariance update. Collapsed component mass fails.

mixtureResponsibilities

mixtureResponsibilities :: GaussianMixture -> Dataset -> Either MathError Dataset Source #

Compute normalized posterior component probabilities with log-sum-exp stabilization.

dbscan

dbscan :: Double -> Int -> Dataset -> Either MathError [Int] Source #

Density expansion using a positive Euclidean radius; minimumPoints includes the observation itself.

optics

optics :: Double -> Int -> Dataset -> Either MathError [(Int, Maybe Double, Maybe Double)] Source #

OPTICS (Ankerst et al., SIGMOD 1999): ordered point index, core distance, reachability distance. Undefined reachability starts each connected expansion.

extractOPTICS

extractOPTICS :: Double -> [(Int, Maybe Double, Maybe Double)] -> Either MathError [Int] Source #

Extract DBSCAN-style labels at epsilon from a checked OPTICS ordering; noise is -1.

meanShift

meanShift :: MLConfig -> Double -> Dataset -> Either MathError (Fit ClusterModel) Source #

Gaussian-kernel mean shift from every training point; modes within bandwidth/2 are merged.

Linkage

data Linkage Source #

Single, complete, average Euclidean distance or Ward variance-increase linkage.

Constructors

Single 
Complete 
Average 
Ward 

Instances

Instances details
Show Linkage Source # 
Instance details

Defined in HMath.MachineLearning.Clustering

Eq Linkage Source # 
Instance details

Defined in HMath.MachineLearning.Clustering

Methods

(==) :: Linkage -> Linkage -> Bool #

(/=) :: Linkage -> Linkage -> Bool #

Merge

data Merge Source #

One hierarchical-clustering merge, retaining child IDs,linkage distance,and merged observation count.

Constructors

Merge 

Fields

Instances

Instances details
Show Merge Source # 
Instance details

Defined in HMath.MachineLearning.Clustering

Methods

showsPrec :: Int -> Merge -> ShowS #

show :: Merge -> String #

showList :: [Merge] -> ShowS #

Eq Merge Source # 
Instance details

Defined in HMath.MachineLearning.Clustering

Methods

(==) :: Merge -> Merge -> Bool #

(/=) :: Merge -> Merge -> Bool #

hierarchical

hierarchical :: Linkage -> Dataset -> Either MathError [Merge] Source #

Agglomerate the closest active clusters to produce all n-1 linkage rows.

cutHierarchy

cutHierarchy :: Int -> Int -> [Merge] -> Either MathError [Int] Source #

Validate the entire hierarchy and return k cluster labels in original observation order.

spectralClustering

spectralClustering :: MLConfig -> Int -> Double -> Dataset -> Either MathError (Fit [Int]) Source #

Cluster row-normalized leading eigenvectors of the normalized Gaussian affinity matrix.

affinityPropagation

affinityPropagation :: MLConfig -> Double -> Double -> Dataset -> Either MathError (Fit [Int]) Source #

The preference is the common diagonal similarity; damping is in [0.5,1). Stops only after exemplar identities remain unchanged for ten iterations.