Equitable Threat Score, Gilbert Skill Score, v, (a - R)/(a + b + c - R), R=(a+b)(a+c)/N
160053
def ets(self):
        """"""
        r = (self.table[0, 0] + self.table[0, 1]) * (self.table[0, 0] + self.table[1, 0]) / self.N
        return (self.table[0, 0] - r) / (self.table[0, 0] + self.table[0, 1] + self.table[1, 0] - r)
772555
function qualityCmp(a, b) {
	if (a.quality === b.quality) {
		return 0;
	} else if (a.quality < b.quality) {
		return 1;
	} else {
		return -1;
	}
}
25483
def dBinaryRochedr (r, D, q, F):
    

    r2 = (r*r).sum()
    r1 = np.sqrt(r2)

    return -1./r2 - q*(r1-r[0]/r1*D)/((r[0]-D)*(r[0]-D)+r[1]*r[1]+r[2]*r[2])**1.5 - q*r[0]/r1/D/D + F*F*(1+q)*(1-r[2]*r[2]/r2)*r1
1361608
public static void addEquals( DMatrix6x6 a , DMatrix6x6 b ) {
        a.a11 += b.a11;
        a.a12 += b.a12;
        a.a13 += b.a13;
        a.a14 += b.a14;
        a.a15 += b.a15;
        a.a16 += b.a16;
        a.a21 += b.a21;
        a.a22 += b.a22;
        a.a23 += b.a23;
        a.a24 += b.a24;
        a.a25 += b.a25;
        a.a26 += b.a26;
        a.a31 += b.a31;
        a.a32 += b.a32;
        a.a33 += b.a33;
        a.a34 += b.a34;
        a.a35 += b.a35;
        a.a36 += b.a36;
        a.a41 += b.a41;
        a.a42 += b.a42;
        a.a43 += b.a43;
        a.a44 += b.a44;
        a.a45 += b.a45;
        a.a46 += b.a46;
        a.a51 += b.a51;
        a.a52 += b.a52;
        a.a53 += b.a53;
        a.a54 += b.a54;
        a.a55 += b.a55;
        a.a56 += b.a56;
        a.a61 += b.a61;
        a.a62 += b.a62;
        a.a63 += b.a63;
        a.a64 += b.a64;
        a.a65 += b.a65;
        a.a66 += b.a66;
    }
