def SolveStatisticalDistribution(self, distributionName, data, inCriteriaForUseInListSorting):
        
        criteriaList = ['AIC', 'AICc_BA', 'nnlf']
        if inCriteriaForUseInListSorting not in criteriaList:
            raise Exception('Criteria to calculate for use in sorting was not in', str(criteriaList))
    
        try:
            exec('distribution = scipy.stats.' + distributionName)
        except:
            return 0

        # only need to calculate these once
        eps = numpy.finfo(float).eps * 2.0
        data_min = data.min()
        data_max = data.max()
        data_mean = data.mean()
        data_range = data_max - data_min
        data_std_dev = numpy.std(data, dtype=numpy.float32) # note on precision http://docs.scipy.org/doc/numpy/reference/generated/numpy.std.html        
        
            
        # Try different starting parameters
        best_nnlf = 1.0E300
        best_parameters = None
    
        if distribution.name in ['beta']:
            try:
                rangeData = (data - data_min) / data_range
                data_mean = rangeData.mean()
                data_var = rangeData.var()
                
                par_a = data_mean * ((data_mean * (1.0 - data_mean) / data_var) - 1.0)
                par_b = (1.0 - data_mean) * ((data_mean * (1.0 - data_mean) / data_var) - 1.0)
                par0 = (par_a, par_b, data_min - 0.001*data_min, data_range * 1.001)
                par_est = tuple(distribution.fit(data, *(par0[:-2]), loc = 0.01*data_min - data_min, scale = data_range * 1.01))
                nnlf = distribution.nnlf(par_est, data)
                if numpy.isfinite(nnlf) and nnlf < best_nnlf:
                    best_parameters = par_est
                    best_nnlf = nnlf
            except:
                pass
    
        if distribution.name in ['truncnorm','betaprime','reciprocal']:
            try:
                par0 = (data_mean-2.0*data_std_dev, data_mean+2.0*data_std_dev)
                par_est = tuple(distribution.fit(data, loc=data_mean, scale=data_std_dev, *par0))
                nnlf = distribution.nnlf(par_est, data)
                if numpy.isfinite(nnlf) and nnlf < best_nnlf:
                    best_parameters = par_est
                    best_nnlf = nnlf
            except:
                pass
            
        try:
            par_est = tuple(distribution.fit(data))
            nnlf = distribution.nnlf(par_est, data)
            if numpy.isfinite(nnlf) and nnlf < best_nnlf:
                best_parameters = par_est
                best_nnlf = nnlf
        except:
            pass
    
        try:
            par_est = tuple(distribution.fit(data, loc=0.0, scale=1.0))
            nnlf = distribution.nnlf(par_est, data)
            if numpy.isfinite(nnlf) and nnlf < best_nnlf:
                best_parameters = par_est
                best_nnlf = nnlf
        except:
            pass
            
        try:
            par_est = tuple(distribution.fit(data, loc=data_mean, scale=data_std_dev))
            nnlf = distribution.nnlf(par_est, data)
            if numpy.isfinite(nnlf) and nnlf < best_nnlf:
                best_parameters = par_est
                best_nnlf = nnlf
        except:
            pass
    
        try:
            par_est = tuple(distribution.fit(data, loc=data_max+eps, scale=data_std_dev))
            nnlf = distribution.nnlf(par_est, data)
            if numpy.isfinite(nnlf) and nnlf < best_nnlf:
                best_parameters = par_est
                best_nnlf = nnlf
        except:
            pass
    
        try:
            par_est = tuple(distribution.fit(data, loc=data_min-eps, scale=data_std_dev))
            nnlf = distribution.nnlf(par_est, data)
            if numpy.isfinite(nnlf) and nnlf < best_nnlf:
                best_parameters = par_est
                best_nnlf = nnlf
        except:
            pass
    
        try:
            par_est = tuple(distribution.fit(data, loc=data_max+eps, scale=data_range))
            nnlf = distribution.nnlf(par_est, data)
            if numpy.isfinite(nnlf) and nnlf < best_nnlf:
                best_parameters = par_est
                best_nnlf = nnlf
        except:
            pass
    
        try:
            par_est = tuple(distribution.fit(data, loc=data_min-eps, scale=data_range))
            nnlf = distribution.nnlf(par_est, data)
            if numpy.isfinite(nnlf) and nnlf < best_nnlf:
                best_parameters = par_est
                best_nnlf = nnlf
        except:
            pass
    
        if (best_nnlf < 1.0E300) and (best_parameters is not None):
            try:
                k = len(best_parameters)
                AIC = 2.0*k + 2.0 * best_nnlf
                n = len(data)
                AICc_BA = AIC + ( (2.0 * k * (k+1.0)) / (n - k - 1.0))

                temp = {}
                temp['distributionName'] = distributionName
                temp['fittedParameters'] = best_parameters
                temp['nnlf'] = best_nnlf
                temp['AIC'] = AIC
                temp['AICc_BA'] = AICc_BA
                
                if inCriteriaForUseInListSorting == 'nnlf':
                    return [best_nnlf, temp]
                elif inCriteriaForUseInListSorting == 'AIC':
                    return [AIC, temp]
                else:
                    return [AICc_BA, temp]
            except:
                return 0
        else:
            return 0
dataset/ETHPy150Open zunzun/pyeq2/Services/SolverService.py/SolverService.SolveStatisticalDistribution/swapped operands of `-`