Fast Random Projection
This section describes the Fast Random Projection (FastRP) node embedding algorithm in the Neo4j Graph Data Science library.
1. Introduction
Fast Random Projection, or FastRP for short, is a node embedding algorithm in the family of random projection algorithms. These algorithms are theoretically backed by the JohnssonLindenstrauss lemma according to which one can project n vectors of arbitrary dimension into O(log(n)) dimensions and still approximately preserve pairwise distances among the points. In fact, a linear projection chosen in a random way satisfies this property.
Such techniques therefore allow for aggressive dimensionality reduction while preserving most of the distance information. The FastRP algorithm operates on graphs, in which case we care about preserving similarity between nodes and their neighbors. This means that two nodes that have similar neighborhoods should be assigned similar embedding vectors. Conversely, two nodes that are not similar should be not be assigned similar embedding vectors.
The FastRP algorithm initially assigns random vectors to all nodes using a technique called very sparse random projection, see (Achlioptas, 2003) below. Moreover, in GDS it is possible to use node properties for the creation of these initial random vectors in a way described below. We will also use projection of a node synonymously with the initial random vector of a node.
Starting with these random vectors and iteratively averaging over node neighborhoods, the algorithm constructs a sequence of intermediate embeddings for each node n. More precisely,
where m ranges over neighbors of n and is the node’s initial random vector.
The embedding of node n, which is the output of the algorithm, is a combination of the vectors and embeddings defined above:
where normalize
is the function which divides a vector with its L2 norm, the value of nodeSelfInfluence
is , and the values of iterationWeights
are .
We will return to Node Self Influence later on.
Therefore, each node’s embedding depends on a neighborhood of radius equal to the number of iterations. This way FastRP exploits higherorder relationships in the graph while still being highly scalable.
The present implementation extends the original algorithm to support weighted graphs, which computes weighted averages of neighboring embeddings using the relationship weights.
In order to make use of this, the relationshipWeightProperty
parameter should be set to an existing relationship property.
The original algorithm is intended only for undirected graphs.
We support running on both on directed graphs and undirected graph.
For directed graphs we consider only the outgoing neighbors when computing the intermediate embeddings for a node.
Therefore, using the orientations NATURAL
, REVERSE
or UNDIRECTED
will all give different embeddings.
In general, it is recommended to first use UNDIRECTED
as this is what the original algorithm was evaluated on.
For more information on this algorithm see:
1.1. Node properties
Most realworld graphs contain node properties which store information about the nodes and what they represent. The FastRP algorithm in the GDS library extends the original FastRP algorithm with a capability to take node properties into account. The resulting embeddings can therefore represent the graph more accurately.
The node property aware aspect of the algorithm is configured via the parameters featureProperties
and propertyRatio
.
Each node property in featureProperties
is associated with a randomly generated vector of dimension propertyDimension
, where propertyDimension = embeddingDimension * propertyRatio
.
Each node is then initialized with a vector of size embeddingDimension
formed by concatenation of two parts:

The first part is formed like in the standard FastRP algorithm,

