-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functions for reconnecting the graph
- Loading branch information
1 parent
d869beb
commit 29d4d8b
Showing
2 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
%connectGraph This function keeps increasing the threshold on the error | ||
%to include more connections, untill the graph is connected. | ||
% | ||
% SYNOPSIS: | ||
% [error_idx] = connectGraph(I,error) | ||
% | ||
% Input: | ||
% I: 2xN matrix of indices indications the connections | ||
% error: vector of error values for every combinations in I | ||
% | ||
% Output: | ||
% error_idx: indices of the to-be-removed connection in I | ||
% | ||
% NOTE: | ||
% | ||
% (C) Copyright 2017 QI Group | ||
% All rights reserved Faculty of Applied Physics | ||
% Delft University of Technology | ||
% Lorentzweg 1 | ||
% 2628 CJ Delft | ||
% The Netherlands | ||
% | ||
% Teun Huijben, June 2020. | ||
|
||
function error_idx = connectGraph(I,error) | ||
|
||
[a,b] = sort(abs(error)); %sort the errors | ||
first_above5 = find(a>5,1); %find the index of lowest error | ||
|
||
error_idx = abs(error)>5; %indices of all errors | ||
I_new = I; | ||
I_new(:,error_idx) = []; %remove errors from graph | ||
|
||
start = first_above5; | ||
while (isConnected(I_new)==0 | max(I_new(:))<max(I(:))) | ||
error_idx = (abs(error)>abs(error(b(start)))); %indices of all errors including new one | ||
I_new = I; | ||
I_new(:,error_idx) = []; | ||
start = start+1; | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
%isConnected This function checks whether the graph is connected | ||
% | ||
% SYNOPSIS: | ||
% [connected] = isConnected(I) | ||
% | ||
% Input: | ||
% I: 2xN matrix of indices indications the connections | ||
% | ||
% Output: | ||
% connected: Boolean indicating whether is connected | ||
% | ||
% NOTE: | ||
% | ||
% (C) Copyright 2017 QI Group | ||
% All rights reserved Faculty of Applied Physics | ||
% Delft University of Technology | ||
% Lorentzweg 1 | ||
% 2628 CJ Delft | ||
% The Netherlands | ||
% | ||
% Teun Huijben, June 2020. | ||
|
||
function connected = isConnected(I) | ||
|
||
Gr = graph(I(1,:),I(2,:)); | ||
clusters = conncomp(Gr); | ||
if max(clusters)==1 | ||
connected = true; | ||
else | ||
connected = false; | ||
end | ||
|
||
end | ||
|