We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 4b9dbe4 commit e78b0aeCopy full SHA for e78b0ae
nipype/algorithms/tsnr.py
@@ -95,15 +95,24 @@ def _list_outputs(self):
95
return outputs
96
97
def regress_poly(degree, data):
98
- timepoints = data.shape[-1]
+ datashape = data.shape
99
+ timepoints = datashape[-1]
100
+
101
+ # Rearrange all voxel-wise time-series in rows
102
+ data = data.reshape((-1, timepoints))
103
104
+ # Generate design matrix
105
X = np.ones((timepoints, 1))
106
for i in range(degree):
107
X = np.hstack((X, legendre(
108
i + 1)(np.linspace(-1, 1, timepoints))[:, None]))
- betas = np.dot(np.linalg.pinv(X), np.rollaxis(data, 3, 2))
- datahat = np.rollaxis(np.dot(X[:, 1:],
- np.rollaxis(
- betas[1:, :, :, :], 0, 3)),
- 0, 4)
109
110
+ # Calculate coefficients
111
+ betas = np.linalg.pinv(X).dot(data.T)
112
113
+ # Estimation
114
+ datahat = X[:, 1:].dot(betas[1:, ...]).T
115
regressed_data = data - datahat
- return regressed_data
116
117
+ # Back to original shape
118
+ return regressed_data.reshape(datashape)
0 commit comments