Computes the f_beta between `preds` and `targets`
977837
def fbeta(y_pred:Tensor, y_true:Tensor, thresh:float=0.2, beta:float=2, eps:float=1e-9, sigmoid:bool=True)->Rank0Tensor:
    ""
    beta2 = beta ** 2
    if sigmoid: y_pred = y_pred.sigmoid()
    y_pred = (y_pred>thresh).float()
    y_true = y_true.float()
    TP = (y_pred*y_true).sum(dim=1)
    prec = TP/(y_pred.sum(dim=1)+eps)
    rec = TP/(y_true.sum(dim=1)+eps)
    res = (prec*rec)/(prec*beta2+rec+eps)*(1+beta2)
    return res.mean()
889098
def int_pars(x, y, vds, **kwargs):
    
    # first do linear regression a la York
    # do Data Model 3 way:
    if 'version' in list(kwargs.keys()) and kwargs['version'] == 3:
        n_key = 'int_n_measurements'
        b_key = 'int_b'
        sigma_key = 'int_b_sigma'
        f_key = 'int_f'
        fvds_key = 'int_fvds'
        g_key = 'int_g'
        q_key = 'int_q'
        b_beta_key = 'int_b_beta'

    else:  # version 2
        n_key = 'specimen_int_n'
        b_key = 'specimen_b'
        sigma_key = 'specimen_b_sigma'
        f_key = 'specimen_f'
        fvds_key = 'specimen_fvds'
        g_key = 'specimen_g'
        q_key = 'specimen_q'
        b_beta_key = 'specimen_b_beta'

    xx, yer, xer, xyer, yy, xsum, ysum, xy = 0., 0., 0., 0., 0., 0., 0., 0.
    xprime, yprime = [], []
    pars = {}
    pars[n_key] = len(x)
    n = float(len(x))
    if n <= 2:
        print("shouldn't be here at all!")
        return pars, 1
    for i in range(len(x)):
        xx += x[i]**2.
        yy += y[i]**2.
        xy += x[i] * y[i]
        xsum += x[i]
        ysum += y[i]
    xsig = np.sqrt(old_div((xx - (old_div(xsum**2., n))), (n - 1.)))
    ysig = np.sqrt(old_div((yy - (old_div(ysum**2., n))), (n - 1.)))
    sum = 0
    for i in range(int(n)):
        yer += (y[i] - old_div(ysum, n))**2.
        xer += (x[i] - old_div(xsum, n))**2.
        xyer += (y[i] - old_div(ysum, n)) * (x[i] - old_div(xsum, n))
    slop = -np.sqrt(old_div(yer, xer))
    pars[b_key] = slop
    s1 = 2. * yer - 2. * slop * xyer
    s2 = (n - 2.) * xer
    sigma = np.sqrt(old_div(s1, s2))
    pars[sigma_key] = sigma
    s = old_div((xy - (xsum * ysum / n)), (xx - old_div((xsum**2.), n)))
    r = old_div((s * xsig), ysig)
    pars["specimen_rsc"] = r**2.
    ytot = abs(old_div(ysum, n) - slop * xsum / n)
    for i in range(int(n)):
        xprime.append(old_div((slop * x[i] + y[i] - ytot), (2. * slop)))
        yprime.append((old_div((slop * x[i] + y[i] - ytot), 2.)) + ytot)
    sumdy, dy = 0, []
    dyt = abs(yprime[0] - yprime[int(n) - 1])
    for i in range((int(n) - 1)):
        dy.append(abs(yprime[i + 1] - yprime[i]))
        sumdy += dy[i]**2.
    f = old_div(dyt, ytot)
    pars[f_key] = f
    pars["specimen_ytot"] = ytot
    ff = old_div(dyt, vds)
    pars[fvds_key] = ff
    ddy = (old_div(1., dyt)) * sumdy
    g = 1. - old_div(ddy, dyt)
    pars[g_key] = g
    q = abs(slop) * f * g / sigma
    pars[q_key] = q
    pars[b_beta_key] = old_div(-sigma, slop)
    return pars, 0
