/** This method does the following length transformation: * * <pre> c'(v,w) = c(v,w) - d (s,w) + d (s,v) </pre> * * @param graph1 the graph * @param slTrans The shortest length transformer * @return the transformed graph * @since 0.3.0 */ private Transformer<E, Double> lengthTransformation(Graph<V, E> graph1, Transformer<V, Number> slTrans) { Map<E, Double> map = new LinkedHashMap<E, Double>(); for (E link : graph1.getEdges()) { double newWeight; if (slTrans.transform(graph1.getSource(link)) == null) { newWeight = Double.MAX_VALUE; } else { newWeight = nev.transform(link) - slTrans.transform(graph1.getDest(link)).doubleValue() + slTrans.transform(graph1.getSource(link)).doubleValue(); if (newWeight < 0 || newWeight > -1e-6) newWeight = 0; /* Numerical errors */ } map.put(link, newWeight); } return MapTransformer.getInstance(map); }
private static void groupCluster(AggregateLayout<VisualNode,VisualEdge> layout, Set<VisualNode> vertices) { if(vertices.size() < layout.getGraph().getVertexCount()) { Point2D center = layout.transform(vertices.iterator().next()); Graph<VisualNode,VisualEdge> subGraph = DirectedSparseGraph.<VisualNode,VisualEdge>getFactory().create(); for(VisualNode v : vertices) { subGraph.addVertex(v); } Layout<VisualNode,VisualEdge> subLayout = new VisualCirclesLayout(subGraph); subLayout.setInitializer(HecataeusViewer.getActiveViewer().getGraphLayout()); subLayout.setSize(new Dimension(40,40)); layout.put(subLayout,center); HecataeusViewer.vv.getRenderContext().setVertexFillPaintTransformer(MapTransformer.<VisualNode,Paint>getInstance(vertexPaints)); HecataeusViewer.getActiveViewer().repaint(); } }
/** * This method does the following length transformation: * * <pre> * c'(v,w) = c(v,w) - d (s,w) + d (s,v) * </pre> * * @param graph1 * the graph * @param slTrans * The shortest length transformer * @return the transformed graph */ private Transformer<E, Double> lengthTransformation(Graph<V, E> graph1, Transformer<V, Number> slTrans) { Map<E, Double> map = new HashMap<E, Double>(); for (E link : graph1.getEdges()) { double newWeight = nev.transform(link).doubleValue() - slTrans.transform(graph1.getDest(link)).doubleValue() + slTrans.transform(graph1.getSource(link)).doubleValue(); map.put(link, newWeight); } return MapTransformer.getInstance(map); }
@Override protected PageRankWithPriors<Vertex, Edge> performPageRank() { PageRankWithPriors<Vertex, Edge> pr = new PageRankWithPriors<Vertex, Edge>( graph, MapTransformer.getInstance(edgeWeights), getRootPrior(graph.getVertices()), 0.13); pr.setMaxIterations(250); pr.evaluate(); return pr; }
@Override protected PageRankWithPriors<Vertex, Edge> performPageRank() { PageRankWithPriors<Vertex, Edge> pr = new PageRankWithPriors<Vertex, Edge>( graph, MapTransformer.getInstance(edgeWeights), getRootPrior(graph.getVertices()), 0.09); pr.setMaxIterations(iterations); pr.evaluate(); return pr; }
@Override protected PageRankWithPriors<Vertex, Edge> performPageRank() { PageRankWithPriors<Vertex, Edge> pr = new PageRankWithPriors<Vertex, Edge>( graph, MapTransformer.getInstance(edgeWeights), getRootPrior(graph.getVertices()), 0.13); pr.setMaxIterations(75); pr.evaluate(); return pr; }
protected PageRankWithPriors<Vertex, Edge> performPageRank() { PageRankWithPriors<Vertex, Edge> pr = new PageRankWithPriors<Vertex, Edge>( graph, MapTransformer.getInstance(edgeWeights), getRootPrior(graph.getVertices()), 0.15); pr.setMaxIterations(200); pr.evaluate(); return pr; }
protected PageRankWithPriors<Vertex, Edge> performPageRank() { PageRankWithPriors<Vertex, Edge> pr = new PageRankWithPriors<Vertex, Edge>(graph, MapTransformer.getInstance(edgeWeights), getRootPrior(graph.getVertices()), 0.15); pr.setMaxIterations(200); pr.evaluate(); return pr; }
@Override public String process(Map<DisambiguatedEntity, Integer> map, Paragraph p, Languages lang) { Set<String> entitySet = new HashSet<String>(); List<String> entities = new LinkedList<String>(); for (Map.Entry<DisambiguatedEntity, Integer> entry : map.entrySet()) { entities.add(entry.getKey().getEntityUri()); entitySet.add(entry.getKey().getEntityUri()); } if (entities.size() == 0) { return ""; } else { computeWord2VecSimilarities(entitySet); DirectedGraph<Vertex, Edge> graph = buildGraph(entities); PageRank<Vertex, Edge> pr = new PageRank<Vertex, Edge>(graph, MapTransformer.getInstance(edgeWeights), 0.1); pr.setMaxIterations(100); pr.evaluate(); Collection<Vertex> vertexCol = graph.getVertices(); String topEntity = null; double max = 0; for (Vertex v : vertexCol) { Double score = pr.getVertexScore(v); if (score > max) { topEntity = v.getUris().get(0); max = score; } } return topEntity; } }
/** * This method does the following length transformation: * <p/> * <pre> * c'(v,w) = c(v,w) - d (s,w) + d (s,v) * </pre> * * @param graph1 the graph * @param slTrans The shortest length transformer * @return the transformed graph */ private Transformer<E, Double> lengthTransformation(Graph<V, E> graph1, Transformer<V, Number> slTrans) { Map<E, Double> map = new HashMap<E, Double>(); for (E link : graph1.getEdges()) { double newWeight = nev.transform(link).doubleValue() - slTrans.transform(graph1.getDest(link)).doubleValue() + slTrans.transform(graph1.getSource(link)).doubleValue(); map.put(link, newWeight); } return MapTransformer.getInstance(map); }
/** * Loads the stationary distribution into a vector if it was passed in, * or calculates it if not. * * @return DoubleMatrix1D */ private DoubleMatrix1D getStationaryDistribution() { DoubleMatrix1D piVector = new DenseDoubleMatrix1D(getVertexCount()); PageRank<V,E> pageRank = new PageRank<V,E>(getGraph(), MapTransformer.getInstance(getEdgeWeights()), 0); pageRank.evaluate(); for (V v : getGraph().getVertices()) piVector.set(mIndexer.get(v), pageRank.getVertexScore(v)); return piVector; }
/** <p>Returns the shortest link-disjoint path pair (in increasing order of weight).</p> <p><b>Important</b>: If only one path can be found, only such a path will be returned.</p> * * @param startVertex Start vertex of the calculated paths * @param endVertex Target vertex of the calculated paths * @return List of paths in increasing order of weight */ private List<List<E>> getDisjointPaths(V startVertex, V endVertex) { List<List<E>> linkDisjointSPs = new LinkedList<List<E>>(); if (!graph.containsVertex(startVertex) || !graph.containsVertex(endVertex) || startVertex.equals(endVertex)) return linkDisjointSPs; /* If target is not reachable, return */ if (dijkstra.getDistance(startVertex, endVertex) == null) return linkDisjointSPs; List<E> sp = dijkstra.getPath(startVertex, endVertex); /* Determine length of shortest path from "source" to any other node */ Map<V, Number> lengthMap = dijkstra.getDistanceMap(startVertex); /* Length transformation */ Transformer<E, Double> lengthTrans = lengthTransformation(graph, MapTransformer.getInstance(lengthMap)); /* Get shortest path in g with reversed shortest path... */ Graph<V, E> revG = reverseEdges(graph, sp); DijkstraShortestPath<V, E> revDijkstra = new DijkstraShortestPath<V, E>(revG, lengthTrans, cached); Number revDistance = revDijkstra.getDistance(startVertex, endVertex); if (revDistance == null || revDistance.doubleValue() == Double.MAX_VALUE) { /* no alternate path, return */ linkDisjointSPs.add(sp); return linkDisjointSPs; } List<E> revSp = revDijkstra.getPath(startVertex, endVertex); validatePath(graph, startVertex, endVertex, sp); validatePath(revG, startVertex, endVertex, revSp); List<E> spCopy = new LinkedList<E>(sp); List<List<E>> paths = findDisjointPaths(sp, revSp); if (paths == null) { /* no disjoint solution found, just return shortest path */ linkDisjointSPs.add(spCopy); return linkDisjointSPs; } /* Check path validity */ for (List<E> path : paths) validatePath(graph, startVertex, endVertex, path); return paths; }
/** * Returns a transformer from vertex sets in the original graph to collapsed vertices * in the transformed graph. */ public Transformer<Set<V>, CV> getSetToCollapsedVertexTransformer() { return MapTransformer.getInstance(set_collapsedv); }