Skip to content

Commit c68167f

Browse files
committed
Use dedicated PageRank variant configs
1 parent 939c441 commit c68167f

File tree

49 files changed

+1186
-421
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1186
-421
lines changed

algo/src/main/java/org/neo4j/gds/algorithms/centrality/PageRankDistributionComputer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
package org.neo4j.gds.algorithms.centrality;
2121

2222
import org.neo4j.gds.core.concurrency.DefaultPool;
23-
import org.neo4j.gds.pagerank.PageRankConfig;
2423
import org.neo4j.gds.pagerank.PageRankResult;
24+
import org.neo4j.gds.pagerank.RankConfig;
2525
import org.neo4j.gds.result.CentralityStatistics;
2626
import org.neo4j.gds.scaling.LogScaler;
2727

@@ -37,7 +37,7 @@ private PageRankDistributionComputer() {}
3737

3838
public static PageRankDistribution computeDistribution(
3939
PageRankResult result,
40-
PageRankConfig configuration,
40+
RankConfig configuration,
4141
boolean shouldComputeCentralityDistribution
4242
) {
4343
Map<String, Object> centralitySummary = new HashMap<>();
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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.pagerank;
21+
22+
import com.carrotsearch.hppc.LongScatterSet;
23+
import org.neo4j.gds.GraphAlgorithmFactory;
24+
import org.neo4j.gds.api.Graph;
25+
import org.neo4j.gds.beta.pregel.Pregel;
26+
import org.neo4j.gds.core.concurrency.DefaultPool;
27+
import org.neo4j.gds.core.utils.progress.tasks.ProgressTracker;
28+
import org.neo4j.gds.core.utils.progress.tasks.Task;
29+
import org.neo4j.gds.mem.MemoryEstimation;
30+
import org.neo4j.gds.termination.TerminationFlag;
31+
32+
import static org.neo4j.gds.pagerank.PageRankVariant.ARTICLE_RANK;
33+
34+
public class ArticleRankAlgorithmFactory<C extends ArticleRankConfig> extends GraphAlgorithmFactory<PageRankAlgorithm<C>, C> {
35+
36+
@Override
37+
public String taskName() {
38+
return ARTICLE_RANK.taskName();
39+
}
40+
41+
@Override
42+
public PageRankAlgorithm<C> build(
43+
Graph graph,
44+
C configuration,
45+
ProgressTracker progressTracker
46+
) {
47+
48+
var degreeFunction = DegreeFunctions.pageRankDegreeFunction(
49+
graph,
50+
configuration.hasRelationshipWeightProperty(), configuration.concurrency()
51+
);
52+
53+
var mappedSourceNodes = new LongScatterSet(configuration.sourceNodes().size());
54+
configuration.sourceNodes().stream()
55+
.mapToLong(graph::toMappedNodeId)
56+
.forEach(mappedSourceNodes::add);
57+
58+
double avgDegree = DegreeFunctions.averageDegree(graph, configuration.concurrency());
59+
var computation = new ArticleRankComputation<>(configuration, mappedSourceNodes, degreeFunction, avgDegree);
60+
61+
return new PageRankAlgorithm<>(
62+
graph,
63+
configuration,
64+
computation,
65+
ARTICLE_RANK,
66+
DefaultPool.INSTANCE,
67+
progressTracker,
68+
TerminationFlag.RUNNING_TRUE
69+
);
70+
}
71+
72+
@Override
73+
public Task progressTask(Graph graph, C config) {
74+
return Pregel.progressTask(graph, config, taskName());
75+
}
76+
77+
@Override
78+
public MemoryEstimation memoryEstimation(C configuration) {
79+
return new PageRankMemoryEstimateDefinition().memoryEstimation();
80+
}
81+
}

algo/src/main/java/org/neo4j/gds/pagerank/ArticleRankComputation.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import java.util.Optional;
3333
import java.util.function.LongToDoubleFunction;
3434

35-
public final class ArticleRankComputation implements PregelComputation<PageRankConfig> {
35+
public final class ArticleRankComputation<C extends ArticleRankConfig> implements PregelComputation<C> {
3636

3737
private static final String PAGE_RANK = "pagerank";
3838

@@ -46,7 +46,7 @@ public final class ArticleRankComputation implements PregelComputation<PageRankC
4646
private final double averageDegree;
4747

4848
public ArticleRankComputation(
49-
PageRankConfig config,
49+
C config,
5050
LongSet sourceNodes,
5151
LongToDoubleFunction degreeFunction,
5252
double averageDegree
@@ -61,24 +61,24 @@ public ArticleRankComputation(
6161
}
6262

6363
@Override
64-
public PregelSchema schema(PageRankConfig config) {
64+
public PregelSchema schema(C config) {
6565
return new PregelSchema.Builder().add(PAGE_RANK, ValueType.DOUBLE).build();
6666
}
6767

6868
@Override
69-
public void init(InitContext<PageRankConfig> context) {
69+
public void init(InitContext<C> context) {
7070
context.setNodeValue(PAGE_RANK, initialValue(context));
7171
}
7272

73-
private double initialValue(InitContext<PageRankConfig> context) {
73+
private double initialValue(InitContext<C> context) {
7474
if (!hasSourceNodes || sourceNodes.contains(context.nodeId())) {
7575
return alpha;
7676
}
7777
return 0;
7878
}
7979

8080
@Override
81-
public void compute(ComputeContext<PageRankConfig> context, Messages messages) {
81+
public void compute(ComputeContext<C> context, Messages messages) {
8282
double rank = context.doubleNodeValue(PAGE_RANK);
8383
double delta = rank;
8484

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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.pagerank;
21+
22+
import org.neo4j.gds.annotation.Configuration;
23+
24+
@Configuration("ArticleRankConfigImpl")
25+
public interface ArticleRankConfig extends RankConfig
26+
{
27+
@Configuration.DoubleRange(min = 0, max = 1, maxInclusive = false)
28+
default double dampingFactor() {
29+
return 0.85;
30+
}
31+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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.pagerank;
21+
22+
import org.neo4j.gds.annotation.Configuration;
23+
import org.neo4j.gds.config.MutateNodePropertyConfig;
24+
import org.neo4j.gds.core.CypherMapWrapper;
25+
26+
@Configuration
27+
public interface ArticleRankMutateConfig extends ArticleRankConfig, MutateNodePropertyConfig {
28+
29+
static ArticleRankMutateConfig of(CypherMapWrapper userInput) {
30+
return new ArticleRankMutateConfigImpl(userInput);
31+
}
32+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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.pagerank;
21+
22+
import org.neo4j.gds.annotation.Configuration;
23+
import org.neo4j.gds.core.CypherMapWrapper;
24+
25+
@Configuration
26+
public interface ArticleRankStatsConfig extends ArticleRankConfig {
27+
28+
public static ArticleRankStatsConfig of(CypherMapWrapper userInput) {
29+
return new ArticleRankStatsConfigImpl(userInput);
30+
}
31+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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.pagerank;
21+
22+
import org.neo4j.gds.annotation.Configuration;
23+
import org.neo4j.gds.core.CypherMapWrapper;
24+
25+
@Configuration
26+
public interface ArticleRankStreamConfig extends ArticleRankConfig {
27+
28+
public static ArticleRankStreamConfig of(CypherMapWrapper userInput) {
29+
return new ArticleRankStreamConfigImpl(userInput);
30+
}
31+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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.pagerank;
21+
22+
import org.neo4j.gds.annotation.Configuration;
23+
import org.neo4j.gds.config.WritePropertyConfig;
24+
import org.neo4j.gds.core.CypherMapWrapper;
25+
26+
@Configuration
27+
public interface ArticleRankWriteConfig extends ArticleRankConfig, WritePropertyConfig {
28+
29+
public static ArticleRankWriteConfig of(CypherMapWrapper userInput) {
30+
return new ArticleRankWriteConfigImpl(userInput);
31+
}
32+
}

0 commit comments

Comments
 (0)