Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
comik/getExpansionPoints.m
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
45 lines (40 sloc)
1.54 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function [expansionPoints, matrixOfDistancesFromCentres] = getExpansionPoints(X, nClusters, rep, debugLevel, debugMsgLocation) | |
% GETEXPANSIONPOINTS | |
% Performs k-means and returns the clusterCentres as the expansion points | |
% | |
% INPUT PARAMS | |
% Param X (matrix) | |
% All bags opened up into instances | |
% | |
% Param nClusters (matrix) | |
% Number of clusters for k-means | |
% | |
% OUTPUT PARAMS | |
% Param 'expansionPoints' (matrix) | |
% a set of expansionPoints, in other words cluster centres | |
% | |
% Param 'matrixOfDistancesFromCentres' (matrix) | |
% As the name suggests, | |
% | |
% ADDITIONAL NOTES | |
% | |
% Author: snikumbh@mpi-inf.mpg.de | |
logMessages(debugMsgLocation, sprintf('--- Obtaining a set of expansion points '), debugLevel); | |
% Obtained X in the input arguments is an n x p matrix, ready for kmeans | |
% expansionPoints, to be returned, is a k-by-p matrix | |
% Below, matrixOfDistancesFromCentres is a n-by-k matrix giving distances from each point to every | |
% cluster centre. | |
% | |
% sumD, from the Matlab documentation, is the within-cluster sums of point-to-centroid distances in a k-by-1 vector | |
% | |
tic; | |
rng('default'); | |
logMessages(debugMsgLocation, sprintf('with K-means: \n'), debugLevel); | |
if debugLevel == 2 | |
[idx, expansionPoints, sumD, matrixOfDistancesFromCentres] = kmeans(X, nClusters, 'Replicates', rep, 'Display','off'); | |
% Display could be set to 'final' | |
elseif debugLevel == 0 | |
[idx, expansionPoints, sumD, matrixOfDistancesFromCentres] = kmeans(X, nClusters, 'Replicates', rep, 'Display','off'); | |
end | |
logMessages(debugMsgLocation, sprintf('--- Took %.3f seconds\n',toc), debugLevel); | |
end |