-
大小: 69KB文件類型: .rar金幣: 2下載: 0 次發(fā)布日期: 2021-05-10
- 語(yǔ)言: Java
- 標(biāo)簽: HITS??java實(shí)現(xiàn)??
資源簡(jiǎn)介
java實(shí)現(xiàn)HITS算法。
包含一個(gè)文檔說(shuō)明。文檔是用的別人的。

代碼片段和文件信息
package?hits;
import?java.util.HashMap;
import?java.util.List;
import?java.util.Map;
public?class?HITS?{
WebGraph?webGraph;
Map?authorityScores;
Map?hubScores;
int?nodeCount;
public?HITS(WebGraph?webGraph)
{
this.webGraph=webGraph;
this.authorityScores?=?new?HashMap();
this.hubScores?=?new?HashMap();
this.nodeCount?=?webGraph.getNodeCount();
//?初始的內(nèi)容權(quán)威度和鏈接權(quán)威度均設(shè)為1
for?(int?i?=?0;?i? this.authorityScores.put(i?1.0);
this.hubScores.put(i?1.0);
}
//?計(jì)算結(jié)點(diǎn)的內(nèi)容權(quán)威度和鏈接權(quán)威度?指定最大迭代次數(shù)為25
computeHITS(1000);
}
/**
?*?計(jì)算結(jié)點(diǎn)的內(nèi)容權(quán)威度和鏈接權(quán)威度
?*?@param?numIterations?最大迭代次數(shù)
?*/
private?void?computeHITS(int?numIterations)?{
//?迭代次數(shù)
int?iterNum?=?numIterations;
//?上一次迭代的內(nèi)容權(quán)威度和鏈接權(quán)威度?初始值均設(shè)為0
Map?preAuthorityScore?=?new?HashMap();
Map?preHubScore?=?new?HashMap();
for?(int?i?=?0;?i? preAuthorityScore.put(i?0.0);
preHubScore.put(i?0.0);
}
System.out.println(“第0次迭代:“);
printAuthorAndHub();
//?如果未達(dá)到最大迭代次數(shù)或未收斂?則繼續(xù)迭代
while?((numIterations--)?>?0&&?!isConvergence(preAuthorityScore?authorityScores
preHubScore?hubScores))?
{
System.out.println(“第“?+?(iterNum?-?numIterations)?+?“次迭代:“);
for?(int?i?=?0;?i? List?inlinks?=?webGraph.getInlinks(i);?//?入鏈接集
double?authorityScore?=?0;?//?內(nèi)容權(quán)威度
for?(Integer?in?:?inlinks)?{
//System.out.println(in);
//?內(nèi)容權(quán)威度等于所有入鏈接的鏈接權(quán)威度之和
authorityScore?+=?hubScores.get(in).doubleValue();
}
authorityScores.put(i?authorityScore);
}
for?(int?i?=?0;?i? List?outlinks?=?webGraph.getOutlinks(i);?//?出鏈接集
double?hubScore?=?0;?//?鏈接權(quán)威度
for?(Integer?out?:?outlinks)?{
//System.out.println(out);
//?鏈接權(quán)威度等于所有出鏈接的內(nèi)容權(quán)威度之和
hubScore?+=?authorityScores.get(out).doubleValue();
}
hubScores.put(i?hubScore);
}
//?歸一化(使用最大值)
double?aMax?=?getMaxValue(authorityScores);
double?hMax?=?getMaxValue(hubScores);
for?(int?i?=?0;?i? double?aScore?=?authorityScores.get(i);
double?hScore?=?hubScores.get(i);
authorityScores.put(i?aScore?/?aMax);
hubScores.put(i?hScore?/?hMax);
}
//?輸出每次迭代所得的值
printAuthorAndHub();
}
}
private?boolean?isConvergence(Map?preAuthorityScore
Map?authorityScores2
Map?preHubScore?Map?hubScores2)?{
for(int?i=0;i {
double?e=?Math.abs(authorityScores2.get(i)-preAuthorityScore.get(i))+Math.abs(hubScores2.get(i)-preHubScore.get(i));
if(e<0.00001)
{
return?true;
}
}
return?false;
}
private?double?getMaxValue(Map?authorityScores2)?{
double?max=0;
for(int?i=0;i
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件????????301??2015-01-25?11:12??HITS\.classpath
?????文件????????380??2015-01-25?11:12??HITS\.project
?????文件????????598??2015-01-25?11:12??HITS\.settings\org.eclipse.jdt.core.prefs
?????文件???????4580??2015-01-25?14:16??HITS\bin\hits\HITS.class
?????文件????????956??2015-01-25?13:38??HITS\bin\hits\Main.class
?????文件???????4441??2015-01-25?14:08??HITS\bin\hits\WebGraph.class
?????文件?????????34??2015-01-25?11:25??HITS\hits.txt
?????文件???????3664??2015-01-25?14:16??HITS\src\hits\HITS.java
?????文件????????466??2015-01-25?13:38??HITS\src\hits\Main.java
?????文件???????3206??2015-01-25?14:08??HITS\src\hits\WebGraph.java
?????文件?????110592??2015-01-25?14:24??HITS\信息檢索之HITS算法.doc
?????目錄??????????0??2015-01-25?14:28??HITS\bin\hits
?????目錄??????????0??2015-01-25?14:28??HITS\src\hits
?????目錄??????????0??2015-01-25?14:28??HITS\.settings
?????目錄??????????0??2015-01-25?14:28??HITS\bin
?????目錄??????????0??2015-01-25?14:28??HITS\src
?????目錄??????????0??2015-01-25?14:28??HITS
-----------?---------??----------?-----??----
???????????????129218????????????????????17
評(píng)論
共有 條評(píng)論