bindsnet.evaluation package

Submodules

bindsnet.evaluation.evaluation module

bindsnet.evaluation.evaluation.all_activity(spikes: torch.Tensor, assignments: torch.Tensor, n_labels: int) → torch.Tensor[source]

Classify data with the label with highest average spiking activity over all neurons.

Parameters:
  • spikes – Binary tensor of shape (n_samples, time, n_neurons) of a layer’s spiking activity.
  • assignments – A vector of shape (n_neurons,) of neuron label assignments.
  • n_labels – The number of target labels in the data.
Returns:

Predictions tensor of shape (n_samples,) resulting from the “all activity” classification scheme.

bindsnet.evaluation.evaluation.assign_labels(spikes: torch.Tensor, labels: torch.Tensor, n_labels: int, rates: Optional[torch.Tensor] = None, alpha: float = 1.0) → Tuple[torch.Tensor, torch.Tensor, torch.Tensor][source]

Assign labels to the neurons based on highest average spiking activity.

Parameters:
  • spikes – Binary tensor of shape (n_samples, time, n_neurons) of a single layer’s spiking activity.
  • labels – Vector of shape (n_samples,) with data labels corresponding to spiking activity.
  • n_labels – The number of target labels in the data.
  • rates – If passed, these represent spike rates from a previous assign_labels() call.
  • alpha – Rate of decay of label assignments.
Returns:

Tuple of class assignments, per-class spike proportions, and per-class firing rates.

bindsnet.evaluation.evaluation.logreg_fit(spikes: torch.Tensor, labels: torch.Tensor, logreg: sklearn.linear_model._logistic.LogisticRegression) → sklearn.linear_model._logistic.LogisticRegression[source]

(Re)fit logistic regression model to spike data summed over time.

Parameters:
  • spikes – Summed (over time) spikes of shape (n_examples, time, n_neurons).
  • labels – Vector of shape (n_samples,) with data labels corresponding to spiking activity.
  • logreg – Logistic regression model from previous fits.
Returns:

(Re)fitted logistic regression model.

bindsnet.evaluation.evaluation.logreg_predict(spikes: torch.Tensor, logreg: sklearn.linear_model._logistic.LogisticRegression) → torch.Tensor[source]

Predicts classes according to spike data summed over time.

Parameters:
  • spikes – Summed (over time) spikes of shape (n_examples, time, n_neurons).
  • logreg – Logistic regression model from previous fits.
Returns:

Predictions per example.

bindsnet.evaluation.evaluation.ngram(spikes: torch.Tensor, ngram_scores: Dict[Tuple[int, ...], torch.Tensor], n_labels: int, n: int) → torch.Tensor[source]

Predicts between n_labels using ngram_scores.

Parameters:
  • spikes – Spikes of shape (n_examples, time, n_neurons).
  • ngram_scores – Previously recorded scores to update.
  • n_labels – The number of target labels in the data.
  • n – The max size of n-gram to use.
Returns:

Predictions per example.

bindsnet.evaluation.evaluation.proportion_weighting(spikes: torch.Tensor, assignments: torch.Tensor, proportions: torch.Tensor, n_labels: int) → torch.Tensor[source]

Classify data with the label with highest average spiking activity over all neurons, weighted by class-wise proportion.

Parameters:
  • spikes – Binary tensor of shape (n_samples, time, n_neurons) of a single layer’s spiking activity.
  • assignments – A vector of shape (n_neurons,) of neuron label assignments.
  • proportions – A matrix of shape (n_neurons, n_labels) giving the per-class proportions of neuron spiking activity.
  • n_labels – The number of target labels in the data.
Returns:

Predictions tensor of shape (n_samples,) resulting from the “proportion weighting” classification scheme.

bindsnet.evaluation.evaluation.update_ngram_scores(spikes: torch.Tensor, labels: torch.Tensor, n_labels: int, n: int, ngram_scores: Dict[Tuple[int, ...], torch.Tensor]) → Dict[Tuple[int, ...], torch.Tensor][source]

Updates ngram scores by adding the count of each spike sequence of length n from the past n_examples.

Parameters:
  • spikes – Spikes of shape (n_examples, time, n_neurons).
  • labels – The ground truth labels of shape (n_examples).
  • n_labels – The number of target labels in the data.
  • n – The max size of n-gram to use.
  • ngram_scores – Previously recorded scores to update.
