Skip to main content

SPICE: Sparse and Interpretable Cognitive Equations

Project description

Computational Discovery of Sparse and Interpretable Cognitive Equations (SPICE)

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

Installation

You can install SPICE using pip:

pip install -e .

Features

  • Scikit-learn compatible estimator interface
  • Customizable network architecture for identifying complex cognitive mechanisms
  • Participant embeddings for identifying individual differences

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.0.tar.gz (47.1 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.0-py3-none-any.whl (51.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: autospice-0.1.0.tar.gz
  • Upload date:
  • Size: 47.1 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.0.tar.gz
Algorithm Hash digest
SHA256 7fd57e8af0fabecaa0cbb35df7c03e42b1787e077fd673d8df0259d0c22f8a91
MD5 8dd5bf3babdfa43ead52ff53ab081d8a
BLAKE2b-256 ac4bb729f12f4c05a642c6cc5e428c82e47dd0d82c56c81f6621b188482436e2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: autospice-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 51.5 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5d4ffa0cdcfd08b486a7417b8dd052bab584c01f5726c04fb9f87b117b4d695f
MD5 4602ec39bf2bb2bb6b662432b6b8744e
BLAKE2b-256 539eb3151340aead6d794a19c2f1d26230e2c8c998f180ebd1d965d8e502ca27

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