53527
public double fBeta(double beta, EvaluationAveraging averaging) {
        if(getNumRowCounter() == 0.0){
            return Double.NaN;  //No data
        }
        int nClasses = confusion().getClasses().size();

        if (nClasses == 2) {
            return EvaluationUtils.fBeta(beta, (long) truePositives.getCount(1), (long) falsePositives.getCount(1),
                            (long) falseNegatives.getCount(1));
        }

        if (averaging == EvaluationAveraging.Macro) {
            double macroFBeta = 0.0;
            int count = 0;
            for (int i = 0; i < nClasses; i++) {
                double thisFBeta = fBeta(beta, i, -1);
                if (thisFBeta != -1) {
                    macroFBeta += thisFBeta;
                    count++;
                }
            }
            macroFBeta /= count;
            return macroFBeta;
        } else if (averaging == EvaluationAveraging.Micro) {
            long tpCount = 0;
            long fpCount = 0;
            long fnCount = 0;
            for (int i = 0; i < nClasses; i++) {
                tpCount += truePositives.getCount(i);
                fpCount += falsePositives.getCount(i);
                fnCount += falseNegatives.getCount(i);
            }
            return EvaluationUtils.fBeta(beta, tpCount, fpCount, fnCount);
        } else {
            throw new UnsupportedOperationException("Unknown averaging approach: " + averaging);
        }
    }
600915
function brcomp(a, b, x, y) {
      var lambda;

      lambda = a - (a + b) * x;
      if (Math.min(a, b) < 8) {
         return a * Math.log(x) + b * Math.log(y) - lbeta(a, b);
      }
      return 0.5 * (Math.log(a) + Math.log(b) - C.log2pi - Math.log(a + b)) -
             a * phi(1 - lambda / a) - b * phi(1 + lambda / b) -
             bcorr(a, b);
   }
18548
def _derY(self,x,y):
        '''
        
        '''
        if _isscalar(x):
            x_pos = max(min(self.xSearchFunc(self.x_list,x),self.x_n-1),1)
            y_pos = max(min(self.ySearchFunc(self.y_list,y),self.y_n-1),1)
        else:
            x_pos = self.xSearchFunc(self.x_list,x)
            x_pos[x_pos < 1] = 1
            x_pos[x_pos > self.x_n-1] = self.x_n-1
            y_pos = self.ySearchFunc(self.y_list,y)
            y_pos[y_pos < 1] = 1
            y_pos[y_pos > self.y_n-1] = self.y_n-1
        alpha = (x - self.x_list[x_pos-1])/(self.x_list[x_pos] - self.x_list[x_pos-1])
        dfdy = (
              ((1-alpha)*self.f_values[x_pos-1,y_pos]
            +  alpha*self.f_values[x_pos,y_pos]) -
              ((1-alpha)*self.f_values[x_pos-1,y_pos-1]
            +  alpha*self.f_values[x_pos,y_pos-1]))/(self.y_list[y_pos] - self.y_list[y_pos-1])
        return dfdy
142622
def stSpectralFlux(X, X_prev):
    
    # compute the spectral flux as the sum of square distances:
    sumX = numpy.sum(X + eps)
    sumPrevX = numpy.sum(X_prev + eps)
    F = numpy.sum((X / sumX - X_prev/sumPrevX) ** 2)

    return F
1366201
def _twofilter_smoothing_ON2(self, t, ti, info, phi, lwinfo):
        
        sp, sw = 0., 0.
        upb = lwinfo.max() + self.wgt[t].lw.max()
        if hasattr(self.model, 'upper_bound_trans'):
            upb += self.model.upper_bound_trans(t + 1)
        # Loop over n, to avoid having in memory a NxN matrix
        for n in range(self.N):
            omegan = np.exp(lwinfo + self.wgt[t].lw[n] - upb
                            + self.model.logpt(t + 1, self.X[t][n],
                                               info.hist.X[ti]))
            sp += np.sum(omegan * phi(self.X[t][n], info.hist.X[ti]))
            sw += np.sum(omegan)
        return sp / sw
