Compute the Jaccard similarity of two bit vectors.

@param v2 Second bit vector
@return Jaccard similarity (intersection / union)
968427
public double jaccardSimilarity(BitVector v2) {
    return BitsUtil.intersectionSize(bits, v2.bits) / (double) BitsUtil.unionSize(bits, v2.bits);
  }
233454
public static double jaccardIndex(IntegerVector a, IntegerVector b) {
        Set<Integer> intersection = new HashSet<Integer>();
        Set<Integer> union = new HashSet<Integer>();
        for (int i = 0; i < a.length(); ++i) {
            int d = a.get(i);
            intersection.add(d);
            union.add(d);
        }
        Set<Integer> tmp = new HashSet<Integer>();
        for (int i = 0; i < b.length(); ++i) {
            int d = b.get(i);
            tmp.add(d);
            union.add(d);
        }

        intersection.retainAll(tmp);
        return ((double)(intersection.size())) / union.size();
    }
1207320
public static double dotDense(NumberVector v1, NumberVector v2) {
    final int dim1 = v1.getDimensionality(), dim2 = v2.getDimensionality();
    final int mindim = (dim1 <= dim2) ? dim1 : dim2;
    double dot = 0;
    for(int k = 0; k < mindim; k++) {
      dot += v1.doubleValue(k) * v2.doubleValue(k);
    }
    return dot;
  }
268478
def jaccard(seq1, seq2):
	
	set1, set2 = set(seq1), set(seq2)
	return 1 - len(set1 & set2) / float(len(set1 | set2))
766539
public static double[] plusTimesEquals(final double[] v1, final double[] v2, final double s2) {
    assert v1.length == v2.length : ERR_VEC_DIMENSIONS;
    for(int i = 0; i < v1.length; i++) {
      v1[i] += s2 * v2[i];
    }
    return v1;
  }
222131
public final double similarity(final String s1, final String s2) {
        int[] mtp = matches(s1, s2);
        float m = mtp[0];
        if (m == 0) {
            return 0f;
        }
        double j = ((m / s1.length() + m / s2.length() + (m - mtp[1]) / m))
                / THREE;
        double jw = j;

        if (j > getThreshold()) {
            jw = j + Math.min(JW_COEF, 1.0 / mtp[THREE]) * mtp[2] * (1 - j);
        }
        return jw;
    }
954255
public static int compareVersions(String v1, String v2) {
		String[] v1a = v1.split("\\.");
		String[] v2a = v2.split("\\.");
		Integer v1M = Integer.parseInt(v1a[0]);
		Integer v2M = Integer.parseInt(v2a[0]);
		if (v1M < v2M) {
			return -1;
		} else if (v1M > v2M) {
			return 1;
		} else {
			Integer v1min = Integer.parseInt(v1a[1]);
			Integer v2min = Integer.parseInt(v2a[1]);
			if (v1min < v2min) {
				return -1;
			} else if (v1min > v2min) {
				return 1;
			} else {
				return 0;
			}
		}
	}
27103
public double compare(String v1, String v2) {
    // FIXME: it should be possible here to say that, actually, we
    // didn't learn anything from comparing these two values, so that
    // probability is set to 0.5.

    if (comparator == null)
      return 0.5; // we ignore properties with no comparator

    // first, we call the comparator, to get a measure of how similar
    // these two values are. note that this is not the same as what we
    // are going to return, which is a probability.
    double sim = comparator.compare(v1, v2);

    // we have been configured with a high probability (for equal
    // values) and a low probability (for different values). given
    // sim, which is a measure of the similarity somewhere in between
    // equal and different, we now compute our estimate of the
    // probability.

    // if sim = 1.0, we return high. if sim = 0.0, we return low. for
    // values in between we need to compute a little.  the obvious
    // formula to use would be (sim * (high - low)) + low, which
    // spreads the values out equally spaced between high and low.

    // however, if the similarity is higher than 0.5 we don't want to
    // consider this negative evidence, and so there's a threshold
    // there.  also, users felt Duke was too eager to merge records,
    // and wanted probabilities to fall off faster with lower
    // probabilities, and so we square sim in order to achieve this.

    if (sim >= 0.5)
      return ((high - 0.5) * (sim * sim)) + 0.5;
    else
      return low;
  }
335392
function EdgeShape(v1, v2) {
  if (!(this instanceof EdgeShape)) {
    return new EdgeShape(v1, v2);
  }

  EdgeShape._super.call(this);

  this.m_type = EdgeShape.TYPE;
  this.m_radius = Settings.polygonRadius;

  // These are the edge vertices
  this.m_vertex1 = v1 ? Vec2.clone(v1) : Vec2.zero();
  this.m_vertex2 = v2 ? Vec2.clone(v2) : Vec2.zero();

  // Optional adjacent vertices. These are used for smooth collision.
  // Used by chain shape.
  this.m_vertex0 = Vec2.zero();
  this.m_vertex3 = Vec2.zero();
  this.m_hasVertex0 = false;
  this.m_hasVertex3 = false;
}
874983
@Override
    public double similarity(Vertex<V> vertex1, Vertex<V> vertex2) {
        return similarity(vertex1.vertexID(), vertex2.vertexID());
    }
65269
public static double[] rotate90Equals(final double[] v1) {
    assert v1.length == 2 : "rotate90Equals is only valid for 2d vectors.";
    final double temp = v1[0];
    v1[0] = v1[1];
    v1[1] = -temp;
    return v1;
  }
1333835
function equals(v1, v2) {
    if (!arraysEqual(v1.size(), v2.size())) return false;
    return Vector.cascadeReduce(Vector.zip(v1, v2, (e1, e2) => e1 === e2), (prev, next) => prev && next, true);
}
317061
@Override
    public double similarity(String label1, String label2) {
        if (label1 == null || label2 == null) {
            log.debug("LABELS: " + label1 + ": " + (label1 == null ? "null" : "exists") + ";" + label2 + " vec2:"
                            + (label2 == null ? "null" : "exists"));
            return Double.NaN;
        }

        INDArray vec1 = getWordVectorMatrix(label1).dup();
        INDArray vec2 = getWordVectorMatrix(label2).dup();

        if (vec1 == null || vec2 == null) {
            log.debug(label1 + ": " + (vec1 == null ? "null" : "exists") + ";" + label2 + " vec2:"
                            + (vec2 == null ? "null" : "exists"));
            return Double.NaN;
        }

        if (label1.equals(label2))
            return 1.0;

        vec1 = Transforms.unitVec(vec1);
        vec2 = Transforms.unitVec(vec2);

        return Transforms.cosineSim(vec1, vec2);
    }
950774
def get_scaled_v2(self, amount):
        """"""

        return Vec2(self.x * amount, self.y * amount)
870502
def _equals(v1_indices, v1_values, v2_indices, v2_values):
        
        v1_size = len(v1_values)
        v2_size = len(v2_values)
        k1 = 0
        k2 = 0
        all_equal = True
        while all_equal:
            while k1 < v1_size and v1_values[k1] == 0:
                k1 += 1
            while k2 < v2_size and v2_values[k2] == 0:
                k2 += 1

            if k1 >= v1_size or k2 >= v2_size:
                return k1 >= v1_size and k2 >= v2_size

            all_equal = v1_indices[k1] == v2_indices[k2] and v1_values[k1] == v2_values[k2]
            k1 += 1
            k2 += 1
        return all_equal
47221
public static double[][] timesTranspose(final double[] v1, final double[] v2) {
    final double[][] re = new double[v1.length][v2.length];
    for(int j = 0; j < v2.length; j++) {
      for(int i = 0; i < v1.length; i++) {
        re[i][j] = v1[i] * v2[j];
      }
    }
    return re;
  }
222292
public Vector2d mul(Vector2dc v, Vector2d dest) {
        dest.x = x * v.x();
        dest.y = y * v.y();
        return dest;
    }