Calculate C (Pearson's C).

    :param chi_square: chi squared
    :type chi_square : float
    :param POP: population
    :type POP : int
    :return: C as float
187099
def pearson_C_calc(chi_square, POP):
    
    try:
        C = math.sqrt(chi_square / (POP + chi_square))
        return C
    except Exception:
        return "None"
692017
def chi_eff(self):
        """"""
        return conversions.chi_eff(self.mass1, self.mass2, self.spin1z,
                                   self.spin2z)
843833
def matthewscc(self, use_global=False):
        
        if use_global:
            if not self.global_total_examples:
                return 0.

            true_pos = float(self.global_true_positives)
            false_pos = float(self.global_false_positives)
            false_neg = float(self.global_false_negatives)
            true_neg = float(self.global_true_negatives)
        else:
            if not self.total_examples:
                return 0.

            true_pos = float(self.true_positives)
            false_pos = float(self.false_positives)
            false_neg = float(self.false_negatives)
            true_neg = float(self.true_negatives)

        terms = [(true_pos + false_pos),
                 (true_pos + false_neg),
                 (true_neg + false_pos),
                 (true_neg + false_neg)]
        denom = 1.
        for t in filter(lambda t: t != 0., terms):
            denom *= t
        return ((true_pos * true_neg) - (false_pos * false_neg)) / math.sqrt(denom)
103575
def _calculate_chi_squared(source_freq, target_prob, source_len):
    
    expected = source_len * target_prob
    return (source_freq - expected)**2 / expected
538517
def rwishart_cov(n, C):
    
    # return rwishart(n, np.linalg.inv(C))

    p = np.shape(C)[0]
    # Need cholesky decomposition of precision matrix C^-1?
    sig = np.linalg.cholesky(C)

    if n <= (p-1):
        raise ValueError('Wishart parameter n must be greater '
                         'than size of matrix.')

    norms = np.random.normal(size=(p * (p - 1)) // 2)
    chi_sqs = np.sqrt(np.random.chisquare(df=np.arange(n, n - p, -1)))
    A = flib.expand_triangular(chi_sqs, norms)

    flib.dtrmm_wrap(sig, A, side='L', uplo='L', transa='N', alpha=1.)
    w = np.asmatrix(np.dot(A, A.T))
    flib.symmetrize(w)
    return w
30615
def cos_c(self, N=None):  # percent=0.9,
		""""""

		if not hasattr(self, 'G') or self.G.shape[1] < self.rank:
			self.fs_c(N=self.rank)  # generate
		self.dc = norm(self.G, axis=1)**2
		# cheaper than diag(self.G.dot(self.G.T))?

		return apply_along_axis(lambda _: _/self.dc, 0, self.G[:, :N]**2)
480297
def main(self, c):
        
        conj = self.conjugate.main(c)
        mult = self.complex_mult.main(c, conj)
        angle = self.angle.main(mult)

        self.y = self.GAIN_SFIX * angle
        return self.y
1161114
public Map<Integer, Double> chi_square(BaseFeatureData stats)
    {
        Map<Integer, Double> selectedFeatures = new HashMap<Integer, Double>();

        double N1dot, N0dot, N00, N01, N10, N11;
        double chisquareScore;
        Double previousScore;
        for (int feature = 0; feature < stats.featureCategoryJointCount.length; feature++)
        {
            int[] categoryList = stats.featureCategoryJointCount[feature];

            //计算 N1. (含有该特征的文档数量)
            N1dot = 0;
            for (int count : categoryList)
            {
                N1dot += count;
            }

            //还有 N0. (不含该特征的文档数量)
            N0dot = stats.n - N1dot;

            for (int category = 0; category < categoryList.length; category++)
            {

                N11 = categoryList[category]; //N11 是含有该特征并属于该类目的文档数量
                N01 = stats.categoryCounts[category] - N11; //N01 是不含该特征却属于该类目的文档数量

                N00 = N0dot - N01; //N00 是不含该特征也不属于该类目的文档数量
                N10 = N1dot - N11; //N10 是含有该特征却不属于该类目的文档数量

                //基于上述统计数据计算卡方分值
                chisquareScore = stats.n * Math.pow(N11 * N00 - N10 * N01, 2) / ((N11 + N01) * (N11 + N10) * (N10 + N00) * (N01 + N00));

                //如果分数大于临界值则加入特征列表
                if (chisquareScore >= chisquareCriticalValue)
                {
                    previousScore = selectedFeatures.get(feature);
                    if (previousScore == null || chisquareScore > previousScore)
                    {
                        selectedFeatures.put(feature, chisquareScore);
                    }
                }
            }
        }
        if (selectedFeatures.size() == 0) // 当特征全部无法通过卡方检测时，取全集作为特征
        {
            for (int feature = 0; feature < stats.featureCategoryJointCount.length; feature++)
            {
                selectedFeatures.put(feature, 0.);
            }
        }
        if (selectedFeatures.size() > maxSize)
        {
            MaxHeap<Map.Entry<Integer, Double>> maxHeap = new MaxHeap<Map.Entry<Integer, Double>>(maxSize, new Comparator<Map.Entry<Integer, Double>>()
            {
                @Override
                public int compare(Map.Entry<Integer, Double> o1, Map.Entry<Integer, Double> o2)
                {
                    return o1.getValue().compareTo(o2.getValue());
                }
            });
            for (Map.Entry<Integer, Double> entry : selectedFeatures.entrySet())
            {
                maxHeap.add(entry);
            }
            selectedFeatures.clear();
            for (Map.Entry<Integer, Double> entry : maxHeap)
            {
                selectedFeatures.put(entry.getKey(), entry.getValue());
            }
        }

        return selectedFeatures;
    }
282295
def reduced_chi_squared(self, p=None):
        
        
        if len(self._set_xdata)==0 or len(self._set_ydata)==0: return None
        if p is None: p = self.results[0]
        
        chi2 = self.chi_squared(p)
        dof  = self.degrees_of_freedom()
        if not _s.fun.is_a_number(chi2) or not _s.fun.is_a_number(dof):
            return None
        
        return _n.divide(self.chi_squared(p), self.degrees_of_freedom())
392711
def C00_(self):
        
        self._check_estimated()
        return self._rc.cov_XX(bessel=self.bessel)
103310
def chi_squared(*choices):
    """"""

    term = lambda expected, observed: float((expected - observed) ** 2) / max(expected, 1)
    mean_success_rate = float(sum([c.rewards for c in choices])) / max(sum([c.plays for c in choices]), 1)
    mean_failure_rate = 1 - mean_success_rate

    return sum([
        term(mean_success_rate * c.plays, c.rewards)
        + term(mean_failure_rate * c.plays, c.plays - c.rewards
    ) for c in choices])
1176911
def _get_population(self, freq, t):  # freq in THz
        
        condition = t > 1.0
        if type(condition) == bool or type(condition) == np.bool_:
            if condition:
                return 1.0 / (np.exp(freq * THzToEv / (Kb * t)) - 1)
            else:
                return 0.0
        else:
            vals = np.zeros(len(t), dtype='double')
            vals[condition] = 1.0 / (
                np.exp(freq * THzToEv / (Kb * t[condition])) - 1)
            return vals
219133
def cnst_AT(self, X):
        
        """

        return np.sum(self.cnst_A0T(X), axis=-1) + self.cnst_A1T(X)
1254270
def getBottomLeft(self):
        
        return (float(self.get_cx()) - float(self.get_r()), float(self.get_cy()) - float(self.get_r()))
796914
private void calculateCL(double[] x) {
    if (values != null) {
      rvfcalculate(x);
      return;
    }
    //System.out.println("Checking at: "+x[0]+" "+x[1]+" "+x[2]);
    value = 0.0;
    if (derivative == null) {
      derivative = new double[x.length];
    } else {
      Arrays.fill(derivative, 0.0);
    }

    if (derivativeNumerator == null) {
      derivativeNumerator = new double[x.length];
      //use dataIterable if data is null & vice versa
      if(data != null) {
        for (int d = 0; d < data.length; d++) {
          //         if (d == testMin) {
          //           d = testMax - 1;
          //           continue;
          //         }
          int[] features = data[d];
          for (int f = 0; f < features.length; f++) {
            int i = indexOf(features[f], labels[d]);
            if (dataweights == null) {
              derivativeNumerator[i] -= 1;
            } else {
              derivativeNumerator[i] -= dataweights[d];
            }
          }
        }
      }
      //TODO: Make sure this work as expected!!
      else if(dataIterable != null) {
        //int index = 0;
        for (Datum<L, F> datum : dataIterable) {
          //         if (d == testMin) {
          //           d = testMax - 1;
          //           continue;
          //         }
          Collection<F> features = datum.asFeatures();
          for (F feature : features) {
            int i = indexOf(featureIndex.indexOf(feature), labelIndex.indexOf(datum.label()));
            if (dataweights == null) {
              derivativeNumerator[i] -= 1;
            } /*else {
              derivativeNumerator[i] -= dataweights[index];
            }*/
          }
        }
      }
      else {
        System.err.println("Both were null!  Couldn't calculate.");
        System.exit(-1);
      }
    }
    copy(derivative, derivativeNumerator);
    //    Arrays.fill(derivative, 0.0);
    double[] sums = new double[numClasses];
    double[] probs = new double[numClasses];
    //    double[] counts = new double[numClasses];
    //    Arrays.fill(counts, 0.0);
    
    Iterator<Datum<L, F>> iter = null;
    int d = -1;
    if(useIterable)
      iter = dataIterable.iterator();
    Datum<L, F> datum = null;
    while(true){
      if(useIterable) {
        if(!iter.hasNext()) break;
        datum = iter.next();
      } else {
        d++;
        if(d >= data.length) break;
      }

      //       if (d == testMin) {
      //         d = testMax - 1;
      //         continue;
      //       }

      // activation
      Arrays.fill(sums, 0.0);
      double total = 0;
      if(!useIterable) {
        int[] featuresArr = data[d];

        for (int c = 0; c < numClasses; c++) {
          for (int f = 0; f < featuresArr.length; f++) {
            int i = indexOf(featuresArr[f], c);
            sums[c] += x[i];
          }
        }
        // expectation (slower routine replaced by fast way)
        // double total = Double.NEGATIVE_INFINITY;
        // for (int c=0; c<numClasses; c++) {
        //   total = SloppyMath.logAdd(total, sums[c]);
        // }
        total = ArrayMath.logSum(sums);
        for (int c = 0; c < numClasses; c++) {
          probs[c] = Math.exp(sums[c] - total);
          if (dataweights != null) {
            probs[c] *= dataweights[d];
          }
          for (int f = 0; f < featuresArr.length; f++) {
            int i = indexOf(featuresArr[f], c);
            derivative[i] += probs[c];
          }
        }
      } else {
        Collection<F> features = datum.asFeatures();
        for (int c = 0; c < numClasses; c++) {
          for (F feature : features) {
            int i = indexOf(featureIndex.indexOf(feature), c);
            sums[c] += x[i];
          }
        }
        // expectation (slower routine replaced by fast way)
        // double total = Double.NEGATIVE_INFINITY;
        // for (int c=0; c<numClasses; c++) {
        //   total = SloppyMath.logAdd(total, sums[c]);
        // }
        total = ArrayMath.logSum(sums);
        for (int c = 0; c < numClasses; c++) {
          probs[c] = Math.exp(sums[c] - total);
          if (dataweights != null) {
            probs[c] *= dataweights[d];
          }
          for (F feature : features) {
            int i = indexOf(featureIndex.indexOf(feature), c);
            derivative[i] += probs[c];
          }
        }
      }

      int labelindex;
      if(useIterable)
        labelindex = labelIndex.indexOf(datum.label());
      else 
        labelindex = labels[d];
      double dV = sums[labelindex] - total;
      if (dataweights != null) {
        dV *= dataweights[d];
      }
      value -= dV;
      
    }
    value += prior.compute(x, derivative);
  }
126497
def pearson_correlation(self):
        x, y, dt = self.data
        X, Y = np.array(x), np.array(y)
        '''  '''
        # Normalise X and Y
        X -= X.mean(0)
        Y -= Y.mean(0)
        # Standardise X and Y
        X /= X.std(0)
        Y /= Y.std(0)
        # Compute mean product
        return (np.mean(X*Y) ** 2) * 100
857498
def doublec(self, j):
        """"""
        if j < (self.k0 + 1):
            return 0
        if self.b[j] != self.b[j - 1]:
            return 0
        return self.cons(j)