Sunday, October 30, 2016

Find probability bins?

I generate a series of random numbers.  What is their probability?  One simple technique is to sort the rounded off integers, set the lower six bits to zero, and sort them on the masked value.   The real values then group according to mask value, and you get the count of values all having the same mask, grouped together.  The count is a good approximation to probability for bins of the particular bit size. I tried it out, it le tme learn how tom do sorting under Pythin.


import random
random.seed()
class Data:
 def __init__(self, val):
  self.val = val
  self.mask = self.val & 0x3e0
 def __repr__(self):
  return repr((self.val, self.mask))

Mylist = []
for i in range(50) :
 j = random.randint(0, 1024)
 Mylist.append(Data(j))
print(sorted(Mylist,key=lambda thing: thing.mask))


On might consider a strategy.  Find the lowest probability group, and bubble the whole groupup as a sub graph.  An imperfect Huffman tree, but it gets the significant groups up the tree ASAP, and you can refine the sort later.
The next step is to make the tree an iterable object, if its possible.

No comments: