Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
0ed0800
Tried to clean up and organize better. Still messy
pollaro Feb 19, 2024
57975ec
Starting repository for quick-fix network test refactor over since I …
pollaro Jan 9, 2024
b9e1210
Added new tests for Network Tests
pollaro Jan 9, 2024
efc59c0
Added result class for new network tests and fixed some of the test c…
pollaro Jan 9, 2024
9f4a74f
add unit tests for new test classes
pollaro Jan 9, 2024
8d97cba
lots of edits to NetworkTestResult for methods. I don't think its goi…
pollaro Jan 9, 2024
f32d021
remove a class i made to test a few things
pollaro Jan 9, 2024
467f9b4
fixed NetworkTestResult to account for different test methods
pollaro Jan 10, 2024
6970620
did a better job with NetworkTestResult and tests. now its ready to i…
pollaro Jan 10, 2024
652b0a1
start fixing up testpool and result rank.
pollaro Jan 10, 2024
2576e32
added unit tests for NetworkTestResult
pollaro Jan 11, 2024
33f46cd
this seems way too easy.
pollaro Jan 11, 2024
6e0a4cf
copied lots of files needed for permutations and test/result running.…
pollaro Jan 12, 2024
0639deb
lots of work on network test results and the result app front to get …
pollaro Jan 17, 2024
418a127
first batch of plotting tools made. not very pleased, but what can yo…
pollaro Jan 19, 2024
a401cde
bug squash to get no permutations to display figures
pollaro Jan 22, 2024
1286369
got most of the interfaces and even some of the plotting done. switch…
pollaro Jan 26, 2024
2c213e0
within net pair plotting
pollaro Jan 30, 2024
985ace9
fix some code to be more concise
pollaro Jan 30, 2024
1cea4c1
fix some code to be more concise
pollaro Jan 30, 2024
c00199d
added chord plotter and trying to integrate it into no permutations
pollaro Feb 1, 2024
f915a51
fixing some chord plotting and adding in trimatrix
pollaro Feb 2, 2024
cff5f3d
fixes for all chords
pollaro Feb 2, 2024
28c1169
added edge tests back that were lost
pollaro Feb 5, 2024
0b30453
rewrite network tests tests
pollaro Feb 6, 2024
7ba62ca
Added some unit tests and fixed a few errors
pollaro Feb 7, 2024
4747bc2
added a test for result rank
pollaro Feb 8, 2024
d9e89df
added convergence plotting functions/methods
pollaro Feb 9, 2024
0d66709
Added MatrixPlot in
pollaro Feb 13, 2024
85bec9a
just a few cleanups
pollaro Feb 8, 2024
9e3950b
cleaned up some code and bug fixes
pollaro Feb 14, 2024
b997055
network level chords working
pollaro Feb 27, 2024
cd7b4d9
remove two unneeded files
pollaro Feb 27, 2024
3b1f4ed
Attempting to get edge chord plotting working
pollaro Feb 28, 2024
f7ce8ae
chordplot used in all chord plotting instead of old function
pollaro Feb 28, 2024
0917337
[NET-148] Statistical Rank of refactored Network Test Results (#7)
pollaro Apr 11, 2024
f2d90ee
[NET-59] Better scaling options for TriMatrix plots (#9)
pollaro Apr 16, 2024
482f88d
[NET-157] Enable colormap choice for TriMatrix (#10)
pollaro Apr 16, 2024
3800ef2
[NET-159] Unit testing framework (#8)
pollaro Apr 19, 2024
2ff92dc
[NET-161] remove "Import nla.*" (#16)
pollaro Apr 25, 2024
35e1802
Development merging in master (#30)
pollaro Jun 4, 2024
27afd41
Revert "Development merging in master" (#34)
pollaro Jun 7, 2024
c6200ec
Merge master into development and rebase (#37)
pollaro Jun 11, 2024
1ae4041
[NET-192] Diagnostic Plot Fix (#33)
pollaro Jun 11, 2024
d6ba522
[NET-193] New Rankings...and other junk? (#39)
pollaro Jun 26, 2024
7a8a8df
[NET-142] Paired-T Edge Test (#48)
pollaro Jul 11, 2024
46f23e0
[NET-203] Network Test selection for figures fix (#52)
pollaro Jul 25, 2024
42ebde5
Exported mlapp files
actions-user Aug 20, 2024
76388ba
[NET-186] Change TriMatrix to single plot (#61)
pollaro Aug 30, 2024
ae0738a
remove unneeded files. AGAIN
pollaro Aug 30, 2024
6c33c38
[NET-218] Remove sort from Eggebrecht ranking (#67)
pollaro Oct 9, 2024
c950f49
[NET-187] Diagnostic Plots (#72)
pollaro Oct 23, 2024
27a0527
[NET-185] Clean up Enums (#73)
pollaro Oct 25, 2024
ba02038
[NET-225] Result P-values (#75)
pollaro Nov 4, 2024
b9fd0d4
[NET-225] Result P-value quick-fix (#76)
pollaro Nov 4, 2024
39b55db
[NET-225] Fix again (#77)
pollaro Nov 4, 2024
07bf74d
[NET-229] Both Benjamini corrections causing errors (#80)
pollaro Nov 5, 2024
7408eaf
[NET-217] Unit test fixes (#83)
pollaro Nov 12, 2024
3141f41
trying to make tests work again
pollaro Nov 13, 2024
300b290
trying to make tests work again
pollaro Nov 13, 2024
cdac585
trying to make tests work again
pollaro Nov 13, 2024
20c6179
trying out the sphinx and read the docs
pollaro Nov 19, 2024
b43b7da
adding network atlas documentation
pollaro Dec 10, 2024
235ca1a
added doc to customize tests
pollaro Jan 6, 2025
438580b
added to network test result doc
pollaro Jan 7, 2025
4555af3
adding to results and how to
pollaro Jan 9, 2025
9aab9b2
added some figures and more documentation
pollaro Jan 21, 2025
22878b3
remove redundancy from rebase
pollaro Mar 25, 2025
0320a1d
more redundancy
pollaro Mar 25, 2025
0960bd5
fixed stupid { instead of (
pollaro Mar 25, 2025
7480dc1
more fixes from rebase
pollaro Mar 25, 2025
c45c852
yet another fix
pollaro Mar 25, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions +nla/+gfx/+chord/ChordPlot.m
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ function connectNetworks(obj)

% boolean array used to determine if networks connected
networks_connected = false(obj.number_of_networks, obj.number_of_networks + 1);

if obj.chord_type == "nla.PlotType.CHORD"
% These two arrays are the networks individucally numbered. Taking the same index of both
% (in vector, network_array.v(idx)) gives the two networks we're testing
Expand All @@ -312,7 +312,7 @@ function connectNetworks(obj)
ROI_center_radians = [];
ROI_centers = [];
end

for network = 1:obj.number_of_networks
if obj.chord_type == "nla.PlotType.CHORD"
% These fill in the four networks above.
Expand Down
4 changes: 0 additions & 4 deletions +nla/+net/+result/+chord/ChordPlotter.m
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ function generateChordFigure(obj, parameters, chord_type)
% thresholding below the "insignificance" value
statistic_matrix = copy(parameters.statistic_plot_matrix);
statistic_matrix.v(~parameters.significance_plot.v) = insignificance;

chord_plotter = nla.gfx.chord.ChordPlot(obj.network_atlas, figure_axis, 500, statistic_matrix,...
'color_map', parameters.color_map, 'direction', parameters.significance_type, 'upper_limit',...
coefficient_bounds(2), 'lower_limit', coefficient_bounds(1), 'chord_type', chord_type);
Expand All @@ -78,8 +77,6 @@ function generateChordFigure(obj, parameters, chord_type)
% Plot edge chord
obj.generateEdgeChordFigure(plot_figure, parameters, chord_type)
end


end
end

Expand Down Expand Up @@ -137,7 +134,6 @@ function generateEdgeChordFigure(obj, plot_figure, parameters, chord_type)

clipped_values.v = obj.edge_test_result.prob.v;
significance_type = "nla.gfx.SigType.DECREASING";

coefficient_min = 0;
coefficient_max = obj.edge_test_result.prob_max;

Expand Down
164 changes: 54 additions & 110 deletions +nla/+net/+result/NetworkTestResult.m
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
classdef NetworkTestResult < matlab.mixin.Copyable
%NETWORKTESTRESULT Network Test Results
% This is the super class that all network test results will be in
% When a result is created the three repositories (within_network_pair, full_connectome, no_permutations) are set
% to false. This makes it easier to do an if/else check on them.
% The three private methods create the structures and trimatrices to keep the data.
% Notation:
% Test Methods: The method used for ranking the statistics (within net pair, full connectome, no permutation)
% Statistics: The statistical results from a specific network test (chi-squared, t-tests)
%
% Output object:
% test_name: The name of the network test run (chi_squared, hypergeometric, etc)
% test_options: The options passed in. Method, plotting methods (formerly input_struct)
% within_network_pair: Results from within_network_pair tests
% full_connectome: Results from full_connectome tests
% no_permutations: Results from the no permutation test
% permutation_results: Results from all the permutations of the network tests. These are used in the ranking to create
% the results for the test methods
%
% Within each of the three results structures will be properties containing the tri-matrices. Each test is different,
% but all contain:
% p_value: TriMatrix with p-values
% single_sample_p_value: TriMatrix with the single sample p-value (if available)
% Network level test results
% Class to store all relevant results for a network level test. Each test will create an instance of this to store results
%
% :param test_name: The name of the network test run
% :param test_display_name: The name of the network test for display
% :param test_options: Options and inputs for tests to be run (also called input_struct)
% :param ranking_statistic: The statistic to be used in ranking to determine p-value
% :param within_network_pair: Results of the within network pair test. Single sample p-values (except :math:`\chi^2`\ and hypergeometric tests). "legacy_" results use the individual test p-values to rank and determine the final p-value. Multiple ranking strategies available
% :param full_connectome: Results of the full_connectome test. Same format as above.
% :param no_permutations: Results for the non-permuted test. Same format as above.
% :param permutation_results: Results of each permutation. Statistics and p-values. Note: The p-values are for each individual permutation test, not the overall p-value.

properties
test_name = "" % Name of the network test run
test_display_name = "" % Name of the network test for the front-end to display
Expand All @@ -43,23 +32,13 @@
end

properties (Constant)
% TODO: replace wtih enums
test_methods = ["no_permutations", "full_connectome", "within_network_pair"]
noncorrelation_input_tests = ["chi_squared", "hypergeometric"] % These are tests that do not use correlation coefficients as inputs
end

methods
function obj = NetworkTestResult(test_options, number_of_networks, test_name, test_display_name,...
test_specific_statistics, ranking_statistic)
%CONSTRUCTOR Used for creating results.
%
% Arguments:
% test_options [Struct]: Options for the test. Formerly 'input_struct'
% number_of_networks [Int]: The number of networks in the data being analyzed
% test_name [String]: The name of the network test being run
% test_specific_statistics [Array[String]]: Test statistics for a test. (Example: t_statistic for a t-Test)
% ranking_statistic [String]: Test statistic that will be used in ranking

import nla.TriMatrix nla.TriMatrixDiag
if nargin == 0
return
Expand All @@ -77,7 +56,15 @@
end
end

% Used for plotting
function output(obj, edge_test_options, updated_test_options, network_atlas, edge_test_result, flags)
% Outputs data to be plotted using nla.net.result.plot.NetworkTestPlot
%
% :param edge_test_options: The test_options used to instantiate the class. Contains the functional connectivity and network atlas among other options
% :param updated_test_options: The network test options. These can also include the options for plotting.
% :param network_atlas: The network atlas
% :param edge_test_result: Results of the edge level test.
% :param flags: More options that are used after the tests have run. One of them is which test method to plot.
import nla.NetworkLevelMethod

if isfield(flags, "show_nonpermuted") && flags.show_nonpermuted
Expand All @@ -93,8 +80,12 @@ function output(obj, edge_test_options, updated_test_options, network_atlas, edg
network_result_plot.drawFigure(nla.PlotType.FIGURE)
end

% Use for merging multiple results together into one
function merge(obj, other_objects)
%MERGE Merge two groups of results together. Not guaranteed to be ordered
% Used to merge multiple results together into one
%
% :param other_objects: The other result objects to merge into this result object

if ~iscell(other_objects)
other_objects = {other_objects};
end
Expand All @@ -111,7 +102,9 @@ function merge(obj, other_objects)
end

function concatenateResult(obj, other_object)
%CONCATENATERESULT Add a result to the back of a TriMatrix. Used to keep permutation data.
% Concatenate results together. This is used to preserve the individual permutation results.
%
% :param other_object: The object to append to the end of the current result

statistics = fieldnames(obj.permutation_results);
for statistic_index = 1:numel(statistics)
Expand All @@ -124,74 +117,7 @@ function concatenateResult(obj, other_object)

obj.last_index = obj.last_index + 1;
end

function histogram = createHistogram(obj, statistic)
if ~endsWith(statistic, "_permutations")
statistic = strcat(statistic, "_permutations");
end
permutation_data = obj.permutation_results.(statistic);
histogram = zeros(nla.HistBin.SIZE, "uint32");

for permutation = 1:obj.permutation_count
histogram = histogram + uint32(histcounts(permutation_data.v(:, permutation), nla.HistBin.EDGES)');
end
end

function runDiagnosticPlots(obj, edge_test_options, updated_test_options, edge_test_result, network_atlas, flags)
import nla.NetworkLevelMethod

diagnostics_plot = nla.gfx.plots.DiagnosticPlot(edge_test_options, updated_test_options,...
edge_test_result, network_atlas, obj);

if isfield(flags, "show_nonpermuted") && flags.show_nonpermuted
test_method = "no_permutations";
elseif isfield(flags, "show_full_conn") && flags.show_full_conn
test_method = "full_connectome";
elseif isfield(flags, "show_within_net_pair") && flags.show_within_net_pair
test_method = "within_network_pair";
end

diagnostics_plot.displayPlots(test_method);
end

% I'm assuming this is Get Significance Matrix. It's used for the convergence plots button, but the naming makes zero sense
% Any help on renaming would be great.
function [test_number, significance_count_matrix, names] = getSigMat(obj, network_test_options, network_atlas, flags)

import nla.TriMatrix nla.TriMatrixDiag

test_number = 0;
significance_count_matrix = TriMatrix(network_atlas.numNets(), 'double', TriMatrixDiag.KEEP_DIAGONAL);
names = [];

if isfield(flags, "show_nonpermuted") && flags.show_nonpermuted
title = "Non-Permuted";
p_values = obj.no_permutations.uncorrected_two_sample_p_value;
fdr_method = network_test_options.fdr_correction;
end
if isfield(flags, "show_full_conn") && flags.show_full_conn
title = "Full Connectome";
p_values = obj.full_connectome.uncorrected_two_sample_p_value;
fdr_method = network_test_options.fdr_correction;
end
if isfield(flags, "show_within_net_pair") && flags.show_within_net_pair
title = "Within Network Pair";
p_values = obj.within_network_pair.uncorrected_single_sample_p_value;
fdr_method = network_test_options.fdr_correction;
end
[significance, name] = obj.singleSigMat(network_atlas, network_test_options, p_values, fdr_method, title);
[test_number, significance_count_matrix, names] = obj.appendSignificanceMatrix(test_number, significance_count_matrix,...
names, significance, name);
end

function table_new = generateSummaryTable(obj, table_old)
table_new = [table_old, table(...
obj.full_connectome.uncorrected_two_sample_p_value.v, 'VariableNames', [obj.test_display_name + "Full Connectome Two Sample p-value"]...
)];
end

%%
% getters for dependent properties

function value = get.permutation_count(obj)
% Convenience method to carry permutation from data through here
if isfield(obj.permutation_results, "two_sample_p_value_permutations") &&...
Expand All @@ -205,8 +131,8 @@ function runDiagnosticPlots(obj, edge_test_options, updated_test_options, edge_t
end
end

% Convenience method to determine if inputs were correlation coefficients, or "significance" values
function value = get.is_noncorrelation_input(obj)
% Convenience method to determine if inputs were correlation coefficients, or "significance" values
value = any(strcmp(obj.noncorrelation_input_tests, obj.test_name));
end

Expand All @@ -220,9 +146,12 @@ function runDiagnosticPlots(obj, edge_test_options, updated_test_options, edge_t

methods (Access = private)
function createResultsStorage(obj, test_options, number_of_networks, test_specific_statistics)
%CREATERESULTSSTORAGE Create the substructures for the methods chosen
% Creates the objects to hold results. Uses statistic names from test objects.
%
% :param test_options: The test options
% :param number_of_networks: The number of networks. Used to determine the size of the TriMatrix result. A property of the Network Atlas
% :param test_specific_statistics: The statistics used in each test. A property of each test.

% create the results containers. This replaces the false boolean with a struct of TriMatrices
for test_method_index = 1:numel(obj.test_methods)
if isequal(obj.(obj.test_methods(test_method_index)), false) &&...
isequal(test_options.(obj.test_methods(test_method_index)), true)
Expand All @@ -235,7 +164,6 @@ function createResultsStorage(obj, test_options, number_of_networks, test_specif
end

function createTestSpecificResultsStorage(obj, number_of_networks, test_specific_statistics)
%CREATETESTSPECIFICRESULTSSTORAGE Create the substructures for the specific statistical tests
import nla.TriMatrix nla.TriMatrixDiag

for statistic_index = 1:numel(test_specific_statistics)
Expand All @@ -247,7 +175,6 @@ function createTestSpecificResultsStorage(obj, number_of_networks, test_specific
end

function createPValueTriMatrices(obj, number_of_networks, test_method)
%CREATEPVALUETRIMATRICES Creates the p-value substructure for the test method
import nla.TriMatrix nla.TriMatrixDiag

non_correlation_test = any(strcmp(obj.test_name, obj.noncorrelation_input_tests));
Expand Down Expand Up @@ -313,13 +240,24 @@ function createPValueTriMatrices(obj, number_of_networks, test_method)
sig_count_mat.v = sig_count_mat.v + sig.v;
names = [names name];
end

function p_value = choosePlottingMethod(obj, test_options, plot_test_type)
p_value = "p_value";
if test_options == nla.gfx.ProbPlotMethod.STATISTIC
p_value = strcat("statistic_", p_value);
end
if ~obj.is_noncorrelation_input && plot_test_type == "within_network_pair"
p_value = strcat("single_sample_", p_value);
end
end
end

methods (Static)
function options = editableOptions()
% options that can be edited post-run (ie: are simple
% thresholds etc. for summary statistics, or generally can be
% modified without requiring re-permutation)
% Static method to return options that can be adjusted afterwards.
%
% :return: Options. Defaults to behavior_count, prob_max (The threshold for p-values), d_max (The threshold for Cohen's D values)

import nla.inputField.Integer nla.inputField.Number
options = {...
Integer('behavior_count', 'Test count:', 1, 1, Inf),...
Expand All @@ -329,6 +267,12 @@ function createPValueTriMatrices(obj, number_of_networks, test_method)
end

function probability = getPValueNames(test_method, test_name)
% Static method to determine prefixes of p-values for test results
%
% :param test_method: No permutations, full connectome, or within network pair
% :param test_name: The name of the test run
% :return: The full name of the p-value. (example: "single_sammple_p_value")

import nla.NetworkLevelMethod
noncorrelation_input_tests = ["chi_squared", "hypergeometric"];
non_correlation_test = any(strcmp(test_name, noncorrelation_input_tests));
Expand Down
4 changes: 1 addition & 3 deletions +nla/+net/+test/StudentTTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,14 @@
network_rho = edge_test_results.coeff.get(network_atlas.nets(network).indexes,...
network_atlas.nets(network2).indexes);
[~, p, ~, stats] = ttest2(network_rho, edge_test_results.coeff.v);

[~, single_sample_p, ~, single_sample_stats] = ttest(network_rho);
result.(permutation_results).(p_value).set(network, network2, p);
result.(permutation_results).(t_statistic).set(network, network2, stats.tstat);

result.(permutation_results).(single_sample_p_value).set(network, network2, single_sample_p);
result.(permutation_results).(single_sample_t_statistic).set(network, network2, single_sample_stats.tstat);
end
end

end
end
end

Expand Down
5 changes: 2 additions & 3 deletions +nla/+net/ResultRank.m
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@
end
end


function ranking = winklerMethodRank(obj, test_method, permutation_results, no_permutation_results, ranking_statistic,...
probability, ranking)

winkler_probability = strcat("winkler_", probability);
max_statistic_array = max(abs(permutation_results.(strcat(ranking_statistic, "_permutations")).v));
for index = 1:numel(no_permutation_results.(strcat("uncorrected_", probability)).v)
Expand All @@ -100,7 +100,6 @@
);
end
end

ranking.(test_method).(winkler_probability).v = ranking.(test_method).(winkler_probability).v ./ obj.permutations;
end

Expand Down Expand Up @@ -159,7 +158,7 @@
end

function value = get.number_of_networks(obj)
value = obj.permuted_network_results.no_permutations.p_value.size;
value = obj.permuted_network_results.no_permutations.p_value.size;
end
%%
end
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run_matlab_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ jobs:
uses: matlab-actions/run-command@v2
with:
command: addpath(genpath(pwd)); results = runTests(); assertSuccess(results)
use-parallel: true
use-parallel: true
Empty file removed README.rst
Empty file.
Binary file added docs/source/_static/behavior_table.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/main_gui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/main_gui2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/result_gui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/test_results_gui.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/trimatrix_plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading