Neurocaps

Latest version: v0.21.0

Safety actively analyzes 693883 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 8 of 19

0.16.3.post0

💻 Metadata
- Uploading fixed readme to Pypi

0.16.3

- Internal refactoring was completed, primarily in `CAPs.caps2plot`, `TimeseriesExtractor.get_bold`, and an
internal function `_extract_timeseries`.
- All existing pytest tests passed following the refactoring.
🐛 Fixes
- Minor improvements were made to error messages for better clarity.
- Annotations can now be specified for `CAP.caps2plot` regional heatmap.

0.16.2.post1

💻 Metadata
- Fix truncated table in README, which did not show all values correctly due to missing an additional row header.

0.16.2

🚀 New/Added
- Transition probabilities has been added to `CAP.calculate_metrics`. Below is a snippet from the codebase
of how the calculation is done.
python
if "transition_probability" in metrics:
temp_dict[group].loc[len(temp_dict[group])] = [subj_id, group, curr_run] + [0.0] * (temp_dict[group].shape[-1] - 3)
Get number of transitions
trans_dict = {
target: np.sum(np.where(predicted_subject_timeseries[subj_id][curr_run][:-1] == target, 1, 0))
for target in group_caps[group]
}
indx = temp_dict[group].index[-1]
Iterate through products and calculate all symmetric pairs/off-diagonals
for prod in products_unique[group]:
target1, target2 = prod[0], prod[1]
trans_array = predicted_subject_timeseries[subj_id][curr_run].copy()
Set all values not equal to target1 or target2 to zero
trans_array[(trans_array != target1) & (trans_array != target2)] = 0
trans_array[np.where(trans_array == target1)] = 1
trans_array[np.where(trans_array == target2)] = 3
2 indicates forward transition target1 -> target2; -2 means reverse/backward transition target2 -> target1
diff_array = np.diff(trans_array, n=1)
Avoid division by zero errors and calculate both the forward and reverse transition
if trans_dict[target1] != 0:
temp_dict[group].loc[indx, f"{target1}.{target2}"] = float(
np.sum(np.where(diff_array == 2, 1, 0)) / trans_dict[target1]
)
if trans_dict[target2] != 0:
temp_dict[group].loc[indx, f"{target2}.{target1}"] = float(
np.sum(np.where(diff_array == -2, 1, 0)) / trans_dict[target2]
)

Calculate the probability for the self transitions/diagonals
for target in group_caps[group]:
if trans_dict[target] == 0:
continue
Will include the {target}.{target} column, but the value is initially set to zero
columns = temp_dict[group].filter(regex=rf"^{target}\.").columns.tolist()
cumulative = temp_dict[group].loc[indx, columns].values.sum()
temp_dict[group].loc[indx, f"{target}.{target}"] = 1.0 - cumulative

Below is a simplified version of the above snippet.
python
import itertools, math, pandas as pd, numpy as np

groups = [["101", "A", "1"], ["102", "B", "1"]]
timeseries_dict = {
"101": np.array([1, 1, 1, 1, 2, 2, 1, 4, 3, 5, 3, 3, 5, 5, 6, 7]),
"102": np.array([1, 2, 1, 1, 3, 3, 1, 4, 3, 5, 3, 3, 4, 5, 6, 8, 7]),
}
caps = list(range(1, 9))
Get all combinations of transitions
products = list(itertools.product(caps, caps))
df = pd.DataFrame(columns=["Subject_ID", "Group", "Run"] + [f"{x}.{y}" for x, y in products])
Filter out all reversed products and products with the self transitions
products_unique = []
for prod in products:
if prod[0] == prod[1]:
continue
Include only the first instance of symmetric pairs
if (prod[1], prod[0]) not in products_unique:
products_unique.append(prod)

for info in groups:
df.loc[len(df)] = info + [0.0] * (df.shape[-1] - 3)
timeseries = timeseries_dict[info[0]]
Get number of transitions
trans_dict = {target: np.sum(np.where(timeseries[:-1] == target, 1, 0)) for target in caps}
indx = df.index[-1]
Iterate through products and calculate all symmetric pairs/off-diagonals
for prod in products_unique:
target1, target2 = prod[0], prod[1]
trans_array = timeseries.copy()
Set all values not equal to target1 or target2 to zero
trans_array[(trans_array != target1) & (trans_array != target2)] = 0
trans_array[np.where(trans_array == target1)] = 1
trans_array[np.where(trans_array == target2)] = 3
2 indicates forward transition target1 -> target2; -2 means reverse/backward transition target2 -> target1
diff_array = np.diff(trans_array, n=1)
Avoid division by zero errors and calculate both the forward and reverse transition
if trans_dict[target1] != 0:
df.loc[indx, f"{target1}.{target2}"] = float(np.sum(np.where(diff_array == 2, 1, 0)) / trans_dict[target1])
if trans_dict[target2] != 0:
df.loc[indx, f"{target2}.{target1}"] = float(np.sum(np.where(diff_array == -2, 1, 0)) / trans_dict[target2])

Calculate the probability for the self transitions/diagonals
for target in caps:
if trans_dict[target] == 0:
continue
Will include the {target}.{target} column, but the value is initially set to zero
columns = df.filter(regex=rf"^{target}\.").columns.tolist()
cumulative = df.loc[indx, columns].values.sum()
df.loc[indx, f"{target}.{target}"] = 1.0 - cumulative

- Added new external function - ``transition_matrix``, which generates and visualizes the average transition probabilities
for all groups, using the transition probability dataframe outputted by `CAP.calculate_metrics`

0.16.1.post3

💻 Metadata
- Minor change to clarify the language in the docstring referring to the Custom parcellation approach and update readme
on PyPi for the installation instructions.

0.16.1.post2

💻 Metadata
- Correct output for example in readme.

Page 8 of 19

© 2025 Safety CLI Cybersecurity Inc. All Rights Reserved.