Skip to content

Commit

Permalink
Merge pull request #40 from eminSerin/dev
Browse files Browse the repository at this point in the history
NBS-Predict v1.0.0-beta.12-hotfix
  • Loading branch information
eminSerin authored Apr 21, 2024
2 parents 47f9478 + 42094be commit b804e13
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/NBSPredict_predict.m
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@
end

% Shrink connectivity matrices into edge matrices.
X = connData(model.preprocess.edgeIdx)';
X = shrinkMat(connData);


% Predicts label using given data.
if ~isempty(model.preprocess.scaler)
Expand Down
2 changes: 1 addition & 1 deletion src/io/MatrixVectorizer.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
else
for i = 1:subjects
cMat = data(:,:,i); % Select current matrix.
if ~issymmetric(cMat)
if ~is_symmetric(cMat)
warning('Given matrix is not symmetric! Data index: %d', i)
end
edgeMat(i,:)=cMat(obj.edgeIdx); % extract edge values.
Expand Down
41 changes: 41 additions & 0 deletions src/io/is_symmetric.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
function isSymmetric = is_symmetric(matrix, tolerance)
% IS_SYMMETRIC Checks if a given matrix is symmetric within a specified tolerance.
%
% Syntax:
% isSymmetric = is_symmetric(matrix, tolerance)
%
% Input Arguments:
% matrix - A square matrix to be checked for symmetry.
% tolerance - A scalar value specifying the tolerance for the symmetry check.
% If not provided, the default value is 1e-15.
%
% Output Argument:
% isSymmetric - A logical value indicating whether the matrix is symmetric
% within the specified tolerance. Returns true if the matrix
% is symmetric and false otherwise.
%
% Example:
% matrix = [1, 2; 2, 1];
% isSymmetric = is_symmetric(matrix, 1e-15);
%
% This will return true as the matrix is symmetric within the tolerance of 1e-15.
%
% Note:
% The function first checks if the matrix is square. If not, it returns false.
% Then it calculates the absolute difference between the matrix and its transpose.
% If all elements in the difference matrix are within the tolerance, it returns true.
% Otherwise, it returns false.
%
if nargin < 2
tolerance = 1e-15;
if size(matrix, 1) ~= size(matrix, 2)
isSymmetric = false;
return;
end

% Calculate the difference between the matrix and its transpose
diffMatrix = abs(matrix - matrix');

% Check if all elements in the difference matrix are within the tolerance
isSymmetric = all(all(diffMatrix <= tolerance));
end
2 changes: 1 addition & 1 deletion src/io/shrinkMat.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
else
for i = 1:subjects
cMat = data(:,:,i); % Select current matrix.
if ~issymmetric(cMat)
if ~is_symmetric(cMat)
warning('Given matrix is not symmetric! Data index: %d', i)
end
edgeMat(i,:)=cMat(edgeIdx); % extract edge values.
Expand Down
2 changes: 1 addition & 1 deletion test/networks/networks/gen_BAnet.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
eIdx = eIdx + m*2;
end

if ~issymmetric(g)
if ~is_symmetric(g)
error('Network is not symmetric. Please run the function again.');
end

Expand Down

0 comments on commit b804e13

Please sign in to comment.