Skip to contents

Computes modulation factors for gradient flow based on vertex density and/or edge length distribution. Returns modulated edge weights along with intermediate objects for inspection and debugging.

Usage

compute.gfc.modulation(
  adj.list,
  weight.list,
  modulation = c("density", "edgelen", "density_edgelen"),
  density = NULL,
  edgelen.bandwidth = "auto",
  normalize.weights = TRUE,
  verbose = TRUE
)

Arguments

adj.list

Graph adjacency list (1-based indexing).

weight.list

Edge weight list (edge lengths).

modulation

Character string specifying modulation type. "density" for vertex density modulation (edges weighted by target vertex density), "edgelen" for edge length modulation (edges weighted by length distribution density), or "density_edgelen" for combined modulation (product of both).

density

Optional numeric vector of pre-computed density values. If NULL, computed from nearest neighbor distances (raw d1 inverse). Smoothed density must be estimated externally; the archived rdgraph-based helper is gflowx::compute.smoothed.density().

edgelen.bandwidth

Bandwidth for edge length KDE. If "auto" (default), uses Sheather-Jones method via bw.SJ(). Can also be a positive numeric value for manual bandwidth, or a character string for other bandwidth selectors: "nrd0", "nrd", "ucv", "bcv", or "SJ".

normalize.weights

Logical; if TRUE (default), normalize modulated weights so that for each vertex the maximum outgoing weight equals the original maximum.

verbose

Logical; print progress information.

Value

An object of class "gfc_modulation" containing:

modulated.weight.list

List of modulated edge weights.

modulation

The modulation type used.

density

Vertex density values (NULL if not computed).

density.raw

Logical; TRUE if density was computed internally (raw d1 inverse).

edgelen.weights

Named list of edge length weights, where names are "v-u" for edge from v to u (NULL if not computed).

edgelen.bandwidth

Bandwidth used for edge length KDE.

edgelen.kde

The full density object from R's density() function, useful for plotting and inspection.

edgelen.lengths

Vector of all unique edge lengths.

edgelen.densities

KDE density at each edge length (before normalization).

n.vertices

Number of vertices.

n.edges

Number of unique edges.

Details

The modulation factors are applied to edge weights as follows. For an edge from v to u with original weight w(v,u), the modulated weight is: for "density", w'(v,u) = w(v,u) * rho(u); for "edgelen", w'(v,u) = w(v,u) * dl(v,u); for "density_edgelen", w'(v,u) = w(v,u) * rho(u) * dl(v,u). Here rho(u) is the density at vertex u and dl(v,u) is the edge length density weight.