Skip to content

Commit

Permalink
Recommited modifications inCMultiFisherNCHypergeometricrnd.m
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoRianiUNIPR committed Jan 22, 2025
1 parent 5135766 commit 4377f89
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions toolbox/+aux/CMultiFisherNCHypergeometricrnd.m
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,24 @@
order3=order1;
weights=w;

% for i=1:colors
% c = order1(i);
% k = i;
% w = weights(c);
% if (source(c)==0)
% w = 0; % // zero number treated as zero weight
% end
%
% for j=i+1:colors
% c2 = order1(j);
% if weights(c2) > w && source(c2)
% w = weights(c2); k = j;
% end
% end
% order1(i) = order1(k);
% order1(k) = c;
% end
[~,order1]=sort(weights,'descend');
% // sort by weight, heaviest first
for i=1:colors
c = order1(i);
k = i;
w = weights(c);
if (source(c)==0)
w = 0; % // zero number treated as zero weight
end

for j=i+1:colors
c2 = order1(j);
if weights(c2) > w && source(c2)
w = weights(c2); k = j;
end
end
order1(i) = order1(k);
order1(k) = c;
end

urn=m(order1);
osource=urn;
Expand Down Expand Up @@ -150,10 +150,10 @@
end


if (n > N / 2)
if n > (N /2)
% // improve accuracy by symmetry transformation
j=colors;
for i=1:j
for i=1:(j-1)
% // reverse order list
c = order1(i);

Expand All @@ -169,7 +169,6 @@
end



%// copy source and weights into ordered lists
%// and pool together colors with same weight
% colors2= number of colors left
Expand All @@ -183,7 +182,12 @@
if (i==1 || weights(c) ~= w)
c2=c2+1;
x = source(c);
oweights(c2) = weights(c);
if invert == true
oweights(c2) = 1/weights(c);
else
oweights(c2)=weights(c);
end

w = weights(c);
else
x = x+ source(c); % // join colors with same weight
Expand Down Expand Up @@ -370,7 +374,11 @@
destination(c1) = osample(c2);
else
%// split colors with same weight that have been treated as one
x = aux.FisherNCHypergeometricrnd(osample(c2), source(c1), osource(c2));
% x = aux.FisherNCHypergeometricrnd(osample(c2), source(c1), osource(c2));

% M. K. N
x = hygernd(osource(c2), source(c1), osample(c2));

destination(c1) = x;
osample(c2) = osample(c2) - x;
osource(c2) = osource(c2) - source(c1);
Expand Down

0 comments on commit 4377f89

Please sign in to comment.