Home > chronux_1_50 > spikesort > split_cluster.m

split_cluster

PURPOSE ^

SPLIT_CLUSTERS Split a cluster after automatic hierarchical aggregation.

SYNOPSIS ^

function spikes = split_cluster(spikes, clustnum)

DESCRIPTION ^

 SPLIT_CLUSTERS  Split a cluster after automatic hierarchical aggregation.
    SPIKES = SPLIT_CLUSTERS(SPIKES, CLUSTER_NUMBER) takes and returns a spike-
    sorting object SPIKES.  SPIKES must have gone through a hierarchical
    clustering aggregation (e.g., SS_AGGREGATE) previous to this function call.
   
    The spikes belonging to the cluster whose label number is given by
    CLUSTER_NUMBER are split into the two clusters by undoing the last step
    in the aggregation tree involving the cluster with label CLUSTER_NUMBER.
    The hierarchical cluster assignments and aggregation tree is modified to
    reflect this change.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function spikes = split_cluster(spikes, clustnum)
0002 % SPLIT_CLUSTERS  Split a cluster after automatic hierarchical aggregation.
0003 %    SPIKES = SPLIT_CLUSTERS(SPIKES, CLUSTER_NUMBER) takes and returns a spike-
0004 %    sorting object SPIKES.  SPIKES must have gone through a hierarchical
0005 %    clustering aggregation (e.g., SS_AGGREGATE) previous to this function call.
0006 %
0007 %    The spikes belonging to the cluster whose label number is given by
0008 %    CLUSTER_NUMBER are split into the two clusters by undoing the last step
0009 %    in the aggregation tree involving the cluster with label CLUSTER_NUMBER.
0010 %    The hierarchical cluster assignments and aggregation tree is modified to
0011 %    reflect this change.
0012 
0013 %   Last Modified By: sbm on Thu Oct  6 20:30:34 2005
0014 
0015 %%%%%%%%%% ARGUMENT CHECKING
0016 if (~isfield(spikes, 'hierarchy'))
0017     error('SS:hierarchical_information_unavailable', 'Hierarchical clustering must be performed before attempting to merge clusters.');
0018 elseif (~ismember(clustnum, unique(spikes.hierarchy.assigns)))
0019     error('SS:cluster_number_not_found', 'The cluster label supplied does not exist.');
0020 end
0021 
0022 %%%%%%%%%% FINDING INDICES OF SPIKES TO SPLIT
0023 tree = spikes.hierarchy.tree;                       % (convenient shorthand)
0024 treeentry = max(find(tree(:,1) == clustnum));       % where was the target cluster last merged into ...
0025 breakaway = tree(treeentry, 2);                     % ... and who was the lucky mergee?
0026 
0027 % The breakaway cluster may have itself been created by merging several original clusters, so
0028 % we need to walk up the aggregation list to find all original (i.e., overcluster) labels
0029 % that contribute to newly formed breakaway.
0030 for (entry = (treeentry-1):-1:1)
0031     if (ismember(tree(entry, 1), breakaway))
0032         breakaway = [breakaway tree(entry,2)];
0033     end
0034 end
0035 
0036 % Now get the list of spikes indices for the new cluster
0037 members_breakaway = find(ismember(spikes.overcluster.assigns, breakaway));
0038 
0039 %%%%%%%%%% DO THE SPLIT
0040 spikes.hierarchy.assigns(members_breakaway) = breakaway(1);  % Using this label keeps the tree accurate
0041 spikes.hierarchy.tree(treeentry,:) = [];

Generated on Mon 09-Oct-2006 00:54:52 by m2html © 2003