From fb3f1cc3106e5cac347ea33fac104c65af83a479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?A=C3=A9cio=20Santos?= Date: Wed, 1 Nov 2017 15:31:27 -0400 Subject: [PATCH] Removed legacy linkanalysis package (#136) --- .../link/linkanalysis/HITS.java | 275 ------------ .../link/linkanalysis/InOutLinks.java | 75 ---- .../link/linkanalysis/SALSA.java | 404 ------------------ 3 files changed, 754 deletions(-) delete mode 100644 src/main/java/focusedCrawler/link/linkanalysis/HITS.java delete mode 100644 src/main/java/focusedCrawler/link/linkanalysis/InOutLinks.java delete mode 100644 src/main/java/focusedCrawler/link/linkanalysis/SALSA.java diff --git a/src/main/java/focusedCrawler/link/linkanalysis/HITS.java b/src/main/java/focusedCrawler/link/linkanalysis/HITS.java deleted file mode 100644 index 7ffee3190..000000000 --- a/src/main/java/focusedCrawler/link/linkanalysis/HITS.java +++ /dev/null @@ -1,275 +0,0 @@ -package focusedCrawler.link.linkanalysis; - -import java.io.IOException; -import java.net.URL; -import java.net.URLDecoder; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Vector; - -import focusedCrawler.link.BipartiteGraphRepository; -import focusedCrawler.util.parser.BackLinkNeighborhood; -import focusedCrawler.util.parser.LinkNeighborhood; -import focusedCrawler.util.persistence.Tuple; -import focusedCrawler.util.vsm.VSMElement; -import focusedCrawler.util.vsm.VSMElementComparator; - -/** - * This class implements the HITS algorithm - * @author lbarbosa - * - */ - - -public class HITS { - - private BipartiteGraphRepository graphRep; - - private HashMap authValues; - - private HashMap hubValues; - - private double maxAuth = 0; - - private double maxHub = 0; - - private int iterations = 1; - - private VSMElement[] hubRelevance; - - private VSMElement[] authRelevance; - - - public HITS(){ - this.authValues = new HashMap(); - this.hubValues = new HashMap(); - } - - public HITS(BipartiteGraphRepository graphRep){ - this.graphRep = graphRep; - this.authValues = new HashMap(); - this.hubValues = new HashMap(); - } - - - public VSMElement[] getHubRelevance(){ - return hubRelevance; - } - - public VSMElement[] getAuthRelevance(){ - return authRelevance; - } - - public void originalHITS() throws Exception{ - Tuple[] authTuples = graphRep.getAuthGraph(); - Tuple[] hubTuples = graphRep.getHubGraph(); -// Tuple[] authTuples = new Tuple[7]; -// Tuple t1 = new Tuple("D", "A###"); -// Tuple t2 = new Tuple("E", "A###"); -// Tuple t3 = new Tuple("F", "A###B###"); -// Tuple t4 = new Tuple("G", "B###"); -// Tuple t5 = new Tuple("H", "B###C###"); -// Tuple t6 = new Tuple("I", "B###C###"); -// Tuple t7 = new Tuple("J", "C###"); -// authTuples[0] = t1; -// authTuples[1] = t2; -// authTuples[2] = t3; -// authTuples[3] = t4; -// authTuples[4] = t5; -// authTuples[5] = t6; -// authTuples[6] = t7; -// Tuple[] hubTuples = new Tuple[3]; -// t1 = new Tuple("A", "D###E###F###"); -// t2 = new Tuple("B", "F###G###H###I###"); -// t3 = new Tuple("C", "H###I###J###"); -// hubTuples[0] = t1; -// hubTuples[1] = t2; -// hubTuples[2] = t3; - inicialization(authTuples,hubTuples); -// normalization(); - for (int l = 0; l < iterations; l++) { - updateHub(hubTuples); - maxNormalizationHub(); - updateAuth(authTuples); - maxNormalizationAuth(); -// normalization(); - maxAuth = 0; - maxHub = 0; -// System.out.println(authValues.toString()); -// System.out.println(hubValues.toString()); - print(); - } - setValues(); - } - - private void inicialization(Tuple[] authTuples, Tuple[] hubTuples){ - for (int i = 0; i < authTuples.length; i++) { - authValues.put(authTuples[i].getKey(), new VSMElement(authTuples[i].getKey(), 1)); - } - for (int i = 0; i < hubTuples.length; i++) { - hubValues.put(hubTuples[i].getKey(), new VSMElement(hubTuples[i].getKey(), 1)); - } - } - - private void print() throws IOException{ - Vector topAuths = new Vector(authValues.values()); - Collections.sort(topAuths,new VSMElementComparator()); - System.out.println("-----TOP AUTHS-----"); - for (int i = 0; i < topAuths.size() && i < 50; i++) { - String url = graphRep.getAuthURL(topAuths.elementAt(i).getWord()); - System.out.println(i + ":" + url + "=" + topAuths.elementAt(i).getWeight()); - } - - Vector topHubs = new Vector(hubValues.values()); - Collections.sort(topHubs,new VSMElementComparator()); - System.out.println("-----TOP HUBS-----"); - for (int i = 0; i < topHubs.size() && i < 50; i++) { - String url = graphRep.getHubURL(topHubs.elementAt(i).getWord()).toString(); - System.out.println(i + ":" + URLDecoder.decode(url, "UTF-8") + "=" + topHubs.elementAt(i).getWeight()); - } - } - - private void setValues() throws IOException{ - Vector topAuths = new Vector(authValues.values()); - Collections.sort(topAuths,new VSMElementComparator()); - - authRelevance = new VSMElement[topAuths.size()]; - for (int i = 0; i < topAuths.size(); i++) { - String url = graphRep.getAuthURL(topAuths.elementAt(i).getWord()); - topAuths.elementAt(i).setWord(url); - authRelevance[i] = topAuths.elementAt(i); - } - Vector topHubs = new Vector(hubValues.values()); - Collections.sort(topHubs,new VSMElementComparator()); - hubRelevance = new VSMElement[topHubs.size()]; - for (int i = 0; i < topHubs.size(); i++) { - String url = graphRep.getHubURL(topHubs.elementAt(i).getWord()).toString(); - topHubs.elementAt(i).setWord(url); - hubRelevance[i] = topHubs.elementAt(i); - } - } - - - private void updateAuth(Tuple[] authTuples){ - for (int i = 0; i < authTuples.length; i++) { - String key = authTuples[i].getKey(); - String[] backlinks = parseRecord(authTuples[i].getValue()); - double totalAuth = 0; - for (int j = 0; j < backlinks.length; j++) { - VSMElement value = hubValues.get(backlinks[j]); - if(value != null){ - totalAuth = totalAuth + value.getWeight(); - } - } - if(totalAuth > maxAuth){ - maxAuth = totalAuth; - } - authValues.put(key, new VSMElement(key,totalAuth)); - } - - } - - private void updateHub(Tuple[] hubTuples){ - for (int i = 0; i < hubTuples.length; i++) { - String key = hubTuples[i].getKey(); - String[] outlinks = parseRecord(hubTuples[i].getValue()); - double totalHub = 0; - for (int j = 0; j < outlinks.length; j++) { - VSMElement value = authValues.get(outlinks[j]); - if(value != null){ - totalHub = totalHub + value.getWeight(); - } - } - if(totalHub > maxHub){ - maxHub = totalHub; - } - hubValues.put(key, new VSMElement(key,totalHub)); - } - } - - private void maxNormalizationAuth(){ - Iterator authKeys = authValues.keySet().iterator(); - while(authKeys.hasNext()){ - String key = authKeys.next(); - VSMElement value = authValues.get(key); - authValues.put(key, new VSMElement(key,value.getWeight()/maxAuth)); - } - } - - private void maxNormalizationHub(){ - Iterator hubKeys = hubValues.keySet().iterator(); - while(hubKeys.hasNext()){ - String key = hubKeys.next(); - VSMElement value = hubValues.get(key); - hubValues.put(key, new VSMElement(key,value.getWeight()/maxHub)); - } - } - - - private String[] parseRecord(String strLinks){ - if(strLinks != null){ - return strLinks.split("###"); - }else{ - return null; - } - } - - public void firstIteration(HashSet relSites) throws Exception{ - authValues = new HashMap(); - hubValues = new HashMap(); - Iterator values = relSites.iterator(); - while(values.hasNext()){ - String site = values.next(); - BackLinkNeighborhood[] backlinks = graphRep.getBacklinks(new URL(site)); - if(backlinks == null){ - continue; - } - for (int j = 0; j < backlinks.length; j++) { - VSMElement count = hubValues.get(backlinks[j].getLink()); - if(count == null){ - count = new VSMElement(backlinks[j].getLink(), 0); - } - count.setWeight(count.getWeight()+1); - hubValues.put(backlinks[j].getLink(), count); - LinkNeighborhood[] outlinks = graphRep.getOutlinks(new URL(backlinks[j].getLink())); - for (int i = 0; i < outlinks.length; i++) { - if(outlinks[i] == null){ - continue; - } - if(!relSites.contains(outlinks[i].getLink().toString())){ - VSMElement count1 = authValues.get(outlinks[i].getLink().toString()); - if(count1 == null){ - count1 = new VSMElement(outlinks[i].getLink().toString(), 0); - } - count1.setWeight(count1.getWeight()+1); - authValues.put(outlinks[i].getLink().toString(), count1); - } - } - } - } - System.out.println("------"); - System.out.println("HUB:" + hubValues.size()); - Vector finalHub = new Vector(hubValues.values()); - Collections.sort(finalHub, new VSMElementComparator()); - hubRelevance = new VSMElement[finalHub.size()]; - finalHub.toArray(hubRelevance); - for (int i = 0; i < 100 && i < finalHub.size(); i++) { - VSMElement elem = finalHub.elementAt(i); - System.out.println(elem.getWord() + ":" + elem.getWeight()); - } - System.out.println("------"); - System.out.println("AUTH:" + authValues.size()); - Vector finalAuth = new Vector(authValues.values()); - Collections.sort(finalAuth, new VSMElementComparator()); - authRelevance = new VSMElement[finalAuth.size()]; - finalAuth.toArray(authRelevance); - for (int i = 0; i < 100 && i < finalAuth.size(); i++) { - VSMElement elem = finalAuth.elementAt(i); - System.out.println(elem.getWord() + ":" + elem.getWeight()); - } - - } - -} diff --git a/src/main/java/focusedCrawler/link/linkanalysis/InOutLinks.java b/src/main/java/focusedCrawler/link/linkanalysis/InOutLinks.java deleted file mode 100644 index 4412b4e53..000000000 --- a/src/main/java/focusedCrawler/link/linkanalysis/InOutLinks.java +++ /dev/null @@ -1,75 +0,0 @@ -package focusedCrawler.link.linkanalysis; - -import java.net.URL; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.Vector; - -import focusedCrawler.link.BipartiteGraphRepository; -import focusedCrawler.util.parser.BackLinkNeighborhood; -import focusedCrawler.util.parser.LinkNeighborhood; -import focusedCrawler.util.vsm.VSMElement; -import focusedCrawler.util.vsm.VSMElementComparator; - -public class InOutLinks { - - private BipartiteGraphRepository graphRep; - - public InOutLinks(BipartiteGraphRepository graphRep){ - this.graphRep = graphRep; - } - - public void execute(HashSet relSites) throws Exception{ - HashMap hubCounts = new HashMap(); - HashMap authCounts = new HashMap(); - Iterator values = relSites.iterator(); - while(values.hasNext()){ - String site = values.next(); - BackLinkNeighborhood[] backlinks = graphRep.getBacklinks(new URL(site)); - if(backlinks == null){ - continue; - } - for (int j = 0; j < backlinks.length; j++) { - VSMElement count = hubCounts.get(backlinks[j].getLink()); - if(count == null){ - count = new VSMElement(backlinks[j].getLink(), 0); - } - count.setWeight(count.getWeight()+1); - hubCounts.put(backlinks[j].getLink(), count); - LinkNeighborhood[] outlinks = graphRep.getOutlinks(new URL(backlinks[j].getLink())); - for (int i = 0; i < outlinks.length; i++) { - if(outlinks[i] == null){ - continue; - } - if(!relSites.contains(outlinks[i].getLink().toString())){ - VSMElement count1 = authCounts.get(outlinks[i].getLink().toString()); - if(count1 == null){ - count1 = new VSMElement(outlinks[i].getLink().toString(), 0); - } - count1.setWeight(count1.getWeight()+1); - authCounts.put(outlinks[i].getLink().toString(), count1); - } - } - } - } - System.out.println("------"); - System.out.println("HUB:" + hubCounts.size()); - Vector finalHub = new Vector(hubCounts.values()); - Collections.sort(finalHub, new VSMElementComparator()); - for (int i = 0; i < 100 && i < finalHub.size(); i++) { - VSMElement elem = finalHub.elementAt(i); - System.out.println(elem.getWord() + ":" + elem.getWeight()); - } - System.out.println("------"); - System.out.println("AUTH:" + authCounts.size()); - Vector finalAuth = new Vector(authCounts.values()); - Collections.sort(finalAuth, new VSMElementComparator()); - for (int i = 0; i < 100 && i < finalAuth.size(); i++) { - VSMElement elem = finalAuth.elementAt(i); - System.out.println(elem.getWord() + ":" + elem.getWeight()); - } - } - -} diff --git a/src/main/java/focusedCrawler/link/linkanalysis/SALSA.java b/src/main/java/focusedCrawler/link/linkanalysis/SALSA.java deleted file mode 100644 index 77199d0fb..000000000 --- a/src/main/java/focusedCrawler/link/linkanalysis/SALSA.java +++ /dev/null @@ -1,404 +0,0 @@ -package focusedCrawler.link.linkanalysis; - -import java.io.IOException; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Vector; - -import focusedCrawler.link.BipartiteGraphRepository; -import focusedCrawler.util.persistence.Tuple; -import focusedCrawler.util.vsm.VSMElement; -import focusedCrawler.util.vsm.VSMElementComparator; - -public class SALSA { - - private HashMap> incidenceHubMatrix; - - private HashMap> incidenceAuthMatrix; - - private BipartiteGraphRepository graphRep; - - private HashMap initialValues; - - private HashMap nodeRelevance; - - private boolean pageRank = false; - - private HashMap hubValues = new HashMap(); - - private HashMap authValues = new HashMap(); - - public SALSA(BipartiteGraphRepository graphRep){ - this.graphRep = graphRep; - this.incidenceHubMatrix = new HashMap>(); - this.incidenceAuthMatrix = new HashMap>(); - this.initialValues = new HashMap(); - this.nodeRelevance = new HashMap(); - } - - public VSMElement[] getHubValues() throws IOException{ - Iterator elems = hubValues.values().iterator(); - VSMElement[] result = new VSMElement[hubValues.values().size()]; - int i = 0; - while(elems.hasNext()){ - VSMElement elem = elems.next(); - String id = elem.getWord(); - String url = graphRep.getHubURL(id); - elem.setWord(url); - result[i] = elem; - i++; - } - return result; - } - - public VSMElement[] getAuthValues(){ - Iterator elems = authValues.values().iterator(); - VSMElement[] result = new VSMElement[authValues.values().size()]; - int i = 0; - while(elems.hasNext()){ - VSMElement elem = elems.next(); - String id = elem.getWord(); - String url = graphRep.getAuthURL(id); - elem.setWord(url); - result[i] = elem; - i++; - } - return result; - } - - public void setPageRank(boolean pageRank){ - this.pageRank = pageRank; - } - - public void setNodeRelevance(HashMap nr){ - this.nodeRelevance = nr; - } - - public void execute() throws Exception{ - createInitialMatrices(); - hubValues = initialValues; - authValues = initialValues; - for (int i = 0; i < 10; i++) { - System.out.println("Iteration:" + i); - hubValues = updateVector(incidenceHubMatrix,hubValues,"hub"); - authValues = updateVector(incidenceAuthMatrix,authValues,"auth"); - } - Vector sortedNodes = new Vector(hubValues.values()); - Collections.sort(sortedNodes, new VSMElementComparator()); - for (int i = 0; i < sortedNodes.size() && i < 100; i++) { - VSMElement elem = sortedNodes.elementAt(i); - String hubURL = graphRep.getHubURL(elem.getWord()).toString(); - System.out.println(i + ":HUB:" + elem.getWord() + ":" + hubURL + "=" + elem.getWeight()); - } - sortedNodes = new Vector(authValues.values()); - Collections.sort(sortedNodes, new VSMElementComparator()); - for (int i = 0; i < sortedNodes.size() && i < 100; i++) { - VSMElement elem = sortedNodes.elementAt(i); - if(graphRep.getAuthURL(elem.getWord()) != null){ - String authURL = graphRep.getAuthURL(elem.getWord()).toString(); - System.out.println(i + ":AUTH:" + elem.getWord() + ":" + authURL + "=" + elem.getWeight()); - } - } - - } - - private void createInitialMatrices() throws Exception{ - HashMap> lr = new HashMap>(); - HashMap> lcTranspose = new HashMap>(); -// Tuple[] authTuples = new Tuple[8]; -// Tuple[] hubTuples = new Tuple[3]; -// authTuples[0] = new Tuple("1","2###"); -// authTuples[1] = new Tuple("0","2###"); -// authTuples[2] = new Tuple("3","2###5###"); -// authTuples[3] = new Tuple("4","5###"); -// authTuples[4] = new Tuple("6","5###7###"); -// authTuples[5] = new Tuple("8","7###"); -// authTuples[6] = new Tuple("9","7###"); -// authTuples[7] = new Tuple("10","7###"); -// hubTuples[0] = new Tuple("2","0###1###3###"); -// hubTuples[1] = new Tuple("5","3###4###6###"); -// hubTuples[2] = new Tuple("7","6###8###9###10###"); - Tuple[] hubTuples = graphRep.getHubGraph(); - for (int i = 0; i < hubTuples.length; i++) {//prob for hubs - String key = hubTuples[i].getKey(); - if(initialValues.get(key) == null){ - initialValues.put(key, new VSMElement(key, 1)); - } - Vector row = lr.get(key); - if(row == null){ - row = new Vector(); - } - String values = hubTuples[i].getValue(); - String[] outlinks = parseRecord(values); - for (int j = 0; j < outlinks.length; j++) { - if(initialValues.get(outlinks[j]) == null){ - initialValues.put(outlinks[j], new VSMElement(outlinks[j], 1)); - } - row.add(new VSMElement(outlinks[j], 1/(double)outlinks.length)); - } - lr.put(key,row); - } - System.out.println("LR:" + lr.size()); - Tuple[] authTuples = graphRep.getAuthGraph(); - for (int i = 0; i < authTuples.length; i++) { - String key = authTuples[i].getKey(); - if(initialValues.get(key) == null){ - initialValues.put(key, new VSMElement(key, 1)); - } - Vector row = lcTranspose.get(key); - if(row == null){ - row = new Vector(); - } - String values = authTuples[i].getValue(); - String[] backlinks = parseRecord(values); - for (int j = 0; j < backlinks.length; j++) { - if(initialValues.get(backlinks[j]) == null){ - initialValues.put(backlinks[j], new VSMElement(backlinks[j], 1)); - } - row.add(new VSMElement(backlinks[j], 1/(double)backlinks.length)); - } - lcTranspose.put(key,row); - } - System.out.println("LC:" + lcTranspose.size()); - incidenceHubMatrix = multiply(lr,lcTranspose); - System.out.println("incidenceHubMatrix:" + incidenceHubMatrix.size()); - incidenceAuthMatrix = multiply(lcTranspose,lr); - System.out.println(incidenceAuthMatrix.size()); - } - - - private HashMap> transpose(HashMap> matrix){ - HashMap> result = new HashMap>(); - Iterator keys = matrix.keySet().iterator(); - while(keys.hasNext()){ - String key = keys.next(); - Vector elems = matrix.get(key); - for (int i = 0; i < elems.size(); i++) { - String newKey = elems.elementAt(i).getWord(); - Vector newValues = result.get(newKey); - if(newValues == null){ - newValues = new Vector(); - } - newValues.add(new VSMElement(key, elems.elementAt(i).getWeight())); - result.put(newKey,newValues); - } - } - return result; - } - - private HashMap> multiply(HashMap> matrix1, HashMap> matrix2){ - HashMap> result = new HashMap>(); - HashMap> matrix2Trans = transpose(matrix2); - Iterator keys = matrix1.keySet().iterator(); - while(keys.hasNext()){ - String key = keys.next(); - Vector elemsMatrix1 = matrix1.get(key); - Iterator keys2 = matrix2Trans.keySet().iterator(); - while(keys2.hasNext()){ - String key2 = keys2.next(); - Vector elemsMatrix2 = matrix2Trans.get(key2); - double sum = sumVectors(elemsMatrix1,elemsMatrix2); - if(sum != 0){ - Vector resultElems = result.get(key); - if(resultElems == null){ - resultElems = new Vector(); - } - resultElems.add(new VSMElement(key2, sum)); - result.put(key, resultElems); - } - } - } - return result; - } - - private double sumVectors(Vector v1, Vector v2){ - double result = 0; - for (int i = 0; i < v1.size(); i++) { - VSMElement elem1 = v1.elementAt(i); - for (int j = 0; j < v2.size(); j++) { - VSMElement elem2 = v2.elementAt(j); - if(elem1.getWord().equals(elem2.getWord())){ - result = result + elem1.getWeight()*elem2.getWeight(); - } - } - } - return result; - } - - private HashMap updateVector(HashMap> incidenceMatrix, HashMap values, String prefix){ - HashMap newValues = new HashMap(); - for (Iterator iterator = incidenceMatrix.keySet().iterator(); iterator.hasNext();) { - String key = (String) iterator.next(); - Vector neighbours = incidenceMatrix.get(key); - for (int j = 0; j < neighbours.size(); j++) { - VSMElement value = values.get(neighbours.elementAt(j).getWord()); - if(value != null){ - double newValue = (value.getWeight()*neighbours.elementAt(j).getWeight()); - VSMElement elem = newValues.get(neighbours.elementAt(j).getWord()); - if(elem != null){ - newValue = newValue + elem.getWeight(); - } - newValues.put(neighbours.elementAt(j).getWord(), new VSMElement(neighbours.elementAt(j).getWord(),newValue)); - } - } - } - if(pageRank){ - Iterator iter = newValues.keySet().iterator(); - while(iter.hasNext()){ - String key = iter.next(); - double rel = 0; - VSMElement nodeRel = nodeRelevance.get(key + "_" + prefix); - if(nodeRel != null){ - rel = nodeRel.getWeight(); - } - VSMElement elem = newValues.get(key); - elem.setWeight(0.15 * elem.getWeight() + 0.85 * rel); - } - } - normalize(newValues); - return newValues; - } - - private void normalize(HashMap values){ - //normalize - double total = 0; - Iterator iter = values.keySet().iterator(); - while(iter.hasNext()){ - String key = iter.next(); - VSMElement elem = values.get(key); - total = total + elem.getWeight(); - } - iter = values.keySet().iterator(); - while(iter.hasNext()){ - String key = iter.next(); - VSMElement elem = values.get(key); - elem.setWeight(elem.getWeight()/total); - } - } - - private String[] parseRecord(String strLinks){ - if(strLinks != null){ - return strLinks.split("###"); - }else{ - return null; - } - } - - - private double[][] transpose(double[][] matrix){ - double[][] result = new double[matrix.length][matrix.length]; - for (int i = 0; i < matrix.length; i++) { - for (int j = 0; j < matrix.length; j++) { - result[j][i] = matrix[i][j]; - } - } - return result; - } - - public double[][] multiply(double[][] matrixA, double[][] matrixB){ - double[][] result = new double[matrixA.length][matrixB.length]; - double[][] matrixC = transpose(matrixB); - for (int i = 0; i < result.length; i++) { - double[] matrixArow = matrixA[i]; - for (int j = 0; j < matrixArow.length; j++) { - double[] matrixCrow = matrixC[j]; - for (int k = 0; k < matrixCrow.length; k++) { - result[i][j] = result[i][j] + matrixArow[k]*matrixCrow[k]; - } - } - } - return result; - } - - public void pageRank(){ - double[] seeds = new double[12]; - seeds[1] = 0.33; - seeds[3] = 0.33; - seeds[4] = 0.33; - double[] weights = new double[12]; - weights[0] = 0; - weights[1] = 0; - weights[2] = 1; - weights[3] = 0; - weights[4] = 0; - weights[5] = 0; - weights[6] = 0; - weights[7] = 0; - weights[8] = 0; - weights[9] = 0; - weights[10] = 0; - weights[11] = 0; - double[][] transMatrix = new double[12][12]; - transMatrix[0][2] = 1; - transMatrix[1][2] = 1; - transMatrix[2][0] = 1; - transMatrix[2][1] = 1; - transMatrix[2][3] = 1; - transMatrix[3][2] = 1; - transMatrix[3][5] = 1; - transMatrix[4][5] = 1; - transMatrix[5][3] = 1; - transMatrix[5][4] = 1; - transMatrix[5][6] = 1; - transMatrix[6][5] = 1; - transMatrix[6][7] = 1; - transMatrix[7][6] = 1; - transMatrix[7][8] = 1; - transMatrix[7][9] = 1; - transMatrix[7][10] = 1; - transMatrix[7][11] = 1; - transMatrix[8][7] = 1; - transMatrix[9][7] = 1; - transMatrix[10][7] = 1; - transMatrix[11][7] = 1; - double[][] lr = new double[12][12]; - for (int i = 0; i < lr.length; i++) { - double[] row = transMatrix[i]; - double total = 0; - for (int j = 0; j < row.length; j++) { - total = total + row[j]; - } - for (int j = 0; j < row.length; j++) { - lr[i][j] = row[j]/total; - } - } - double[][] lc = new double[12][12]; - for (int i = 0; i < lc.length; i++) { - double total = 0; - for (int j = 0; j < lc.length; j++) { - total = total + transMatrix[j][i]; - } - for (int j = 0; j < lc.length; j++) { - lc[j][i] = transMatrix[j][i]/total; - } - } - double[][] hubMatrix = new double[12][12]; - hubMatrix = multiply(lr,transpose(lc)); -// double[][] authMatrix = new double[12][12]; -// authMatrix = multiply(transpose(lc),lr); - for (int l = 0; l < 100; l++) { - double total = 0; - for (int i = 0; i < weights.length; i++) { - total = total + weights[i]; - } - for (int i = 0; i < weights.length; i++) { - weights[i] = weights[i]/total; - } - double[] newWeights = new double[12]; - for (int i = 0; i < hubMatrix.length; i++) { - double[] values = hubMatrix[i]; - double newValue = 0; - for (int j = 0; j < values.length; j++) { - newValue= newValue + weights[j]*values[j]; - } -// newWeights[i] = 0.85*newValue + 0.15*seeds[i]; - newWeights[i] = newValue; - System.out.print(i + ":" + newWeights[i] + " "); - } - System.out.println("\n"); - weights = newWeights; - } - } - -}