Skip to content

Commit

Permalink
Use nested cells of vectors
Browse files Browse the repository at this point in the history
Signed-off-by: Liang Zhang <[email protected]>
  • Loading branch information
psychelzh committed Dec 14, 2023
1 parent 8197f00 commit 86833bb
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions representation.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
%% intersubject similarity

% acquire: trial-level
simi_inter_by_trial = utils.filter_triangular( ...
utils.preallocate(regions_id, 1:len_trial, subjs_id, subjs_id, ...
VariableNames=["region_id", "trial_id", "subj_id_col", "subj_id_row"]));
simi_inter_by_trial = ...
utils.preallocate(regions_id, 1:len_trial, ...
VariableNames=["region_id", "trial_id"], ...
ScalarFisherZ=false);
fprintf("Processing trial level intersubject similarity...\n")
for i_region = regions_id
chan_in_reg = channel.code(channel.("region" + string(i_region)) ~= 0);
Expand All @@ -24,9 +25,9 @@
% collapse channel and time (thus spatiotemporal pattern)
cur_cor_mat = corr(reshape(grp_data(chan_in_reg, :, i_trial, :), ...
length(chan_in_reg) * len_time_point, []));
simi_inter_by_trial.fisher_z( ...
simi_inter_by_trial.fisher_z{ ...
simi_inter_by_trial.region_id == i_region & ...
simi_inter_by_trial.trial_id == i_trial) = ...
simi_inter_by_trial.trial_id == i_trial} = ...
atanh(cur_cor_mat(idx_keep_cors));
end
end
Expand All @@ -36,17 +37,18 @@
clearvars simi_inter_by_trial

% acquire: whole-time-series
simi_inter_by_whole = utils.filter_triangular( ...
utils.preallocate(regions_id, subjs_id, subjs_id, ...
VariableNames=["region_id", "subj_id_col", "subj_id_row"]));
simi_inter_by_whole = ...
utils.preallocate(regions_id, ...
VariableNames="region_id", ...
ScalarFisherZ=false);
fprintf("Processing whole time series intersubject similarity...\n")
for i_region = progress(regions_id)
chan_in_reg = channel.code(channel.("region" + string(i_region)) ~= 0);
cur_cor_mat = corr(reshape(grp_data(chan_in_reg, :, :, :), ...
length(chan_in_reg) * len_time_point * len_trial, []), ...
rows="pairwise");
simi_inter_by_whole.fisher_z( ...
simi_inter_by_whole.region_id == i_region) = ...
simi_inter_by_whole.fisher_z{ ...
simi_inter_by_whole.region_id == i_region} = ...
atanh(cur_cor_mat(idx_keep_cors));
end
parquetwrite( ...
Expand Down Expand Up @@ -123,10 +125,11 @@
length(chan_in_reg) * size_window, [])); %#ok<*PFBNS>
fisher_z{i_win} = atanh(cur_cor_mat(idx_keep_cors));
end
cur_simi_inter_by_window = utils.filter_triangular( ...
utils.preallocate(i_region, i_trial, 1:length(window_start), subjs_id, subjs_id, ...
VariableNames=["region_id", "trial_id", "window_id", "subj_id_col", "subj_id_row"]));
cur_simi_inter_by_window.fisher_z = vertcat(fisher_z{:});
cur_simi_inter_by_window = ...
utils.preallocate(i_region, i_trial, 1:length(window_start), ...
VariableNames=["region_id", "trial_id", "window_id"], ...
ScalarFisherZ=false);
cur_simi_inter_by_window.fisher_z = fisher_z;
path_trial = fullfile(path_region, "trial-" + string(i_trial));
if (~exist(path_trial, "dir")), mkdir(path_trial), end
parquetwrite(fullfile(path_trial, "rs.parquet"), cur_simi_inter_by_window)
Expand Down Expand Up @@ -156,7 +159,7 @@
cur_simi_grp_by_window = ...
utils.preallocate(i_region, i_trial, 1:length(window_start), subjs_id, ...
VariableNames=["region_id", "trial_id", "window_id", "subj_id"]);
cur_simi_grp_by_window.fisher_z = vertcat(fisher_z{:});
cur_simi_grp_by_window.fisher_z = fisher_z;
path_trial = fullfile(path_region, "trial-" + string(i_trial));
if (~exist(path_trial, "dir")), mkdir(path_trial), end
parquetwrite(fullfile(path_trial, "rs.parquet"), cur_simi_grp_by_window)
Expand All @@ -174,9 +177,10 @@
% type: intersubject similarity
fprintf("Processing stepped window intersubject similarity...\n")
for i_region = regions_id
cur_simi_inter_by_window = utils.filter_triangular( ...
utils.preallocate(i_region, 1:len_trial, 1:length(window_start), subjs_id, subjs_id, ...
VariableNames=["region_id", "trial_id", "window_id", "subj_id_col", "subj_id_row"]));
cur_simi_inter_by_window = ...
utils.preallocate(i_region, 1:len_trial, 1:length(window_start), ...
VariableNames=["region_id", "trial_id", "window_id"], ...
ScalarFisherZ=false);
cur_reg = "region" + string(i_region);
chan_in_reg = channel.code(channel.(cur_reg) ~= 0);
fprintf(cur_reg + "\n")
Expand All @@ -192,7 +196,7 @@
end
cur_simi_inter_by_window.fisher_z( ...
cur_simi_inter_by_window.trial_id == i_trial) = ...
vertcat(fisher_z{:});
fisher_z;
end
parquetwrite( ...
fullfile("data", "type-inter_acq-window_region-" + cur_reg + "_rs.parquet"), ...
Expand Down

0 comments on commit 86833bb

Please sign in to comment.