pyspi: Statistics for Pairwise Interactions
pyspi GitHub
  • Welcome to pyspi
    • Citing pyspi
  • Installing and using pyspi
    • Installation
      • Alternative Installation Options
      • Troubleshooting
    • Usage
      • Walkthrough Tutorials
        • Getting Started: A Simple Demonstration
        • Neuroimaging: fMRI Time Series
        • Finance: Stock Price Time Series
        • Distributing Calculations
      • Advanced Usage
        • Creating a reduced SPI set
        • Distributing calculations on a cluster
      • FAQ
  • Information about pyspi
    • SPIs
      • Glossary of Terms
      • Table of SPIs
      • SPI Descriptions
        • Basic Statistics
        • Distance Similarity
        • Causal Inference
        • Information Theory
        • Spectral
        • Miscellaneous
      • SPI Subsets
    • API Reference
      • pyspi.calculator.CorrelationFrame
      • pyspi.calculator.Calculator
      • pyspi.data.Data
      • pyspi.calculator.CalculatorFrame
      • pyspi.utils.filter_spis
    • Publications using pyspi
    • Related Packages
  • Development
    • Development
      • Incorporating new SPIs
      • Contributing to pyspi
      • Code of Conduct
    • License
Powered by GitBook

All page cover images on this wiki are created with the help of DALL-E, an AI program developed by OpenAI, or stock images from Unsplash.

On this page
  • Filtering an SPI Set
  • Manually specifying a reduced set
  1. Installing and using pyspi
  2. Usage
  3. Advanced Usage

Creating a reduced SPI set

PreviousAdvanced UsageNextDistributing calculations on a cluster

Last updated 1 year ago

Filtering an SPI Set

If you would like to filter SPIs based on their corresponding keywords, you can do so using the filter_spis function in pyspi. This will return a new config file containing the reduced SPI set that you can provide to the Calculator object.

As an example, let's use the filter to obtain a subset of SPIs with the keywords linear and signed:

from pyspi.utils import filter_spis

# let's only select SPIs with the keywords "linear" and "signed"
# we will need to provide these keywords in a list
keywords = ["linear", "signed"]

# we will need to specify the location of the original config.yaml
filter_spis(keywords=keywords, output_name="linear_signed.yaml")

Note that here we do not specify a source config.yaml file. By default, the filter_spis function will use the original config.yaml (containing the full set of SPIs) located in the pyspi directory. If you would like to provide a custom YAML as the source file, you can provide the location of the file to the function with the optional keyword configfile.

[OPTIONAL] Filtering from a user-specified YAML

Here, we tell the filter function to use a custom yaml file myconfig.yaml located in the current working directory:

filter_spis(keywords=keywords, output_name="linear_signed.yaml", configfile="./myconfig.yaml") 

You must ensure that the custom config YAML conforms to the structure of a pyspi YAML otherwise the filter function will not work as expected. See for more information about the structure pyspi expects.

We should obtain a reduced subset of SPIs with the keywords "linear" and "signed". Let's now compute this reduced set on some data:

from pyspi.calculator import Calculator
import numpy as np

data = np.random.randn(3, 100) # your time series data
calc = Calculator(configfile="linear_signed.yaml", dataset=data)

# print the number of SPIs initialised in the Calculator instance
print(calc.n_spis)

Manually specifying a reduced set

You can use a subset of the SPIs by copying a version of the config.yaml file to a local directory and manually removing those you don’t want the calculator to compute. First, copy the config.yaml file to your workspace:

import os, shutil
import pyspi

# chose the location where you would like to save the copy 
destination = "./myconfig.yaml"
# get the pyspi directory where config.yaml is located
source = os.path.dirname(pyspi.__file__) + "/config.yaml"
shutil.copy(source, destination)

Once you've got a local copy of config.yaml edit the file to remove any SPIs you're not interested in. A minimal configuration file might look like the following if you're only interested in computing a covariance matrix using the maximum likelihood estimator:

myconfig.yaml
# Basic statistics
.statistics.basic:
    # Covariance
    covariance:
       labels:
          - undirected
          - linear
          - signed
          - multivariate
          - contemporaneous
       dependencies:
       configs:
        # Maximum likehood estimator
        - estimator: EmpiricalCovariance

Ensure you retain the labels and dependencies keys from the original config.yaml file when creating your custom set.

When you instantiate the calculator, instead of using the default config.yaml, you can input your bespoke configuration file:

from pyspi.calculator import Calculator

calc = Caculator(dataset=dataset, configfile='myconfig.yaml')

Then use the calculator as normal (see ).

Getting Started
manually specifying a reduced set
Page cover image