The second one is a linear combination of the property vectors, using the property values of the node as weights.
The algorithm then proceeds with the same logic as the FastRP algorithm.
Therefore, the algorithm will output arrays of size embeddingDimension
.
The last propertyDimension
coordinates in the embedding captures information about property values of nearby nodes (the "property part" below), and the remaining coordinates (embeddingDimension
 propertyDimension
of them; "topology part") captures information about nearby presence of nodes.
[0, 1, ...  ..., N  1, N] ^^^^^^^^^^^^^^^^  ^^^^^^^^^^^^^^^ topology part  property part ^ property ratio
2. Tuning algorithm parameters
In order to improve the embedding quality using FastRP on one of your graphs, it is possible to tune the algorithm parameters. This process of finding the best parameters for your specific use case and graph is typically referred to as hyperparameter tuning. We will go through each of the configuration parameters and explain how they behave.
For statistically sound results, it is a good idea to reserve a test set excluded from parameter tuning. After selecting a set of parameter values, the embedding quality can be evaluated using a downstream machine learning task on the test set. By varying the parameter values and studying the precision of the machine learning task, it is possible to deduce the parameter values that best fit the concrete dataset and use case. To construct such a set you may want to use a dedicated node label in the graph to denote a subgraph without the test data.
2.1. Embedding dimension
The embedding dimension is the length of the produced vectors. A greater dimension offers a greater precision, but is more costly to operate over.
The optimal embedding dimension depends on the number of nodes in the graph. Since the amount of information the embedding can encode is limited by its dimension, a larger graph will tend to require a greater embedding dimension. A typical value is a power of two in the range 128  1024. A value of at least 256 gives good results on graphs in the order of 10^{5} nodes, but in general increasing the dimension improves results. Increasing embedding dimension will however increase memory requirements and runtime linearly.
2.2. Normalization strength
The normalization strength is used to control how node degrees influence the embedding.
Using a negative value will downplay the importance of high degree neighbors, while a positive value will instead increase their importance.
The optimal normalization strength depends on the graph and on the task that the embeddings will be used for.
In the original paper, hyperparameter tuning was done in the range of [1,0]
(no positive values), but we have found cases where a positive normalization strengths gives better results.
2.3. Iteration weights
The iteration weights parameter control two aspects: the number of iterations, and their relative impact on the final node embedding. The parameter is a list of numbers, indicating one iteration per number where the number is the weight applied to that iteration.
In each iteration, the algorithm will expand across all relationships in the graph. This has some implications:

With a single iteration, only direct neighbors will be considered for each node embedding.

With two iterations, direct neighbors and seconddegree neighbors will be considered for each node embedding.

With three iterations, direct neighbors, seconddegree neighbors, and thirddegree neighbors will be considered for each node embedding. Direct neighbors may be reached twice, in different iterations.

In general, the embedding corresponding to the
i
:th iteration contains features depending on nodes reachable with paths of lengthi
. If the graph is undirected, then a node reachable with a path of lengthL
can also be reached with lengthL+2k
, for any integerk
. 
In particular, a node may reach back to itself on each even iteration (depending on the direction in the graph).
It is good to have at least one nonzero weight in an even and in an odd position. Typically, using at least a few iterations, for example three, is recommended. However, a too high value will consider nodes far away and may not be informative or even be detrimental. The intuition here is that as the projections reach further away from the node, the less specific the neighborhood becomes. Of course, a greater number of iterations will also take more time to complete.
2.4. Node Self Influence
Node Self Influence is a variation of the original FastRP algorithm.
How much a node’s embedding is affected by the intermediate embedding at iteration i is controlled by the i'th element of iterationWeights
.
This can also be seen as how much the initial random vectors, or projections, of nodes that can be reached in i hops from a node affect the embedding of the node.
Similarly, nodeSelfInfluence
behaves like an iteration weight for a 0 th iteration, or the amount of influence the projection of a node has on the embedding of the same node.
A reason for setting this parameter to a nonzero value is if your graph has low connectivity or a significant amount of isolated nodes.
Isolated nodes combined with using propertyRatio = 0.0
leads to embeddings that contain all zeros.
However using node properties along with node self influence can thus produce more meaningful embeddings for such nodes.
This can be seen as producing fallback features when graph structure is (locally) missing.
Moreover, sometimes a node’s own properties are simply informative features and are good to include even if connectivity is high.
Finally, node self influence can be used for pure dimensionality reduction to compress node properties used for node classification.
If node properties are not used, using nodeSelfInfluence
may also have a positive effect, depending on other settings and on the problem.
2.5. Orientation
Choosing the right orientation when creating the graph may have the single greatest impact.
The FastRP algorithm is designed to work with undirected graphs, and we expect this to be the best in most cases.
If you expect only outgoing or incoming relationships to be informative for a prediction task, then you may want to try using the orientations NATURAL
or REVERSE
respectively.
3. Syntax
This section covers the syntax used to execute the FastRP algorithm in each of its execution modes. We are describing the named graph variant of the syntax. To learn more about general syntax variants, see Syntax overview.
CALL gds.fastRP.stream(
graphName: String,
configuration: Map
) YIELD
nodeId: Integer,
embedding: List of Float
Name  Type  Default  Optional  Description 

graphName 
String 

no 
The name of a graph stored in the catalog. 
configuration 
Map 

