Skip to content

Commit 8b69296

Browse files
authored
Merge pull request #135 from eurunuela/docs_stability
Clarify explanation of Stability Selection method in examples.md
2 parents 7a06d4e + 3d262d2 commit 8b69296

File tree

2 files changed

+98
-8
lines changed

2 files changed

+98
-8
lines changed

.circleci/config.yml

Lines changed: 96 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,30 @@ jobs:
6767
apt-get update
6868
apt-get install -yqq make
6969
apt-get install -yqq curl
70-
cp -r /opt/conda/envs/py<< parameters.PYTHON >>_env /opt/miniconda-latest/envs/py<< parameters.PYTHON >>_env
71-
source activate py<< parameters.PYTHON >>_env
70+
# Initialize conda for bash shell
71+
eval "$(conda shell.bash hook)"
72+
# Check what environments conda knows about
73+
echo "Available conda environments:"
74+
conda info --envs
75+
# Ensure the environment exists and activate it properly
76+
if conda env list | grep -q "py<< parameters.PYTHON >>_env"; then
77+
echo "Environment py<< parameters.PYTHON >>_env found in conda list"
78+
conda activate py<< parameters.PYTHON >>_env
79+
elif [[ -d "/opt/conda/envs/py<< parameters.PYTHON >>_env" ]]; then
80+
echo "Environment directory found but not registered, re-creating conda environment"
81+
# Remove the directory and recreate properly
82+
rm -rf "/opt/conda/envs/py<< parameters.PYTHON >>_env"
83+
conda create -n py<< parameters.PYTHON >>_env python=<< parameters.PYTHON >> -yq
84+
conda activate py<< parameters.PYTHON >>_env
85+
pip install -e .[tests,doc]
86+
else
87+
echo "Environment not found, creating new one"
88+
conda create -n py<< parameters.PYTHON >>_env python=<< parameters.PYTHON >> -yq
89+
conda activate py<< parameters.PYTHON >>_env
90+
pip install -e .[tests,doc]
91+
fi
92+
python --version
93+
which python
7294
make unittest
7395
no_output_timeout: 20m
7496
- codecov/upload:
@@ -93,8 +115,30 @@ jobs:
93115
apt-get update
94116
apt-get install -yqq make
95117
apt-get install -yqq curl
96-
cp -r /opt/conda/envs/py<< parameters.PYTHON >>_env /opt/miniconda-latest/envs/py<< parameters.PYTHON >>_env
97-
source activate py<< parameters.PYTHON >>_env
118+
# Initialize conda for bash shell
119+
eval "$(conda shell.bash hook)"
120+
# Check what environments conda knows about
121+
echo "Available conda environments:"
122+
conda info --envs
123+
# Ensure the environment exists and activate it properly
124+
if conda env list | grep -q "py<< parameters.PYTHON >>_env"; then
125+
echo "Environment py<< parameters.PYTHON >>_env found in conda list"
126+
conda activate py<< parameters.PYTHON >>_env
127+
elif [[ -d "/opt/conda/envs/py<< parameters.PYTHON >>_env" ]]; then
128+
echo "Environment directory found but not registered, re-creating conda environment"
129+
# Remove the directory and recreate properly
130+
rm -rf "/opt/conda/envs/py<< parameters.PYTHON >>_env"
131+
conda create -n py<< parameters.PYTHON >>_env python=<< parameters.PYTHON >> -yq
132+
conda activate py<< parameters.PYTHON >>_env
133+
pip install -e .[tests,doc]
134+
else
135+
echo "Environment not found, creating new one"
136+
conda create -n py<< parameters.PYTHON >>_env python=<< parameters.PYTHON >> -yq
137+
conda activate py<< parameters.PYTHON >>_env
138+
pip install -e .[tests,doc]
139+
fi
140+
python --version
141+
which python
98142
make integrationtest
99143
no_output_timeout: 30m
100144
- codecov/upload:
@@ -112,7 +156,30 @@ jobs:
112156
- run:
113157
name: Build documentation
114158
command: |
115-
source activate py3.9_env
159+
# Initialize conda for bash shell
160+
eval "$(conda shell.bash hook)"
161+
# Check what environments conda knows about
162+
echo "Available conda environments:"
163+
conda info --envs
164+
# Ensure the environment exists and activate it properly
165+
if conda env list | grep -q "py3.9_env"; then
166+
echo "Environment py3.9_env found in conda list"
167+
conda activate py3.9_env
168+
elif [[ -d "/opt/conda/envs/py3.9_env" ]]; then
169+
echo "Environment directory found but not registered, re-creating conda environment"
170+
# Remove the directory and recreate properly
171+
rm -rf "/opt/conda/envs/py3.9_env"
172+
conda create -n py3.9_env python=3.9 -yq
173+
conda activate py3.9_env
174+
pip install -e .[tests,doc]
175+
else
176+
echo "Environment not found, creating new one"
177+
conda create -n py3.9_env python=3.9 -yq
178+
conda activate py3.9_env
179+
pip install -e .[tests,doc]
180+
fi
181+
python --version
182+
which python
116183
apt-get update
117184
apt-get install -yqq make pandoc
118185
make -C docs html
@@ -132,7 +199,30 @@ jobs:
132199
- run:
133200
name: Linting
134201
command: |
135-
source activate py3.9_env
202+
# Initialize conda for bash shell
203+
eval "$(conda shell.bash hook)"
204+
# Check what environments conda knows about
205+
echo "Available conda environments:"
206+
conda info --envs
207+
# Ensure the environment exists and activate it properly
208+
if conda env list | grep -q "py3.9_env"; then
209+
echo "Environment py3.9_env found in conda list"
210+
conda activate py3.9_env
211+
elif [[ -d "/opt/conda/envs/py3.9_env" ]]; then
212+
echo "Environment directory found but not registered, re-creating conda environment"
213+
# Remove the directory and recreate properly
214+
rm -rf "/opt/conda/envs/py3.9_env"
215+
conda create -n py3.9_env python=3.9 -yq
216+
conda activate py3.9_env
217+
pip install -e .[tests,doc]
218+
else
219+
echo "Environment not found, creating new one"
220+
conda create -n py3.9_env python=3.9 -yq
221+
conda activate py3.9_env
222+
pip install -e .[tests,doc]
223+
fi
224+
python --version
225+
which python
136226
apt-get update
137227
apt-get install -yqq make
138228
make lint

