Skip to main content

SPICE: Sparse and Interpretable Cognitive Equations

Project description

Computational Discovery of Sparse and Interpretable Cognitive Equations (SPICE)

SPICE Logo

SPICE is a framework for automating scientific practice in cognitive science and is based on a two cornerstones:

  1. A task-specific RNN is trained to predict human behavior and thus learn implicitly latent cognitive mechanisms.

  2. Sparse Identification of nonlinear Dynamics (SINDy; an equation discovery algorithm) is used to obtain mathematically interpretable equations for the learned cognitive mechanisms.

The resulting model with the neural-network architecture but with equations instead of RNN modules is called SPICE model. An overview is given in Figure 1.

This README file gives an overview on how to install and run SPICE as a scikit-learn estimator. To learn how to use SPICE in more comprehensive scenarios, you can go to tutorials.

Figure 1 - SPICE Overview

Installation

You can install SPICE using pip:

pip install autospice

or, you can clone this repository and install it locally from the root folder:

pip install -e .

Features

  • Scikit-learn compatible estimator interface
  • Customizable network architecture for identifying complex cognitive mechanisms
  • Participant embeddings for identifying individual differences
  • Precoded models for simple Rescorla-Wagner, forgetting mechanism, choise perseveration and parcitipant embeddings

Quick Start

from spice.estimator import SpiceEstimator
import numpy as np

# Create and configure the model
spice_estimator = SpiceEstimator(
    hidden_size=8,
    epochs=128,
    n_actions=2,
    n_participants=10,
    learning_rate=1e-2,
    sindy_optim_threshold=0.03,
    verbose=True
)

# Generate example data
conditions = np.random.rand(10, 100, 5)  # (n_participants, n_trials, n_features)
targets = np.random.randint(0, 2, size=(10, 100, 2))  # (n_participants, n_trials, n_actions)

# Fit the model
spice_estimator.fit(conditions, targets)

# Make predictions
pred_rnn, pred_sindy = model.predict(conditions)

# Get learned features
features = model.get_sindy_features()

Requirements

See requirements.txt for a complete list of dependencies.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Citation

If you use this package in your research, please cite:

@software{spice2025,
  title = {SPICE: Sparse and Interpretable Cognitive Equations},
  year = {2025},
  author = {Weinhardt, Daniel},
  url = {https://github.com/whyhardt/SPICE}
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

autospice-0.1.2.tar.gz (184.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

autospice-0.1.2-py3-none-any.whl (51.7 kB view details)

Uploaded Python 3

File details

Details for the file autospice-0.1.2.tar.gz.

File metadata

  • Download URL: autospice-0.1.2.tar.gz
  • Upload date:
  • Size: 184.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for autospice-0.1.2.tar.gz
Algorithm Hash digest
SHA256 9a679b7991b799da81316e7b5258b9f748cf4b0850b4bb9c28354efb92199326
MD5 94f95e423ec3a4852c85e1a8e71aa6ad
BLAKE2b-256 6cfd393ab21c82e1f22018299d7dc2382e6fed63117437cca34687122eb160eb

See more details on using hashes here.

File details

Details for the file autospice-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: autospice-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 51.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.0

File hashes

Hashes for autospice-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 676c7f44336e6161578a5753317df61068c84bad65dbaa10f9c26e4398679d80
MD5 c8e289eeb339881fcad3b07e6638d158
BLAKE2b-256 b1e250ae33c5287405ee18d79a4399f3cb4ae7e66f13ace683bc08e3702986a2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page