Random Swap
UnsupervisedClustering.RandomSwap — TypeRandomSwap{LS}(
local_search::LS
verbose::Bool = DEFAULT_VERBOSE
max_iterations::Int = 200
max_iterations_without_improvement::Int = 150
) where {LS <: AbstractAlgorithm}RandomSwap is a meta-heuristic approach used for clustering problems. It follows an iterative process that combines local optimization with perturbation to explore the search space effectively. A local optimization algorithm is applied at each iteration to converge toward a local optimum. Then, a perturbation operator generates a new starting point and continues the search.
Type Parameters
LS: the specific type of the local search algorithm
Fields
local_search: the clustering algorithm applied to improve the solution in each meta-heuristics iteration.verbose: controls whether the algorithm should display additional information during execution.max_iterations: represents the maximum number of iterations the algorithm will perform before stopping.max_iterations_without_improvement: represents the maximum number of iterations allowed without improving the best solution.
References
- Fränti, Pasi. Efficiency of random swap clustering. Journal of big data 5.1 (2018): 1-29.
UnsupervisedClustering.fit — Methodfit(
meta::RandomSwap,
data::AbstractMatrix{<:Real},
k::Integer
)The fit function applies a random swap to a clustering problem and returns a result object representing the clustering outcome.
Parameters:
meta: an instance representing the clustering settings and parameters.data: a floating-point matrix, where each row represents a data point, and each column represents a feature.k: an integer representing the number of clusters.
Example
n = 100
d = 2
k = 2
data = rand(n, d)
kmeans = Kmeans()
random_swap = RandomSwap(local_search = kmeans)
result = fit(random_swap, data, k)