def fitWeibull(x,ilog=None):
    '''
    Emperically fit a Weibull distribution to x 
    
    @param x: a list containing the x.
    @type x: a list of floats
    @param ilog: an image log to save fit information.
    @type ilog: pv.ImageLog
    @returns: (k,lambda) 
    '''
    x = np.array(x)
    assert x.min() >= 0.0
    
    n = len(x)

    def nll(params):
        ''' Negative log liklyhood'''
        shape,scale = params
        
        mask = x > 0
        pdf = pdfWeibull(x, shape, scale)
        #pdf = (shape/scale)*((x/scale)**(shape-1))*np.exp(-(x/scale)**shape)
        ll = np.log(pdf[mask]).sum()
        t1 = (~mask).sum()
        ll += t1*np.log(0.000001)

        return len(x)/-ll

    tmp = sp.optimize.fmin(nll,[1.0,np.mean(x)],disp=0)
    shape,scale = tmp
    
    if ilog != None:
        # Plot the CDF
        order = x.argsort()
        x = x[order]
        del order
        
        points = [0,0]
        points = [[0,0]] + [ [x[i],float(i)/n] for i in range(n)]
        plot = pv.Plot(title="Weibull CDF")
        plot.points(points)
        
        #cdf = cdfWeibull(x, shape, scale)
        
        lines = [[0,0]] + [ [x[i],cdfWeibull(x[i], shape, scale)] for i in range(n)]
        plot.lines(lines)
        ilog(plot,"WeibullCDF")

        plot = pv.Plot(title="Weibull PDF")
        y = pdfWeibull(x, shape, scale)
        points = np.array([x,y]).reshape(2,n).T
        plot.lines(points,color='red',width=3)
        
        hist, bins = np.histogram(x, 5, normed=True)
        
        t1 = 0.5*(bins[:-1] + bins[1:])
        points = np.array([t1,hist]).reshape(2,5).T
        plot.lines(points,color='blue',width=3)
        ilog(plot,"WeibullPDF")
        
        
    return shape,scale
dataset/ETHPy150Open bolme/pyvision/src/pyvision/analysis/stats.py/fitWeibull/swapped operands of `/`