コード例 #1
0
ファイル: TermVectorDouble.java プロジェクト: htools/htools
 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;
 }
コード例 #2
0
ファイル: TermVectorDouble.java プロジェクト: htools/htools
 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;
 }
コード例 #3
0
ファイル: TermVectorDouble.java プロジェクト: htools/htools
 public TermVectorDouble normalize() {
   double total = total();
   if (total != 1) {
     for (Object2DoubleMap.Entry<String> entry : object2DoubleEntrySet()) {
       entry.setValue(entry.getDoubleValue() / total);
     }
   }
   magnitude = null;
   total = 1;
   return this;
 }
コード例 #4
0
ファイル: TermVectorDouble.java プロジェクト: htools/htools
 public String getMax() {
   double max = Double.MIN_VALUE;
   String maxterm = null;
   for (Object2DoubleMap.Entry<String> entry : object2DoubleEntrySet()) {
     if (max < entry.getDoubleValue()) {
       max = entry.getDoubleValue();
       maxterm = entry.getKey();
     }
   }
   return maxterm;
 }
コード例 #5
0
ファイル: TermVectorDouble.java プロジェクト: htools/htools
 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;
 }
コード例 #6
0
ファイル: TermVectorDouble.java プロジェクト: htools/htools
 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;
 }
コード例 #7
0
ファイル: TermVectorDouble.java プロジェクト: htools/htools
 public double cossimDebug(TermVectorDouble v) {
   if (this.size() > v.size()) {
     return v.cossimDebug(this);
   }
   double dotproduct = 0;
   for (Object2DoubleMap.Entry<String> entry : object2DoubleEntrySet()) {
     dotproduct += v.getDouble(entry.getKey()) * entry.getDoubleValue();
     log.info(
         "%s %f %f %s",
         entry.getKey(), v.getDouble(entry.getKey()), entry.getDoubleValue(), dotproduct);
   }
   double magnitude = magnitude() * v.magnitude();
   log.info("magnitude %s %s %s", magnitude(), v.magnitude(), dotproduct / magnitude);
   return (magnitude == 0) ? 0 : dotproduct / magnitude;
 }
コード例 #8
0
ファイル: TermVectorDouble.java プロジェクト: htools/htools
 public void remove(TermVectorDouble v) {
   for (Object2DoubleMap.Entry<String> entry : v.object2DoubleEntrySet()) {
     add(entry.getKey(), -entry.getDoubleValue());
   }
   magnitude = null;
 }