View source: R/align_prior_to_vertices.R
| align_prior_to_vertices | R Documentation |
Builds a personalization / teleport vector for
igraph::page_rank(personalized = ) from a per-URL external-authority
prior (e.g. Ahrefs referring domains), aligned to the final graph
vertex set. This is the core of TIPR ("topic/true internal PageRank"),
where the random surfer's teleport mass is distributed in proportion to
external authority instead of uniformly.
The prior URLs are expected to already share the vertex namespace (i.e.
canonicalized with the same rurl settings and folded through the
same redirect map as the edges). [pagerank()] performs that
canonicalization and redirect-fold before calling this function; call it
directly only when your prior URLs already match vertex_names.
align_prior_to_vertices(
vertex_names,
prior_df,
prior_url_col = "url",
prior_weight_col = "weight",
transform = c("none", "log", "percentile", "minmax", "zipf", "rank_linear"),
alpha = 0,
exclude_nodes = character(0),
verbose = TRUE
)
vertex_names |
Character vector of the graph's vertex names, in graph
order (typically |
prior_df |
A data frame with one row per URL carrying a raw authority weight (e.g. referring-domain counts). Multiple rows for the same URL are summed (raw counts are additive — summing happens before any transform). |
prior_url_col |
Name of the URL column in |
prior_weight_col |
Name of the numeric weight column in |
transform |
Character, how to shape the raw authority before it becomes
teleport mass. Passed to [transform_weights()]; one of |
alpha |
Numeric in |
exclude_nodes |
Character vector of vertex names that must receive
zero teleport in both components: the synthetic sinks
(e.g. |
verbose |
Logical, whether to emit coverage diagnostics via
|
Alignment proceeds as: sum raw weights per URL -> match onto
vertex_names (unmatched vertices get raw 0) -> apply transform
to the vertices that carry authority -> normalize to an authority share ->
mix with a uniform-over-real-vertices vector via alpha -> normalize to
sum 1. Because igraph re-normalizes the personalization vector
internally, only the relative weights matter; normalization here is
for interpretability and to make alpha and exclude_nodes behave
predictably.
A numeric vector the same length as vertex_names, in the same
order, summing to 1 (suitable for
igraph::page_rank(personalized = )).
Excluded vertices get exactly 0. If the prior matches no vertex and
alpha = 0, the function falls back to a uniform vector over the
non-excluded vertices and warns.
[pagerank()], [transform_weights()]
v <- c("https://x/a", "https://x/b", "https://x/c", "__pr_waste_sink__")
prior <- data.frame(
url = c("https://x/a", "https://x/b"),
weight = c(900, 100)
)
# Pure linear authority share; sink excluded
align_prior_to_vertices(v, prior,
exclude_nodes = "__pr_waste_sink__",
verbose = FALSE
)
# Compress the dynamic range
align_prior_to_vertices(v, prior,
transform = "log",
exclude_nodes = "__pr_waste_sink__", verbose = FALSE
)
# Authority-tilted uniform (every real page keeps a baseline)
align_prior_to_vertices(v, prior,
alpha = 0.15,
exclude_nodes = "__pr_waste_sink__", verbose = FALSE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.