Learn R Programming

cograph (version 2.7.2)

simplify: Simplify a Network

Description

Removes self-loops and (where representable) merges duplicate (multi-)edges, similar to igraph::simplify().

Usage

simplify(x, remove_loops, remove_multiple, edge_attr_comb, ...)

# S3 method for matrix simplify( x, remove_loops = TRUE, remove_multiple = TRUE, edge_attr_comb = "mean", ... )

# S3 method for cograph_network simplify( x, remove_loops = TRUE, remove_multiple = TRUE, edge_attr_comb = "mean", ... )

# S3 method for igraph simplify( x, remove_loops = TRUE, remove_multiple = TRUE, edge_attr_comb = "mean", ... )

# S3 method for tna simplify( x, remove_loops = TRUE, remove_multiple = TRUE, edge_attr_comb = "mean", ... )

# S3 method for default simplify( x, remove_loops = TRUE, remove_multiple = TRUE, edge_attr_comb = "mean", ... )

Value

The simplified network, in the same format and class as the input (matrix in / matrix out, cograph_network in / cograph_network

out, and so on). The default method raises an error for any other class.

Arguments

x

Network input (matrix, cograph_network, igraph, tna object).

remove_loops

Logical. Remove self-loops (diagonal entries)?

remove_multiple

Logical. Merge duplicate edges? No-op for matrix/tna inputs (see Details).

edge_attr_comb

How to combine weights of duplicate edges: "sum", "mean", "max", "min", "first", or a custom function. Ignored for matrix/tna inputs.

...

Additional arguments (currently unused).

Details

The extent of simplification depends on the input representation:

  • matrix and tna: edges are stored as an n x n weight matrix. Each cell (i, j) is unique by construction, so duplicate-edge merging is a no-op regardless of remove_multiple / edge_attr_comb; only self-loops (the diagonal) can be removed. Convert to cograph_network or igraph first if you need true duplicate aggregation.

  • cograph_network: duplicate edges in the edge-list are merged via aggregate_duplicate_edges() using edge_attr_comb.

  • igraph: delegates to igraph::simplify().

See Also

filter_edges for conditional edge removal, centrality which has its own simplify parameter

Examples

Run this code
# igraph also exports simplify(); qualify the call when both are loaded.
# Matrix with self-loops
mat <- matrix(c(0.5, 0.3, 0, 0.3, 0.2, 0.4, 0, 0.4, 0.1), 3, 3)
rownames(mat) <- colnames(mat) <- c("A", "B", "C")
cograph::simplify(mat)

# Edge list with duplicates
edges <- data.frame(from = c(1, 1, 2), to = c(2, 2, 3), weight = c(0.3, 0.7, 0.5))
net <- cograph(edges, layout = NULL)
cograph::simplify(net)
cograph::simplify(net, edge_attr_comb = "sum")

Run the code above in your browser using DataLab