1341739
function (r, a, sqrtassist) {
  var r1 = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
  var r2 = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
  var r3 = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
  var r4 = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
  var r5 = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];
  var i=0;
  curve25519_sqrmodp(r2, a);					//  2 === 2 * 1
  curve25519_sqrmodp(r3, r2);					//  4 === 2 * 2
  curve25519_sqrmodp(r1, r3);					//  8 === 2 * 4
  curve25519_mulmodp(r3, r1, a);				//  9 === 8 + 1
  curve25519_mulmodp(r1, r3, r2);				// 11 === 9 + 2
  curve25519_sqrmodp(r2, r1);					// 22 === 2 * 11
  curve25519_mulmodp(r4, r2, r3);				// 31 === 22 + 9
 												//	=== 2^5   - 2^0
  curve25519_sqrmodp(r2, r4);					// 2^6   - 2^1
  curve25519_sqrmodp(r3, r2);					// 2^7   - 2^2
  curve25519_sqrmodp(r2, r3);					// 2^8   - 2^3
  curve25519_sqrmodp(r3, r2);					// 2^9   - 2^4
  curve25519_sqrmodp(r2, r3);					// 2^10  - 2^5
  curve25519_mulmodp(r3, r2, r4);				// 2^10  - 2^0
  curve25519_sqrmodp(r2, r3);					// 2^11  - 2^1
  curve25519_sqrmodp(r4, r2);					// 2^12  - 2^2
  for (i = 1; i < 5; i++) {
	curve25519_sqrmodp(r2, r4);
	curve25519_sqrmodp(r4, r2);
  } 											// 2^20  - 2^10
  curve25519_mulmodp(r2, r4, r3);				// 2^20  - 2^0
  curve25519_sqrmodp(r4, r2);					// 2^21  - 2^1
  curve25519_sqrmodp(r5, r4);					// 2^22  - 2^2
  for (i = 1; i < 10; i++) {
	curve25519_sqrmodp(r4, r5);
	curve25519_sqrmodp(r5, r4);
  } 											// 2^40  - 2^20
  curve25519_mulmodp(r4, r5, r2);				// 2^40  - 2^0
  for (i = 0; i < 5; i++) {
	curve25519_sqrmodp(r2, r4);
	curve25519_sqrmodp(r4, r2);
  } 											// 2^50  - 2^10
  curve25519_mulmodp(r2, r4, r3);				// 2^50  - 2^0
  curve25519_sqrmodp(r3, r2);					// 2^51  - 2^1
  curve25519_sqrmodp(r4, r3);					// 2^52  - 2^2
  for (i = 1; i < 25; i++) {
	curve25519_sqrmodp(r3, r4);
	curve25519_sqrmodp(r4, r3);
  } 											// 2^100 - 2^50
  curve25519_mulmodp(r3, r4, r2);				// 2^100 - 2^0
  curve25519_sqrmodp(r4, r3);					// 2^101 - 2^1
  curve25519_sqrmodp(r5, r4);					// 2^102 - 2^2
  for (i = 1; i < 50; i++) {
	curve25519_sqrmodp(r4, r5);
	curve25519_sqrmodp(r5, r4);
  } 											// 2^200 - 2^100
  curve25519_mulmodp(r4, r5, r3);				// 2^200 - 2^0
  for (i = 0; i < 25; i++) {
	curve25519_sqrmodp(r5, r4);
	curve25519_sqrmodp(r4, r5);
  } 											// 2^250 - 2^50
  curve25519_mulmodp(r3, r4, r2);				// 2^250 - 2^0
  curve25519_sqrmodp(r2, r3);					// 2^251 - 2^1
  curve25519_sqrmodp(r3, r2);					// 2^252 - 2^2
  if (sqrtassist === 1) {
	curve25519_mulmodp(r, a, r3);				// 2^252 - 3
  } else {
	curve25519_sqrmodp(r2, r3);					// 2^253 - 2^3
	curve25519_sqrmodp(r3, r2);					// 2^254 - 2^4
	curve25519_sqrmodp(r2, r3);					// 2^255 - 2^5
	curve25519_mulmodp(r, r2, r1);				// 2^255 - 21
  }
}
221273
def iqr(b, perc=(25, 75)):
    
    b = checkma(b)
    low, high = calcperc(b, perc)
    return low, high, high - low
541113
private boolean allowPerfectQuality() {
		int i = m_label % OCTAVE;
		return (i == UNISON) || (i == FOURTH) || (i == FIFTH);
	}
295969
private static double score1static(Chunk[] chks, int treeIdx, double offset, double[] fs, int row, Distribution dist, int nClasses) {
    double f = chks[treeIdx].atd(row) + offset;
    double p = dist.linkInv(f);
    if (dist.distribution == DistributionFamily.modified_huber || dist.distribution == DistributionFamily.bernoulli || dist.distribution == DistributionFamily.quasibinomial) {
      fs[2] = p;
      fs[1] = 1.0 - p;
      return 1;                 // f2 = 1.0 - f1; so f1+f2 = 1.0
    } else if (dist.distribution == DistributionFamily.multinomial) {
      if (nClasses == 2) {
        // This optimization assumes the 2nd tree of a 2-class system is the
        // inverse of the first.  Fill in the missing tree
        fs[1] = p;
        fs[2] = 1 / p;
        return fs[1] + fs[2];
      }
      // Multinomial loss function; sum(exp(data)).  Load tree data
      assert (offset == 0);
      fs[1] = f;
      for (int k = 1; k < nClasses; k++)
        fs[k + 1] = chks[treeIdx + k].atd(row);
      // Rescale to avoid Infinities; return sum(exp(data))
      return hex.genmodel.GenModel.log_rescale(fs);
    } else {
      return fs[0] = p;
    }
  }
1302424
def lower_brkpts(a,b,c,e,f,p_min,p_max,n):
    
    EPS = 1.e-12        # for avoiding round-off errors
    if f == 0: f = math.pi/(p_max-p_min)
    brk = []
    nvalve = int(math.ceil(f*(p_max-p_min)/math.pi))
    for i in range(nvalve+1):
        p0 = p_min + i*math.pi/f
        if p0 >= p_max-EPS:
            brk.append((p_max,cost(a,b,c,e,f,p_min,p_max)))
            break
        for j in range(n):
            p = p0 + j*math.pi/f/n
            if p >= p_max:
                break
            brk.append((p,cost(a,b,c,e,f,p_min,p)))
    return brk
