CORR returns the coefficient of correlation of a set of number pairs.

@param expr1 first arg
@param expr2 second arg
@return corr(expr1, expr2)
193040
public static WindowOver<Double> corr(Expression<? extends Number> expr1, Expression<? extends Number> expr2) {
        return new WindowOver<Double>(Double.class, SQLOps.CORR, expr1, expr2);
    }
318430
public static double computeCorrelation(final List<Double> list1, final List<Double> list2)
    {
        final SpearmansRankCorrelation_old src = new SpearmansRankCorrelation_old();
        for (int i = 0; i < list1.size(); i++) {
            src.addXValue(Integer.toString(i), list1.get(i));
            src.addYValue(Integer.toString(i), list2.get(i));
            i++;
        }
        return src.calculate();
    }
1255394
def exp2prob(expression_vector):
    
    v = np.asarray(expression_vector)
    if np.sum(v) == 0:
        return np.zeros(len(expression_vector))
    else:
        return v / np.sum(v)
1102802
def cov2corr(cov):
    
    assert cov.ndim == 2, 'covariance matrix should be 2D array'
    inv_sd = 1 / np.sqrt(np.diag(cov))
    corr = cov * inv_sd[None, :] * inv_sd[:, None]
    return corr
5393
public static double uncenteredCorrelation(NumberVector x, NumberVector y) {
    final int xdim = x.getDimensionality(), ydim = y.getDimensionality();
    if(xdim != ydim) {
      throw new IllegalArgumentException("Invalid arguments: number vectors differ in dimensionality.");
    }
    double sumXX = 0., sumYY = 0., sumXY = 0.;
    for(int i = 0; i < xdim; i++) {
      final double xv = x.doubleValue(i), yv = y.doubleValue(i);
      sumXX += xv * xv;
      sumYY += yv * yv;
      sumXY += xv * yv;
    }
    // One or both series were constant:
    if(!(sumXX > 0. && sumYY > 0.)) {
      return (sumXX == sumYY) ? 1. : 0.;
    }
    return sumXY / FastMath.sqrt(sumXX * sumYY);
  }
1264857
public static <S extends Solution<?>> S getBestSolution(S solution1, S solution2, Comparator<S> comparator) {
    return getBestSolution(solution1, solution2, comparator, () -> JMetalRandom.getInstance().nextDouble());
  }
287744
public static Expression atan(String expression1, String expression2) {
        return atan(x(expression1), x(expression2));
    }
503453
public static double euclidean(EuclideanCoordinate coord1, EuclideanCoordinate coord2) {
		int size = Math.min(coord1.dimensions(), coord2.dimensions());
		double distance = 0;
		for(int i = 0; i < size; i++) {
			double diff = coord1.get(i) - coord2.get(i);
			distance += diff * diff;
		}
		distance = Math.sqrt(distance);
		return distance;
	}
260933
public static Expression posInfIf(Expression expression1, Expression expression2) {
        return x("POSINFIF(" + expression1.toString() + ", " + expression2.toString() + ")");
    }
8298
def score_cosine(self, term1, term2, **kwargs):

        

        t1_kde = self.kde(term1, **kwargs)
        t2_kde = self.kde(term2, **kwargs)

        return 1-distance.cosine(t1_kde, t2_kde)
1249566
public static double angle(NumberVector v1, NumberVector v2, NumberVector o) {
    final int dim1 = v1.getDimensionality(), dim2 = v2.getDimensionality(),
        dimo = o.getDimensionality();
    final int mindim = (dim1 <= dim2) ? dim1 : dim2;
    // Essentially, we want to compute this:
    // v1' = v1 - o, v2' = v2 - o
    // v1'.transposeTimes(v2') / (v1'.euclideanLength()*v2'.euclideanLength());
    // We can just compute all three in parallel.
    double cross = 0, l1 = 0, l2 = 0;
    for(int k = 0; k < mindim; k++) {
      final double ok = k < dimo ? o.doubleValue(k) : 0.;
      final double r1 = v1.doubleValue(k) - ok;
      final double r2 = v2.doubleValue(k) - ok;
      cross += r1 * r2;
      l1 += r1 * r1;
      l2 += r2 * r2;
    }
    for(int k = mindim; k < dim1; k++) {
      final double ok = k < dimo ? o.doubleValue(k) : 0.;
      final double r1 = v1.doubleValue(k) - ok;
      l1 += r1 * r1;
    }
    for(int k = mindim; k < dim2; k++) {
      final double ok = k < dimo ? o.doubleValue(k) : 0.;
      final double r2 = v2.doubleValue(k) - ok;
      l2 += r2 * r2;
    }
    final double a = (cross == 0.) ? 0. : //
        (l1 == 0. || l2 == 0.) ? 1. : //
            FastMath.sqrt((cross / l1) * (cross / l2));
    return (a < 1.) ? a : 1.;
  }
