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.
- Combine
alg.rngandalg.seedintorngwithresolve_rng. Ifseedis stated,resolve_rngcopiesalg.rngand seeds the copy, soalg.rngdoes not advance and two calls of one estimator draw the same starts. Ifseedisnothing,rngisalg.rngitself, so its state advances and the next call draws different starts. - Call
Clustering.kmeans(D, k; rng = rng, alg.kwargs...)and return the partition. Lloyd's algorithm runs inside that call, andClustering.jlowns 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
res::Clustering.ClusteringResult: The partition. It has at least the fields thatoptimal_number_clustersreads, which areassignmentsand, underSecondOrderDifference,costs.
Related