yes 
Configuration for algorithmspecifics and/or graph filtering. 
Name  Type  Default  Optional  Description 

List of String 

yes 
Filter the named graph using the given node labels. 

List of String 

yes 
Filter the named graph using the given relationship types. 

Integer 

yes 
The number of concurrent threads used for running the algorithm. 
Name  Type  Default  Optional  Description 

propertyRatio 
Float 

yes 
The desired ratio of the property embedding dimension to the total 
featureProperties 
List of String 

yes 
The names of the node properties that should be used as input features. All property names must exist in the inmemory graph and be of type Float or List of Float. 
embeddingDimension 
Integer 

no 
The dimension of the computed node embeddings. Minimum value is 1. 
iterationWeights 
List of Float 

yes 
Contains a weight for each iteration. The weight controls how much the intermediate embedding from the iteration contributes to the final embedding. 
nodeSelfInfluence 
Float 

yes 
Controls for each node how much its initial random vector contributes to its final embedding. 
normalizationStrength 
Float 

yes 
The initial random vector for each node is scaled by its degree to the power of 
randomSeed 
Integer 

yes 
A random seed which is used for all randomness in computing the embeddings. 
String 

yes 
Name of the relationship property to use for weighted random projection. If unspecified, the algorithm runs unweighted. 

The number of iterations is equal to the length of 

It is required that 
Name  Type  Description 

nodeId 
Integer 
Node ID. 
embedding 
List of Float 
FastRP node embedding. 
CALL gds.fastRP.stats(
graphName: String,
configuration: Map
) YIELD
nodeCount: Integer,
createMillis: Integer,
computeMillis: Integer,
configuration: Map
Name  Type  Default  Optional  Description 

graphName 
String 

no 
The name of a graph stored in the catalog. 
configuration 
Map 

yes 
Configuration for algorithmspecifics and/or graph filtering. 
Name  Type  Default  Optional  Description 

List of String 

yes 
Filter the named graph using the given node labels. 

List of String 

yes 
Filter the named graph using the given relationship types. 

Integer 

yes 
The number of concurrent threads used for running the algorithm. 
Name  Type  Default  Optional  Description 

propertyRatio 
Float 

yes 
The desired ratio of the property embedding dimension to the total 
featureProperties 
List of String 

yes 
The names of the node properties that should be used as input features. All property names must exist in the inmemory graph and be of type Float or List of Float. 
embeddingDimension 
Integer 

no 
The dimension of the computed node embeddings. Minimum value is 1. 
iterationWeights 
List of Float 

yes 
Contains a weight for each iteration. The weight controls how much the intermediate embedding from the iteration contributes to the final embedding. 
nodeSelfInfluence 
Float 

yes 
Controls for each node how much its initial random vector contributes to its final embedding. 
normalizationStrength 
Float 

yes 
The initial random vector for each node is scaled by its degree to the power of 
randomSeed 
Integer 

yes 
A random seed which is used for all randomness in computing the embeddings. 
String 

yes 
Name of the relationship property to use for weighted random projection. If unspecified, the algorithm runs unweighted. 

The number of iterations is equal to the length of 

It is required that 
Name  Type  Description 

nodeCount 
Integer 
Number of nodes processed. 
createMillis 
Integer 
Milliseconds for creating the graph. 
computeMillis 
Integer 
Milliseconds for running the algorithm. 
configuration 
Map 
Configuration used for running the algorithm. 
CALL gds.fastRP.mutate(
graphName: String,
configuration: Map
) YIELD
nodeCount: Integer,
nodePropertiesWritten: Integer,
createMillis: Integer,
computeMillis: Integer,
mutateMillis: Integer,
configuration: Map
Name  Type  Default  Optional  Description 

graphName 
String 

no 
The name of a graph stored in the catalog. 
configuration 
Map 

yes 
Configuration for algorithmspecifics and/or graph filtering. 
Name  Type  Default  Optional  Description 

List of String 

yes 
Filter the named graph using the given node labels. 

List of String 

yes 
Filter the named graph using the given relationship types. 

Integer 

yes 
The number of concurrent threads used for running the algorithm. 

mutateProperty 
String 

no 
The node property in the GDS graph to which the embedding is written. 
Name  Type  Default  Optional  Description 

