mojolearn.PageRank#
- class mojolearn.PageRank(alpha=0.85, *, personalization=None, max_iter=100, tol=1e-06, nstart=None, weight=True, dangling=None)[source]#
Bases:
_XNeighborsPageRank scores of a directed graph by power iteration.
Follows networkx’s
pagerank: a row-stochastic transition matrix, dangling nodes’ mass redistributed bydangling(or the personalization), and iteration until the summed absolute change is belown * tol. The graph is a weighted adjacency matrix withA[i, j]the weight of the edge i -> j, given as a dense square array, a scipy.sparse matrix (any format; its indices must be sorted within each row), or an(indptr, indices, n)CSR tuple in which every edge weighs 1. Vectors over nodes are length-n arrays (networkx uses dicts over nodes 0..n-1). Computation is float32.- Parameters:
alpha (float, default 0.85) – Damping factor.
personalization (array-like of shape (n,) or None, default None) – Teleport distribution, normalized to sum to one; None is uniform.
max_iter (int, default 100) – Maximum number of iterations. Not converging raises
RuntimeError.tol (float, default 1e-6) – Per-node convergence tolerance.
nstart (array-like of shape (n,) or None, default None) – Starting vector, normalized to sum to one; None is uniform.
weight (bool or None, default True) – Use the edge weights. False or None treats every edge as weight 1.
dangling (array-like of shape (n,) or None, default None) – Where the mass of nodes without out-edges goes, normalized to sum to one; None uses the personalization.
numeric_mode ({‘identical’, ‘deterministic’, ‘fast’} or None, default None) – Numeric mode for this estimator (
'fast'is Apple only). None uses the process default.The ``personalization``, ``nstart`` and ``dangling`` vectors must have
length n, be non-negative and not all zero (``ValueError`` otherwise).
- Variables:
Examples
>>> import numpy as np, mojolearn >>> A = (np.random.default_rng(0).random((500, 500)) < 0.01).astype(np.float32) >>> scores = mojolearn.PageRank(alpha=0.85).fit(A).pagerank_
- __init__(alpha=0.85, *, personalization=None, max_iter=100, tol=1e-06, nstart=None, weight=True, dangling=None)[source]#
Methods
fit(A[, y])Compute the PageRank scores of the graph.
get_params([deep])numeric_mode_used()The numeric mode this estimator runs in.
set_params(**params)Set constructor parameters.
vendor_used()The GPU backend this estimator runs on.
- fit(A, y=None)[source]#
Compute the PageRank scores of the graph.
- Parameters:
A (array-like of shape (n, n), scipy.sparse matrix, or tuple) – Weighted adjacency matrix (
A[i, j]is the weight of i -> j): a dense square array, a scipy.sparse matrix, or an(indptr, indices, n)CSR tuple.y (None) – Ignored.
- Returns:
self (PageRank) – The fitted estimator, with
pagerank_andn_iter_.- Raises:
RuntimeError – If the iteration does not converge within
max_itersteps.