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 the given non-hierarchical algorithm.
The whole extension contract of AbstractNonHierarchicalClusteringAlgorithm: a new member is a struct and one method of this function.
Algorithm
The KMeansAlgorithm method runs these steps.
- Combine
alg.rngandalg.seedwithresolve_rng, givingrng. A statedseedcopiesalg.rngand seeds the copy, soalg.rngnever advances and two calls of one estimator draw the same starts. Aseedofnothingpassesalg.rngitself through, so its state advances and the next call draws different starts. - Call
Clustering.kmeans(D, k; rng = rng, alg.kwargs...), giving the partition. Lloyd's algorithm runs inside that call, so the steps belowkmeansbelong toClustering.jl.
Arguments
alg: Non-hierarchical clustering algorithm.D: Distance matrix,assets x assets. Its columns are the points to cluster.k: Number of clusters to produce.
Returns
res::Clustering.ClusteringResult: The partition, carrying at least the fieldsoptimal_number_clustersreads —assignmentsand, underSecondOrderDifference,costs.
Related