validate_edge_weights: Validate Edge Weights and Per-Source Totals

View source: R/validate_edge_weights.R

validate_edge_weightsR Documentation

Validate Edge Weights and Per-Source Totals

Description

Inspect 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.

Usage

validate_edge_weights(
  edge_list_df,
  weight_col = "weight",
  from_col = "from",
  expected_total = NULL,
  tolerance = sqrt(.Machine$double.eps),
  action = c("error", "warning", "none")
)

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
)

pagerankr documentation built on Oct. 1, 2026, 5:09 p.m.