


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 % Last Modified By: sbm on Thu Oct 6 20:30:34 2005 0015 0016 %%%%%%%%%% ARGUMENT CHECKING 0017 if (~isfield(spikes, 'hierarchy')) 0018 error('SS:hierarchical_information_unavailable', 'Hierarchical clustering must be performed before attempting to merge clusters.'); 0019 elseif (~all(ismember([to,from], unique(spikes.hierarchy.assigns)))) 0020 error('SS:cluster_numbers_not_found', 'One or both of the cluster labels supplied does not exist.'); 0021 elseif ((length(from) > 1) | (length(to) > 1)) 0022 error('SS:one_at_a_time', 'The ''from'' and ''to'' labels must be scalar values.'); 0023 end 0024 if (to == 0) 0025 warning('Adding spikes to the outlier cluster.'); 0026 end 0027 0028 %%%%%%%%%% MERGING ASSIGNMENTS 0029 members_from = find(spikes.hierarchy.assigns == from); % Get list of spikes to move ... 0030 orig_members_to = find(spikes.hierarchy.assigns == to); % (we need this below) 0031 spikes.hierarchy.assigns(members_from) = to; % ... and relabel them. 0032 0033 %%%%%%%%%% COMPUTE CONNECTION STRENGTHS FROM INTERFACE ENERGY 0034 %% Temporary hack; this should be recomputed from the interface energy 0035 cs = 1; 0036 0037 %%%%%%%%%% MODIFY AGGREGATION TREE 0038 tmin = size(spikes.waveforms,2)./spikes.Fs; tref = max(0.002, tmin*1.5); 0039 if (isfield(spikes, 'spiketimes')) % might as well compute the isi score if we can ... 0040 t1 = spikes.spiketimes(orig_members_to); 0041 t2 = spikes.spiketimes(members_from); 0042 [allow, score] = isiQuality(t1, t2, tmin, 0.010, tref, spikes.Fs); 0043 score = score(3); 0044 else % ... but no stress if we can't 0045 score = 0; 0046 end 0047 spikes.hierarchy.tree = [spikes.hierarchy.tree; to from cs score]; 0048