


MERGE_CLUSTERS Merge two clusters after automatic hierarchical aggregation.
SPIKES = MERGE_CLUSTERS(SPIKES, TO, FROM) 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.
All spikes belonging to the cluster whose label number is given by FROM
are merged into the cluster with label TO. The hierarchical clustering
assignments and aggregation tree are modified to reflect this change.
If SPIKES contains a SPIKETIMES vector, the ratio of the interspike
interval count below 2 msec to the count below 10 msec is computed and
entered into the SPIKES.HIERARCHY.TREE.

0001 function spikes = merge_clusters(spikes, to, from) 0002 % MERGE_CLUSTERS Merge two clusters after automatic hierarchical aggregation. 0003 % SPIKES = MERGE_CLUSTERS(SPIKES, TO, FROM) 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 % All spikes belonging to the cluster whose label number is given by FROM 0008 % are merged into the cluster with label TO. The hierarchical clustering 0009 % assignments and aggregation tree are modified to reflect this change. 0010 % If SPIKES contains a SPIKETIMES vector, the ratio of the interspike 0011 % interval count below 2 msec to the count below 10 msec is computed and 0012 % entered into the SPIKES.HIERARCHY.TREE. 0013 0014 %%%%%%%%%% ARGUMENT CHECKING 0015 if (~isfield(spikes, 'hierarchy')) 0016 error('SS:hierarchical_information_unavailable', 'Hierarchical clustering must be performed before attempting to merge clusters.'); 0017 elseif (~all(ismember([to,from], unique(spikes.hierarchy.assigns)))) 0018 error('SS:cluster_numbers_not_found', 'One or both of the cluster labels supplied does not exist.'); 0019 elseif ((length(from) > 1) || (length(to) > 1)) 0020 error('SS:one_at_a_time', 'The ''from'' and ''to'' labels must be scalar values.'); 0021 end 0022 if (to == 0) 0023 warning('SS:merge_outliers', 'Adding spikes to the outlier cluster.'); 0024 end 0025 0026 %%%%%%%%%% MERGING ASSIGNMENTS 0027 members_from = find(spikes.hierarchy.assigns == from); % Get list of spikes to move ... 0028 orig_members_to = find(spikes.hierarchy.assigns == to); % (we need this below) 0029 spikes.hierarchy.assigns(members_from) = to; % ... and relabel them. 0030 0031 %%%%%%%%%% COMPUTE CONNECTION STRENGTHS FROM INTERFACE ENERGY 0032 %% Temporary hack; this should be recomputed from the interface energy 0033 cs = 1; 0034 0035 %%%%%%%%%% MODIFY AGGREGATION TREE 0036 tmin = size(spikes.waveforms,2)./spikes.Fs; tref = max(0.002, tmin*1.5); 0037 if (isfield(spikes, 'spiketimes')) % might as well compute the isi score if we can ... 0038 t1 = spikes.spiketimes(orig_members_to); 0039 t2 = spikes.spiketimes(members_from); 0040 [allow, score] = isiQuality(t1, t2, tmin, 0.010, tref, spikes.Fs); 0041 score = score(3); 0042 else % ... but no stress if we can't 0043 score = 0; 0044 end 0045 spikes.hierarchy.tree = [spikes.hierarchy.tree; to from cs score]; 0046