870421
def compute_agreement_score(num_matches, num1, num2):
    
    denom = num1 + num2 - num_matches
    if denom == 0:
        return 0
    return num_matches / denom
567275
def accumulate_scores( scoring_scheme, text1, text2, skip_ref_gaps=False ):
    
    if skip_ref_gaps:
        rval = zeros( len( text1 ) - text1.count( scoring_scheme.gap1 ) )
    else:
        rval = zeros( len( text1 ) )
    score = 0
    pos = 0
    last_gap_a = last_gap_b = False
    for i in range( len( text1 ) ):
        a = text1[i]
        b = text2[i]
        # Ignore gap/gap pair
        if a == scoring_scheme.gap1 and b == scoring_scheme.gap2: 
            continue
        # Gap in first species
        elif a == scoring_scheme.gap1:
            score -= scoring_scheme.gap_extend
            if not last_gap_a:
               score -= scoring_scheme.gap_open
               last_gap_a = True
               last_gap_b = False
        # Gap in second species
        elif b == scoring_scheme.gap2:
            score -= scoring_scheme.gap_extend
            if not last_gap_b:
               score -= scoring_scheme.gap_open
               last_gap_a = False
               last_gap_b = True
        # Aligned base
        else:   
            score += scoring_scheme._get_score((ord(a),ord(b)))
            last_gap_a = last_gap_b = False
        if not( skip_ref_gaps ) or a != scoring_scheme.gap1:
            rval[pos] = score
            pos += 1
    return rval
231173
def gt(self, v, limit=None, offset=None):
        
        if limit is not None and offset is None:
            offset = 0
        return self.zrangebyscore("(%f" % v, self._max_score,
                start=offset, num=limit)
158394
def _relative_score(self, start_eot, end_eot, active, passive):
        
        active_start = self._score_eot_for_actor(start_eot, active)
        passive_start = self._score_eot_for_actor(start_eot, passive)
        active_end = self._score_eot_for_actor(end_eot, active)
        passive_end = self._score_eot_for_actor(end_eot, passive)
        return (active_end - passive_end) - (active_start - passive_start)
425782
def value(self):
        

        if self.scores.numel() == 0:
            return 0
        ap = torch.zeros(self.scores.size(1))
        rg = torch.arange(1, self.scores.size(0)).float()

        # compute average precision for each class
        for k in range(self.scores.size(1)):
            # sort scores
            scores = self.scores[:, k]
            targets = self.targets[:, k]

            # compute average precision
            ap[k] = AveragePrecisionMeter.average_precision(scores, targets, self.difficult_examples)
        return ap
430090
function scorePattern(point, ratios, matrix) {
        try {
            const horizontalRun = countBlackWhiteRun(point, { x: -1, y: point.y }, matrix, ratios.length);
            const verticalRun = countBlackWhiteRun(point, { x: point.x, y: -1 }, matrix, ratios.length);
            const topLeftPoint = {
                x: Math.max(0, point.x - point.y) - 1,
                y: Math.max(0, point.y - point.x) - 1,
            };
            const topLeftBottomRightRun = countBlackWhiteRun(point, topLeftPoint, matrix, ratios.length);
            const bottomLeftPoint = {
                x: Math.min(matrix.width, point.x + point.y) + 1,
                y: Math.min(matrix.height, point.y + point.x) + 1,
            };
            const bottomLeftTopRightRun = countBlackWhiteRun(point, bottomLeftPoint, matrix, ratios.length);
            const horzError = scoreBlackWhiteRun(horizontalRun, ratios);
            const vertError = scoreBlackWhiteRun(verticalRun, ratios);
            const diagDownError = scoreBlackWhiteRun(topLeftBottomRightRun, ratios);
            const diagUpError = scoreBlackWhiteRun(bottomLeftTopRightRun, ratios);
            const ratioError = Math.sqrt(horzError.error * horzError.error +
                vertError.error * vertError.error +
                diagDownError.error * diagDownError.error +
                diagUpError.error * diagUpError.error);
            const avgSize = (horzError.averageSize + vertError.averageSize + diagDownError.averageSize + diagUpError.averageSize) / 4;
            const sizeError = (Math.pow((horzError.averageSize - avgSize), 2) +
                Math.pow((vertError.averageSize - avgSize), 2) +
                Math.pow((diagDownError.averageSize - avgSize), 2) +
                Math.pow((diagUpError.averageSize - avgSize), 2)) / avgSize;
            return ratioError + sizeError;
        }
        catch (_a) {
            return Infinity;
        }
    }
20809
public static void fe_sq(int[] h, int[] f) {
        int f0 = f[0];
        int f1 = f[1];
        int f2 = f[2];
        int f3 = f[3];
        int f4 = f[4];
        int f5 = f[5];
        int f6 = f[6];
        int f7 = f[7];
        int f8 = f[8];
        int f9 = f[9];
        int f0_2 = 2 * f0;
        int f1_2 = 2 * f1;
        int f2_2 = 2 * f2;
        int f3_2 = 2 * f3;
        int f4_2 = 2 * f4;
        int f5_2 = 2 * f5;
        int f6_2 = 2 * f6;
        int f7_2 = 2 * f7;
        int f5_38 = 38 * f5; /* 1.959375*2^30 */
        int f6_19 = 19 * f6; /* 1.959375*2^30 */
        int f7_38 = 38 * f7; /* 1.959375*2^30 */
        int f8_19 = 19 * f8; /* 1.959375*2^30 */
        int f9_38 = 38 * f9; /* 1.959375*2^30 */
        long f0f0 = f0 * (long) f0;
        long f0f1_2 = f0_2 * (long) f1;
        long f0f2_2 = f0_2 * (long) f2;
        long f0f3_2 = f0_2 * (long) f3;
        long f0f4_2 = f0_2 * (long) f4;
        long f0f5_2 = f0_2 * (long) f5;
        long f0f6_2 = f0_2 * (long) f6;
        long f0f7_2 = f0_2 * (long) f7;
        long f0f8_2 = f0_2 * (long) f8;
        long f0f9_2 = f0_2 * (long) f9;
        long f1f1_2 = f1_2 * (long) f1;
        long f1f2_2 = f1_2 * (long) f2;
        long f1f3_4 = f1_2 * (long) f3_2;
        long f1f4_2 = f1_2 * (long) f4;
        long f1f5_4 = f1_2 * (long) f5_2;
        long f1f6_2 = f1_2 * (long) f6;
        long f1f7_4 = f1_2 * (long) f7_2;
        long f1f8_2 = f1_2 * (long) f8;
        long f1f9_76 = f1_2 * (long) f9_38;
        long f2f2 = f2 * (long) f2;
        long f2f3_2 = f2_2 * (long) f3;
        long f2f4_2 = f2_2 * (long) f4;
        long f2f5_2 = f2_2 * (long) f5;
        long f2f6_2 = f2_2 * (long) f6;
        long f2f7_2 = f2_2 * (long) f7;
        long f2f8_38 = f2_2 * (long) f8_19;
        long f2f9_38 = f2 * (long) f9_38;
        long f3f3_2 = f3_2 * (long) f3;
        long f3f4_2 = f3_2 * (long) f4;
        long f3f5_4 = f3_2 * (long) f5_2;
        long f3f6_2 = f3_2 * (long) f6;
        long f3f7_76 = f3_2 * (long) f7_38;
        long f3f8_38 = f3_2 * (long) f8_19;
        long f3f9_76 = f3_2 * (long) f9_38;
        long f4f4 = f4 * (long) f4;
        long f4f5_2 = f4_2 * (long) f5;
        long f4f6_38 = f4_2 * (long) f6_19;
        long f4f7_38 = f4 * (long) f7_38;
        long f4f8_38 = f4_2 * (long) f8_19;
        long f4f9_38 = f4 * (long) f9_38;
        long f5f5_38 = f5 * (long) f5_38;
        long f5f6_38 = f5_2 * (long) f6_19;
        long f5f7_76 = f5_2 * (long) f7_38;
        long f5f8_38 = f5_2 * (long) f8_19;
        long f5f9_76 = f5_2 * (long) f9_38;
        long f6f6_19 = f6 * (long) f6_19;
        long f6f7_38 = f6 * (long) f7_38;
        long f6f8_38 = f6_2 * (long) f8_19;
        long f6f9_38 = f6 * (long) f9_38;
        long f7f7_38 = f7 * (long) f7_38;
        long f7f8_38 = f7_2 * (long) f8_19;
        long f7f9_76 = f7_2 * (long) f9_38;
        long f8f8_19 = f8 * (long) f8_19;
        long f8f9_38 = f8 * (long) f9_38;
        long f9f9_38 = f9 * (long) f9_38;
        long h0 = f0f0 + f1f9_76 + f2f8_38 + f3f7_76 + f4f6_38 + f5f5_38;
        long h1 = f0f1_2 + f2f9_38 + f3f8_38 + f4f7_38 + f5f6_38;
        long h2 = f0f2_2 + f1f1_2 + f3f9_76 + f4f8_38 + f5f7_76 + f6f6_19;
        long h3 = f0f3_2 + f1f2_2 + f4f9_38 + f5f8_38 + f6f7_38;
        long h4 = f0f4_2 + f1f3_4 + f2f2 + f5f9_76 + f6f8_38 + f7f7_38;
        long h5 = f0f5_2 + f1f4_2 + f2f3_2 + f6f9_38 + f7f8_38;
        long h6 = f0f6_2 + f1f5_4 + f2f4_2 + f3f3_2 + f7f9_76 + f8f8_19;
        long h7 = f0f7_2 + f1f6_2 + f2f5_2 + f3f4_2 + f8f9_38;
        long h8 = f0f8_2 + f1f7_4 + f2f6_2 + f3f5_4 + f4f4 + f9f9_38;
        long h9 = f0f9_2 + f1f8_2 + f2f7_2 + f3f6_2 + f4f5_2;
        long carry0;
        long carry1;
        long carry2;
        long carry3;
        long carry4;
        long carry5;
        long carry6;
        long carry7;
        long carry8;
        long carry9;

        carry0 = (h0 + (long) (1 << 25)) >> 26;
        h1 += carry0;
        h0 -= carry0 << 26;
        carry4 = (h4 + (long) (1 << 25)) >> 26;
        h5 += carry4;
        h4 -= carry4 << 26;

        carry1 = (h1 + (long) (1 << 24)) >> 25;
        h2 += carry1;
        h1 -= carry1 << 25;
        carry5 = (h5 + (long) (1 << 24)) >> 25;
        h6 += carry5;
        h5 -= carry5 << 25;

        carry2 = (h2 + (long) (1 << 25)) >> 26;
        h3 += carry2;
        h2 -= carry2 << 26;
        carry6 = (h6 + (long) (1 << 25)) >> 26;
        h7 += carry6;
        h6 -= carry6 << 26;

        carry3 = (h3 + (long) (1 << 24)) >> 25;
        h4 += carry3;
        h3 -= carry3 << 25;
        carry7 = (h7 + (long) (1 << 24)) >> 25;
        h8 += carry7;
        h7 -= carry7 << 25;

        carry4 = (h4 + (long) (1 << 25)) >> 26;
        h5 += carry4;
        h4 -= carry4 << 26;
        carry8 = (h8 + (long) (1 << 25)) >> 26;
        h9 += carry8;
        h8 -= carry8 << 26;

        carry9 = (h9 + (long) (1 << 24)) >> 25;
        h0 += carry9 * 19;
        h9 -= carry9 << 25;

        carry0 = (h0 + (long) (1 << 25)) >> 26;
        h1 += carry0;
        h0 -= carry0 << 26;

        h[0] = (int) h0;
        h[1] = (int) h1;
        h[2] = (int) h2;
        h[3] = (int) h3;
        h[4] = (int) h4;
        h[5] = (int) h5;
        h[6] = (int) h6;
        h[7] = (int) h7;
        h[8] = (int) h8;
        h[9] = (int) h9;
    }
738455
def cont_r(self, percent=0.9, N=None):
		""""""

		if not hasattr(self, 'F'):
			self.fs_r(N=self.rank)  # generate F
		return apply_along_axis(lambda _: _/self.L[:N], 1,
			   apply_along_axis(lambda _: _*self.r, 0, self.F[:, :N]**2))