⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 euclideandocdistance.java

📁 dragontoolkit用于机器学习
💻 JAVA
字号:
package dragon.ir.clustering.docdistance;
import dragon.ir.index.*;
import dragon.matrix.*;

/**
 * <p>Document similarity or distance based on Euclidean distance </p>
 * <p> </p>
 * <p>Copyright: Copyright (c) 2006</p>
 * <p>Company: Drexel University</p>
 * @author Xiaodan Zhang, Davis Zhou
 * @version 1.0
 */

public class EuclideanDocDistance extends AbstractDocDistance{

     public EuclideanDocDistance(SparseMatrix doctermMatrix) {
         super(doctermMatrix);
     }

     public double getDistance(IRDoc first, IRDoc second){
         int firstNum,secondNum,x,y, firstIndexList[], secondIndexList[];
         double sum;
         double firstScoreList[], secondScoreList[];

         firstScoreList = matrix.getNonZeroDoubleScoresInRow(first.getIndex());
         secondScoreList=matrix.getNonZeroDoubleScoresInRow(second.getIndex());
         firstIndexList=matrix.getNonZeroColumnsInRow(first.getIndex());
         secondIndexList=matrix.getNonZeroColumnsInRow(second.getIndex());
         firstNum = firstScoreList.length;
         secondNum = secondScoreList.length;

         x=0;
         y=0;
         sum=0;

         while (x < firstNum && y < secondNum) {
             if (firstIndexList[x] < secondIndexList[y]){
                 if(featureFilter==null || featureFilter.map(firstIndexList[x])>=0)
                     sum+=firstScoreList[x]*firstScoreList[x];
                 x++;
             }
             else if (firstIndexList[x]==secondIndexList[y]) {
                 if(featureFilter==null || featureFilter.map(firstIndexList[x])>=0)
                     sum+=(firstScoreList[x]-secondScoreList[y])*(firstScoreList[x]-secondScoreList[y]);
                 x++;
                 y++;
             }
             else{
                 if(featureFilter==null || featureFilter.map(secondIndexList[y])>=0)
                     sum=sum+secondScoreList[y]*secondScoreList[y];
                 y++;
             }
         }
         while(x<firstNum){
             if(featureFilter==null || featureFilter.map(firstIndexList[x])>=0)
                 sum+=firstScoreList[x]*firstScoreList[x];
             x++;
         }
         while(y<secondNum){
             if(featureFilter==null || featureFilter.map(secondIndexList[y])>=0)
                 sum+=secondScoreList[y]*secondScoreList[y];
             y++;
         }
         return Math.sqrt(sum);
     }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -