2 * Created on Jul 12, 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.util;
14 import java.util.Collection;
16 import org.apache.commons.collections15.Transformer;
18 import edu.uci.ics.jung.algorithms.scoring.HITS;
21 * Methods for assigning values (to be interpreted as prior probabilities) to vertices in the context
22 * of random-walk-based scoring algorithms.
24 public class ScoringUtils
27 * Assigns a probability of 1/<code>roots.size()</code> to each of the elements of <code>roots</code>.
28 * @param <V> the vertex type
29 * @param roots the vertices to be assigned nonzero prior probabilities
32 public static <V> Transformer<V, Double> getUniformRootPrior(Collection<V> roots)
34 final Collection<V> inner_roots = roots;
35 Transformer<V, Double> distribution = new Transformer<V, Double>()
37 public Double transform(V input)
39 if (inner_roots.contains(input))
40 return new Double(1.0 / inner_roots.size());
50 * Returns a Transformer that hub and authority values of 1/<code>roots.size()</code> to each
51 * element of <code>roots</code>.
52 * @param <V> the vertex type
53 * @param roots the vertices to be assigned nonzero scores
54 * @return a Transformer that assigns uniform prior hub/authority probabilities to each root
56 public static <V> Transformer<V, HITS.Scores> getHITSUniformRootPrior(Collection<V> roots)
58 final Collection<V> inner_roots = roots;
59 Transformer<V, HITS.Scores> distribution =
60 new Transformer<V, HITS.Scores>()
62 public HITS.Scores transform(V input)
64 if (inner_roots.contains(input))
65 return new HITS.Scores(1.0 / inner_roots.size(), 1.0 / inner_roots.size());
67 return new HITS.Scores(0.0, 0.0);