From 29d4d8b021b63bba023bd7fe944605ea97bf1aba Mon Sep 17 00:00:00 2001 From: TeunHuijben Date: Sun, 14 Jun 2020 17:17:47 +0200 Subject: [PATCH] Add functions for reconnecting the graph --- MATLAB/avg/connectGraph.m | 42 +++++++++++++++++++++++++++++++++++++++ MATLAB/avg/isConnected.m | 34 +++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 MATLAB/avg/connectGraph.m create mode 100644 MATLAB/avg/isConnected.m diff --git a/MATLAB/avg/connectGraph.m b/MATLAB/avg/connectGraph.m new file mode 100644 index 0000000..66d847b --- /dev/null +++ b/MATLAB/avg/connectGraph.m @@ -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(:))abs(error(b(start)))); %indices of all errors including new one + I_new = I; + I_new(:,error_idx) = []; + start = start+1; + end + +end diff --git a/MATLAB/avg/isConnected.m b/MATLAB/avg/isConnected.m new file mode 100644 index 0000000..a3ab092 --- /dev/null +++ b/MATLAB/avg/isConnected.m @@ -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 +