Returns:

Dictionary mapping n-grams to vectors of per-class spike counts.

Module contents

bindsnet.evaluation.assign_labels(spikes: torch.Tensor, labels: torch.Tensor, n_labels: int, rates: Optional[torch.Tensor] = None, alpha: float = 1.0) → Tuple[torch.Tensor, torch.Tensor, torch.Tensor][source]

Assign labels to the neurons based on highest average spiking activity.

Parameters:
  • spikes – Binary tensor of shape (n_samples, time, n_neurons) of a single layer’s spiking activity.
  • labels – Vector of shape (n_samples,) with data labels corresponding to spiking activity.
  • n_labels – The number of target labels in the data.
  • rates – If passed, these represent spike rates from a previous assign_labels() call.
  • alpha – Rate of decay of label assignments.
Returns:

Tuple of class assignments, per-class spike proportions, and per-class firing rates.

bindsnet.evaluation.logreg_fit(spikes: torch.Tensor, labels: torch.Tensor, logreg: sklearn.linear_model._logistic.LogisticRegression) → sklearn.linear_model._logistic.LogisticRegression[source]

(Re)fit logistic regression model to spike data summed over time.

Parameters:
  • spikes – Summed (over time) spikes of shape (n_examples, time, n_neurons).
  • labels – Vector of shape (n_samples,) with data labels corresponding to spiking activity.
  • logreg – Logistic regression model from previous fits.
Returns:

(Re)fitted logistic regression model.

bindsnet.evaluation.logreg_predict(spikes: torch.Tensor, logreg: sklearn.linear_model._logistic.LogisticRegression) → torch.Tensor[source]

Predicts classes according to spike data summed over time.

Parameters:
  • spikes – Summed (over time) spikes of shape (n_examples, time, n_neurons).
  • logreg – Logistic regression model from previous fits.
Returns:

Predictions per example.

bindsnet.evaluation.all_activity(spikes: torch.Tensor, assignments: torch.Tensor, n_labels: int) → torch.Tensor[source]

Classify data with the label with highest average spiking activity over all neurons.

Parameters:
  • spikes – Binary tensor of shape (n_samples, time, n_neurons) of a layer’s spiking activity.
  • assignments – A vector of shape (n_neurons,) of neuron label assignments.
  • n_labels – The number of target labels in the data.
Returns:

Predictions tensor of shape (n_samples,) resulting from the “all activity” classification scheme.

bindsnet.evaluation.proportion_weighting(spikes: torch.Tensor, assignments: torch.Tensor, proportions: torch.Tensor, n_labels: int) → torch.Tensor[source]

Classify data with the label with highest average spiking activity over all neurons, weighted by class-wise proportion.

Parameters:
  • spikes – Binary tensor of shape (n_samples, time, n_neurons) of a single layer’s spiking activity.
  • assignments – A vector of shape (n_neurons,) of neuron label assignments.
  • proportions – A matrix of shape (n_neurons, n_labels) giving the per-class proportions of neuron spiking activity.
  • n_labels – The number of target labels in the data.
Returns:

Predictions tensor of shape (n_samples,) resulting from the “proportion weighting” classification scheme.

bindsnet.evaluation.ngram(spikes: torch.Tensor, ngram_scores: Dict[Tuple[int, ...], torch.Tensor], n_labels: int, n: int) → torch.Tensor[source]

Predicts between n_labels using ngram_scores.

Parameters:
  • spikes – Spikes of shape (n_examples, time, n_neurons).
  • ngram_scores – Previously recorded scores to update.
  • n_labels – The number of target labels in the data.
  • n – The max size of n-gram to use.
Returns:

Predictions per example.

bindsnet.evaluation.update_ngram_scores(spikes: torch.Tensor, labels: torch.Tensor, n_labels: int, n: int, ngram_scores: Dict[Tuple[int, ...], torch.Tensor]) → Dict[Tuple[int, ...], torch.Tensor][source]

Updates ngram scores by adding the count of each spike sequence of length n from the past n_examples.

Parameters:
  • spikes – Spikes of shape (n_examples, time, n_neurons).
  • labels – The ground truth labels of shape (n_examples).
  • n_labels – The number of target labels in the data.
  • n – The max size of n-gram to use.
  • ngram_scores – Previously recorded scores to update.
Returns:

Dictionary mapping n-grams to vectors of per-class spike counts.