%distribution=estimatedGoogle(iterations,states,F,varF,nv,pp,c,p)

%This function approximates the Google PageRank algorithm by taking random walks along the network with a chance of randomly going anywhere

%Parameters:
%Iterations: number of random walks to be taken
%States: a list of the states we care about keeping track of 
%F, varF, nv,p: corresponding to boolean network we are walking on 
%pp- (1-pp) is the chance we have of randomly going to a new state
%c- the propensites that govern our random walks

%Returns a list showing percent of time spent at states we care about according to approximation of google PageRank

%Uses: SDDSNextState.m

%Author: Jacob Miller, 4/28/16

function distribution=estimatedGoogle(iterations,states,F,varF,nv,pp,c,p)
n=length(nv); %number of genes
distribution=zeros(1,length(states));

currenti=randi(2^n);%start at random state
currents=dec2bin(currenti-1,n);%change integer to binary array
current=currents-48;  
%Take all necessary steps
for j=1:iterations
  
  states_index=find(states==currenti);  %keep track of amount of times we are on a state we care about
  if (states_index>0)
    distribution(states_index)=distribution(states_index)+1;
  end
  
  if (rand<pp)%There is a chance we randomly choose a new state
    currenti=randi(2^n);
    currents=dec2bin(currenti-1,n);
    current=currents-48;
  else
    current=SDDSNextState(current,F,varF,nv,p,c);%Take step in random walk
    currenti=1;
    for i=1:n 
      currenti=currenti+2^(i-1)*current(end+1-i);
    end
  end
end
distribution=distribution/iterations;
end