800748
def cross_correlation_matrix(imts, corr='yes'):
    
    assert corr in 'yes no full', corr
    # if there is only PGA this is a 1x1 identity matrix
    M = len(imts)
    cross_matrix = numpy.zeros((M, M))
    for i, im in enumerate(imts):
        T1 = im.period or 0.05

        for j in range(M):
            T2 = imts[j].period or 0.05
            if i == j:
                cross_matrix[i, j] = 1
            else:
                Tmax = max([T1, T2])
                Tmin = min([T1, T2])
                II = 1 if Tmin < 0.189 else 0
                if corr == 'full':
                    cross_matrix[i, j] = 0.99999
                elif corr == 'yes':
                    cross_matrix[i, j] = 1 - math.cos(math.pi / 2 - (
                        0.359 + 0.163 * II * math.log(Tmin / 0.189)
                    ) * math.log(Tmax / Tmin))

    return cross_matrix
973720
def correlation(s, o):
    
    # s,o = filter_nan(s,o)
    if s.size == 0:
        corr = np.NaN
    else:
        corr = np.corrcoef(o, s)[0, 1]
    return corr
63343
public static <A extends Number & Comparable<?>> NumberExpression<Double> cos(Expression<A> num) {
        return Expressions.numberOperation(Double.class, Ops.MathOps.COS, num);
    }
859218
def Conjunction(expr1: Expression, expr2: Expression) -> Expression:
    """"""
    expr = Expression(ast.BoolOp(ast.And(), [expr1.body, expr2.body]))
    return ast.fix_missing_locations(expr)
881660
public static double calculateCorrelation(TransposeDataList transposeDataList) { //unsafe internalData pointer. modifying the variable internalData
        Object[] keys = transposeDataList.keySet().toArray();
        if(keys.length!=2) {
            throw new IllegalArgumentException("The collection must contain observations from 2 groups.");
        }
        
        Object keyX = keys[0];
        Object keyY = keys[1];
        
        FlatDataList flatDataListX = transposeDataList.get(keyX);
        FlatDataList flatDataListY = transposeDataList.get(keyY);

        int n = flatDataListX.size();
        if(n<=0 || n!=flatDataListY.size()) {
            throw new IllegalArgumentException("The number of observations in each group must be equal and larger than 0.");
        }

        //The following loops calculate twice the scores. That the check both if A>B and B<A and count it twice
        int numberOfConcordant=0;
        int numberOfDisconcordant=0;
        
        
        for(int i=0;i<n;++i) {
            for(int j=0;j<n;++j) {
                double xi = flatDataListX.getDouble(i);
                double xj = flatDataListX.getDouble(j);
                double yi = flatDataListY.getDouble(i);
                double yj = flatDataListY.getDouble(j);
                
                double sign=(xi-xj)*(yi-yj); //if this has a positive sign then they are concordant
                if(sign>0) {
                    ++numberOfConcordant;
                }
                else if(sign<0) {
                    ++numberOfDisconcordant;
                }
            }
        }
        /*
        foreach(transposeDataList[0] as i=>&xi) {
            foreach(transposeDataList[0] as j=>&xj) {
            }
        }
        */
        numberOfConcordant/=2; //divide by 2 because we counted them twice
        numberOfDisconcordant/=2; //divide by 2 because we counted them twice

        double R=(numberOfConcordant-numberOfDisconcordant)/(n*(n-1.0)/2.0);

        return R;
    }
1153832
public static RAExpressionAttributes crossJoin(RAExpressionAttributes re1, RAExpressionAttributes re2) throws IllegalJoinException {

        checkRelationAliasesConsistency(re1, re2);

        ImmutableMap<QualifiedAttributeID, Term> attributes = merge(
                re1.selectAttributes(id ->
                        (id.getRelation() != null) || re2.isAbsent(id.getAttribute())),

                re2.selectAttributes(id ->
                        (id.getRelation() != null) || re1.isAbsent(id.getAttribute())));

        return new RAExpressionAttributes(attributes,
                getAttributeOccurrences(re1, re2, id -> attributeOccurrencesUnion(id, re1, re2)));
    }