https://github.com/nwbarendregt/AdaptNormThresh
Raw File
Tip revision: 2878a3d9f5a3b9b89a0084a897bef3414e9de4a2 authored by nwbarendregt on 03 May 2022, 15:08:29 UTC
Add files via upload
Tip revision: 2878a3d
prob_choice.m
function p = prob_choice(nTokensPro, nTokensCon, nTokensTot)

% PROB_CHOICE Calculate the probability that a given bin will receive more tokens
%
% p = prob_choice(nTokensPro, nTokensCon, nTokensTot)
%
% nTokensPro      - Number of tokens in favor of the choice
% nTokensCon      - Number of tokens against the choice
% nTokensTot      - Total number of tokens
%
% p               - Probability that Pro will be larger than Con when all tokens are committed

if rem(nTokensTot,2)==0
   nTokensTot = nTokensTot-1;
end

nNeedPro = ceil(nTokensTot / 2) - nTokensCon;  % Need this many more tokens to be in favor

nTokensLeft = nTokensTot - nTokensPro - nTokensCon;

p = 0;

for n=0:nNeedPro-1
   
   if nTokensLeft<n
      return;
   end
   
   % pNK = the probability of getting exactly K pro given that we have N left
   nCombs = 2^nTokensLeft;
   nGoodCombs = factorial(nTokensLeft) / (factorial(n) * factorial(nTokensLeft-n));
   
   pNK = nGoodCombs / nCombs;
   
   p = p + pNK;
   
end


back to top