def fitbinnedgmm(distfn, freq, binedges, start, fixed=None, weightsoptimal=True):
 if (not (fixed is None)):
  raise NotImplementedError
 nobs = np.sum(freq)
 if weightsoptimal:
  weights = (freq / float(nobs))
 else:
  weights = np.ones(len(freq))
 freqnormed = (freq / float(nobs))
 def gmmobjective(params):
  'negative loglikelihood function of binned data\n\n        corresponds to multinomial\n        '
  prob = np.diff(distfn.cdf(binedges, *params))
  momcond = (freqnormed - prob)
  return np.dot((momcond * weights), momcond)
 return optimize.fmin(gmmobjective, start)

def fitbinnedgmm ( distfn , freq , binedges , start , fixed = None , weightsoptimal = True ) : if ( not ( fixed is None ) ) : raise NotImplementedError nobs = np . sum ( freq ) if weightsoptimal : weights = ( freq / float ( nobs ) ) else : weights = np . ones ( len ( freq ) ) freqnormed = ( freq / float ( nobs ) ) def gmmobjective ( params ) : prob = np . diff ( distfn . cdf ( binedges , * params ) ) momcond = ( freqnormed - prob ) return np . dot ( ( momcond * weights ) , momcond ) return optimize . fmin ( gmmobjective , start )
estimate parameters of distribution function for binned data using gmm parameters distfn : distribution instance needs to have cdf method .