2525
2626import info .debatty .java .graphs .Graph ;
2727import info .debatty .java .graphs .SimilarityInterface ;
28- import info .debatty .java .graphs .build .NNDescent ;
28+ import info .debatty .java .graphs .build .ThreadedNNDescent ;
2929import java .util .ArrayList ;
3030import java .util .Random ;
31+ import java .util .concurrent .ExecutionException ;
3132
3233public class PruneExample {
3334
34- public static void main (String [] args ) {
35+ public static void main (String [] args ) throws InterruptedException , ExecutionException {
3536 Random r = new Random ();
36- int count = 50000 ;
37- int k = 10 ;
37+ int count = 100000 ;
38+ int k = 20 ;
3839
3940 // Create the nodes
4041 ArrayList <Integer > nodes = new ArrayList <Integer >(count );
@@ -44,9 +45,9 @@ public static void main(String[] args) {
4445 }
4546
4647 // Instantiate and configure the build algorithm
47- NNDescent builder = new NNDescent ();
48+ ThreadedNNDescent builder = new ThreadedNNDescent ();
4849 builder .setK (k );
49- builder .setDelta (0.01 );
50+ builder .setDelta (0.1 );
5051 builder .setRho (0.5 );
5152
5253 builder .setSimilarity (new SimilarityInterface <Integer >() {
@@ -60,44 +61,11 @@ public double similarity(final Integer v1, final Integer v2) {
6061 // Run the algorithm and get computed graph
6162 Graph <Integer > graph = builder .computeGraph (nodes );
6263
64+ System .out .println ("Start prunning..." );
6365 long start = System .nanoTime ();
6466 graph .prune (0.5 );
6567 long end = System .nanoTime ();
6668 System .out .println ("n = " + count );
6769 System .out .println ("time: " + (end - start ));
68-
69- count = 100000 ;
70- k = 10 ;
71-
72- // Create the nodes
73- nodes = new ArrayList <Integer >(count );
74- for (int i = 0 ; i < count ; i ++) {
75- // The value of our nodes will be an int
76- nodes .add (r .nextInt ());
77- }
78-
79- // Instantiate and configure the build algorithm
80- builder = new NNDescent ();
81- builder .setK (k );
82- builder .setDelta (0.01 );
83- builder .setRho (0.5 );
84-
85- builder .setSimilarity (new SimilarityInterface <Integer >() {
86-
87- @ Override
88- public double similarity (final Integer v1 , final Integer v2 ) {
89- return 1.0 / (1.0 + Math .abs (v1 - v2 ));
90- }
91- });
92-
93- // Run the algorithm and get computed graph
94- graph = builder .computeGraph (nodes );
95-
96- start = System .nanoTime ();
97- graph .prune (0.5 );
98- end = System .nanoTime ();
99- System .out .println ("n = " + count );
100- System .out .println ("time: " + (end - start ));
101-
10270 }
10371}
0 commit comments