Returns normalized score, with 0.0 meaning no similarity at all,
and 1.0 meaning full equality.
196616
public static double similarity(String s1, String s2) {
    if (s1.equals(s2))
      return 1.0;

    // ensure that s1 is shorter than or same length as s2
    if (s1.length() > s2.length()) {
      String tmp = s2;
      s2 = s1;
      s1 = tmp;
    }
    /*
     * this list of Boolean values is used for avoiding duplicated count of
     * common characters in S2
     */
    List<Boolean> isCommonCharInS2 = new ArrayList<Boolean>();
    for (int i=0; i<s2.length(); i++) {
      isCommonCharInS2.add(false);
    }

    // (1) find the number of characters the two strings have in common.
    // note that matching characters can only be half the length of the
    // longer string apart.
    int maxdist = (int) Math.floor(s2.length() / 2) ;
    int c = 0; // count of common characters
    int t = 0; // count of transpositions
    int prevpos = -1;
    for (int ix = 0; ix < s1.length(); ix++) {
      char ch = s1.charAt(ix);

      // now try to find it in s2
      for (int ix2 = Math.max(0, ix - maxdist);
           ix2 < Math.min(s2.length(), ix + maxdist);
           ix2++) {
        if (ch == s2.charAt(ix2) && !isCommonCharInS2.get(ix2)) {
          c++; // we found a common character
          isCommonCharInS2.set(ix2, true);
          if (prevpos != -1 && ix2 < prevpos)
            t++; // moved back before earlier
          prevpos = ix2;
          break;
        }
      }
    }

    // we don't divide t by 2 because as far as we can tell, the above
    // code counts transpositions directly.

    // System.out.println("c: " + c);
    // System.out.println("t: " + t);
    // System.out.println("c/m: " + (c / (double) s1.length()));
    // System.out.println("c/n: " + (c / (double) s2.length()));
    // System.out.println("(c-t)/c: " + ((c - t) / (double) c));

    // we might have to give up right here
    if (c == 0)
      return 0.0;

    // first compute the score
    double score = ((c / (double) s1.length()) +
            (c / (double) s2.length()) +
            ((c - t) / (double) c)) / 3.0;

    // (2) common prefix modification
    int p = 0; // length of prefix
    int last = Math.min(4, s1.length());
    for (; p < last && s1.charAt(p) == s2.charAt(p); p++)
      ;

    score = score + ((p * (1 - score)) / 10);

    // (3) longer string adjustment
    // I'm confused about this part. Winkler's original source code includes
    // it, and Yancey's 2005 paper describes it. However, Winkler's list of
    // test cases in his 2006 paper does not include this modification. So
    // is this part of Jaro-Winkler, or is it not? Hard to say.
    //
    //   if (s1.length() >= 5 && // both strings at least 5 characters long
    //       c - p >= 2 && // at least two common characters besides prefix
    //       c - p >= ((s1.length() - p) / 2)) // fairly rich in common chars
    //     {
    //     System.out.println("ADJUSTED!");
    //     score = score + ((1 - score) * ((c - (p + 1)) /
    //                                     ((double) ((s1.length() + s2.length())
    //                                                - (2 * (p - 1))))));
    // }

    // (4) similar characters adjustment
    // the same holds for this as for (3) above.

    return score;
  }
1374199
def similarity(self, other):
        """"""
        if self.magnitude == 0 or other.magnitude == 0:
            return 0

        return self.dot(other) / self.magnitude
1327130
public float getScore(int i) {
		if (i < 0 || i >=scores.size())
			return Float.NEGATIVE_INFINITY;
		return scores.get(i);
	}
403099
def get_score(self, error=None):
        '''
        '''

        if error is not None:
            self.error = error
        if self.error >= 0:
            return 1 / (self.error + 1)
        else:
            return 1 + abs(self.error)
1198362
def get_similar(obj, labels, default=None, min_similarity=0.5):
    
    raise NotImplementedError(
        "Unfinished implementation, needs to be in fuzzy_get where list of scores & keywords is sorted.")
    labels = listify(labels)

    def not_found(*args, **kwargs):
        return 0

    min_score = int(min_similarity * 100)
    for similarity_score in [100, 95, 90, 80, 70, 50, 30, 10, 5, 0]:
        if similarity_score <= min_score:
            similarity_score = min_score
        for label in labels:
            try:
                result = obj.get(label, not_found)
            except AttributeError:
                try:
                    result = obj.__getitem__(label)
                except (IndexError, TypeError):
                    result = not_found
            if result is not not_found:
                return result
        if similarity_score == min_score:
            if result is not not_found:
                return result
495467
def _compare_versions(v1, v2):
    
    def normalize(v):
        # strip trailing .0 or .00 or .0.0 or ...
        v = re.sub(r'(\.0+)*$', '', v)
        result = []
        for part in v.split('.'):
            # just digits
            m = re.match(r'^(\d+)$', part)
            if m:
                result.append(int(m.group(1)))
                continue
            # digits letters
            m = re.match(r'^(\d+)([a-zA-Z]+)$', part)
            if m:
                result.append(int(m.group(1)))
                result.append(m.group(2))
                continue
            # digits letters digits
            m = re.match(r'^(\d+)([a-zA-Z]+)(\d+)$', part)
            if m:
                result.append(int(m.group(1)))
                result.append(m.group(2))
                result.append(int(m.group(3)))
                continue
        return tuple(result)

    n1 = normalize(v1)
    n2 = normalize(v2)

    return (n1 > n2) - (n1 < n2)
231173
def gt(self, v, limit=None, offset=None):
        
        if limit is not None and offset is None:
            offset = 0
        return self.zrangebyscore("(%f" % v, self._max_score,
                start=offset, num=limit)
822307
def normalized_mutual_info_score(self, reference_clusters):
        
        return normalized_mutual_info_score(self.get_labels(self), self.get_labels(reference_clusters))
1225227
public Formula normalize() {
    final LNGVector<Literal> normPs = new LNGVector<>(this.literals.length);
    final LNGIntVector normCs = new LNGIntVector(this.literals.length);
    int normRhs;
    switch (this.comparator) {
      case EQ:
        for (int i = 0; i < this.literals.length; i++) {
          normPs.push(this.literals[i]);
          normCs.push(this.coefficients[i]);
        }
        normRhs = this.rhs;
        final Formula f1 = this.normalize(normPs, normCs, normRhs);
        normPs.clear();
        normCs.clear();
        for (int i = 0; i < this.literals.length; i++) {
          normPs.push(this.literals[i]);
          normCs.push(-this.coefficients[i]);
        }
        normRhs = -this.rhs;
        final Formula f2 = this.normalize(normPs, normCs, normRhs);
        return this.f.and(f1, f2);
      case LT:
      case LE:
        for (int i = 0; i < this.literals.length; i++) {
          normPs.push(this.literals[i]);
          normCs.push(this.coefficients[i]);
        }
        normRhs = this.comparator == CType.LE ? this.rhs : this.rhs - 1;
        return this.normalize(normPs, normCs, normRhs);
      case GT:
      case GE:
        for (int i = 0; i < this.literals.length; i++) {
          normPs.push(this.literals[i]);
          normCs.push(-this.coefficients[i]);
        }
        normRhs = this.comparator == CType.GE ? -this.rhs : -this.rhs - 1;
        return this.normalize(normPs, normCs, normRhs);
      default:
        throw new IllegalStateException("Unknown pseudo-Boolean comparator: " + this.comparator);
    }
  }
316427
function normaliseScale(s) {
  if (s>1) throw('s must be <1');
  s = 0 | (1/s);
  var l = log2(s);
  var mask = 1 << l;
  var accuracy = 4;
  while(accuracy && l) { l--; mask |= 1<<l; accuracy--; }
  return 1 / ( s & mask );
}
997839
def normalize(data):
    
    data = data.astype(float)
    data -= data.mean()
    
    return data / data.std()
1159045
def _linear_normalization_from_0to1(
        data,
        mask,
        theoretical_max,
        theoretical_min=0,
        message="normalizing equalized data to fit in 0 to 1 range"):
    

    LOG.debug(message)
    if theoretical_min != 0:
        data[mask] = data[mask] - theoretical_min
        theoretical_max = theoretical_max - theoretical_min
    data[mask] = data[mask] / theoretical_max
549583
def normalization_factor(self):
        
        return 1.0 / (self.num_atoms - self.composition.get('H', 0)
                      - self.composition.get('O', 0))
884514
def f1_score(prediction, ground_truth):
    '''
    
    '''
    prediction_tokens = normalize_answer(prediction).split()
    ground_truth_tokens = normalize_answer(ground_truth).split()
    common = Counter(prediction_tokens) & Counter(ground_truth_tokens)
    num_same = sum(common.values())
    if num_same == 0:
        return 0
    precision = 1.0 * num_same / len(prediction_tokens)
    recall = 1.0 * num_same / len(ground_truth_tokens)
    f1_result = (2 * precision * recall) / (precision + recall)
    return f1_result
928622
public Vector3d normalizedPositiveY(Vector3d dest) {
        dest.x = m01;
        dest.y = m11;
        dest.z = m21;
        return dest;
    }
391531
def get_lowest_numeric_score(self):
        
        if self.is_based_on_grades():
            raise errors.IllegalState('This GradeSystem is based on grades')
        if self._my_map['lowestNumericScore'] is None:
            return None
        else:
            return Decimal(str(self._my_map['lowestNumericScore']))
822074
def homogeneity_score(self, reference_clusters):
        
        return homogeneity_score(self.get_labels(self), self.get_labels(reference_clusters))