propertyRatio 
Float 

yes 
The desired ratio of the property embedding dimension to the total 
featureProperties 
List of String 

yes 
The names of the node properties that should be used as input features. All property names must exist in the inmemory graph and be of type Float or List of Float. 
embeddingDimension 
Integer 

no 
The dimension of the computed node embeddings. Minimum value is 1. 
iterationWeights 
List of Float 

yes 
Contains a weight for each iteration. The weight controls how much the intermediate embedding from the iteration contributes to the final embedding. 
nodeSelfInfluence 
Float 

yes 
Controls for each node how much its initial random vector contributes to its final embedding. 
normalizationStrength 
Float 

yes 
The initial random vector for each node is scaled by its degree to the power of 
randomSeed 
Integer 

yes 
A random seed which is used for all randomness in computing the embeddings. 
String 

yes 
Name of the relationship property to use for weighted random projection. If unspecified, the algorithm runs unweighted. 

The number of iterations is equal to the length of 

It is required that 
Name  Type  Description 

nodeCount 
Integer 
Number of nodes processed. 
nodePropertiesWritten 
Integer 
Number of node properties written. 
createMillis 
Integer 
Milliseconds for creating the graph. 
computeMillis 
Integer 
Milliseconds for running the algorithm. 
mutateMillis 
Integer 
Milliseconds for adding properties to the inmemory graph. 
configuration 
Map 
Configuration used for running the algorithm. 
CALL gds.fastRP.write(
graphName: String,
configuration: Map
) YIELD
nodeCount: Integer,
nodePropertiesWritten: Integer,
createMillis: Integer,
computeMillis: Integer,
writeMillis: Integer,
configuration: Map
Name  Type  Default  Optional  Description 

graphName 
String 

no 
The name of a graph stored in the catalog. 
configuration 
Map 

yes 
Configuration for algorithmspecifics and/or graph filtering. 
Name  Type  Default  Optional  Description 

List of String 

yes 
Filter the named graph using the given node labels. 

List of String 

yes 
Filter the named graph using the given relationship types. 

Integer 

yes 
The number of concurrent threads used for running the algorithm. Also provides the default value for 'writeConcurrency'. 

Integer 

yes 
The number of concurrent threads used for writing the result to Neo4j. 

String 

no 
The node property in the Neo4j database to which the embedding is written. 
Name  Type  Default  Optional  Description 

propertyRatio 
Float 

yes 
The desired ratio of the property embedding dimension to the total 
featureProperties 
List of String 

yes 
The names of the node properties that should be used as input features. All property names must exist in the inmemory graph and be of type Float or List of Float. 
embeddingDimension 
Integer 

no 
The dimension of the computed node embeddings. Minimum value is 1. 
iterationWeights 
List of Float 

yes 
Contains a weight for each iteration. The weight controls how much the intermediate embedding from the iteration contributes to the final embedding. 
nodeSelfInfluence 
Float 

yes 
Controls for each node how much its initial random vector contributes to its final embedding. 
normalizationStrength 
Float 

yes 
The initial random vector for each node is scaled by its degree to the power of 
randomSeed 
Integer 

yes 
A random seed which is used for all randomness in computing the embeddings. 
String 

yes 
Name of the relationship property to use for weighted random projection. If unspecified, the algorithm runs unweighted. 

The number of iterations is equal to the length of 

It is required that 
Name  Type  Description 

nodeCount 
Integer 
Number of nodes processed. 
nodePropertiesWritten 
Integer 
Number of node properties written. 
createMillis 
Integer 
Milliseconds for creating the graph. 
computeMillis 
Integer 
Milliseconds for running the algorithm. 
writeMillis 
Integer 
Milliseconds for writing result data back to Neo4j. 
configuration 
Map 
Configuration used for running the algorithm. 
3.1. Anonymous graphs
It is also possible to execute the algorithm on a graph that is projected in conjunction with the algorithm execution.
In this case, the graph does not have a name, and we call it anonymous.
When executing over an anonymous graph the configuration map contains a graph projection configuration as well as an algorithm configuration.
All execution modes support execution on anonymous graphs, although we only show syntax and modespecific configuration for the write
mode for brevity.
For more information on syntax variants, see Syntax overview.
CALL gds.fastRP.write(
configuration: Map
)
YIELD
nodeCount: Integer,
nodePropertiesWritten: Integer,
createMillis: Integer,
computeMillis: Integer,
writeMillis: Integer,
configuration: Map
Name  Type  Default  Optional  Description 

