Measured similarity between two points in a multi-dimensional space.

    Returns:
        1.0 if the two points completely overlap,
        0.0 if the two points are infinitely far apart.
356895
def tanimoto_coefficient(a, b):
    
    return sum(map(lambda (x,y): float(x)*float(y), zip(a,b))) / sum([
          -sum(map(lambda (x,y): float(x)*float(y), zip(a,b))),
           sum(map(lambda x: float(x)**2, a)),
           sum(map(lambda x: float(x)**2, b))])
623840
public static boolean epsilonEquals (IPoint p1, IPoint p2) {
        return epsilonEquals(p1, p2, MathUtil.EPSILON);
    }
754125
public static Boolean areCoordinatesWithinThreshold(Tuple2<Double, Double> point1, Tuple2<Double, Double> point2) {
        return getDistanceBetweenCoordinates(point1, point2) < COORDINATE_THRESHOLD;
    }
551747
def is_full_overlap(self1):
      
      if len(self1.overs) == 0: return False
      if len(self1.dif1) > 0:
        if max(self1.dif1) != 1 or max(self1.dif2) != 1: return False
      if self1.start1 and self1.end1 and self1.start2 and self1.end2:
        return True
      return False
1133138
def _distance_squared(self, p2: "Point2") -> Union[int, float]:
        
        return (self[0] - p2[0]) ** 2 + (self[1] - p2[1]) ** 2
418224
def unitcube_overlap(self, ndraws=10000, rstate=None):
        """"""

        if rstate is None:
            rstate = np.random

        samples = [self.sample(rstate=rstate) for i in range(ndraws)]
        nin = sum([unitcheck(x) for x in samples])

        return 1. * nin / ndraws
809675
def similarity(self, other: Trigram) -> Tuple[float, L]:
        

        return max(
            ((t % other, l) for t, l in self.trigrams),
            key=lambda x: x[0],
        )
1099777
private static boolean multiPointExactlyEqualsMultiPoint_(
			MultiPoint multipoint_a, MultiPoint multipoint_b, double tolerance,
			ProgressTracker progress_tracker) {
		if (multipoint_a.getPointCount() != multipoint_b.getPointCount())
			return false;

		Point2D ptA = new Point2D(), ptB = new Point2D();
		boolean bAllPointsEqual = true;
		double tolerance_sq = tolerance * tolerance;

		for (int i = 0; i < multipoint_a.getPointCount(); i++) {
			multipoint_a.getXY(i, ptA);
			multipoint_b.getXY(i, ptB);

			if (Point2D.sqrDistance(ptA, ptB) > tolerance_sq) {
				bAllPointsEqual = false;
				break;
			}
		}

		if (!bAllPointsEqual)
			return false;

		return true;
	}
932682
def Similarity(self, value=None):  # pylint: disable=C0103
        """"""
        if value is None:
            value = 0.0
        return Similarity(value, threshold=self.threshold)
454051
def similarity(self, other):
        """"""
        numerator, denominator = sorted((self.value, other.value))
        try:
            ratio = float(numerator) / denominator
        except ZeroDivisionError:
            ratio = 0.0 if numerator else 1.0
        similarity = self.Similarity(ratio)
        return similarity
201975
function isInLine(p1, m, p2, accuracy) {
  var a = p1.sub(m).sqr();
  var b = p2.sub(m).sqr();
  var c = p1.sub(p2).sqr();

  // control point not between anchors
  if ((a > (b + c)) || (b > (a + c))) {
    return false;
  }

  // count distance via scalar multiplication
  var distance = Math.sqrt(Math.pow((p1.x - m.x) * (p2.y - m.y) - (p2.x - m.x) * (p1.y - m.y), 2) / c);

  return distance < accuracy ? true : false;
}
1374401
public double overlapAbsolute(DoubleRange other) {
    if (!intersects(other)) {
      return 0;
    }
    int loCmp = lo.compareTo(other.lo);
    int hiCmp = hi.compareTo(other.hi);
    if (loCmp >= 0 && hiCmp <= 0) {
      return this.length();
    } else if (loCmp <= 0 && hiCmp >= 0) {
      return other.length();
    } else {
      double newLo = (loCmp >= 0) ? this.lo : other.lo;
      double newHi = (hiCmp <= 0) ? this.hi : other.hi;
      return newHi - newLo;
    }
  }
416990
def overlaps(self, begin, end=None):
        
        if end is not None:
            return self.overlaps_range(begin, end)
        elif isinstance(begin, Number):
            return self.overlaps_point(begin)
        else:
            return self.overlaps_range(begin.begin, begin.end)
87384
def segment_similarity(A, B, T=CLOSE_DISTANCE_THRESHOLD):
    
    l_a = len(A.points)
    l_b = len(B.points)

    idx = index.Index()
    dex = 0
    for i in range(l_a-1):
        idx.insert(dex, bounding_box_from(A.points, i, i+1, T), obj=[A.points[i], A.points[i+1]])
        dex = dex + 1

    prox_acc = []

    for i in range(l_b-1):
        ti = B.points[i].gen2arr()
        ti1 = B.points[i+1].gen2arr()
        bb = bounding_box_from(B.points, i, i+1, T)
        intersects = idx.intersection(bb, objects=True)
        n_prox = []
        i_prox = 0
        a = 0
        for x in intersects:
            a = a + 1
            pi = x.object[0].gen2arr()
            pi1 = x.object[1].gen2arr()
            prox = line_similarity(ti, ti1, pi, pi1, T)
            i_prox = i_prox + prox
            n_prox.append(prox)

        if a != 0:
            prox_acc.append(i_prox / a)
            # prox_acc.append(max(n_prox))
        else:
            prox_acc.append(0)

    return np.mean(prox_acc), prox_acc
396258
def ApproximateDistanceBetweenStops(stop1, stop2):
  """"""
  if (stop1.stop_lat is None or stop1.stop_lon is None or
      stop2.stop_lat is None or stop2.stop_lon is None):
    return None
  return ApproximateDistance(stop1.stop_lat, stop1.stop_lon,
                             stop2.stop_lat, stop2.stop_lon)
981486
def distance(a, b, metric="cosine"):
    
    if metric == "cosine":
        return np.dot(a, b.T)
    raise Exception("Unknown metric '{metric}'".format(metric=metric))
569324
def almost_equal(self, v2, places=7):
        

        try:
            return (
                len(self) == len(v2) and
                _float_almost_equal(self.x, v2.x, places) and
                _float_almost_equal(self.y, v2.y, places) and
                _float_almost_equal(self.z, v2.z, places))
        except:
            return False