... '''
... p = params # convenient alias
... p[1] = abs(p[1]) # cannot have negative std. dev.
- ... self._model_data.counts = self.info['N']/(p[1]*sqrt(2*pi)) * (
+ ... self._model_data.counts = (
+ ... self.info['binwidth']*self.info['N']/(p[1]*sqrt(2*pi)) *
... exp(-((self._model_data.bin_centers - p[0])/p[1])**2 / 2))
... return self._model_data
... def guess_initial_params(self):
... pstrings.append('%s=%.3f' % (name, param))
... return ', '.join(pstrings)
- >>> mu = 1.45
- >>> sigma = 3.14
+ >>> mu = 3.14
+ >>> sigma = 1.45
>>> data = array([gauss(mu,sigma) for i in range(int(1e4))])
>>> h = Histogram()
>>> h.from_data(data, h.calculate_bin_edges(data, 1))
>>> print m.model_string()
p(x) = A exp((x-mu)^2 / (2 sigma^2))
>>> print m.param_string(params) # doctest: +ELLIPSIS
- mu=1.4..., sigma=3.1...
+ mu=3.1..., sigma=1.4...
"""
def set_data(self, data, info=None, rescale=False):
self._data = data # Histogram() instance
if self._rescale == True:
params = [p*s for p,s in zip(params, self._param_scale_factors)]
residual = self._data.counts - self.model(params).counts
- if True: # fit debugging
+ if False: # fit debugging
if not hasattr(self, '_i_'):
self._i_ = 0
self._data.to_stream(open('hist-data.%d' % self._i_, 'w'))