Jaccard similarity
174259
def subject_pair_overlap(subject1, subject2, object_category=None, **kwargs):
    
    set1 = get_object_closure(subject1,
                              object_category=object_category,
                              **kwargs)
    set2 = get_object_closure(subject2,
                              object_category=object_category,
                              **kwargs)
    return len(set1.intersection(set2)), len(set1.union(set2))
93331
public function similarity(&$A, &$B)
    {
        // Make the arrays into sets
        $a = array_fill_keys($A,1);
        $b = array_fill_keys($B,1);

        // Count the cardinalities of the sets
        $a_count = count($a);
        $b_count = count($b);

        if ($a_count == 0 || $b_count == 0) {
            return 0;
        }

        // Compute the intersection and count its cardinality
        $intersect = count(array_intersect_key($a,$b));

        return $intersect/min($a_count,$b_count);
    }
1096659
public static <T extends Levenshtein> T jaccard(String baseTarget, String compareTarget) {
		return jaccard(baseTarget, compareTarget, null);
	}
1291159
def similarity(w1, w2, threshold=0.5):
    
    ratio = SM(None, str(w1).lower(), str(w2).lower()).ratio()
    return ratio if ratio > threshold else 0
451927
def overall_jaccard_index_calc(jaccard_list):
    
    try:
        jaccard_sum = sum(jaccard_list)
        jaccard_mean = jaccard_sum / len(jaccard_list)
        return (jaccard_sum, jaccard_mean)
    except Exception:
        return "None"
1019544
public void similar(IMatrix U, IMatrix result) {
        if ((result.rows != U.columns) || (result.columns != U.columns)) result.reshape(U.columns, U.columns);

        double realsum, imagsum, realinnersum, imaginnersum;
        for (int i = 0; i < U.columns; i++)
            for (int j = 0; j < U.columns; j++) {
                realsum = 0d;
                imagsum = 0d;
                for (int k = 0; k < U.columns; k++) {
                    realinnersum = 0d;
                    imaginnersum = 0d;
                    for (int l = 0; l < U.columns; l++) {
                        realinnersum += realmatrix[k][l] * U.realmatrix[l][j] - imagmatrix[k][l] * U.imagmatrix[l][j];
                        imaginnersum += realmatrix[k][l] * U.imagmatrix[l][j] + imagmatrix[k][l] * U.realmatrix[l][j];
                    }
                    realsum += U.realmatrix[k][i] * realinnersum - U.imagmatrix[k][i] * imaginnersum;
                    imagsum += U.realmatrix[k][i] * imaginnersum + U.imagmatrix[k][i] * realinnersum;
                }
                result.realmatrix[i][j] = realsum;
                result.imagmatrix[i][j] = imagsum;
            }
    }
1085880
def similarity(self, other: 'Trigram') -> float:
        
        if not len(self._trigrams) or not len(other._trigrams):
            return 0

        count = float(len(self._trigrams & other._trigrams))
        len1 = float(len(self._trigrams))
        len2 = float(len(other._trigrams))

        return count / (len1 + len2 - count)
446435
def similarity(self, other):
        """"""
        ratio = 1.0 if (str(self).lower() == str(other).lower()) else 0.0
        similarity = self.Similarity(ratio)
        return similarity
1330916
function(otherUserId, callback){
          // if there is only one other user or the other user is the same user
          if (otherUserIdsWhoRated.length === 1 || userId === otherUserId){
            // then call the callback and exciting the similarity check
            callback();
          }
          // if the userid is not the same as the user
          if (userId !== otherUserId){
            // calculate the jaccard coefficient for similarity. it will return a value between -1 and 1 showing the two users
            // similarity
            jaccardCoefficient(userId, otherUserId, function(result) {
              // with the returned similarity score, add it to a sorted set named above
              client.zadd(similarityZSet, result, otherUserId, function(err){
                // call the async callback function once finished to indicate that the process is finished
                callback();
              });
            });
          }
        }
254458
public float similarity() {
        int match = 0, mismatch = 0;

        AlignmentIteratorForward<S> iterator = forwardIterator();
        while (iterator.advance()) {
            final int mut = iterator.getCurrentMutation();
            if (mut == NON_MUTATION)
                ++match;
            else
                ++mismatch;
        }

        return 1.0f * match / (match + mismatch);
    }
1271521
def sequence_matcher_similarity(state_a, state_b):
        
        addrs_a = tuple(state_a.history.bbl_addrs)
        addrs_b = tuple(state_b.history.bbl_addrs)
        return SequenceMatcher(a=addrs_a, b=addrs_b).ratio()
876029
@Override
	public void computeHessian(DMatrixSparseCSC jacLeft , DMatrixSparseCSC jacRight) {
		A.reshape(jacLeft.numCols,jacLeft.numCols,1);
		B.reshape(jacLeft.numCols,jacRight.numCols,1);
		D.reshape(jacRight.numCols,jacRight.numCols,1);

		// take advantage of the inner product's symmetry when possible to reduce
		// the number of calculations
		CommonOps_DSCC.innerProductLower(jacLeft,tmp0,gw,gx);
		CommonOps_DSCC.symmLowerToFull(tmp0,A,gw);
		CommonOps_DSCC.multTransA(jacLeft,jacRight,B,gw,gx);
		CommonOps_DSCC.innerProductLower(jacRight,tmp0,gw,gx);
		CommonOps_DSCC.symmLowerToFull(tmp0,D,gw);
	}
145071
def similarity(self, other):
        """"""
        # Select the longer list as the basis for comparison
        if len(self.items) > len(other.items):
            first, second = self, other
        else:
            first, second = other, self
        items = list(first.items)  # backup items list
        length = len(items)
        sim = self.Similarity(0.0 if length else 1.0)

        # Calculate the similarity for each permutation of items
        cname = self.__class__.__name__

        for num, perm in enumerate(permutations(items, length), start=1):
            first.items = perm
            aname = 'items-p{}'.format(num)
            self.log(first, second, '%', cname=cname, aname=aname)
            permutation_sim = super(Group, first).similarity(second)
            self.log(first, second, '%', cname=cname, aname=aname,
                     result=permutation_sim)

            sim = max(sim, permutation_sim)
            logging.debug("highest similarity: %s", sim)

        first.items = items  # restore original items list

        return sim
381541
def _calc_jaccard(
    markers1: dict,
    markers2: dict,
):
    
    jacc_results=np.zeros((len(markers1), len(markers2)))

    j=0
    for marker_group in markers1:
        tmp = [len(markers2[i].intersection(markers1[marker_group]))/
               len(markers2[i].union(markers1[marker_group])) for i in markers2.keys()]
        jacc_results[j,:] = tmp
        j += 1

    return jacc_results
1072695
def compute_jaccard_index(x_set, y_set):
    
    if not x_set or not y_set:
        return 0.0

    intersection_cardinal = len(x_set & y_set)
    union_cardinal = len(x_set | y_set)

    return intersection_cardinal / float(union_cardinal)
83989
private static boolean relationCompare_(int[] matrix, String scl) {
		for (int i = 0; i < 9; i++) {
			switch (scl.charAt(i)) {
			case 'T':
				assert (matrix[i] != -2);
				if (matrix[i] == -1)
					return false;
				break;

			case 'F':
				assert (matrix[i] != -2);
				if (matrix[i] != -1)
					return false;
				break;

			case '0':
				assert (matrix[i] != -2);
				if (matrix[i] != 0)
					return false;
				break;

			case '1':
				assert (matrix[i] != -2);
				if (matrix[i] != 1)
					return false;
				break;

			case '2':
				assert (matrix[i] != -2);
				if (matrix[i] != 2)
					return false;
				break;

			default:
				break;
			}
		}

		return true;
	}
354601
def similarity(self, other: Trigram) -> float:
        
        return max((self._match(x, other) for x in self.trigrams), default=0)