-
-
Save anonymous/2840728 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def discrete_sample(self,num_samples,burn_in=0): | |
sample = randint(self.range[0],self.range[1],self.size) | |
samples = [] | |
prop_dist = 1.0/(self.range[1]**2) | |
print prop_dist | |
print self.dist([0,0]) | |
print self.dist([0,1]) | |
print self.dist([1,0]) | |
print self.dist([1,1]) | |
proposal = randint(self.range[0],self.range[1],self.size) | |
while len(samples) < num_samples: | |
proposal_prob = min(1, self.dist(proposal)*1.0/self.dist(sample)) | |
# print 'self.dist(prop): %f | self.dist(sample): %f' %(self.dist(proposal),self.dist(sample)) | |
# print self.dist(proposal)*1.0/self.dist(sample) | |
# print proposal_prob | |
if proposal_prob > np.random.rand(): | |
print sample | |
samples.append(sample) | |
sample = proposal | |
proposal = randint(self.range[0],self.range[1],self.size) | |
return samples |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input distribution | |
..[[ 0.05 0.45] | |
[ 0.25 0.25]] | |
output distribution after 10,000 samples | |
[[ 0.3 0.3] | |
[ 0.2 0.2]] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment