Skip to content

Commit

Permalink
Merge pull request #1515 from softmatterlab/develop
Browse files Browse the repository at this point in the history
BRAPH 2.0.0.a3
  • Loading branch information
giovannivolpe authored Nov 30, 2022
2 parents 83cc3ec + 1e7bf19 commit f1fc297
Show file tree
Hide file tree
Showing 1,325 changed files with 9,033 additions and 671 deletions.
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ authors:
orcid: 'https://orcid.org/0000-0002-5388-7712'
- given-names: Anna
family-names: Canal-Garcia
email: [email protected]
email: anna.canal.garcia@ki.se
affiliation: Karolinska Institute
orcid: 'https://orcid.org/0000-0001-7460-741X'
- given-names: Yu-Wei
Expand Down
1 change: 1 addition & 0 deletions braph2genesis/measures/_EdgeOverlap.gen.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
MultiplexBUT
MultiplexWD
MultiplexWU
OrderedMultiplexWU

%% ¡props_update!

Expand Down
1 change: 1 addition & 0 deletions braph2genesis/measures/_MultiRichClubDegree.gen.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
MultiplexBUT
MultiplexWD
MultiplexWU
OrderedMultiplexWU

%% ¡props!

Expand Down
1 change: 1 addition & 0 deletions braph2genesis/measures/_MultiRichClubStrength.gen.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
%%% ¡compatible_graphs!
MultiplexWD
MultiplexWU
OrderedMultiplexWU

%% ¡props!

Expand Down
1 change: 1 addition & 0 deletions braph2genesis/measures/_MultiplexClustering.gen.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
MultiplexBU
MultiplexBUD
MultiplexBUT
OrderedMultiplexWU

%% ¡props_update!

Expand Down
1 change: 1 addition & 0 deletions braph2genesis/measures/_MultiplexClusteringAv.gen.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
MultiplexBU
MultiplexBUD
MultiplexBUT
OrderedMultiplexWU

%% ¡props_update!

Expand Down
1 change: 1 addition & 0 deletions braph2genesis/measures/_MultiplexCorePeriphery.gen.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ the default coefficients are (1/layernumber).
MultiplexBUT
MultiplexWD
MultiplexWU
OrderedMultiplexWU

%% ¡props_update!

Expand Down
1 change: 1 addition & 0 deletions braph2genesis/measures/_MultiplexKCore.gen.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
MultiplexBU
MultiplexWD
MultiplexWU
OrderedMultiplexWU

%% ¡props!
%%% ¡prop!
Expand Down
1 change: 1 addition & 0 deletions braph2genesis/measures/_MultiplexKCorenessCentrality.gen.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ but not to the (k+1)-core.
MultiplexWD
MultiplexBU
MultiplexBD
OrderedMultiplexWU

%% ¡props_update!

Expand Down
1 change: 1 addition & 0 deletions braph2genesis/measures/_MultiplexParticipation.gen.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
MultiplexBUD
MultiplexBUT
MultiplexWU
OrderedMultiplexWU

%% ¡props_update!

Expand Down
1 change: 1 addition & 0 deletions braph2genesis/measures/_MultiplexParticipationAv.gen.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
MultiplexBUD
MultiplexBUT
MultiplexWU
OrderedMultiplexWU

%% ¡props_update!

Expand Down
1 change: 1 addition & 0 deletions braph2genesis/measures/_MultiplexTriangles.gen.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
MultiplexBU
MultiplexBUD
MultiplexBUT
OrderedMultiplexWU

%% ¡props_update!

Expand Down
1 change: 1 addition & 0 deletions braph2genesis/measures/_Multirichness.gen.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ the default coefficients are (1/layernumber).
MultiplexBUT
MultiplexWD
MultiplexWU
OrderedMultiplexWU

%% ¡props!
%%% ¡prop!
Expand Down
1 change: 1 addition & 0 deletions braph2genesis/measures/_OverlappingDegree.gen.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
MultiplexBUD
MultiplexBUT
MultiplexWU
OrderedMultiplexWU

%% ¡props_update!

