Computes the correlation between two datasets.
@param list1 The first dataset as a double array.
@param list2 The second dataset as a double array.
@return The correlation between the two datasets.
967429
public static double computeCorrelation(final double[] list1, final double[] list2)
    {
        // R = { N* (Sum(x*y) - Sum(x)*Sum(y)} / sqrt( { N* Sum( x**2 ) - Sum( x )**2} ) * sqrt ( {N
        // * Sum( y**2 ) - Sum( y )**2} )
        double sumXY = 0;
        double sumX = 0;
        double sumY = 0;
        double sumXsquares = 0;
        double sumYsquares = 0;
        final long N = list1.length; // we assume that both list are of equal length

        if (list1.length != list2.length) {
            log.fatal("Lists are not the same size (" + list1.length + " - " + list2.length + ").");
            System.exit(1);
        }

        for (int i = 0; i < N; i++) {
            final double x = list1[i];
            final double y = list2[i];
            sumXY += x * y;
            sumX += x;
            sumY += y;
            sumXsquares += x * x;
            sumYsquares += y * y;
        }

        final double nominator = (N * sumXY - sumX * sumY);

        final double root1 = N * sumXsquares - sumX * sumX;
        final double root2 = N * sumYsquares - sumY * sumY;
        final double denominator = Math.sqrt(root1) * Math.sqrt(root2);

        final double correlation = nominator / denominator;

        return correlation;
    }
207771
public static float calculate(Map<String, Integer> features1, Map<String, Integer> features2) {
        TreeSet<String> keys = new TreeSet<String>(features1.keySet());
        keys.addAll(features2.keySet());

        float sum = 0.0f;
        for (String key : keys) {
            Integer c1 = features1.get(key);
            Integer c2 = features2.get(key);

            c1 = c1 == null ? 0 : c1;
            c2 = c2 == null ? 0 : c2;
            sum += 1.0 - Math.abs(c1 - c2) / (c1 + c2);
        }

        return sum / keys.size();
    }
202073
public static final double correlation(double y1[],double y2[],int n) {

    int i;
    double av1 = 0.0, av2 = 0.0, y11 = 0.0, y22 = 0.0, y12 = 0.0, c;
    
    if (n <= 1) {
      return 1.0;
    }
    for (i = 0; i < n; i++) {
      av1 += y1[i];
      av2 += y2[i];
    }
    av1 /= (double) n;
    av2 /= (double) n;
    for (i = 0; i < n; i++) {
      y11 += (y1[i] - av1) * (y1[i] - av1);
      y22 += (y2[i] - av2) * (y2[i] - av2);
      y12 += (y1[i] - av1) * (y2[i] - av2);
    }
    if (y11 * y22 == 0.0) {
      c=1.0;
    } else {
      c = y12 / Math.sqrt(Math.abs(y11 * y22));
    }
    
    return c;
  }
215111
public static Expression arrayConcat(JsonArray array1, JsonArray array2) {
        return arrayConcat(x(array1), x(array2));
    }
533411
public double[][] toMatrix(List<K1> firstKeys, List<K2> secondKeys) {
    double[][] counts = new double[firstKeys.size()][secondKeys.size()];
    for (int i = 0; i < firstKeys.size(); i++) {
      for (int j = 0; j < secondKeys.size(); j++) {
        counts[i][j] = getCount(firstKeys.get(i), secondKeys.get(j));
      }
    }
    return counts;
  }
1113522
protected List<Reference> mergeReferences(
			List<? extends Reference> references1,
			List<? extends Reference> references2) {
		List<Reference> result = new ArrayList<>();
		for (Reference reference : references1) {
			addBestReferenceToList(reference, result);
		}
		for (Reference reference : references2) {
			addBestReferenceToList(reference, result);
		}
		return result;
	}
952639
public DoublePoint Add(DoublePoint point1, DoublePoint point2) {
        DoublePoint result = new DoublePoint(point1);
        result.Add(point2);
        return result;
    }
