Non hierarchical clustering: private API

PortfolioOptimisers.get_k_clusters_from_alg — Function
get_k_clusters_from_alg(alg, D, k)

Partition the assets into k clusters with a non-hierarchical algorithm.

A new subtype of AbstractNonHierarchicalClusteringAlgorithm needs a struct and one method of this function. The method returns the result that # Returns states.

Algorithm

The KMeansAlgorithm method runs these steps.

  1. Combine alg.rng and alg.seed into rng with resolve_rng. If seed is stated, resolve_rng copies alg.rng and seeds the copy, so alg.rng does not advance and two calls of one estimator draw the same starts. If seed is nothing, rng is alg.rng itself, so its state advances and the next call draws different starts.
  2. Call Clustering.kmeans(D, k; rng = rng, alg.kwargs...) and return the partition. Lloyd's algorithm runs inside that call, and Clustering.jl owns its steps.

Arguments

  • alg: The non-hierarchical clustering algorithm.
  • D: The distance matrix, assets x assets. Its columns are the points to cluster.
  • k: The number of clusters to make.

Returns

Related

source