Find the ideal threshold.

    The ideal threshold is the one that minimizes the z_cost function.
498859
def find_threshold(errors, z_range=(0, 10)):
    

    mean = errors.mean()
    std = errors.std()

    min_z, max_z = z_range
    best_z = min_z
    best_cost = np.inf
    for z in range(min_z, max_z):
        best = fmin(z_cost, z, args=(errors, mean, std), full_output=True, disp=False)
        z, cost = best[0:2]
        if cost < best_cost:
            best_z = z[0]

    return mean + best_z * std
289781
def get_thresholds(points=100, power=3) -> list:
    """"""
    return [(i / (points + 1)) ** power for i in range(1, points + 1)]
217958
def xAxisIsMinor(self):
        '''
        
        '''
        return min(self.radius.x, self.radius.y) == self.radius.x
1196649
def tail_threshold(vals, N=1000):
    """"""
    vals = numpy.array(vals)
    if len(vals) < N:
        raise RuntimeError('Not enough input values to determine threshold')
    vals.sort()
    return min(vals[-N:])
669635
def fit(self):
        
        # the objective function that will be minimized in the least square
        # fitting
        objective_func = lambda pars, x, y: y - self._func(x, pars)
        self._params = self._initial_guess()
        self.eos_params, ierr = leastsq(
            objective_func, self._params, args=(self.volumes, self.energies))
        # e0, b0, b1, v0
        self._params = self.eos_params
        if ierr not in [1, 2, 3, 4]:
            raise EOSError("Optimal parameters not found")
1229310
def __find_smallest(self):
        """"""
        minval = sys.maxsize
        for i in range(self.n):
            for j in range(self.n):
                if (not self.row_covered[i]) and (not self.col_covered[j]):
                    if minval > self.C[i][j]:
                        minval = self.C[i][j]
        return minval
958028
def objective_bounds(self):
        
        if self.ideal and self.nadir:
            return self.ideal, self.nadir
        raise NotImplementedError(
            "Ideal and nadir value calculation is not yet implemented"
        )
741630
def get_minimum(self, other):
        """"""
        return Point(min(self.x, other.x), min(self.y, other.y))
434713
def optimize(self, x0, target):
        """"""
        x = x0
        for i in range(self.maxiter):
            g = self.g(x, target)
            h = self.h(x, target)
            if i == 0:
                alpha = 0
                m = g
            else:
                alpha = - np.dot(m, np.dot(h, g)) / np.dot(m, np.dot(h, m))
                m = g + np.dot(alpha, m)
            t = - np.dot(m, g) / np.dot(m, np.dot(h, m))
            delta = np.dot(t, m)
            x = x + delta
            if np.linalg.norm(delta) < self.tol:
                break
        return x
993772
def get_threshold(self):
        """"""
        value_map = dict()
        for key, value in list(self.threshold_classes.items()):
            value_map[key] = [
                value[0].value(),
                value[1].value(),
            ]
        return value_map
527868
def filter_threshold(self, inst_rc, threshold, num_occur=1):
    '''
    
    '''
    inst_df = self.dat_to_df()

    inst_df = run_filter.filter_threshold(inst_df, inst_rc, threshold,
      num_occur)

    self.df_to_dat(inst_df)
682026
def minimise_xyz(xyz):
    """"""
    x, y, z = xyz
    m = max(min(x, y), min(max(x, y), z))
    return (x-m, y-m, z-m)
511983
function (threshold) {
		var axis = this,
			isLog = axis.isLog;

		var realMin = isLog ? lin2log(axis.min) : axis.min,
			realMax = isLog ? lin2log(axis.max) : axis.max;
		
		if (realMin > threshold || threshold === null) {
			threshold = realMin;
		} else if (realMax < threshold) {
			threshold = realMax;
		}

		return axis.translate(threshold, 0, 1, 0, 1);
	}
1024121
public void calcExpectation(double[] expected, double Z, int size)
    {
        double c = Math.exp(alpha + beta - cost - Z);
        for (int i = 0; fVector.get(i) != -1; i++)
        {
            int idx = fVector.get(i) + y;
            expected[idx] += c;
        }
        for (Path p : lpath)
        {
            p.calcExpectation(expected, Z, size);
        }
    }
343917
def z2r(z):
    
    with np.errstate(invalid='ignore', divide='ignore'):
        return (np.exp(2 * z) - 1) / (np.exp(2 * z) + 1)
771400
def _minimize_c(c, z=0, a_tilde=1, b_tilde=-1,
                Ascaling=900, omega_M_0=0.25, omega_lambda_0=0.75):
    

    # Fn 1 (LHS of Eqn 18)

    Y1 = np.log(2) - 0.5
    Yc = np.log(1+c) - c/(1+c)
    f1 = Y1/Yc

    # Fn 2 (RHS of Eqn 18)

    # Eqn 14 - Define the mean inner density
    rho_2 = 200 * c**3 * Y1 / Yc

    # Eqn 17 rearranged to solve for Formation Redshift
    # essentially when universe had rho_2 density
    zf = (((1 + z)**3 + omega_lambda_0/omega_M_0) *
          (rho_2/Ascaling) - omega_lambda_0/omega_M_0)**(1/3) - 1

    # RHS of Eqn 19
    f2 = ((1 + zf - z)**a_tilde) * np.exp((zf - z) * b_tilde)

    # LHS - RHS should be zero for the correct concentration
    return(f1-f2)
1235146
def threshold(self, value, inclusive=False):
        
        if inclusive:
            def function(x, y):
                return True if x >= y else False
        else:
            def function(x, y):
                return True if x > y else False
        return self.operation(value, function)