Skip to main content
Ctrl+K

SpikeRNN

Getting Started

  • Installation
  • Quick Start Guide
  • Examples

API Reference

  • Rate RNN
    • Rate RNN Model
    • Utilities
  • Spiking RNN
    • LIF Network Function
    • Go-NoGo Evaluation
    • Scaling Factor Grid Search
    • Utilities

User Guide

  • SpikeRNN: Tutorials
  • Contributing to SpikeRNN

Scaling Factor Grid Search

Contents

  • Main Functions
    • lambda_grid_search()
    • evaluate_single_trial()
  • Grid Search Parameters
  • Single Trial Evaluation
  • Example Usage
  • Optimization Process
  • Performance Metrics
  • Output Files
  • Output

Scaling Factor Grid Search#

Functions for optimizing the scaling factor (lambda) used in rate-to-spike conversion. The scaling factor is crucial for maintaining task performance when converting from continuous rate dynamics to discrete spiking dynamics.

The optimization process:

  • Tests multiple scaling factors across a predefined range

  • Evaluates spiking network performance for each scaling factor

  • Uses parallel processing for efficient computation

  • Saves the optimal scaling factor to the model file

  • Supports all cognitive tasks (Go-NoGo, XOR, Mante)

Main Functions#

spiking.lambda_grid_search.lambda_grid_search(model_dir='../models/go-nogo/P_rec_0.2_Taus_4.0_20.0', n_trials=100, scaling_factors=[20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75], task_name='go-nogo')[source]#

Perform a grid search to find the optimal scaling factor for a given task.

Parameters:
  • model_dir (str) – The directory containing the trained rate RNN model .mat files. Default: ‘../models/go-nogo/P_rec_0.2_Taus_4.0_20.0’

  • n_trials (int) – The number of trials to use to evaluate the LIF RNN. Default: 100

  • scaling_factors (list) – The scaling factor values to try for grid search. Default: [20, 25, 30, …, 75]

  • task_name (str) – The name of the task to evaluate (‘go-nogo’, ‘xor’, or ‘mante’). Default: ‘go-nogo’

The optimal scaling factor and performance metrics are saved back to the original .mat file with the following new fields: - opt_scaling_factor: The scaling factor that achieved best performance - all_perfs: Performance scores for all tested scaling factors - scaling_factors: List of all scaling factors that were tested

spiking.lambda_grid_search.evaluate_single_trial(args)[source]#

Helper function for parallel processing of single trials

Grid Search Parameters#

The main grid search function accepts:

  • model_dir (str): Directory containing trained rate RNN model .mat files (default: ‘../models/go-nogo/P_rec_0.2_Taus_4.0_20.0’)

  • n_trials (int): Number of trials to evaluate each scaling factor (default: 100)

  • scaling_factors (list): List of scaling factors to test (default: [20, 25, 30, …, 75])

  • task_name (str): Task type (‘go-nogo’, ‘xor’, or ‘mante’) (default: ‘go-nogo’)

Single Trial Evaluation#

The evaluate_single_trial function tests a specific scaling factor:

  • curr_full (str): Full path to model file

  • scaling_factor (float): Scaling factor to test

  • trial_params (dict): Trial parameters including stimulus and task settings

  • task_name (str): Name of the task to evaluate

Returns performance metrics for the given scaling factor.

Example Usage#

from spiking import lambda_grid_search

# Basic grid search with default parameters
lambda_grid_search()

# Grid search with custom parameters
lambda_grid_search(
    model_dir='models/go-nogo',
    n_trials=50,
    scaling_factors=list(range(30, 81, 5)),
    task_name='go-nogo'
)

# Evaluate a single trial
from spiking.lambda_grid_search import evaluate_single_trial

performance = evaluate_single_trial(
    model_path='models/go-nogo/trained_model.mat',
    scaling_factor=50.0,
    trial_params={},
    task_name='go-nogo'
)

Optimization Process#

The grid search follows these steps:

  1. Load trained rate models from the specified directory

  2. Generate test stimuli appropriate for the task type

  3. Iterate through scaling factors in the specified range

  4. Convert to spiking network for each scaling factor

  5. Evaluate performance using task-specific metrics

  6. Select optimal scaling factor based on performance

  7. Save optimal value to model file for future use

Performance Metrics#

Different metrics are used depending on the task:

Go-NoGo Task:

  • Response accuracy for Go trials

  • Response inhibition accuracy for NoGo trials

  • Combined accuracy score

XOR Task:

  • Output accuracy for all input combinations

  • Temporal precision of responses

Mante Task:

  • Context-dependent decision accuracy

  • Sensory integration performance

Output Files#

The function modifies each input .mat file to include:

  • opt_scaling_factor: The optimal scaling factor found

  • all_perfs: Performance scores for all tested scaling factors

  • scaling_factors: List of all scaling factors that were tested

Output#

The function outputs:

  • Progress updates during optimization

  • Performance scores for each scaling factor tested

  • Optimal scaling factor and its performance

  • Updated model file with optimal scaling factor saved

previous

Go-NoGo Evaluation

next

Utilities

Contents
  • Main Functions
    • lambda_grid_search()
    • evaluate_single_trial()
  • Grid Search Parameters
  • Single Trial Evaluation
  • Example Usage
  • Optimization Process
  • Performance Metrics
  • Output Files
  • Output

By NuttidaLab

© Copyright 2025, NuttidaLab.