Skip to content

Commit 38044b8

Browse files
Demonstrate and fix bug
Co-authored-by: Veselin Nikolov <veselin.nikolov@neotechnology.com>
1 parent eb9edc3 commit 38044b8

File tree

2 files changed

+59
-5
lines changed
  • algo/src/main/java/org/neo4j/gds/influenceMaximization
  • alpha/alpha-algo/src/test/java/org/neo4j/gds/impl/influenceMaximization

2 files changed

+59
-5
lines changed

algo/src/main/java/org/neo4j/gds/influenceMaximization/CELF.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ protected boolean lessThan(long a, long b) {
9595
public LongDoubleScatterMap compute() {
9696
//Find the first node with greedy algorithm
9797
progressTracker.beginSubTask();
98-
greedyPart();
98+
var firstSeedNode = greedyPart();
9999
//Find the next k-1 nodes using the list-sorting procedure
100-
lazyForwardPart();
100+
lazyForwardPart(firstSeedNode);
101101
progressTracker.endSubTask();
102102

103103
return seedSetNodes;
104104
}
105105

106-
private void greedyPart() {
106+
private long greedyPart() {
107107
HugeDoubleArray singleSpreadArray = HugeDoubleArray.newArray(graph.nodeCount());
108108
progressTracker.beginSubTask(graph.nodeCount());
109109
var tasks = PartitionUtils.rangePartition(
@@ -136,15 +136,16 @@ private void greedyPart() {
136136
gain = spreads.cost(highestNode);
137137
spreads.pop();
138138
seedSetNodes.put(highestNode, gain);
139+
return highestNode;
139140
}
140141

141-
private void lazyForwardPart() {
142+
private void lazyForwardPart(long firstSeedNode) {
142143

143144
var independentCascade = ICLazyForwardMC.create(
144145
graph,
145146
propagationProbability,
146147
monteCarloSimulations,
147-
seedSetNodes.keys[0],
148+
firstSeedNode,
148149
(int) seedSetCount,
149150
concurrency,
150151
executorService,
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Neo4j is free software: you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation, either version 3 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License
18+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
19+
*/
20+
package org.neo4j.gds.impl.influenceMaximization;
21+
22+
import org.junit.jupiter.params.ParameterizedTest;
23+
import org.junit.jupiter.params.provider.ValueSource;
24+
import org.neo4j.gds.api.schema.Direction;
25+
import org.neo4j.gds.beta.generator.RandomGraphGenerator;
26+
import org.neo4j.gds.beta.generator.RelationshipDistribution;
27+
import org.neo4j.gds.core.concurrency.Pools;
28+
import org.neo4j.gds.core.utils.progress.tasks.ProgressTracker;
29+
import org.neo4j.gds.influenceMaximization.CELF;
30+
31+
import static org.assertj.core.api.Assertions.assertThat;
32+
33+
class CelfTest {
34+
35+
@ParameterizedTest
36+
@ValueSource(ints = {2, 7})
37+
void shouldNotReturnNegativeGains(int seedSize) {
38+
var graph = RandomGraphGenerator
39+
.builder()
40+
.averageDegree(5)
41+
.relationshipDistribution(RelationshipDistribution.POWER_LAW)
42+
.direction(Direction.DIRECTED)
43+
.nodeCount(60)
44+
.seed(42)
45+
.build()
46+
.generate();
47+
48+
var celf = new CELF(graph, seedSize, 0.1, 3, Pools.DEFAULT, 1, 10, 5, ProgressTracker.NULL_TRACKER).compute();
49+
for (var a : celf) {
50+
assertThat(a.value).isNotNegative();
51+
}
52+
}
53+
}

0 commit comments

Comments
 (0)