/timm's /charming /python /tricks
Download
aboutd.py.
Read more on How to be Charming (in Python).
01: import sys 02: sys.dont_write_bytecode=True # don't make .pyc files 03: from about import * 04: 05: @demo1 06: def symd(): 07: resetSeed(1) 08: s = Sym() 09: lst = list('to be or not to be') 10: # here, we remember all the things we find 11: for x in lst: 12: s.seen(x) 13: print s 14: # here, we report what's seen so far 15: print ':counts', mostest(s.counts) 16: # now, we pull 50 things from that distribution 17: sampler = s.sample(50) 18: samples = sorted(c for c in sampler) 19: print '['+''.join(samples) + ']' 20: 21: def numd(): 22: resetSeed(1) 23: n = Num() 24: for _ in range(100): 25: n.seen(rand()**2) 26: print n 27: sampler = n.sample(50) 28: print sampler 29: samples = sorted(n for n in sampler) 30: print gs(samples) 31: 32: def numPlusd(): 33: i,j = Num(), Num() 34: for _ in range(10): i.seen(rand()/100) 35: for _ in range(10): j.seen(rand()*100) 36: k = i+j 37: k.kept.sorted() 38: print gs(k.cached()) 39: print k.median() 40: 41: if __name__ == '__main__' : 42: eval(cmd('symd()')) 43:
This file is part of Timm's charming Python tricks.
© 2014, Tim Menzies:
tim.menzies@gmail.com,
http://menzies.us.
Timm's charming Python tricks are free software: you can redistribute it and/or modify it under the terms of the GNU Lesser Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
Timm's charming Python tricks are distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU Lesser Public License along with Foobar. If not, see http://www.gnu.org/licenses.