Пример #1
0
 def compute_metric(self, num_channels_to_compare, max_spikes_per_cluster, **kwargs):
     params_dict = update_all_param_dicts_with_kwargs(kwargs)
     save_property_or_features = params_dict['save_property_or_features']
     seed = params_dict['seed']
     l_ratios_all = metrics.calculate_pc_metrics(
         spike_clusters=self._metric_data._spike_clusters_pca,
         total_units=self._metric_data._total_units,
         pc_features=self._metric_data._pc_features,
         pc_feature_ind=self._metric_data._pc_feature_ind,
         num_channels_to_compare=num_channels_to_compare,
         max_spikes_for_cluster=max_spikes_per_cluster,
         channel_locations=self._metric_data._channel_locations,
         spikes_for_nn=None,
         n_neighbors=None,
         metric_names=["l_ratio"],
         seed=seed,
         spike_cluster_subset=self._metric_data._unit_indices,
         verbose=self._metric_data.verbose,
     )[1]
     l_ratios_list = []
     for i in self._metric_data._unit_indices:
         l_ratios_list.append(l_ratios_all[i])
     l_ratios = np.asarray(l_ratios_list)
     if save_property_or_features:
         self.save_property_or_features(self._metric_data._sorting, l_ratios, self._metric_name)
     return l_ratios
Пример #2
0
    def compute_metric(self, num_channels_to_compare, max_spikes_per_cluster, **kwargs):
        params_dict = update_all_param_dicts_with_kwargs(kwargs)
        save_property_or_features = params_dict['save_property_or_features']
        seed = params_dict['seed']

        isolation_distances_epochs = []
        for epoch in self._metric_data._epochs:
            in_epoch = self._metric_data.get_in_epoch_bool_mask(epoch, self._metric_data._spike_times_pca)
            isolation_distances_all = metrics.calculate_pc_metrics(
                spike_clusters=self._metric_data._spike_clusters_pca[in_epoch],
                total_units=self._metric_data._total_units,
                pc_features=self._metric_data._pc_features[in_epoch, :, :],
                pc_feature_ind=self._metric_data._pc_feature_ind,
                num_channels_to_compare=num_channels_to_compare,
                max_spikes_for_cluster=max_spikes_per_cluster,
                spikes_for_nn=None,
                n_neighbors=None,
                metric_names=["isolation_distance"],
                seed=seed,
                verbose=self._metric_data.verbose,
            )[0]
            isolation_distances_list = []
            for i in self._metric_data._unit_indices:
                isolation_distances_list.append(isolation_distances_all[i])
            isolation_distances = np.asarray(isolation_distances_list)
            isolation_distances_epochs.append(isolation_distances)
        if save_property_or_features:
            self.save_property_or_features(self._metric_data._sorting, isolation_distances_epochs, self._metric_name)
        return isolation_distances_epochs
    def compute_metric(self, num_channels_to_compare, max_spikes_per_cluster,
                       seed, save_as_property):

        isolation_distances_epochs = []
        for epoch in self._metric_data._epochs:
            in_epoch = np.logical_and(
                self._metric_data._spike_times_pca > epoch[1],
                self._metric_data._spike_times_pca < epoch[2],
            )
            isolation_distances_all = metrics.calculate_pc_metrics(
                spike_clusters=self._metric_data._spike_clusters_pca[in_epoch],
                total_units=self._metric_data._total_units,
                pc_features=self._metric_data._pc_features[in_epoch, :, :],
                pc_feature_ind=self._metric_data._pc_feature_ind,
                num_channels_to_compare=num_channels_to_compare,
                max_spikes_for_cluster=max_spikes_per_cluster,
                spikes_for_nn=None,
                n_neighbors=None,
                metric_names=["isolation_distance"],
                seed=seed,
                verbose=self._metric_data.verbose,
            )[0]
            isolation_distances_list = []
            for i in self._metric_data._unit_indices:
                isolation_distances_list.append(isolation_distances_all[i])
            isolation_distances = np.asarray(isolation_distances_list)
            isolation_distances_epochs.append(isolation_distances)
        if save_as_property:
            self.save_as_property(self._metric_data._sorting,
                                  isolation_distances_epochs,
                                  self._metric_name)
        return isolation_distances_epochs
Пример #4
0
    def compute_metric(self, num_channels_to_compare, max_spikes_per_cluster,
                       max_spikes_for_nn, n_neighbors, **kwargs):
        params_dict = update_all_param_dicts_with_kwargs(kwargs)
        save_property_or_features = params_dict['save_property_or_features']
        seed = params_dict['seed']

        nn_hit_rates_epochs = []
        nn_miss_rates_epochs = []
        for epoch in self._metric_data._epochs:
            in_epoch = self._metric_data.get_in_epoch_bool_mask(
                epoch, self._metric_data._spike_times_pca)
            spikes_in_epoch = np.sum(in_epoch)
            spikes_for_nn = np.min([spikes_in_epoch, max_spikes_for_nn])
            nn_hit_rates_all, nn_miss_rates_all = metrics.calculate_pc_metrics(
                spike_clusters=self._metric_data._spike_clusters_pca[in_epoch],
                total_units=self._metric_data._total_units,
                pc_features=self._metric_data._pc_features[in_epoch, :, :],
                pc_feature_ind=self._metric_data._pc_feature_ind,
                num_channels_to_compare=num_channels_to_compare,
                max_spikes_for_cluster=max_spikes_per_cluster,
                spikes_for_nn=spikes_for_nn,
                n_neighbors=n_neighbors,
                metric_names=["nearest_neighbor"],
                seed=seed,
                verbose=self._metric_data.verbose,
            )[3:5]
            nn_hit_rates_list = []
            nn_miss_rates_list = []
            for i in self._metric_data._unit_indices:
                nn_hit_rates_list.append(nn_hit_rates_all[i])
                nn_miss_rates_list.append(nn_miss_rates_all[i])
            nn_hit_rates = np.asarray(nn_hit_rates_list)
            nn_miss_rates = np.asarray(nn_miss_rates_list)
            nn_hit_rates_epochs.append(nn_hit_rates)
            nn_miss_rates_epochs.append(nn_miss_rates)
        if save_property_or_features:
            self.save_property_or_features(self._metric_data._sorting,
                                           nn_hit_rates_epochs,
                                           metric_name="nn_hit_rate")
            self.save_property_or_features(self._metric_data._sorting,
                                           nn_miss_rates_epochs,
                                           metric_name="nn_miss_rate")
        return list(zip(nn_hit_rates_epochs, nn_miss_rates_epochs))
Пример #5
0
    def compute_metric(self, num_channels_to_compare, max_spikes_per_cluster,
                       max_spikes_for_nn, n_neighbors, seed, save_as_property):

        nn_hit_rates_epochs = []
        nn_miss_rates_epochs = []
        for epoch in self._metric_data._epochs:
            in_epoch = np.logical_and(
                self._metric_data._spike_times_pca > epoch[1],
                self._metric_data._spike_times_pca < epoch[2])
            spikes_in_epoch = np.sum(in_epoch)
            spikes_for_nn = np.min([spikes_in_epoch, max_spikes_for_nn])
            nn_hit_rates_all, nn_miss_rates_all = metrics.calculate_pc_metrics(
                spike_clusters=self._metric_data._spike_clusters_pca[in_epoch],
                total_units=self._metric_data._total_units,
                pc_features=self._metric_data._pc_features[in_epoch, :, :],
                pc_feature_ind=self._metric_data._pc_feature_ind,
                num_channels_to_compare=num_channels_to_compare,
                max_spikes_for_cluster=max_spikes_per_cluster,
                spikes_for_nn=spikes_for_nn,
                n_neighbors=n_neighbors,
                metric_names=["nearest_neighbor"],
                seed=seed,
                verbose=self._metric_data.verbose,
            )[3:5]
            nn_hit_rates_list = []
            nn_miss_rates_list = []
            for i in self._metric_data._unit_indices:
                nn_hit_rates_list.append(nn_hit_rates_all[i])
                nn_miss_rates_list.append(nn_miss_rates_all[i])
            nn_hit_rates = np.asarray(nn_hit_rates_list)
            nn_miss_rates = np.asarray(nn_miss_rates_list)
            nn_hit_rates_epochs.append(nn_hit_rates)
            nn_miss_rates_epochs.append(nn_miss_rates)
        if save_as_property:
            self.save_as_property(self._metric_data._sorting,
                                  nn_hit_rates_epochs,
                                  metric_name="nn_hit_rate")
            self.save_as_property(self._metric_data._sorting,
                                  nn_miss_rates_epochs,
                                  metric_name="nn_miss_rate")
        return list(zip(nn_hit_rates_epochs, nn_miss_rates_epochs))
Пример #6
0
 def compute_metric(self, num_channels_to_compare, max_spikes_per_cluster,
                    max_spikes_for_nn, n_neighbors, **kwargs):
     params_dict = update_all_param_dicts_with_kwargs(kwargs)
     save_property_or_features = params_dict['save_property_or_features']
     seed = params_dict['seed']
     total_spikes = self._metric_data._spike_clusters_pca.shape[0]
     spikes_for_nn = np.min([total_spikes, max_spikes_for_nn])
     nn_hit_rates_all, nn_miss_rates_all = metrics.calculate_pc_metrics(
         spike_clusters=self._metric_data._spike_clusters_pca,
         total_units=self._metric_data._total_units,
         pc_features=self._metric_data._pc_features,
         pc_feature_ind=self._metric_data._pc_feature_ind,
         num_channels_to_compare=num_channels_to_compare,
         max_spikes_for_cluster=max_spikes_per_cluster,
         spikes_for_nn=spikes_for_nn,
         n_neighbors=n_neighbors,
         channel_locations=self._metric_data._channel_locations,
         metric_names=["nearest_neighbor"],
         seed=seed,
         spike_cluster_subset=self._metric_data._unit_indices,
         verbose=self._metric_data.verbose,
     )[3:5]
     nn_hit_rates_list = []
     nn_miss_rates_list = []
     for i in self._metric_data._unit_indices:
         nn_hit_rates_list.append(nn_hit_rates_all[i])
         nn_miss_rates_list.append(nn_miss_rates_all[i])
     nn_hit_rates = np.asarray(nn_hit_rates_list)
     nn_miss_rates = np.asarray(nn_miss_rates_list)
     if save_property_or_features:
         self.save_property_or_features(self._metric_data._sorting,
                                        nn_hit_rates,
                                        metric_name="nn_hit_rate")
         self.save_property_or_features(self._metric_data._sorting,
                                        nn_miss_rates,
                                        metric_name="nn_miss_rate")
     return [nn_hit_rates_list, nn_miss_rates]