Normalized Euclidean distance.

@param ts1 the first series.
@param ts2 the second series.
@return the distance value.
178719
protected double eculideanDistNorm(double[] ts1, double[] ts2) {
    double dist = 0;
    double tsLen = ts1.length;

    for (int i = 0; i < ts1.length; i++) {
      double diff = ts1[i] - ts2[i];
      dist += Math.pow(diff, 2);
    }

    return Math.sqrt(dist) / tsLen;
  }
1208303
private static double squaredDistance(FinderPattern a, FinderPattern b) {
    double x = a.getX() - b.getX();
    double y = a.getY() - b.getY();
    return x * x + y * y;
  }
597127
def distance(vec1, vec2):
        """"""
        if isinstance(vec1, Vector2) \
                and isinstance(vec2, Vector2):
            dist_vec = vec2 - vec1
            return dist_vec.length()
        else:
            raise TypeError("vec1 and vec2 must be Vector2's")
1160535
public static double getDistance(double x1, double y1, double x2, double y2, int w2, int h2)
    {
        final double maxX = x2 + w2;
        final double maxY = y2 + h2;

        double min = getDistance(x1, y1, x2, y2);
        for (double x = x2; Double.compare(x, maxX) <= 0; x++)
        {
            for (double y = y2; Double.compare(y, maxY) <= 0; y++)
            {
                final double dist = getDistance(x1, y1, x, y);
                if (dist < min)
                {
                    min = dist;
                }
            }
        }
        return min;
    }
1229406
public float distance(INDArray arr1, INDArray arr2) {
        if (scalars == null)
            scalars = new ThreadLocal<>();

        if (Nd4j.scalar(0.0f).equals(scalars.get()))
            scalars.set(Nd4j.scalar(0.0));

        switch (similarityFunction) {
            case "jaccard":
                float ret7 = Nd4j.getExecutioner()
                        .execAndReturn(new JaccardDistance(arr1, arr2, scalars.get()))
                        .getFinalResult().floatValue();
                return invert ? -ret7 : ret7;
            case "hamming":
                float ret8 = Nd4j.getExecutioner()
                        .execAndReturn(new HammingDistance(arr1, arr2, scalars.get()))
                        .getFinalResult().floatValue();
                return invert ? -ret8 : ret8;
            case "euclidean":
                float ret = Nd4j.getExecutioner()
                        .execAndReturn(new EuclideanDistance(arr1, arr2, scalars.get()))
                        .getFinalResult().floatValue();
                return invert ? -ret : ret;
            case "cosinesimilarity":
                float ret2 = Nd4j.getExecutioner()
                        .execAndReturn(new CosineSimilarity(arr1, arr2, scalars.get()))
                        .getFinalResult().floatValue();
                return invert ? -ret2 : ret2;
            case "cosinedistance":
                float ret6 = Nd4j.getExecutioner()
                        .execAndReturn(new CosineDistance(arr1, arr2, scalars.get()))
                        .getFinalResult().floatValue();
                return invert ? -ret6 : ret6;
            case "manhattan":
                float ret3 = Nd4j.getExecutioner()
                        .execAndReturn(new ManhattanDistance(arr1, arr2, scalars.get()))
                        .getFinalResult().floatValue();
                return invert ? -ret3 : ret3;
            case "dot":
                float dotRet = (float) Nd4j.getBlasWrapper().dot(arr1, arr2);
                return invert ? -dotRet : dotRet;
            default:
                float ret4 = Nd4j.getExecutioner()
                        .execAndReturn(new EuclideanDistance(arr1, arr2, scalars.get()))
                        .getFinalResult().floatValue();
                return invert ? -ret4 : ret4;

        }
    }
230801
public static float distanceEuclidean(HashSparseVector sv1 ,HashSparseVector sv2) {
		float dist = 0.0f;
		TIntFloatIterator it1 = sv1.data.iterator();
		TIntFloatIterator it2 = sv2.data.iterator();
		int increa = 0;
		while(it1.hasNext()&&it2.hasNext()){
			if(increa==0){
				it1.advance();
				it2.advance();
			}else if(increa==1){
				it1.advance();
			}else if(increa==2){
				it2.advance();
			}
			if(it1.key()<it2.key()){
				dist += it1.value()*it1.value();
				increa = 1;
			}else if(it1.key()>it2.key()){
				dist += it2.value()*it2.value();
				increa = 2;
			}else{
				float t = it1.value() - it2.value();
				dist += t*t;
				increa = 0;
			}
		}
		while(it1.hasNext()){
			it1.advance();
			dist += it1.value()*it1.value();			
		}
		while(it2.hasNext()){
			it2.advance();
			dist += it2.value()*it2.value();

		}
		return dist;
	}
