Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions scripts/dwi_gp_estimation_error_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import argparse
from collections import defaultdict
from pathlib import Path
from typing import DefaultDict, List

import numpy as np
import pandas as pd
Expand All @@ -49,7 +50,7 @@ def cross_validate(
cv: int,
n_repeats: int,
gpr: DiffusionGPR,
) -> dict[int, list[tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]]]:
) -> np.ndarray:
"""
Perform the experiment by estimating the dMRI signal using a Gaussian process model.

Expand All @@ -68,7 +69,7 @@ def cross_validate(

Returns
-------
:obj:`dict`
:obj:`~numpy.ndarray`
Data for the predicted signal and its error.

"""
Expand Down Expand Up @@ -202,12 +203,14 @@ def main() -> None:
# max_iter=2e5,
)

n_repeats = 10

if args.kfold:
# Use Scikit-learn cross validation
scores = defaultdict(list, {})
scores: DefaultDict[str, List[float | str]] = defaultdict(list)
for n in args.kfold:
for i in range(args.repeats):
cv_scores = -1.0 * cross_validate(X, y.T, n, gpr)
cv_scores = -1.0 * cross_validate(X, y.T, n, n_repeats, gpr)
scores["rmse"] += cv_scores.tolist()
scores["repeat"] += [i] * len(cv_scores)
scores["n_folds"] += [n] * len(cv_scores)
Expand All @@ -217,7 +220,7 @@ def main() -> None:
print(f"Finished {n}-fold cross-validation")

scores_df = pd.DataFrame(scores)
scores_df.to_csv(args.output_scores, sep="\t", index=None, na_rep="n/a")
scores_df.to_csv(args.output_scores, sep="\t", index=False, na_rep="n/a")

grouped = scores_df.groupby(["n_folds"])
print(grouped[["rmse"]].mean())
Expand Down
Loading