2 * Created on Jul 14, 2007
4 * Copyright (c) 2007, the JUNG Project and the Regents of the University
8 * This software is open-source under the BSD license; see either
10 * http://jung.sourceforge.net/license.txt for a description.
12 package edu.uci.ics.jung.algorithms.scoring;
14 import org.apache.commons.collections15.Transformer;
16 import edu.uci.ics.jung.graph.Hypergraph;
19 * An abstract class for iterative random-walk-based vertex scoring algorithms
21 * fixed probability, for each vertex, of 'jumping' to that vertex at each
22 * step in the algorithm (rather than following a link out of that vertex).
24 * @param <V> the vertex type
25 * @param <E> the edge type
26 * @param <S> the score type
28 public abstract class AbstractIterativeScorerWithPriors<V,E,S> extends
29 AbstractIterativeScorer<V,E,S> implements VertexScorer<V,S>
32 * The prior probability of each vertex being visited on a given
33 * 'jump' (non-link-following) step.
35 protected Transformer<V,? extends S> vertex_priors;
38 * The probability of making a 'jump' at each step.
40 protected double alpha;
43 * Creates an instance for the specified graph, edge weights, vertex
44 * priors, and jump probability.
45 * @param g the graph whose vertices are to be assigned scores
46 * @param edge_weights the edge weights to use in the score assignment
47 * @param vertex_priors the prior probabilities of each vertex being 'jumped' to
48 * @param alpha the probability of making a 'jump' at each step
50 public AbstractIterativeScorerWithPriors(Hypergraph<V,E> g,
51 Transformer<E,? extends Number> edge_weights,
52 Transformer<V,? extends S> vertex_priors, double alpha)
54 super(g, edge_weights);
55 this.vertex_priors = vertex_priors;
61 * Creates an instance for the specified graph, vertex priors, and jump
62 * probability, with edge weights specified by the subclass.
63 * @param g the graph whose vertices are to be assigned scores
64 * @param vertex_priors the prior probabilities of each vertex being 'jumped' to
65 * @param alpha the probability of making a 'jump' at each step
67 public AbstractIterativeScorerWithPriors(Hypergraph<V,E> g,
68 Transformer<V,? extends S> vertex_priors, double alpha)
71 this.vertex_priors = vertex_priors;
77 * Initializes the state of this instance.
80 public void initialize()
83 // initialize output values to priors
84 // (output and current are swapped before each step(), so current will
85 // have priors when update()s start happening)
86 for (V v : graph.getVertices())
87 setOutputValue(v, getVertexPrior(v));
91 * Returns the prior probability for <code>v</code>.
92 * @param v the vertex whose prior probability is being queried
93 * @return the prior probability for <code>v</code>
95 protected S getVertexPrior(V v)
97 return vertex_priors.transform(v);
101 * Returns a Transformer which maps each vertex to its prior probability.
102 * @return a Transformer which maps each vertex to its prior probability
104 public Transformer<V, ? extends S> getVertexPriors()
106 return vertex_priors;
110 * Returns the probability of making a 'jump' (non-link-following step).
111 * @return the probability of making a 'jump' (non-link-following step)
113 public double getAlpha()