Expand Down
1 change: 1 addition & 0 deletions braph2genesis/measures/_OverlappingDegreeAv.gen.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
MultiplexBUD
MultiplexBUT
MultiplexWU
OrderedMultiplexWU

%% ¡props_update!

Expand Down
1 change: 1 addition & 0 deletions braph2genesis/measures/_OverlappingStrength.gen.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

%%% ¡compatible_graphs!
MultiplexWU
OrderedMultiplexWU

%% ¡props_update!

Expand Down
1 change: 1 addition & 0 deletions braph2genesis/measures/_OverlappingStrengthAv.gen.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

%%% ¡compatible_graphs!
MultiplexWU
OrderedMultiplexWU

%% ¡props_update!

Expand Down
1 change: 1 addition & 0 deletions braph2genesis/measures/_PathLength.gen.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
end
value = path_length;


%% ¡tests!

%%% ¡test!
Expand Down
1 change: 1 addition & 0 deletions braph2genesis/measures/_Richness.gen.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
MultiplexBUT
MultiplexWD
MultiplexWU
OrderedMultiplexWU

%% ¡props_update!

Expand Down
1 change: 1 addition & 0 deletions braph2genesis/measures/_Strength.gen.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
%%% ¡compatible_graphs!
GraphWU
MultiplexWU
OrderedMultiplexWU

%% ¡props_update!

Expand Down
1 change: 1 addition & 0 deletions braph2genesis/measures/_StrengthAv.gen.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
%%% ¡compatible_graphs!
GraphWU
MultiplexWU
OrderedMultiplexWU

%% ¡props_update!

Expand Down
1 change: 1 addition & 0 deletions braph2genesis/measures/_WeightedEdgeOverlap.gen.m
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
%%% ¡compatible_graphs!
MultiplexWD
MultiplexWU
OrderedMultiplexWU

%% ¡props_update!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

%%% ¡compatible_graphs!
MultiplexWU
OrderedMultiplexWU

%% ¡props_update!

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

%%% ¡compatible_graphs!
MultiplexWU
OrderedMultiplexWU

%% ¡props_update!

Expand Down
55 changes: 45 additions & 10 deletions braph2genesis/neuralnetworks/_NNClassifierCrossValidation.gen.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
%%%% ¡default!
[100 100]
%%%% ¡gui!
pr = PanelPropRVectorSmart('EL', nncv, 'PROP', NNClassifierCrossValidation.LAYERS, 'MAX', 100000, 'MIN', 1, varargin{:});
pr = PanelPropRVectorSmart('EL', nncv, 'PROP', NNClassifierCrossValidation.LAYERS, 'MAX', 100000, 'MIN', 1, 'UNIQUE_VALUE', false, varargin{:});

%%% ¡prop!
BATCH (parameter, scalar) is the size of the mini-batch to use for each training iteration.
Expand Down Expand Up @@ -226,32 +226,67 @@
FEATURE_IMPORTANCE (result, cell) is the feature importance obtained with permutation analysis.
%%%% ¡calculate!
if ~isa(nncv.get('GR1').getr('SUB_DICT'), 'NoValue')
nne_dict = nncv.memorize('NNE_DICT');
feature_importances = nne_dict.getItem(1).get('FEATURE_PERMUTATION_IMPORTANCE');
if length(feature_importances) == 0
if any(ismember(nncv.get('GR1').get('SUB_DICT').getItem(1).get('INPUT_LABEL'), subclasses('Measure', [], [], true)))
feature_importances = {};
if ~braph2_testing
questdlg('Feature importance analysis does not apply to the input of graph measures.', ...
'User Request', ...
'Ok', 'Ok');
end
else
for i = 2:1:nne_dict.length()
feature_importance = nne_dict.getItem(i).get('FEATURE_PERMUTATION_IMPORTANCE');
feature_importances = cellfun(@(x, y) x + y, feature_importances, feature_importance, 'UniformOutput', false);
nne_dict = nncv.memorize('NNE_DICT');
wb = braph2waitbar(nncv.get('WAITBAR'), 0, 'Analysing feature importance...');
feature_importances = nne_dict.getItem(1).get('FEATURE_PERMUTATION_IMPORTANCE');
braph2waitbar(wb, .30 + .70 * 1 / nne_dict.length, ['Analysing feature importance for the fold ' num2str(1) ' out of ', num2str(nne_dict.length), '...']);
if length(feature_importances) == 0
feature_importances = {};
else
for i = 2:1:nne_dict.length()
feature_importance = nne_dict.getItem(i).get('FEATURE_PERMUTATION_IMPORTANCE');
feature_importances = cellfun(@(x, y) x + y, feature_importances, feature_importance, 'UniformOutput', false);
braph2waitbar(wb, .30 + .70 * i / nne_dict.length, ['Analysing feature importance for the fold ' num2str(i) ' out of ', num2str(nne_dict.length), '...']);
end
feature_importances = cellfun(@(x) x/nne_dict.length, feature_importances, 'UniformOutput', false);
end
feature_importances = cellfun(@(x) x/nne_dict.length, feature_importances, 'UniformOutput', false);
braph2waitbar(wb, 'close')
end
else
feature_importances = {};
end

