Validate Edge Weights and Per-Source Totals
Source:R/validate_edge_weights.R
validate_edge_weights.RdInspect a weighted edge list before it reaches the PageRank solver. The report identifies negative and non-finite weights, degenerate sources whose outgoing weights are all zero, and (optionally) source totals that do not match an expected probability total.
Arguments
- edge_list_df
A data frame containing source and weight columns.
- weight_col
Name of the numeric edge-weight column.
- from_col
Name of the source-node column used to define outgoing choice sets.
- expected_total
Optional finite, non-negative total expected for each source. Use `1` to validate an already-normalized transition-probability column. `NULL` (default) reports totals without enforcing a target.
- tolerance
Non-negative numeric tolerance for `expected_total`.
- action
How validation failures are handled: `"error"` (default), `"warning"`, or `"none"`. The report is returned in every mode.
Value
A data frame with one row per source and columns describing edge count, weight total, invalid-value counts, all-zero status, optional total agreement, and overall validity.
Examples
edges <- data.frame(
from = c("A", "A", "B"),
to = c("B", "C", "C"),
probability = c(0.25, 0.75, 1)
)
validate_edge_weights(
edges,
weight_col = "probability",
expected_total = 1
)
#> source n_edges total n_negative n_na n_nan n_infinite all_zero total_ok valid
#> 1 A 2 1 0 0 0 0 FALSE TRUE TRUE
#> 2 B 1 1 0 0 0 0 FALSE TRUE TRUE