docs/examples.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ You can see that the innovation signal captures the instances where the BOLD res
127127

128128
## What do AUC time series look like?
129129

130-
To avoid the selection of the regularization parameter, we can use the Stability Selection method. This method is based on subsampling the data and solving the regularization path for each subsample a number of times. You can think of it as a cross-validation approach. The method then calculates the probability of every time point having a non-zero coefficient. The following code snippet shows how to use the Stability Selection method:
130+
To avoid having to select the regularization parameter manually, we can use the Stability Selection method. This method works by subsampling the data multiple times and solving the regularization path for each subsample. You can think of it as a cross-validation approach. This process provides a snapshot of which time points are selected more frequently. For each value of lambda, the method calculates the probability that every time point has a non-zero coefficient, based on how often it is selected across all runs. These probability curves (one per time point) are then used to calculate the area under the curve (AUC). The AUC serves as a proxy for how likely a time point is to have a non-zero coefficient across all possible lambdas, and therefore to be truly non-zero. The following code snippet shows how to use the Stability Selection method:
131131

132132
```python
133133
from pySPFM.deconvolution.hrf_generator import HRFMatrix
@@ -147,7 +147,7 @@ The AUC time series for the spike model is shown below:
147147
<img src="https://raw.githubusercontent.com/Paradigm-Free-Mapping/pySPFM/main/docs/charts/stability_selection.png" alt="Stability Selection results">
148148
</div>
149149

150-
By definition, the AUC time series cannot have zero values. However, that will only happen if the entire space of the regularization path is explored; i.e., if all the regularization parameters are considered. This means that we still have to apply a threshold to the AUC time series to obtain the final estimates. One way to do this is to select a region of the brain where you do not expect to see any activity, like the deep white matter. You can then use the 95th percentile of the AUC time series in that region as a threshold.
150+
By definition, the AUC time series cannot have zero values. However, that will only happen if the entire space of the regularization path is explored; i.e., if all the regularization parameters are considered. This means that we still have to apply a threshold to the AUC time series to obtain the final estimates. One way to do this is to select a region of the brain where you do not expect to see any activity, like the deep white matter. Assuming you have run stability selection throughout the brain, you can calculate the histogram of AUC values in the deep white matter (you can just erode the white matter mask to make it deep enough). You can then use the 95th percentile (or 99th, depending on how strict or sparse you want your estimates to be) of this histogram as a threshold throughout the brain.
151151

152152
Here is what the thresholded AUC time series would look like if we thresholded the AUC time series above with a 0.15 threshold:
153153

0 commit comments

Comments
 (0)