Question

I have created a Graph with a set of edges I have (4000K Edges and 4K nodes). Now I want to take 10% of the edges from the corpus to create a train and test data set.

I want to pick an edge in random, verify if the vertices of this edge has an edge with a random vertex. If so, I will remove that edge in the graph and also write that edge in a test file. So, that later I will predict the edges of the test file using some similarity function.

Logic is I am trying to predict A->C, given A->B and B->C.

Now the problem is, I cannot get a way to randomly pick an edge and randomly pick a vertex in JGraphT. My vertex names are some strings with random numbers.

Any one has a solution for this ?

Était-ce utile?

La solution

There is a possibility. See the example first:

DirectedGraph<String, DefaultEdge> graph = new DefaultDirectedGraph<String, DefaultEdge>(DefaultEdge.class);
Object[] vertexSet = graph.vertexSet().toArray();
Object[] edgeSet = graph.edgeSet().toArray();
String someRndNode = (String) vertexSet [ getSomeRandomNumberBetween(0, vertexSet.length)];
DefaultEdge someRndEdge = (DefaultEdge) edgeSet [ getSomeRandomNumberBetween(0, edgeSet.length)];

You simply get the set of edges and nodes of your graph. Determine a random number based on the arrays. Get the stuff you need out of it.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top