In [34]:
import hashlib, struct
import cPickle as pickle
import numpy as np
from pisa.utils.jsons import dumps
from pisa.utils.hash import hash_obj
In [35]:
len(hashlib.md5(dumps([0,1,2])).hexdigest())
Out[35]:
Old version that was developed here (now probably out of sync with official version in PISA...):
def hash_obj(obj):
hash_val, = struct.unpack('<q', hashlib.md5(
pickle.dumps(obj, pickle.HIGHEST_PROTOCOL)
).digest()[:8])
return hash_val
In [38]:
print hash_obj([0, 1, 2])
In [39]:
bits = 64*2
n_elements = 200
np.log10(2*2**bits/(n_elements*(n_elements-1)))
Out[39]:
Testing out a container class but that:
c[0] = 1 assigns 1 to the object that lives at position 0c['aeff_scale'] = 1 has the same effectc returns values for all objects in cc.values does the samec.values[2:8] = [6, 1, 8, 9, 5] assigns those values to the values properties of the third through seventh entities in cc.priors returns priors for all objects in c
In [40]:
l = list(['zero', 'one', 'two'])
l.__getitem__(0)
Out[40]:
In [41]:
[x for x in l.__iter__()]
Out[41]:
In [42]:
l.__setitem__(1, 1)
print l
In [43]:
l.__getslice__(1,3)
Out[43]:
In [44]:
l.__setslice__(1, 3, ('b', 'c'))
print l
In [45]:
from functools import total_ordering
from collections import OrderedDict
In [46]:
from pisa.core.param import Param, ParamSet
In [47]:
p0 = Param(name='c', value=1.5, prior=None, range=[1,2],
is_fixed=False, is_discrete=False, tex=r'\int{\rm c}')
p1 = Param(name='a', value=2.5, prior=None, range=[1,5],
is_fixed=False, is_discrete=False, tex=r'{\rm a}')
p2 = Param(name='b', value=1.5, prior=None, range=[1,2],
is_fixed=False, is_discrete=False, tex=r'{\rm b}')
c = ParamSet(p0, p1, p2)
print c.values
print c[0]
c[0].value = 1
print c.values
print c.tex
In [48]:
c.values = [3, 2, 1]
print c.values
print c.values[0]
print c[0].value
In [49]:
print 'priors:', c.priors
print 'names:', c.names
In [50]:
print c['a']
print c['a'].value
c['a'].value = 33
print c['a'].value
In [51]:
print c['c'].is_fixed
c['c'].is_fixed = True
print c['c'].is_fixed
print c.are_fixed
c.fix('c')
print c.are_fixed
c.unfix('a')
print c.are_fixed
c.unfix([0,1,2])
print c.are_fixed
In [52]:
fixed_params = c.fixed
print fixed_params.are_fixed
free_params = c.free
print free_params.are_fixed
print c.free.values
In [53]:
print c.values_hash
print c.fixed.values_hash
print c.free.values_hash
In [54]:
print c[0].state
print c.state_hash
print c.fixed.state_hash
print c.free.state_hash
In [55]:
print 'fixed:', c.fixed.names
print 'fixed, discrete:', c.fixed.discrete.names
print 'fixed, continuous:', c.fixed.continuous.names
print 'free:', c.free.names
print 'free, discrete:', c.free.discrete.names
print 'free, continuous:', c.free.continuous.names
print 'continuous, free:', c.continuous.free.names
print 'free, continuous hash:', c.free.continuous.values_hash
print 'continuous, free hash:', c.continuous.free.values_hash
In [56]:
print c.b.prior
print c.priors_llh