def run(self, V, cname=None, bins=10, range=None, density=False, cumulative=False): """ generates and stores histogram data for numerical data in V """ super(Histogram, self).__init__() try: V = sorted(_flatten(list(V))) except: raise TypeError('V must be a list-like object') if len(V) == 0: raise Exception('V has zero length') if cname == None: self.cname = '' else: self.cname = cname values, bin_edges = pystaggrelite3.hist(V, bins=bins, range=range, density=density, cumulative=cumulative) self['values'] = values self['bin_edges'] = bin_edges if cname == None: self.cname = '' else: self.cname = cname self.bins = bins self.range = range self.density = density self.cumulative = cumulative
def test(self): # build the test data V = [] for i in range(300): V.append(normalvariate(100., 10.)) # build some weight vectors to test W1 = [.001 for i in range(300)] W2 = [1. for i in range(300)] W2[0] = 10000. W3 = [-1. for i in range(300)] W = [W1, W2, W3, None] # factorially examine the conditions in this DictSet # see: http://code.google.com/p/dictset/ ds = DictSet({ 'bins': [1, 2, 10, 171, 500], 'range': [(0, 100), None], 'density': [True, False], 'weights': [0, 1, 2, 3], 'cumulative': [True, False] }) for b, r, d, w, c in ds.unique_combinations( ['bins', 'range', 'density', 'weights', 'cumulative']): print(b, r, d, w, c) DN, DB = pystaggrelite3.hist(V, b, r, d, W[w], c) pylab.figure() RN, RB, patches = pylab.hist(V, b, r, d, W[w], c) pylab.close() for d, r in zip(DN, RN): self.assertAlmostEqual(d, r) for d, r in zip(DB, RB): self.assertAlmostEqual(d, r)
def test(self): # build the test data V=[] for i in range(300): V.append(normalvariate(100.,10.)) # build some weight vectors to test W1=[.001 for i in range(300)] W2=[1. for i in range(300)] W2[0]=10000. W3=[-1. for i in range(300)] W=[W1, W2, W3, None] # factorially examine the conditions in this DictSet # see: http://code.google.com/p/dictset/ ds = DictSet({'bins':[1,2,10,171,500], 'range':[(0,100),None], 'density':[True, False], 'weights':[0, 1, 2, 3], 'cumulative':[True, False]}) for b,r,d,w,c in ds.unique_combinations( ['bins','range','density','weights','cumulative']): print(b,r,d,w,c) DN, DB = pystaggrelite3.hist(V, b, r, d, W[w], c) pylab.figure() RN, RB, patches = pylab.hist(V, b, r, d, W[w], c) pylab.close() for d,r in zip(DN, RN): self.assertAlmostEqual(d, r) for d,r in zip(DB, RB): self.assertAlmostEqual(d, r)