nodeProjection 
String, List of String or Map 

yes 
The node projection used for anonymous graph creation via a Native projection. 
relationshipProjection 
String, List of String or Map 

yes 
The relationship projection used for anonymous graph creation a Native projection. 
nodeQuery 
String 

yes 
The Cypher query used to select the nodes for anonymous graph creation via a Cypher projection. 
relationshipQuery 
String 

yes 
The Cypher query used to select the relationships for anonymous graph creation via a Cypher projection. 
nodeProperties 
String, List of String or Map 

yes 
The node properties to project during anonymous graph creation. 
relationshipProperties 
String, List of String or Map 

yes 
The relationship properties to project during anonymous graph creation. 
Integer 

yes 
The number of concurrent threads used for running the algorithm. Also provides the default value for 'readConcurrency' and 'writeConcurrency'. 

readConcurrency 
Integer 

yes 
The number of concurrent threads used for creating the graph. 
Integer 

yes 
WRITE mode only: The number of concurrent threads used for writing the result. 

String 

no 
WRITE mode only: The node property to which the embedding is written to. 
Name  Type  Default  Optional  Description 

propertyRatio 
Float 

yes 
The desired ratio of the property embedding dimension to the total 
featureProperties 
List of String 

yes 
The names of the node properties that should be used as input features. All property names must exist in the inmemory graph and be of type Float or List of Float. 
embeddingDimension 
Integer 

no 
The dimension of the computed node embeddings. Minimum value is 1. 
iterationWeights 
List of Float 

yes 
Contains a weight for each iteration. The weight controls how much the intermediate embedding from the iteration contributes to the final embedding. 
nodeSelfInfluence 
Float 

yes 
Controls for each node how much its initial random vector contributes to its final embedding. 
normalizationStrength 
Float 

yes 
The initial random vector for each node is scaled by its degree to the power of 
randomSeed 
Integer 

yes 
A random seed which is used for all randomness in computing the embeddings. 
String 

yes 
Name of the relationship property to use for weighted random projection. If unspecified, the algorithm runs unweighted. 

The number of iterations is equal to the length of 

It is required that 
The results are the same as for running write mode with a named graph, see the write mode syntax above.
4. Examples
In this section we will show examples of running the FastRP node embedding algorithm on a concrete graph. The intention is to illustrate what the results look like and to provide a guide in how to make use of the algorithm in a real setting. We will do this on a small social network graph of a handful nodes connected in a particular pattern. The example graph looks like this:
CREATE
(dan:Person {name: 'Dan', age: 18}),
(annie:Person {name: 'Annie', age: 12}),
(matt:Person {name: 'Matt', age: 22}),
(jeff:Person {name: 'Jeff', age: 51}),
(brie:Person {name: 'Brie', age: 45}),
(elsa:Person {name: 'Elsa', age: 65}),
(john:Person {name: 'John', age: 64}),
(dan)[:KNOWS {weight: 1.0}]>(annie),
(dan)[:KNOWS {weight: 1.0}]>(matt),
(annie)[:KNOWS {weight: 1.0}]>(matt),
(annie)[:KNOWS {weight: 1.0}]>(jeff),
(annie)[:KNOWS {weight: 1.0}]>(brie),
(matt)[:KNOWS {weight: 3.5}]>(brie),
(brie)[:KNOWS {weight: 1.0}]>(elsa),
(brie)[:KNOWS {weight: 2.0}]>(jeff),
(john)[:KNOWS {weight: 1.0}]>(jeff);
This graph represents seven people who know one another.
A relationship property weight
denotes the strength of the knowledge between two persons.
With the graph in Neo4j we can now project it into the graph catalog to prepare it for algorithm execution.
We do this using a native projection targeting the Person
nodes and the KNOWS
relationships.
For the relationships we will use the UNDIRECTED
orientation.
This is because the FastRP algorithm has been measured to compute more predictive node embeddings in undirected graphs.
We will also add the weight
relationship property which we will make use of when running the weighted version of FastRP.
In the examples below we will use named graphs and native projections as the norm. However, anonymous graphs and/or Cypher projections can also be used. 
CALL gds.graph.create(
'persons',
'Person',
{
KNOWS: {
orientation: 'UNDIRECTED',
properties: 'weight'
}
},
{ nodeProperties: ['age'] }
)
4.1. Memory Estimation
First off, we will estimate the cost of running the algorithm using the estimate
procedure.
This can be done with any execution mode.
We will use the stream
mode in this example.
Estimating the algorithm is useful to understand the memory impact that running the algorithm on your graph will have.
When you later actually run the algorithm in one of the execution modes the system will perform an estimation.
If the estimation shows that there is a very high probability of the execution going over its memory limitations, the execution is prohibited.
To read more about this, see Automatic estimation and execution blocking.
For more details on estimate
in general, see Memory Estimation.
CALL gds.fastRP.stream.estimate('persons', {embeddingDimension: 128})
YIELD nodeCount, relationshipCount, bytesMin, bytesMax, requiredMemory
nodeCount  relationshipCount  bytesMin  bytesMax  requiredMemory 

