# dwidenoise validation: Patch2Self reference on the ds005134 slab | File | Content | | --- | --- | | `sub-01_dir-AP_desc-slabpatch2self_dwi.nii.gz` | Patch2Self output of the noddi example slab, float32, 67 × 92 × 10 × 137 | ## Input `noddi/examples/sub-01_dir-AP_desc-slab_dwi.nii.gz` with its `.bval` in this dataset (OpenNeuro ds005134 sub-01, CC0; see `noddi/examples/README.md`). The input is not copied here. Input SHA-256: `1e7c8461d9bfc3c80633f930dc1df16d892a6bfd5e15db4c5a2be9d021e48d00`. Volumes: 13 b0, 12 × b500, 48 × b1000, 64 × b2000. ## Method Patch2Self (Fadnavis et al., NeurIPS 2020), DIPY version 1 with patch radius 0: each volume is predicted by ordinary least squares with an intercept from the other volumes of its group, fitted over all voxels (no mask) and applied to all voxels. The b0 volumes (bval <= 50) and the DWI volumes are two separate groups. No intensity shift, no clipping. Software: DIPY 1.12.1, scikit-learn 1.9.1, NumPy 2.5.4, Python 3.12.13, Linux x86-64. The input was read as float64 (`get_fdata(dtype=np.float64)`), computed in float64, and cast to float32 for this file (largest rounding change 3.1e-5). The NIfTI header is the input's header with the data type set to float32 and slope 1, intercept 0. ```python from dipy.denoise.patch2self import patch2self from sklearn import linear_model from sklearn.base import BaseEstimator linear_model.BaseEstimator = BaseEstimator # see note 1 model = linear_model.Ridge(alpha=1e-10, copy_X=True) den = patch2self(data, bvals, model=model, b0_threshold=50, version=1, patch_radius=0) ``` ### Notes 1. DIPY 1.12.1 accepts a model instance only when it is an instance of `sklearn.linear_model.BaseEstimator`. scikit-learn 1.9 does not export that name, so the alias is set to `sklearn.base.BaseEstimator` before the call. This changes nothing else. 2. The model is given explicitly because `model="ols"` in DIPY 1.12.1 makes `Ridge(alpha=1e-10, copy_X=False)`. With `copy_X=False`, scikit-learn centres the regressor array in place during `fit`, and version 1 then calls `predict` on the centred array. Each output volume then has a constant error equal to `mean(X) . w` (about 46 signal units on this data; RMSE / raw noise 5.4 on the simulation). The fit itself is the same: the `model="ols"` output plus that per-volume constant equals this file's float64 values to 4e-14 of the signal range. Version 3 (the DIPY default) is not affected. 3. An independent float64 implementation (Gram matrix of the volumes in one pass, Cholesky solve per volume, `spec.py` in the dwidenoise port) reproduces the float64 values to 2.3e-14 of the signal range (largest absolute difference 1.4e-11). ## Checksums `SHA256SUMS` lists the files in this directory. Upload under `dwidenoise/validation/` and pin the commit in the app's manifest.