def MetropolisJsampling(J,B,alpha): # Metropolis sampling algorithm for Jars Jmean=np.array([0]*len(J)) # declare a J mean. #Jtemp=np.array([0]*len(J)) for i in range(1,1000): # run the iteration for 1000 times. Jnew=b.Jrandom(J) # Randomize the Jar sequence Value acceptance_ratio=b.PalphaJB(alpha,Jnew,B)/b.PalphaJB(alpha,J,B) # find Acceptance Ratio, which is division of probabilities with new vs old values if random.uniform(0,1)<= acceptance_ratio: # choose a random number, if It is less than acceptance ratio J[:]=Jnew[:] # if it is less than, then assign it to a temp varaibale Jmean[:]=np.add(J[:],Jmean[:]) # add temp variable to Jmean entries return [x/1000.0 for x in Jmean[:]] # return mean of all entries for J values.