Creating a reduced SPI set
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.
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:
# 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).
Last updated