% Example calculation of the unweighted imbalance in Octave % (for smaller amounts the unweighted imbalance is important) % % Imbalance of a channel: % b <-> 0 = 100% % 0 <-> b = 100% % 1/2b <-> 1/2b = 0% % Set 3 channel balances (in msatoshi) peer(1)=1000000000; we(1)=500000000; peer(2)=1100000000; we(2)=300000000; peer(3)=0; we(3)=300000000; num_channels=length(peer); imbalance=0; tot=0; for n=1:3 totc=peer(n)+we(n); % total of this channel tot=tot+totc; % total of all channels % Normalize difference <= 1, square and sum imbalance=imbalance+((peer(n)-we(n))/totc)^2; end % Normalize sum of differences <= 1, take root and multiply by 100 imbalance=100*sqrt(imbalance/num_channels) % 69.225 per cent