Skip to content

Commit e78b0ae

Browse files
committed
make regress_poly take any kind of input data
1 parent 4b9dbe4 commit e78b0ae

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

nipype/algorithms/tsnr.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,24 @@ def _list_outputs(self):
9595
return outputs
9696

9797
def regress_poly(degree, data):
98-
timepoints = data.shape[-1]
98+
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
99105
X = np.ones((timepoints, 1))
100106
for i in range(degree):
101107
X = np.hstack((X, legendre(
102108
i + 1)(np.linspace(-1, 1, timepoints))[:, None]))
103-
betas = np.dot(np.linalg.pinv(X), np.rollaxis(data, 3, 2))
104-
datahat = np.rollaxis(np.dot(X[:, 1:],
105-
np.rollaxis(
106-
betas[1:, :, :, :], 0, 3)),
107-
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
108115
regressed_data = data - datahat
109-
return regressed_data
116+
117+
# Back to original shape
118+
return regressed_data.reshape(datashape)

0 commit comments

Comments
 (0)