value = feature_importances;
%%%% ¡gui!
if ~braph2_testing && ~isa(nncv.get('GR').get('SUB_DICT'), 'NoValue')
if string(nncv.get('GR1').get('SUB_DICT').getItem(1).get('INPUT_TYPE')) == 'structural_data'
pr = PPNNEvaluatorFeatureImportanceStructuralData('EL', nncv, 'PROP', NNClassifierCrossValidation.FEATURE_IMPORTANCE, varargin{:});
elseif string(nncv.get('GR1').get('SUB_DICT').getItem(1).get('INPUT_TYPE')) == 'adjacency_matrices'
pr = PPNNEvaluatorFeatureImportanceAdjacency('EL', nncv, 'PROP', NNClassifierCrossValidation.FEATURE_IMPORTANCE, varargin{:});
else
pr = PanelPropCell('EL', nncv, 'PROP', NNClassifierCrossValidation.FEATURE_IMPORTANCE, varargin{:});
end
end

%% ¡props_update!

%%% ¡prop!
GR (data, item) is a group of NN subjects.
%%%% ¡settings!
'NNGroup'
%%%% ¡postprocessing!
if ~braph2_testing && isempty(nncv.get('GR').get('SUB_DICT').get('IT_LIST'))
nncv.set('GR', nncv.get('GR1'));
end