209165
@CheckReturnValue
	@VisibleForTesting
	ImmutableList<Server> mergeServerLists(List<Server> firstList, List<Server> secondList) {
		ImmutableList.Builder<Server> results = ImmutableList.builder();
		List<Server> toProcess = new ArrayList<>(secondList);
		for (Server firstServer : firstList) {
			if (toProcess.contains(firstServer)) {
				Server found = toProcess.get(secondList.indexOf(firstServer));
				results.add(merge(firstServer, found));
				// remove server as it is already merged
				toProcess.remove(found);
			} else {
				results.add(firstServer);
			}
		}
		// add servers from the second list that are not in the first one
		results.addAll(toProcess);
		return results.build();
	}
1065059
public static <T> List<T> disjoint(final List<? extends T> list1, final List<? extends T> list2) {
		List<T> intersection = intersection(list1, list2);
		List<T> towIntersection = union(intersection, intersection);
		return difference(union(list1, list2), towIntersection);
	}
286596
public static <T1, T2> void forEachInBoth(List<T1> list1, List<T2> list2, Procedure2<? super T1, ? super T2> procedure)
    {
        if (list1 != null && list2 != null)
        {
            if (list1.size() == list2.size())
            {
                if (list1 instanceof RandomAccess && list2 instanceof RandomAccess)
                {
                    RandomAccessListIterate.forEachInBoth(list1, list2, procedure);
                }
                else
                {
                    Iterator<T1> iterator1 = list1.iterator();
                    Iterator<T2> iterator2 = list2.iterator();
                    int size = list2.size();
                    for (int i = 0; i < size; i++)
                    {
                        procedure.value(iterator1.next(), iterator2.next());
                    }
                }
            }
            else
            {
                throw new RuntimeException("Attempt to call forEachInBoth with two Lists of different sizes :"
                        + list1.size()
                        + ':'
                        + list2.size());
            }
        }
    }
1257917
public static void add(double[] array1, double[] array2) {
        assert (array1.length == array2.length);
        for (int i=0; i<array1.length; i++) {
            array1[i] += array2[i];
        }
    }
1114877
private List<IAtom> getUnion(List<IAtom> list1, List<IAtom> list2) {
        // FIXME: the JavaDoc does not describe what happens: that vec1 gets to be the union!
        // jm: pretty sure retainAll would do the trick here but don't want to change the
        //     functionality as item only present in list1 are not removed (i.e. not union)
        List<IAtom> is = new ArrayList<IAtom>(list1);
        for (int f = list2.size() - 1; f > -1; f--) {
            if (!list1.contains(list2.get(f))) is.add(list2.get(f));
        }
        return is;
    }
1318958
@InternalFunction()
    public Boolean match(final List<ProxyField> list,final List<ProxyField> list2)
    {
    	if (list == null)
    	{
    		return Boolean.TRUE;
    	}
        for (ProxyField proxyField: list)
        {
            boolean found = false;
            for (ProxyField proxyField2: list2)
            {
                if (proxyField.getValue().equals(proxyField2.getValue()))
                {
                    found = true;
                    break;
                }
            }
            if (!found)
            {
                return Boolean.FALSE;
            }
        }
        return Boolean.TRUE;
    }
787939
def asym_list_diff(list1, list2):
    
    diff_list = []
    for item in list1:
        if not item in list2:
            diff_list.append(item)
    return diff_list
57936
public static double getSignificance(double correlation1, double correlation2, int n1, int n2) throws MathException {
        
        // transform to Fisher Z-values
        double zv1 = FisherZTransformation.transform(correlation1);
        double zv2 = FisherZTransformation.transform(correlation2);

        // difference of the Z-values
        double zDifference = (zv1 - zv2) / Math.sqrt(2d) / Math.sqrt( (double)1/(n1-3) + (double)1/(n2-3));
        
        // get p value from the complementary error function
        double p = Erf.erfc( Math.abs(zDifference));
        return p;
    }
1162352
public static <T> List<T> getLeftDiff(List<T> list1, List<T> list2) {
        if (isEmpty(list2)) {
            return list1;
        }
        List<T> list = new ArrayList<T>();
        if (isNotEmpty(list1)) {
            for (T o : list1) {
                if (!list2.contains(o)) {
                    list.add(o);
                }
            }
        }
        return list;
    }
1065308
def equal(list1, list2):
    
    return [item1 == item2 for item1, item2 in broadcast_zip(list1, list2)]