public static aceRelationMatrix <String, String, Double> GetIDMatrix(this freeGraph graph) { List <freeGraphNodeBase> nodes = graph.nodes; List <String> nodeIDs = nodes.Select(x => x.name).ToList(); aceRelationMatrix <String, String, Double> output = new aceRelationMatrix <String, String, Double>(nodeIDs, nodeIDs, 0); foreach (freeGraphNodeBase node in nodes) { var links = graph.GetLinks(node.name, true, true); foreach (freeGraphLinkBase link in links.links) { if (link.nodeNameA == node.name) { output[link.nodeNameA, link.nodeNameB] += link.weight; } else { output[link.nodeNameB, link.nodeNameA] += link.weight; } } } return(output); }
/// <summary> /// Transforms the free graph into relationship matrix /// </summary> /// <param name="graph">The graph.</param> /// <returns></returns> public static aceRelationMatrix <freeGraphNodeBase, freeGraphNodeBase, Double> GetMatrix(this freeGraph graph) { List <freeGraphNodeBase> nodes = graph.nodes; aceRelationMatrix <freeGraphNodeBase, freeGraphNodeBase, Double> output = new aceRelationMatrix <freeGraphNodeBase, freeGraphNodeBase, Double>(nodes, nodes, 0); foreach (freeGraphNodeBase node in nodes) { var links = graph.GetLinks(node.name, true, true); foreach (freeGraphLinkBase link in links.links) { var nodeA = graph.GetNode(link.nodeNameA); var nodeB = graph.GetNode(link.nodeNameB); if (link.nodeNameA == node.name) { output[nodeA, nodeB] += link.weight; } else { output[nodeB, nodeA] += link.weight; } } } return(output); }
public ArrayList GetLinkMatrix() { var loaded = GetLoaded(); if (loaded.Any()) { linkMatrix = new aceRelationMatrix <ISpiderTarget, ISpiderTarget, int>(loaded, items.Values, getLinkCount); return(linkMatrix.GetMatrix()); } else { return(null); } }
public static aceRelationMatrix <String, String, Int32> GetIDMatrix(this freeGraph graph, Int32 scoreFactor) { List <freeGraphNodeBase> nodes = graph.nodes; List <String> nodeIDs = nodes.Select(x => x.name).ToList(); aceRelationMatrix <String, String, Double> output = GetIDMatrix(graph); aceRelationMatrix <String, String, Int32> outputInt32 = new aceRelationMatrix <string, string, Int32>(output.GetXAxis(), output.GetYAxis(), 0); foreach (string kx in output.GetXAxis()) { foreach (string ky in output.GetYAxis()) { outputInt32[kx, ky] = Convert.ToInt32(output[kx, ky] * scoreFactor); } } return(outputInt32); }
public void recalculate(ISpiderTargetCollection targets, double convergence = 0.0001, int checkSteps = 20) { targetToScore = new Dictionary <string, HITSScore>(); foreach (ISpiderTarget target in targets) { targetToScore.Add(target.targetHash, new HITSScore(1, 1)); } aceRelationMatrix <ISpiderTarget, ISpiderTarget, int> matrix = targets.GetAceMatrixRotated(); if (matrix == null) { return; } for (int i = 0; i < checkSteps; i++) { // <---- resets value change record, in order to detect convergence at the end of iteration foreach (ISpiderTarget target in targets) { targetToScore[target.targetHash].resetChangeMeasure(); } // <--- Authority foreach (ISpiderTarget xTarget in matrix.GetXAxis()) { foreach (ISpiderTarget yTarget in matrix.GetYAxis()) { targetToScore[xTarget.targetHash].a += targetToScore[yTarget.targetHash].h; } } // Normalize authority double nfact = 0; foreach (ISpiderTarget target in targets) { nfact += Math.Pow(targetToScore[target.targetHash].a, 2); } nfact = Math.Sqrt(nfact); foreach (ISpiderTarget target in targets) { if (nfact != 0) { targetToScore[target.targetHash].a = targetToScore[target.targetHash].a / nfact; } } // <--- hub foreach (ISpiderTarget xTarget in matrix.GetXAxis()) { foreach (ISpiderTarget yTarget in matrix.GetYAxis()) { targetToScore[yTarget.targetHash].h += targetToScore[xTarget.targetHash].a; } } // <--- normalization nfact = 0; foreach (ISpiderTarget target in targets) { nfact += Math.Pow(targetToScore[target.targetHash].h, 2); } nfact = Math.Sqrt(nfact); foreach (ISpiderTarget target in targets) { targetToScore[target.targetHash].resetChangeMeasure(); if (nfact != 0) { targetToScore[target.targetHash].h = targetToScore[target.targetHash].h / nfact; } } double maxChange = 0; // <---- resets value change record, in order to detect convergence at the end of iteration foreach (ISpiderTarget target in targets) { maxChange = Math.Max(targetToScore[target.targetHash].a_delta, maxChange); maxChange = Math.Max(targetToScore[target.targetHash].h_delta, maxChange); } if (maxChange < convergence) { break; } else { } } }