Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Andrei-Claudiu Roibu
BrainMapper
Commits
209ce07e
Commit
209ce07e
authored
Jul 02, 2020
by
Andrei Roibu
Browse files
added code for calculating the linear regression weights
parent
221ddd6d
Changes
1
Hide whitespace changes
Inline
Side-by-side
utils/data_utils.py
View file @
209ce07e
...
...
@@ -119,6 +119,10 @@ def data_test_train_validation_split(data_folder_name, test_percentage, subject_
else
:
subDirectoryList
,
_
=
directory_reader
(
data_directory
,
subject_number
)
###
### For subject in the directory list, calculate the wd-wf pairs byh calling function
###
subDirectoryList
=
np
.
array
(
subDirectoryList
)
create_folder
(
data_folder_name
)
...
...
@@ -609,4 +613,58 @@ def load_and_preprocess_targets(target_path, mean_mask_path):
target
=
Image
(
target_path
[
0
]).
data
[:,:,:,
0
]
target_demeaned
=
np
.
subtract
(
target
,
Image
(
mean_mask_path
).
data
[:,:,:,
0
])
return
target
,
target_demeaned
\ No newline at end of file
return
target
,
target_demeaned
def
regression_weight_calculator
(
data_directory
,
subject
):
""" Calculator for linear regression weights
This function cals the calculator for the weights required for peforming linear regression
Args:
data_directory (str): A string containing the address of the required directory.
subject (str): Path to the relevant subject's data file
Returns:
w_dMRI (float): Linear regression weight for dMRI data
w_rsfMRI (flat): Linear regression weight for rsfMRI data
"""
w_dMRI
=
weight_calculator
(
data_directory
,
subject
,
data_type
=
'dmri'
)
w_rsfMRI
=
weight_calculator
(
data_directory
,
subject
,
data_type
=
'fmri'
)
return
w_dMRI
,
w_rsfMRI
def
weight_calculator
(
data_directory
,
subject
,
data_type
):
""" Calculator for linear regression weights
This function calcualtes the weights required for peforming linear regression
Args:
data_directory (str): A string containing the address of the required directory.
subject (str): Path to the relevant subject's data file
data_type (str): Flag indicating the data type
Returns:
weigth (float): Linear regressiong weight.
"""
if
data_type
==
'dmri'
:
mean_path
=
'utils/mean_tractsNormSummed_downsampled.nii.gz'
data_path
=
"dMRI/autoptx_preproc/tractsNormSummed.nii.gz"
mean_volume
=
Image
(
mean_path
).
data
subject_path
=
os
.
path
.
join
(
os
.
path
.
expanduser
(
"~"
),
data_directory
,
subject
,
data_path
)
subject_volume
,
_
=
resampleToPixdims
(
Image
(
dMRI_subject_path
),
(
2
,
2
,
2
))
elif
data_type
=
'fmri'
:
mean_path
=
'utils/mean_dr_stage2.nii.gz'
data_path
=
"fMRI/rfMRI_25.dr/dr_stage2.nii.gz"
mean_volume
=
Image
(
mean_path
).
data
[:,:,:,
0
]
subject_path
=
os
.
path
.
join
(
os
.
path
.
expanduser
(
"~"
),
data_directory
,
subject
,
data_path
)
subject_volume
=
Image
(
rsfMRI_subject_path
).
data
[:,:,:,
0
]
x
=
np
.
reshape
(
mean_volume
,
-
1
)
y
=
np
.
reshape
(
subject_volume
,
-
1
)
x_matrix
=
np
.
vstack
((
np
.
ones
(
len
(
x
)),
x
)).
T
beta_hat
=
np
.
linalg
.
inv
(
x_matrix
.
T
.
dot
(
x_matrix
)).
dot
(
x_matrix
.
T
).
dot
(
y
)
w
=
beta_hat
[
1
]
return
w
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment