Ejemplo n.º 1
0
 public double cossim(TermVectorInt v) {
   double dotproduct = 0;
   for (Object2DoubleMap.Entry<String> entry : object2DoubleEntrySet()) {
     dotproduct += v.getInt(entry.getKey()) * entry.getValue();
   }
   double magnitude = magnitude() * v.magnitude();
   return (magnitude == 0) ? 0 : dotproduct / magnitude;
 }
Ejemplo n.º 2
0
 public double dotproduct(TermVectorDouble v) {
   if (size() > v.size()) return v.dotproduct(this);
   double dotproduct = 0;
   for (Object2DoubleMap.Entry<String> entry : object2DoubleEntrySet()) {
     dotproduct += v.getDouble(entry.getKey()) * entry.getValue();
   }
   return dotproduct;
 }
Ejemplo n.º 3
0
 public TermVectorDouble multiply(TermVectorInt v) {
   if (size() > v.size()) return v.multiply(this);
   TermVectorDouble result = new TermVectorDouble();
   for (Object2DoubleMap.Entry<String> entry : object2DoubleEntrySet()) {
     int d = v.getInt(entry.getKey());
     if (d != 0) {
       result.put(entry.getKey(), entry.getValue() * d);
     }
   }
   return result;
 }
Ejemplo n.º 4
0
 public TermVectorDouble multiply(Map<String, Double> v) {
   if (size() > v.size() && v instanceof TermVector) return ((TermVector) v).multiply(this);
   TermVectorDouble result = new TermVectorDouble();
   for (Object2DoubleMap.Entry<String> entry : object2DoubleEntrySet()) {
     Double d = v.get(entry.getKey());
     if (d != 0) {
       result.put(entry.getKey(), entry.getValue() * d);
     }
   }
   return result;
 }