7 
18 
11424 
11424 
"11424 Bytes" 
4.2. Stream
In the stream
execution mode, the algorithm returns the embedding for each node.
This allows us to inspect the results directly or postprocess them in Cypher without any side effects.
For example, we can collect the results and pass them into a similarity algorithm.
For more details on the stream
mode in general, see Stream.
CALL gds.fastRP.stream('persons',
{
embeddingDimension: 4,
randomSeed: 42
}
)
YIELD nodeId, embedding
nodeId  embedding 

0 
[0.4774002134799957, 0.6602408289909363, 0.36686956882476807, 1.7089111804962158] 
1 
[0.7989360094070435, 0.4918718934059143, 0.41281944513320923, 1.6314401626586914] 
2 
[0.47275322675704956, 0.49587157368659973, 0.3340468406677246, 1.7141895294189453] 
3 
[0.8290714025497437, 0.3260476291179657, 0.3317275643348694, 1.4370529651641846] 
4 
[0.7749264240264893, 0.4773247539997101, 0.0675133764743805, 1.5248265266418457] 
5 
[0.8408374190330505, 0.37151476740837097, 0.12121132016181946, 1.530960202217102] 
6 
[1.0, 0.11054422706365585, 0.3697933852672577, 0.9225144982337952] 
The results of the algorithm are not very intuitively interpretable, as the node embedding format is a mathematical abstraction of the node within its neighborhood, designed for machine learning programs.
What we can see is that the embeddings have four elements (as configured using embeddingDimension
) and that the numbers are relatively small (they all fit in the range of [2, 2]
).
The magnitude of the numbers is controlled by the embeddingDimension
, the number of nodes in the graph, and by the fact that FastRP performs euclidean normalization on the intermediate embedding vectors.
Due to the random nature of the algorithm the results will vary between the runs. However, this does not necessarily mean that the pairwise distances of two node embeddings vary as much. 
4.3. Stats
In the stats
execution mode, the algorithm returns a single row containing a summary of the algorithm result.
This execution mode does not have any side effects.
It can be useful for evaluating algorithm performance by inspecting the computeMillis
return item.
In the examples below we will omit returning the timings.
The full signature of the procedure can be found in the syntax section.
For more details on the stats
mode in general, see Stats.
CALL gds.fastRP.stats('persons', { embeddingDimension: 8 })
YIELD nodeCount
nodeCount 

7 
The stats
mode does not currently offer any statistical results for the embeddings themselves.
We can however see that the algorithm has successfully processed all seven nodes in our example graph.
4.4. Mutate
The mutate
execution mode extends the stats
mode with an important side effect: updating the named graph with a new node property containing the embedding for that node.
The name of the new property is specified using the mandatory configuration parameter mutateProperty
.
The result is a single summary row, similar to stats
, but with some additional metrics.
The mutate
mode is especially useful when multiple algorithms are used in conjunction.
For more details on the mutate
mode in general, see Mutate.
mutate
mode:CALL gds.fastRP.mutate(
'persons',
{
embeddingDimension: 8,
mutateProperty: 'fastrpembedding'
}
)
YIELD nodePropertiesWritten
nodePropertiesWritten 

