1 package edu.uci.ics.jung.algorithms.scoring;
2
3 import java.util.HashMap;
4 import java.util.HashSet;
5 import java.util.Map;
6 import java.util.Set;
7
8 import junit.framework.TestCase;
9
10 import com.google.common.base.Functions;
11
12 import edu.uci.ics.jung.algorithms.scoring.util.ScoringUtils;
13 import edu.uci.ics.jung.graph.DirectedGraph;
14 import edu.uci.ics.jung.graph.DirectedSparseMultigraph;
15
16 public class TestKStepMarkov extends TestCase
17 {
18 DirectedGraph<Number,Number> mGraph;
19 double[][] mTransitionMatrix;
20 Map<Number,Number> edgeWeights = new HashMap<Number,Number>();
21
22 @Override
23 protected void setUp()
24 {
25 mGraph = new DirectedSparseMultigraph<Number,Number>();
26 mTransitionMatrix = new double[][]
27 {{0.0, 0.5, 0.5},
28 {1.0/3.0, 0.0, 2.0/3.0},
29 {1.0/3.0, 2.0/3.0, 0.0}};
30
31 for (int i = 0; i < mTransitionMatrix.length; i++)
32 mGraph.addVertex(i);
33
34 for (int i = 0; i < mTransitionMatrix.length; i++) {
35 for (int j = 0; j < mTransitionMatrix[i].length; j++)
36 {
37 if (mTransitionMatrix[i][j] > 0)
38 {
39 int edge = i*mTransitionMatrix.length+j;
40 mGraph.addEdge(edge, i, j);
41 edgeWeights.put(edge, mTransitionMatrix[i][j]);
42 }
43 }
44 }
45 }
46
47 public void testRanker() {
48
49 Set<Number> priors = new HashSet<Number>();
50 priors.add(1);
51 priors.add(2);
52 KStepMarkov<Number,Number> ranker =
53 new KStepMarkov<Number,Number>(mGraph, Functions.forMap(edgeWeights),
54 ScoringUtils.getUniformRootPrior(priors),2);
55
56
57
58 for (int i = 0; i < 10; i++)
59 {
60
61
62
63 ranker.step();
64 }
65
66
67
68 }
69
70 }