Learn R Programming

PCBN (version 0.1.1)

active_cycles: Checks if a graph contains active cycles

Description

Checks if a graph contains active cycles

Usage

active_cycles(DAG, early.stopping = FALSE)

has_active_cycles(DAG)

plot_active_cycles(DAG, active_cycles_list = NULL)

Value

active_cycles returns a list containing the active cycles. Each active cycle is a character vector of the name of the nodes involved in the active cycle. The first element of this vector is the converging node of the active cycle.

has_active_cycles returns TRUE if at least 1 active cycle is found. Otherwise, it returns FALSE.

plot_active_cycles is called for its side-effects only. It plots the active cycles if any, and else prints a message.

Arguments

DAG

Directed Acyclic

early.stopping

if TRUE, stop at the first active cycle that is found.

active_cycles_list

a list of active cycles as given by active_cycles. If this is NULL, the function active_cycles is run on DAG to find the active cycles to be displayed.

See Also

the helper functions path_hasConvergingConnections, path_hasChords that are used to find the active cycles.

is_restrictedDAG to check also whether the DAG contains interfering v-structures.

Examples

Run this code

DAG = create_empty_DAG(4)
DAG = bnlearn::set.arc(DAG, 'U1', 'U3')
DAG = bnlearn::set.arc(DAG, 'U2', 'U3')
DAG = bnlearn::set.arc(DAG, 'U1', 'U4')
DAG = bnlearn::set.arc(DAG, 'U2', 'U4')
DAG = bnlearn::set.arc(DAG, 'U3', 'U4')

active_cycles(DAG)  # no active cycle

DAG = create_empty_DAG(4)
DAG = bnlearn::set.arc(DAG, 'U1', 'U2')
DAG = bnlearn::set.arc(DAG, 'U1', 'U3')
DAG = bnlearn::set.arc(DAG, 'U2', 'U4')
DAG = bnlearn::set.arc(DAG, 'U3', 'U4')

active_cycles(DAG)  # 1 active cycle

DAG = create_empty_DAG(5)
DAG = bnlearn::set.arc(DAG, 'U1', 'U2')
DAG = bnlearn::set.arc(DAG, 'U1', 'U3')
DAG = bnlearn::set.arc(DAG, 'U2', 'U4')
DAG = bnlearn::set.arc(DAG, 'U3', 'U4')
DAG = bnlearn::set.arc(DAG, 'U2', 'U5')
DAG = bnlearn::set.arc(DAG, 'U3', 'U5')

active_cycles(DAG)  # 2 active cycles
active_cycles(DAG, early.stopping = TRUE)  # The first active cycle

# Plotting the active cycles
plot_active_cycles(DAG)
# which is the same as
plot_active_cycles(DAG, active_cycles_list = active_cycles(DAG))

# We now fix the active cycles by adding the some arcs.
fixedDAG = fix_active_cycles(DAG)
# We can see that no active cycles is plotted anymore
plot_active_cycles(fixedDAG)
has_active_cycles(fixedDAG)
# This is because two edges have been added, as can be seen on:
plot(fixedDAG)

Run the code above in your browser using DataLab