File tree Expand file tree Collapse file tree 4 files changed +79
-1
lines changed
algorithms-compute-facade/src
main/java/org/neo4j/gds/community
algo/src/main/java/org/neo4j/gds/hdbscan Expand file tree Collapse file tree 4 files changed +79
-1
lines changed Original file line number Diff line number Diff line change 2121
2222import org .neo4j .gds .collections .ha .HugeLongArray ;
2323
24- public record Labels (HugeLongArray labels , long numberOfNoisePoints , long numberOfClusters ) {}
24+ public record Labels (HugeLongArray labels , long numberOfNoisePoints , long numberOfClusters ) {
25+
26+ public static Labels EMPTY = new Labels (HugeLongArray .newArray (0 ),0 , 0 );
27+ }
Original file line number Diff line number Diff line change 3434import org .neo4j .gds .conductance .ConductanceResult ;
3535import org .neo4j .gds .core .concurrency .DefaultPool ;
3636import org .neo4j .gds .core .utils .progress .JobId ;
37+ import org .neo4j .gds .hdbscan .HDBScan ;
38+ import org .neo4j .gds .hdbscan .HDBScanParameters ;
39+ import org .neo4j .gds .hdbscan .Labels ;
3740import org .neo4j .gds .result .TimedAlgorithmResult ;
3841import org .neo4j .gds .termination .TerminationFlag ;
3942
@@ -162,4 +165,35 @@ CompletableFuture<TimedAlgorithmResult<ConductanceResult>> conductance(
162165 );
163166 }
164167
168+ CompletableFuture <TimedAlgorithmResult <Labels >> hdbscan (
169+ Graph graph ,
170+ HDBScanParameters parameters ,
171+ JobId jobId ,
172+ boolean logProgress
173+ ) {
174+
175+ if (graph .isEmpty ()) {
176+ return CompletableFuture .completedFuture (TimedAlgorithmResult .empty (Labels .EMPTY ));
177+ }
178+
179+ var progressTracker = progressTrackerFactory .create (
180+ tasks .hdbscan (graph ),
181+ jobId ,
182+ parameters .concurrency (),
183+ logProgress
184+ );
185+
186+ var algorithm = new HDBScan (
187+ graph ,
188+ graph .nodeProperties (parameters .nodeProperty ()),
189+ parameters ,
190+ progressTracker ,
191+ terminationFlag
192+ );
193+
194+ return algorithmCaller .run (
195+ algorithm ::compute ,
196+ jobId
197+ );
198+ }
165199}
Original file line number Diff line number Diff line change 3434import org .neo4j .gds .conductance .ConductanceParameters ;
3535import org .neo4j .gds .conductance .ConductanceResult ;
3636import org .neo4j .gds .core .utils .progress .JobId ;
37+ import org .neo4j .gds .hdbscan .HDBScanParameters ;
38+ import org .neo4j .gds .hdbscan .Labels ;
3739import org .neo4j .gds .termination .TerminationFlag ;
3840
3941import static org .assertj .core .api .Assertions .assertThat ;
@@ -114,4 +116,21 @@ void conductance(){
114116 verifyNoInteractions (algorithmCallerMock );
115117 }
116118
119+ @ Test
120+ void hdbscan (){
121+
122+ var future = facade .hdbscan (
123+ graph ,
124+ mock (HDBScanParameters .class ),
125+ jobIdMock ,
126+ false
127+ );
128+
129+ var results = future .join ();
130+
131+ assertThat (results .result ()).isEqualTo (Labels .EMPTY );
132+ verifyNoInteractions (progressTrackerFactoryMock );
133+ verifyNoInteractions (algorithmCallerMock );
134+ }
135+
117136}
Original file line number Diff line number Diff line change 3939import org .neo4j .gds .extension .IdFunction ;
4040import org .neo4j .gds .extension .Inject ;
4141import org .neo4j .gds .extension .TestGraph ;
42+ import org .neo4j .gds .hdbscan .HDBScanParameters ;
4243import org .neo4j .gds .logging .Log ;
4344import org .neo4j .gds .termination .TerminationFlag ;
4445
@@ -158,4 +159,25 @@ void conductance(){
158159 assertThat (results .result ().globalAverageConductance ()).isGreaterThan (0d );
159160 assertThat (results .computeMillis ()).isNotNegative ();
160161 }
162+
163+ @ Test
164+ void hdbscan (){
165+ var future = facade .hdbscan (
166+ graph ,
167+ new HDBScanParameters (
168+ new Concurrency (4 ),
169+ 1 ,
170+ 3 ,
171+ 1 ,
172+ "prop"
173+ ),
174+ jobIdMock ,
175+ false
176+ );
177+
178+ var results = future .join ();
179+
180+ assertThat (results .result ().labels ().toArray ()).hasSize (3 );
181+ assertThat (results .computeMillis ()).isNotNegative ();
182+ }
161183}
You can’t perform that action at this time.
0 commit comments