Skip to contents

This function is part of the probabilistic network module, whose API may still evolve in future versions.

Usage

prob_net_update(
  graph,
  add_links = NULL,
  remove_links = NULL,
  update_distributions = NULL
)

Arguments

graph

An existing probabilistic network created by prob_net().

Optional. A data frame with columns source and target to add new links.

Optional. A data frame with columns source and target to remove existing links.

update_distributions

Optional. A named list of distributions to update. Format follows prob_net().

Value

An updated prob_net object with modified links and/or distributions.

Details

This function updates an existing probabilistic network by adding or removing dependencies (edges) and updating probability distributions for nodes.

The updated network is re-validated with the same rules prob_net() applies, so the edge changes and the distribution changes must agree. Removing the edge into a conditional node without also replacing that node's distribution is an error, which is what makes remove_links structurally meaningful: an intervention that severs a dependency has to sever it in both the graph and the distribution list.

Examples

nodes <- data.frame(id = c("A", "B", "C"))
links <- data.frame(source = c("A", "B"), target = c("B", "C"))
distributions <- list(
  A = list(type = "discrete", values = c(1, 0), probs = c(0.5, 0.5)),
  B = list(
    type = "conditional", condition = "A",
    true_dist  = list(type = "normal", mean = 5, sd = 1),
    false_dist = list(type = "normal", mean = 1, sd = 1)
  ),
  C = list(type = "aggregate", nodes = "B")
)
graph <- prob_net(nodes, links, distributions)

# Intervene on B: sever its dependence on A and fix it to the baseline cost.
updated_graph <- prob_net_update(
  graph,
  remove_links = data.frame(source = "A", target = "B"),
  update_distributions = list(B = list(type = "normal", mean = 1, sd = 1))
)