789480
protected static double distanceSq(double[] a, double[] b) {
		double sum = 0;
		for (int i = 0; i < a.length; i++) {
			double d = a[i]-b[i];
			sum += d*d;
		}
		return sum;
	}
562372
@Pure
	public static boolean epsilonEqualsDistance(Point3D<?, ?> p1, Point3D<?, ?> p2) {
		final double distance = p1.getDistance(p2);
		return distance >= -distancePrecision && distance <= distancePrecision;
	}
1352256
private double preDistance(NumberVector v1, NumberVector v2, final int start, final int end) {
    double agg = 0.;
    for(int d = start; d < end; d++) {
      final double xd = v1.doubleValue(d), yd = v2.doubleValue(d);
      final double delta = xd >= yd ? xd - yd : yd - xd;
      agg += MathUtil.powi(delta, intp);
    }
    return agg;
  }
800327
public static function distance(Vector $value1, Vector $value2) : float {
        return sqrt(self::distance2($value1, $value2));
    }
1344822
public final double distance(final double[] value1, final double[] value2) {
        double agg = 0;
        for (int i = 0; i < value1.length; i++) {
            agg += (value1[i] - value2[i]) * (value1[i] - value2[i]);
        }
        return Math.sqrt(agg);
    }
1209999
public static double euclidean(AssociativeArray a1, AssociativeArray a2) {
        Map<Object, Double> columnDistances = columnDistances(a1, a2, null);
        
        double distance = 0.0;
        for(double columnDistance : columnDistances.values()) {
            distance+=(columnDistance*columnDistance);
        }
        
        return Math.sqrt(distance);
    }
1288241
public static <S extends Solution<?>> double distanceBetweenObjectives(S firstSolution, S secondSolution) {

    double diff;
    double distance = 0.0;

    //euclidean distance
    for (int nObj = 0; nObj < firstSolution.getNumberOfObjectives(); nObj++) {
      diff = firstSolution.getObjective(nObj) - secondSolution.getObjective(nObj);
      distance += Math.pow(diff, 2.0);
    }

    return Math.sqrt(distance);
  }
64043
private int hammingDistance(String simHash1, String simHash2) {
        if (simHash1.length() != simHash2.length()) {
            return -1;
        }
        int distance = 0;
        int len = simHash1.length();
        for (int i = 0; i < len; i++) {
            if (simHash1.charAt(i) != simHash2.charAt(i)) {
                distance++;
            }
        }
        return distance;
    }
1334992
@Override
  public double distance(NumberVector v1, NumberVector v2) {
    if(v1.getDimensionality() != v2.getDimensionality()) {
      throw new IllegalArgumentException("Different dimensionality of FeatureVectors\n  " + "first argument: " + v1 + "\n  " + "second argument: " + v2);
    }

    double sqrDist = 0;
    for(int d = BitsUtil.nextSetBit(dimensions, 0); d >= 0; d = BitsUtil.nextSetBit(dimensions, d + 1)) {
      final double delta = v1.doubleValue(d) - v2.doubleValue(d);
      sqrDist += delta * delta;
    }
    return FastMath.sqrt(sqrDist);
  }
780876
def l2_distance_sq(t1, t2, name=None):
  
  with tf.name_scope(name, 'l2_distance_sq', [t1, t2]) as scope:
    t1 = tf.convert_to_tensor(t1, name='t1')
    t2 = tf.convert_to_tensor(t2, name='t2')
    return length_squared(tf.subtract(t1, t2), name=scope)
139798
public static double getCosinValue(double[] vector1, double[] vector2) {
        if (vector1 == null || vector2 == null) {
            return 0;
        }
        double dotProduct = VectorUtils.dotProduct(vector1, vector2);
        double euclideanDistance = VectorUtils.vectorLen(vector1) * VectorUtils.vectorLen(vector2);
        double cosineValue = Math.abs(dotProduct / euclideanDistance);
        return cosineValue > 1.0D ? 1.0D : cosineValue;  // because of the precision error
    }