7 
The returned result is similar to the stats
example.
Additionally, the graph 'persons' now has a node property fastrpembedding
which stores the node embedding for each node.
To find out how to inspect the new schema of the inmemory graph, see Listing graphs.
4.5. Write
The write
execution mode extends the stats
mode with an important side effect: writing the embedding for each node as a property to the Neo4j database.
The name of the new property is specified using the mandatory configuration parameter writeProperty
.
The result is a single summary row, similar to stats
, but with some additional metrics.
The write
mode enables directly persisting the results to the database.
For more details on the write
mode in general, see Write.
write
mode:CALL gds.fastRP.write(
'persons',
{
embeddingDimension: 8,
writeProperty: 'fastrpembedding'
}
)
YIELD nodePropertiesWritten
nodePropertiesWritten 

7 
The returned result is similar to the stats
example.
Additionally, each of the seven nodes now has a new property fastrpembedding
in the Neo4j database, containing the node embedding for that node.
4.6. Weighted
By default, the algorithm is considering the relationships of the graph to be unweighted.
To change this behaviour we can use configuration parameter called relationshipWeightProperty
.
Below is an example of running the weighted variant of algorithm.
CALL gds.fastRP.stream(
'persons',
{
embeddingDimension: 4,
randomSeed: 42,
relationshipWeightProperty: 'weight'
}
)
YIELD nodeId, embedding
nodeId  embedding 

0 
[0.10945529490709305, 0.5032674074172974, 0.464673787355423, 1.7539862394332886] 
1 
[0.3639600872993469, 0.39210301637649536, 0.46271592378616333, 1.829423427581787] 
2 
[0.12314096093177795, 0.3213110864162445, 0.40100979804992676, 1.471055269241333] 
3 
[0.30704641342163086, 0.24944794178009033, 0.3947891891002655, 1.3463698625564575] 
4 
[0.23112300038337708, 0.30148714780807495, 0.584831714630127, 1.2822188138961792] 
5 
[0.14497177302837372, 0.2312137484550476, 0.5552002191543579, 1.2605633735656738] 
6 
[0.5139184594154358, 0.07954332232475281, 0.3690345287322998, 0.9176374077796936] 
Since the initial state of the algorithm is randomised, it isn’t possible to intuitively analyse the effect of the relationship weights.
4.7. Using node properties as features
To explain the novel initialization using node properties, let us consider an example where embeddingDimension
is 10, propertyRatio
is 0.2.
The dimension of the embedded properties, propertyDimension
is thus 2.
Assume we have a property f1
of scalar type, and a property f2
storing arrays of length 2.
This means that there are 3 features which we order like f1
followed by the two values of f2
.
For each of these three features we sample a two dimensional random vector.
Let’s say these are p1=[0.0, 2.4]
, p2=[2.4, 0.0]
and p3=[2.4, 0.0]
.
Consider now a node (n {f1: 0.5, f2: [1.0, 1.0]})
.
The linear combination mentioned above, is in concrete terms 0.5 * p1 + 1.0 * p2  1.0 * p3 = [4.8, 1.2]
.
The initial random vector for the node n
contains first 8 values sampled as in the original FastRP paper, and then our computed values 4.8
and 1.2
, totalling 10 entries.
In the example below, we again set the embedding dimension to 2, but we set propertyRatio
to 1, which means the embedding is computed from node properties only.
CALL gds.fastRP.stream('persons', {
randomSeed: 42,
embeddingDimension: 2,
propertyRatio: 1.0,
featureProperties: ['age'],
iterationWeights: [1.0]
}) YIELD nodeId, embedding
nodeId  embedding 

0 
[0.0, 1.0] 
1 
[0.0, 1.0] 
2 
[0.0, 0.9999999403953552] 
3 
[0.0, 1.0] 
4 
[0.0, 0.9999999403953552] 
5 
[0.0, 1.0] 
6 
[0.0, 1.0] 
In this example, the embeddings are based on the age
property.
Because of L2 normalization which is applied to each iteration (here only one iteration), all nodes have the same embedding despite having different age values (apart from rounding errors).
Was this page helpful?