%%% ¡prop!
PFFI (gui, item) contains the panel figure of the feature importance.
%%%% ¡settings!
'PFFeatureImportance'
%%%% ¡postprocessing!
if ~braph2_testing % to avoid problems with isqual when the element is recursive
nncv.memorize('PFFI').set('NNE', nncv, 'PROP', NNClassifierCrossValidation.FEATURE_IMPORTANCE, 'BA', nncv.get('GR1').get('SUB_DICT').getItem(1).get('BA'))
nncv.memorize('PFFI').set('NNE', nncv, ...
'PROP', NNClassifierCrossValidation.FEATURE_IMPORTANCE, ...
'INPUT_TYPE', nncv.get('GR1').get('SUB_DICT').getItem(1).get('INPUT_TYPE'), ...
'BA', nncv.get('GR1').get('SUB_DICT').getItem(1).get('BA'))
end
%%%% ¡gui!
pr = PanelPropItem('EL', nncv, 'PROP', NNClassifierCrossValidation.PFFI, ...
Expand All @@ -264,7 +299,7 @@
'NNGroup'
%%%% ¡calculate!
if ~isa(nncv.get('GR1').getr('SUB_DICT'), 'NoValue')
gr = nncv.get('NNE_DICT').getItem(1).get('GR_PREDICTION');
gr = nncv.memorize('NNE_DICT').getItem(1).memorize('GR_PREDICTION');
gr_prediction = NNGroup( ...
'ID', 'NN Group with NN prediction', ...
'LABEL', 'The predictions are obatined from K-fold cross validation', ...
Expand Down
30 changes: 20 additions & 10 deletions braph2genesis/neuralnetworks/_NNClassifierDNN.gen.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
end
end
%%%% ¡gui!
pr = PanelPropRVectorSmart('EL', nn, 'PROP', NNClassifierDNN.LAYERS, 'MAX', 100000, 'MIN', 1, varargin{:});
pr = PanelPropRVectorSmart('EL', nn, 'PROP', NNClassifierDNN.LAYERS, 'MAX', 100000, 'MIN', 1, 'UNIQUE_VALUE', false, varargin{:});

%%% ¡prop!
BATCH (parameter, scalar) is the size of the mini-batch to use for each training iteration.
Expand Down Expand Up @@ -48,7 +48,7 @@
1

%%% ¡prop!
VERBOSE (parameter, logical) is an indicator to display trining progress information.
VERBOSE (parameter, logical) is an indicator to display training progress information.
%%%% ¡default!
false

Expand Down Expand Up @@ -127,38 +127,48 @@
end

%% ¡methods!
function [inputs, num_features] = reconstruct_inputs(nn, gr)
function [inputs, num_features, masks] = reconstruct_inputs(nn, gr)
%RECONSTRUCT_INPUTS reconstructs the inputs for NN
%
% [INPUTS, NUM_FEATURES] = RECONSTRUCT_INPUTS(NN, GR) reconstructs the
% inputs from NN group. According to the tyep of this fully-connected NN,
% this function will flatten the input into a vector for each datapoint
% and return the number of features for input layer as well.

if gr.get('SUB_DICT').length() == 0
inputs = [];
num_features = 0;
else
% get the mask for selecting the relevant input features
% get the mask for selecting the relevant input features
mask_tmp = gr.get('FEATURE_SELECTION_MASK');
masks = {};
for i = 1:1:length(mask_tmp)
masks = cell(size(mask_tmp));
for i = 1:1:numel(mask_tmp)
mask = mask_tmp{i};
mask = rescale(mask);
[~, idx_all] = sort(mask(:), 'descend');
percentile = nn.get('FEATURE_SELECTION_RATIO');
num_top_idx = ceil(percentile * numel(mask));
mask(idx_all(1:num_top_idx)) = 1;
mask(idx_all(end - (length(idx_all) - num_top_idx - 1):end)) = 0;
masks{i} = mask;
end

% apply the mask to select input features
inputs = [];
inputs_tmp = gr.get('INPUTS');
for i = 1:1:length(inputs_tmp)
input = inputs_tmp{i};
input_per_sub = cellfun(@(x, y) x(y == 1), input, masks, 'UniformOutput', false);
input_per_sub = cell2mat(input_per_sub');
input_per_sub = cellfun(@(x, y) transpose(x(y == 1)), input, masks, 'UniformOutput', false);
for j = 1:1:numel(input_per_sub)
data = input_per_sub{j};
data(isnan(data)) = 0;
data(isinf(data)) = 0;
if size(data, 1) < size(data, 2)
data = data';
end
input_per_sub_vector{j} = data;
end
input_per_sub = cell2mat(input_per_sub_vector');
inputs = [inputs input_per_sub];
end
num_features = length(inputs(:, 1));
Expand Down
4 changes: 2 additions & 2 deletions braph2genesis/neuralnetworks/_NNClassifierDataSplit.gen.m
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@
y = cellfun(@(x) cell2mat(x.get('TARGET')), gr_train.get('SUB_DICT').getItems(), 'UniformOutput', false);
y = cell2mat(y);
label = y(1, :);
num_feature_cluster = length(data{1});
num_feature_cluster = numel(data{1});
value = cell(size(data{1}));

% setup counter for waitbar
Expand All @@ -171,7 +171,7 @@
if ~isempty(mask)
for i = 1:numel(mask)
data_per_feature = cellfun(@(v)v(i), data_per_cluster);
if(any(isinf(data_per_feature)))
if(any(isinf(data_per_feature)) || any(isnan(data_per_feature)))
mask(i) = 0;
else
mask(i) = nnds.mutual_information_analysis(data_per_feature, label, 5);
Expand Down
Loading

0 comments on commit f1fc297

Please sign in to comment.