new.incgraph.network: IncGraph network

Description Usage Arguments Details Value See Also Examples

View source: R/incgraph_wrapper.R

Description

new.incgraph.network creates a new IncGraph object containing either an empty network or a network initialised from a given matrix.

Usage

1
2
3
4
5
new.incgraph.network(amnt.nodes, links=NULL)

new.incgraph.network(amnt.nodes=NULL, links)

new.incgraph.network(amnt.nodes, links)

Arguments

amnt.nodes

The number of nodes in the network

links

A matrix with 2 columns and N rows, 1 row for each edge to be loaded in the network

Details

This creates a new instance of the incgraph.network class. At least one of the parameters (amnt.nodes or links) needs to be passed to this function. Please note that this is a stateful object.

Value

An instance of the incgraph.network class

See Also

incgraph, calculate.orbit.counts, calculate.delta

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# Create a new (empty) network with 4 nodes
net <- new.incgraph.network(amnt.nodes = 4)

# Create a new network with 4 nodes and some edges
net <- new.incgraph.network(links = matrix(c(1, 2, 2, 3, 1, 4), ncol=2))

# Create a new network with 10 nodes and some edges
net <- new.incgraph.network(amnt.nodes = 10, links = matrix(c(1, 2, 2, 3, 1, 4), ncol=2))

# Create a more complex network from a matrix
mat <- matrix(c(1, 2,
                1, 3,
                1, 4,
                1, 5,
                1, 6,
                1, 7,
                2, 7,
                2, 8,
                2, 9,
                2, 10), ncol=2)
net <- new.incgraph.network(links=mat)
# Calculate the initial orbit counts using orca
orb.counts <- calculate.orbit.counts(net)
# Modify an edge and calculate the differences in orbit counts
flip(net, 5, 10) # add (5,10)
delta1 <- calculate.delta(net, 5, 10)
# Modify another edge
flip(net, 6, 10) # add (6, 10)
delta2 <- calculate.delta(net, 6, 10)
# And another
flip(net, 1, 5)  # remove (1, 5)
delta3 <- calculate.delta(net, 1, 5)
# Verify that the new orbit counts equals the old orbit counts plus the delta counts
new.orb.counts.incremental <- orb.counts +
  delta1$add - delta1$rem +
  delta2$add - delta2$rem +
  delta3$add - delta3$rem
new.orb.counts <- calculate.orbit.counts(net)
all(new.orb.counts.incremental == new.orb.counts) # TRUE

## Additional helper functions
# Transform the network to a matrix
network.as.matrix(net)
# Get all neighbours of a node
get.neighbours(net, 1)
# Does the network contain a specific interaction?
contains(net, 5, 10)
contains(net, 7, 10)
# Reinitialise to an empty network
reset(net)
network.as.matrix(net)

rcannood/incgraph documentation built on Dec. 11, 2019, 12:25 p.m.