Title: | Random Walk Clustering on Weighted Graphs |
---|---|
Description: | Implements the random walk clustering algorithm for weighted graphs as found in Harel and Koren (2001) <https://link.springer.com/chapter/10.1007/3-540-45294-X_3>. |
Authors: | Carson Sprock [aut, cre] |
Maintainer: | Carson Sprock <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2025-02-08 04:22:41 UTC |
Source: | https://github.com/csprock/rwclust |
Generic helper for extracting adjacency matrix from rwclust object.
adjacency(x) ## Default S3 method: adjacency(x) ## S3 method for class 'rwclust' adjacency(x)
adjacency(x) ## Default S3 method: adjacency(x) ## S3 method for class 'rwclust' adjacency(x)
x |
rwclust object |
Matrix object containing the adjacency matrix of the after the final iteration
Apply similarity function to rows of a matrix
apply_similarity(idx, mat, similarity, ...)
apply_similarity(idx, mat, similarity, ...)
idx |
vector of length two containing row indices |
mat |
a matrix |
similarity |
similarity function to apply |
... |
additional parameters to be passed to the similarity function |
a scalar
Apply similarity function over edges of graph
compute_similarities(edgelist, mat, similarity, ...)
compute_similarities(edgelist, mat, similarity, ...)
edgelist |
3-column dataframe |
mat |
a matrix |
similarity |
the similarity function to apply |
... |
other parameters to pass to the similarity function |
a vector containing updated weights
Compute transition matrix
compute_transition_matrix(x)
compute_transition_matrix(x)
x |
sparseMatrix or denseMatrix |
transition matrix
Takes the weights from compute_kernel and creates weighted adjacency matrix
create_weight_matrix(edgelist, weights, ...)
create_weight_matrix(edgelist, weights, ...)
edgelist |
a dataframe with two columns |
weights |
a vector of weights |
... |
other parameters to be passed to Matrix::sparseMatrix() |
sparseMatrix
First demonstration test graph used in the original.
example1
example1
A data frame with three columns representing a weighted graph. Each row represents an edge with a weight:
An integer vertex id
An integer vertex id
A double representing the edge weight
data(example1, package="Rwclust")
data(example1, package="Rwclust")
Second demonstration test graph used in the original paper.
example2
example2
A data frame with three columns representing a weighted graph. Each row represents an edge with a weight.
An integer vertex id
An integer vertex id
A double representing the edge weight
data(example2, package="Rwclust")
data(example2, package="Rwclust")
Returns a object of class "rwclust" for use with generic summary and plotting functions.
new_rwclust(x)
new_rwclust(x)
x |
output of |
Generic function for plotting the distribution of weights. Calls hist
under the hood.
## S3 method for class 'rwclust' plot(x, cutoff = NULL, ...)
## S3 method for class 'rwclust' plot(x, cutoff = NULL, ...)
x |
rwclust object |
cutoff |
optional numeric, will plot the cutoff value as a vertical line |
... |
additional graphical parameters passed to the |
Execute main algorithm loop
run_main_loop(M, edgelist, similarity, k, iter)
run_main_loop(M, edgelist, similarity, k, iter)
M |
transition matrix |
edgelist |
dataframe edgelist |
similarity |
a similarity function |
k |
integer, length of longest walk |
iter |
number of iterations |
list
Sharpens the weights of a weighted graph for later pruning.
rwclust(x, iter = 5, k = 3, similarity = "hk") ## S3 method for class 'data.frame' rwclust(x, iter = 5, k = 3, similarity = "hk") ## S3 method for class 'matrix' rwclust(x, iter = 5, k = 3, similarity = "hk")
rwclust(x, iter = 5, k = 3, similarity = "hk") ## S3 method for class 'data.frame' rwclust(x, iter = 5, k = 3, similarity = "hk") ## S3 method for class 'matrix' rwclust(x, iter = 5, k = 3, similarity = "hk")
x |
matrix or dataframe with three columns
|
iter |
integer, number of iterations |
k |
integer, maximum length of random walk |
similarity |
string, the name of the similarity metric used to update weights |
list
A vector of the updated edge weights
Updated adjacency matrix containing updated weights
Internally, the edgelist passed to rwclust
is converted
into a transition matrix, whose powers are used to compute the
probability of reaching a vertex from vertex
in
steps for all
and
. New edge weights are computed
using the similarity between these "walk probabilities" for each pair
of vertices. The intuition is that vertices who have similar
neighborhoods in terms of random walk reachability are similar
to each other.
The returned weights can be used for clustering by deleting edges with weights below a certain threshold. The connected components of the resulting graph form the clusters.
Harel, David, and Yehuda Koren. "On clustering using random walks." International Conference on Foundations of Software Technology and Theoretical Computer Science. Springer, Berlin, Heidelberg, 2001.
Update edge weights
update_weights(M, edgelist, similarity, k)
update_weights(M, edgelist, similarity, k)
M |
matrix |
edgelist |
dataframe representing weighted edgelist |
similarity |
a similarity function |
k |
integer, length of longest walk |
list