Documentation
¶
Overview ¶
Package transform contains structure-preserving and structure-randomizing graph transformations: copying, relabeling, and degree-preserving edge swaps.
Index ¶
- func Copy(g *gonx.Graph) *gonx.Graph
- func DoubleEdgeSwap(g *gonx.Graph, nswap, maxTries int, r *rand.Rand) (*gonx.Graph, int, error)
- func RelabelNodes(g *gonx.Graph, perm []int) (*gonx.Graph, error)
- func Shuffle(g *gonx.Graph, r *rand.Rand) *gonx.Graph
- func ShuffleWithPerm(g *gonx.Graph, r *rand.Rand) (*gonx.Graph, []int)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DoubleEdgeSwap ¶
DoubleEdgeSwap randomizes a graph while exactly preserving every node's degree. It repeatedly picks two edges {a,b} and {c,d} and rewires them to {a,d} and {c,b}, rejecting any swap that would create a self-loop or a duplicate edge. It performs up to nswap successful swaps, giving up after maxTries attempts. The returned int is the number of swaps actually performed.
The operation works on a copy; g is left unchanged. This mirrors networkx.double_edge_swap and is the standard way to build degree-preserving null models: graphs with the same degree sequence as the original but otherwise randomized wiring.
Example ¶
package main
import (
"fmt"
"github.com/LuisLSousa/gonx"
"github.com/LuisLSousa/gonx/generators"
"github.com/LuisLSousa/gonx/transform"
)
func main() {
g, _ := generators.WattsStrogatz(100, 6, 0, gonx.NewRand(1))
swapped, n, _ := transform.DoubleEdgeSwap(g, 50, 10000, gonx.NewRand(2))
// Swaps rewire edges but every node keeps its exact degree.
fmt.Println(n, swapped.NumEdges() == g.NumEdges(), swapped.Degree(0) == g.Degree(0))
}
Output: 50 true true
func RelabelNodes ¶
RelabelNodes returns a new graph in which node i becomes node perm[i]. perm must be a permutation of [0, N). The transformation is a graph isomorphism: it preserves the degree sequence and all structural metrics, changing only the identities attached to each position.
Types ¶
This section is empty.