def __init__(self, loc, scale, skew): try: self._sknorm = pdf_moments((loc, scale**2, skew)) self.st = (loc, scale**2, skew) except ValueError: self._sknorm = pdf_moments((loc, 1e-8, skew)) self.st = (loc, 1e-8, skew) self.pdf = self._sknorm
def __init__(self, *args): """ Initializes the class. Should be given a list of tuples: [('norm', (norm1_mean, norm1_std), 0.4), ('norm', (norm2_mean, norm2_std), 0.6)] Can be given: 'norm', (mean, std), weight 'skewnorm', (mean, std, skewness), weight 'uniform', (min, max), weight """ self.dists = [] self.weights = [] self.cutoff = None self.use_bc = False if len(args) == 0: return for name, params, weight in args[0]: if name == 'norm': self.dists.append(norm(*params)) self.weights.append(weight) elif name == 'skewnorm': #pdf_moments takes the VARIANCE ... so must square the std params = (params[0], params[1]**2, params[2]) self.dists.append(pdf_moments(params)) self.weights.append(weight) elif name == 'uniform': self.dists.append(uniform(*params)) self.weights.append(weight) else: raise KeyError, 'Unknown distribution %s' % name assert N.sum(self.weights) == 1, 'sum(weight) != 1'