Skip to content

Commit

Permalink
Nb weighted sg test (#126)
Browse files Browse the repository at this point in the history
* Add weighted stimgen

* Create r2 viz function

* Fix typo

* Variable touchup

* Bold doc header

* Only viz if comparing trial fractions
  • Loading branch information
nelson-barnett authored Oct 27, 2022
1 parent 1566006 commit 168507b
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 4 deletions.
9 changes: 7 additions & 2 deletions code/scripts/pilot_reconstructions.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
% - A figure of reconstructions plotted against the target signal and simulated answers.

DATA_DIR = ['/Users/nelsonbarnett/Desktop/Prof. Lammert Research/' ...
'Tinnitus/tinnitus-project/code/experiment/Data/data-paper-bugfixes'];
'Tinnitus/tinnitus-project/code/experiment/Data/data-weighted-test'];
PROJECT_DIR = pathlib.strip(mfilename('fullpath'), 3);
PUBLISH = false;

Expand Down Expand Up @@ -97,7 +97,7 @@

%% Compute the reconstructions

trial_fractions = 1; %linspace(0.1, 1, 10);
trial_fractions = 0.1:0.1:1;

% Container for r^2 values
r2_cs_bins = zeros(height(T), length(trial_fractions));
Expand Down Expand Up @@ -228,6 +228,11 @@
end
end

%% Visualize results if comparing trial fractions
if length(trial_fractions) > 1
r2_bar(T)
end

%% Saving Results

% Save the reconstruction waveforms
Expand Down
2 changes: 1 addition & 1 deletion code/utils/cs.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
% where `n` is the number of trials/samples
% and `m` is the dimensionality of the stimuli/spectrum/bins
%
% **OUTPUTS:*
% **OUTPUTS:**
% - x: compressed sensing reconstruction of the signal.

function x = cs(responses, Phi, Gamma)
Expand Down
78 changes: 78 additions & 0 deletions code/utils/r2_bar.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
% ### r2_bar
%
% Plots bar charts of r^2 values from table data.
% A separate figure is made for each subject.
%
% **ARGUMENTS:**
%
% - T: `table` that includes r^2 values of interest
%
% **OUTPUTS:**
% - n figures, where n is the number of subjects included
% in the table.
%
% See Also:
% pilot_reconstructions

function r2_bar(T)

arguments
T (:,:) {mustBeUnderlyingType(T, "table")}
end

% Get indices of r^2 data from table
r2_lr_inds = contains(T.Properties.VariableNames,'r2_lr');
r2_cs_inds = contains(T.Properties.VariableNames,'r2_cs');

% Determine unique subjects
subjects = unique(T.subject_ID);

% Get column names with trial fraction information
fracs = T.Properties.VariableNames(r2_lr_inds);

% Create nice x-labels from column name info
frac_labels = cell(1, sum(r2_lr_inds));
for i = 1:length(fracs)
temp = regexprep(fracs{i}, {'\D*([\d\.]+\d)[^\d]*', ...
'[^\d\.]*'}, {'$1 ', ''}); % Parse for only numbers
frac_labels{i} = strcat(temp(2),'.',temp(3:end));
end

% Create a figure for each subject
for i = 1:length(subjects)
figure
t = tiledlayout('flow');
exp_rows = find(contains(T.subject_ID, subjects{i}));

% Plot two tiles (lr & cs) for each experiment within subject
for j = 1:length(exp_rows)
target_signal_name = T.target_signal_name{exp_rows(j)};
total_trials = T.total_trials(exp_rows(j));

nexttile
bar(table2array(T(exp_rows(j), r2_lr_inds)))
grid on
set(gca, 'XTickLabel', frac_labels)
xlabel(['Fraction of ', num2str(total_trials),...
' trials'], 'FontSize', 14)
ylabel('r^2', 'FontSize',14)
title(['Linear ', target_signal_name], ...
'FontSize', 14)

nexttile
bar(table2array(T(exp_rows(j), r2_cs_inds)))
grid on
set(gca, 'XTickLabel', frac_labels)
xlabel(['Fraction of ', num2str(total_trials),...
' trials'], 'FontSize', 14)
ylabel('r^2', 'FontSize',14)
title(['CS ', target_signal_name], ...
'FontSize', 14)
end
title(t, ['Subject: ', subjects{i}], 'FontSize', 18)
end

end %function



26 changes: 25 additions & 1 deletion docs/utils.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ Write the stimuli into the stimuli file.
where `n` is the number of trials/samples
and `m` is the dimensionality of the stimuli/spectrum/bins

**OUTPUTS:*
**OUTPUTS:**
- x: compressed sensing reconstruction of the signal.


Expand Down Expand Up @@ -522,6 +522,30 @@ stringified_properties = prop2str(obj, [], '&&')



-------

### r2_bar

Plots bar charts of r^2 values from table data.
A separate figure is made for each subject.

**ARGUMENTS:**

- T: `table` that includes r^2 values of interest

**OUTPUTS:**
- n figures, where n is the number of subjects included
in the table.



!!! info "See Also"
* [pilot_reconstructions](../scripts/#pilot_reconstructions)





-------

### spect2binnedrepr
Expand Down

0 comments on commit 168507b

Please sign in to comment.