1137687
def K(self, X, X2, target):
        """"""
        self._K_computations(X, X2)
        target += self.variance*self._K_dvar
604899
function precBase(base, value, precision) {
	const val = value.toString(base);
	const floatingPoint = val.indexOf('.');
	if (precision === 0 && floatingPoint > -1) {
		return val.substring(0, floatingPoint);//Node version > 0.10.*
	}
	if (floatingPoint === -1) {
		return val;
	}
	if (val.length - floatingPoint > precision) {
		return val.substring(0, floatingPoint + precision + 1);
	}
}
783977
def gen_weights(self, f_target): 
        

        # calculate x and psi   
        x_track = self.cs.rollout()
        psi_track = self.gen_psi(x_track)

        #efficiently calculate weights for BFs using weighted linear regression
        for d in range(self.dmps):
            for b in range(self.bfs): 
                self.w[d,b] = np.dot(psi_track[:,b], f_target[:,d]) / \
                              (np.sum(psi_track[:,b]) + 1e-10)
970104
public static double fBeta(double beta, long tp, long fp, long fn) {
        double prec = tp / ((double) tp + fp);
        double recall = tp / ((double) tp + fn);
        return fBeta(beta, prec, recall);
    }
1020201
def down_alpha_beta(returns, factor_returns, **kwargs):
    
    return down(returns, factor_returns, function=alpha_beta_aligned, **kwargs)
574642
def beta_r(self, r, kwargs):
        
        if self._type == 'const':
            return self.const_beta(kwargs)
        elif self._type == 'r_ani':
            return self.beta_r_ani(r, kwargs)
        else:
            raise ValueError('anisotropy type %s not supported!' % self._type)
1247614
def obfn_fvar(self, i):
        
        """

        return self.X[..., i] if self.opt['fEvalX'] else self.Y
1286929
double betaFunction(List<Double> x, int type) {
    double beta;
    beta = 0;
    int dim = x.size();

    if (dim == 0) {
      beta = 0;
    }

    if (type == 1) {
      beta = 0;
      for (int i = 0; i < dim; i++) {
        beta += x.get(i) * x.get(i);
      }
      beta = 2.0 * beta / dim;
    }

    if (type == 2) {
      beta = 0;
      for (int i = 0; i < dim; i++) {
        beta += Math.sqrt(i + 1) * x.get(i) * x.get(i);
      }
      beta = 2.0 * beta / dim;
    }

    if (type == 3) {
      double sum = 0, xx;
      for (int i = 0; i < dim; i++) {
        xx = 2 * x.get(i);
        sum += (xx * xx - Math.cos(4 * Math.PI * xx) + 1);
      }
      beta = 2.0 * sum / dim;
    }

    if (type == 4) {
      double sum = 0, prod = 1, xx;
      for (int i = 0; i < dim; i++) {
        xx = 2 * x.get(i);
        sum += xx * xx;
        prod *= Math.cos(10 * Math.PI * xx / Math.sqrt(i + 1));
      }
      beta = 2.0 * (sum - 2 * prod + 2) / dim;
    }

    return beta;
  }
1324769
public static double fBeta(double beta, double precision, double recall) {
        if (precision == 0.0 || recall == 0.0)
            return 0;

        double numerator = (1 + beta * beta) * precision * recall;
        double denominator = beta * beta * precision + recall;

        return numerator / denominator;
    }
663302
def gen_weights(self, f_target):
        

        # calculate x and psi   
        x_track = self.cs.rollout()
        psi_track = self.gen_psi(x_track)

        #efficiently calculate weights for BFs using weighted linear regression
        self.w = np.zeros((self.dmps, self.bfs))
        for d in range(self.dmps):
            # spatial scaling term
            k = 1.#(self.goal[d] - self.y0[d])
            for b in range(self.bfs):
                numer = np.sum(x_track * psi_track[:,b] * f_target[:,d])
                denom = np.sum(x_track**2 * psi_track[:,b])
                self.w[d,b] = numer / (k * denom)