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

Uploaded Python 3

File details

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

File metadata

  • Download URL: autospice-0.1.1.tar.gz
  • Upload date:
  • Size: 152.5 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.1.tar.gz
Algorithm Hash digest
SHA256 0e184365671569c2f68dac8fcccec9bef9c094aa379585bebcf7fb7b53dc7d8a
MD5 760cfae81e9e3c9695d5bc9e210d7574
BLAKE2b-256 d09bb5894465e12887ec815120544ad693556fa1acf2f4a96e99316b2005ec44

See more details on using hashes here.

File details

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

File metadata

  • Download URL: autospice-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 181ead2ed7faf8fc7498a87f8b8c8cc392623df0b337e1690146a4d5117a246b
MD5 6b43c86b32e5862784ecf62a79d22156
BLAKE2b-256 1155035fddc15a6428d76c1183d6c7a498d93a14d767aac5d5777038d46c926c

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