riantr/moonbit_dowhy/graph does not have a README file

    CausalGraph

    pub struct CausalGraph {
    treatment_name : Array[String]
    outcome_name : Array[String]
    graph : DirectedGraph
    observed : Map[String, Bool]
    effect_modifiers : Array[String]
    }

    A causal graph with the semantic role of every node.

    CausalGraph::add_missing_nodes_as_common_causes

    fn CausalGraph::add_missing_nodes_as_common_causes(self : CausalGraph, observed_node_names : Array[String]) -> DirectedGraph

    Add the columns of the data that are not part of the graph as confounders.

    CausalGraph::add_unobserved_common_cause

    fn CausalGraph::add_unobserved_common_cause(self : CausalGraph) -> DirectedGraph

    Add an unobserved common cause to the graph.

    CausalGraph::all_observed

    fn CausalGraph::all_observed(self : CausalGraph, node_names : Array[String]) -> Bool

    Whether every given node is observed.

    CausalGraph::check_dseparation

    fn CausalGraph::check_dseparation(self : CausalGraph, nodes1 : Array[String], nodes2 : Array[String], nodes3 : Array[String], new_graph : DirectedGraph?) -> Bool

    Whether the two node sets are d-separated given the conditioning set.

    CausalGraph::check_valid_backdoor_set

    fn CausalGraph::check_valid_backdoor_set(self : CausalGraph, nodes1 : Array[String], nodes2 : Array[String], nodes3 : Array[String], new_graph : DirectedGraph?, algo? : DseparationAlgorithm) -> Bool

    Whether the candidate set blocks the backdoor paths.

    The default algorithm of the upstream removes the outgoing edges of the treatment and asks for the d-separation of the two node sets given the candidate set; the naive one asks for every backdoor path to be blocked.

    CausalGraph::check_valid_frontdoor_set

    fn CausalGraph::check_valid_frontdoor_set(self : CausalGraph, nodes1 : Array[String], nodes2 : Array[String], candidate_nodes : Array[String], frontdoor_paths : Array[Array[String]], new_graph : DirectedGraph?, algo? : DseparationAlgorithm) -> Bool

    Whether the candidate set is a valid frontdoor set.

    The default algorithm of the upstream asks for the d-separation of the two node sets given the candidate set; the naive one asks for every directed path from the treatment to the outcome to be blocked.

    CausalGraph::check_valid_mediation_set

    fn CausalGraph::check_valid_mediation_set(self : CausalGraph, nodes1 : Array[String], nodes2 : Array[String], candidate_nodes : Array[String], mediation_paths : Array[Array[String]]) -> Bool

    Whether the candidate set mediates the effect.

    CausalGraph::directed_graph

    fn CausalGraph::directed_graph(self : CausalGraph) -> DirectedGraph

    The underlying directed graph.

    CausalGraph::do_surgery

    fn CausalGraph::do_surgery(self : CausalGraph, node_names : Array[String], remove_outgoing_edges : Bool, remove_incoming_edges : Bool, target_node_names : Array[String], remove_only_direct_edges_to_target : Bool) -> DirectedGraph

    A graph with the edges of the given nodes removed.

    CausalGraph::get_adjacency_matrix

    The adjacency matrix of the graph.

    CausalGraph::get_all_directed_paths

    fn CausalGraph::get_all_directed_paths(self : CausalGraph, nodes1 : Array[String], nodes2 : Array[String]) -> Array[Array[String]]

    The directed paths between two singleton node sets.

    CausalGraph::get_all_nodes

    fn CausalGraph::get_all_nodes(self : CausalGraph, include_unobserved : Bool) -> Array[String]

    The nodes of the graph.

    CausalGraph::get_ancestors

    fn CausalGraph::get_ancestors(self : CausalGraph, node_name : String) ->
    Set
    [String]

    The strict ancestors of a node.

    CausalGraph::get_common_causes

    fn CausalGraph::get_common_causes(self : CausalGraph, nodes1 : Array[String], nodes2 : Array[String]) -> Array[String]

    The common causes of two node sets.

    The treatment contributes its ancestors, the outcome contributes its parents and their ancestors.

    CausalGraph::get_descendants

    fn CausalGraph::get_descendants(self : CausalGraph, nodes : Array[String]) ->
    Set
    [String]

    The strict descendants of a set of nodes.

    CausalGraph::get_effect_modifiers

    fn CausalGraph::get_effect_modifiers(self : CausalGraph, nodes1 : Array[String], nodes2 : Array[String]) -> Array[String]

    The effect modifiers of the graph.

    CausalGraph::get_instruments

    fn CausalGraph::get_instruments(self : CausalGraph, treatment_nodes : Array[String], outcome_nodes : Array[String]) -> Array[String]

    The instruments of the treatment.

    CausalGraph::get_parents

    fn CausalGraph::get_parents(self : CausalGraph, node_name : String) -> Array[String]

    The parents of a node.

    CausalGraph::has_directed_path

    fn CausalGraph::has_directed_path(self : CausalGraph, action_nodes : Array[String], outcome_nodes : Array[String]) -> Bool

    Whether every treatment reaches an outcome and vice versa.

    CausalGraph::is_observed

    fn CausalGraph::is_observed(self : CausalGraph, node_name : String) -> Bool

    Whether a node is observed.

    CausalGraph::new

    fn CausalGraph::new(treatment_name : Array[String], outcome_name : Array[String], graph : DirectedGraph?, common_cause_names : Array[String], instrument_names : Array[String], effect_modifier_names : Array[String], mediator_names : Array[String], observed_node_names : Array[String]) -> CausalGraph

    Build a causal graph.

    When graph is given it is used as is, otherwise the graph is built from the semantic roles of the variables.

    CausalGraph::observed_nodes

    fn CausalGraph::observed_nodes(self : CausalGraph) -> Array[String]

    The observed nodes of the graph.

    CausalGraph::outcomes

    fn CausalGraph::outcomes(self : CausalGraph) -> Array[String]

    The outcome variables.

    CausalGraph::treatments

    fn CausalGraph::treatments(self : CausalGraph) -> Array[String]

    The treatment variables.

    DirectedGraph

    pub struct DirectedGraph {
    nodes : Array[String]
    node_set :
    Set
    [String]
    succ : Map[String, Array[String]]
    pred : Map[String, Array[String]]
    edges : Array[(String, String)]
    }

    A directed graph, the substrate of every causal graph in the library.

    Node and edge insertion order is preserved, which keeps the generated results (adjustment sets, paths, topological orders) deterministic.

    DirectedGraph::add_edge

    fn DirectedGraph::add_edge(self : DirectedGraph, from : String, to : String) -> Unit

    Add an edge, creating the endpoints when they are new.

    DirectedGraph::add_node

    fn DirectedGraph::add_node(self : DirectedGraph, name : String) -> Unit

    Add a node, ignoring duplicates.

    DirectedGraph::all_simple_paths

    fn DirectedGraph::all_simple_paths(self : DirectedGraph, from : String, to : String) -> Array[Array[String]]

    All simple paths from from to to.

    The paths are enumerated in the order the neighbours are stored, which keeps the result deterministic.

    DirectedGraph::all_simple_paths_undirected

    fn DirectedGraph::all_simple_paths_undirected(self : DirectedGraph, from : String, to : String) -> Array[Array[String]]

    All simple paths between two nodes, ignoring the direction of the edges.

    The backdoor paths live in the underlying undirected graph, so the traversal walks both the parents and the children of a node.

    DirectedGraph::ancestors

    fn DirectedGraph::ancestors(self : DirectedGraph, name : String) ->
    Set
    [String]

    The strict ancestors of a node.

    DirectedGraph::ancestors_of

    fn DirectedGraph::ancestors_of(self : DirectedGraph, names : Array[String]) ->
    Set
    [String]

    The union of the ancestors of several nodes.

    DirectedGraph::copy

    A copy of the graph.

    DirectedGraph::descendants

    fn DirectedGraph::descendants(self : DirectedGraph, name : String) ->
    Set
    [String]

    The strict descendants of a node.

    DirectedGraph::descendants_of

    fn DirectedGraph::descendants_of(self : DirectedGraph, names : Array[String]) ->
    Set
    [String]

    The union of the descendants of several nodes.

    DirectedGraph::edge_count

    fn DirectedGraph::edge_count(self : DirectedGraph) -> Int

    The number of edges.

    DirectedGraph::edge_list

    fn DirectedGraph::edge_list(self : DirectedGraph) -> Array[(String, String)]

    The edges of the graph in insertion order.

    DirectedGraph::has_edge

    fn DirectedGraph::has_edge(self : DirectedGraph, from : String, to : String) -> Bool

    Whether the graph contains the edge.

    DirectedGraph::has_node

    fn DirectedGraph::has_node(self : DirectedGraph, name : String) -> Bool

    Whether the graph contains the node.

    DirectedGraph::has_path

    fn DirectedGraph::has_path(self : DirectedGraph, from : String, to : String) -> Bool

    Whether a path exists from from to to.

    DirectedGraph::is_dag

    fn DirectedGraph::is_dag(self : DirectedGraph) -> Bool

    Whether the graph is acyclic.

    DirectedGraph::new

    A new empty graph.

    DirectedGraph::node_connected_subgraph_view

    fn DirectedGraph::node_connected_subgraph_view(self : DirectedGraph, name : String) -> DirectedGraph

    The sub graph induced by the nodes that can reach the given node.

    This is the port of dowhy.graph.node_connected_subgraph_view, which keeps the nodes of the graph that have a path to the given node.

    DirectedGraph::node_count

    fn DirectedGraph::node_count(self : DirectedGraph) -> Int

    The number of nodes.

    DirectedGraph::node_list

    fn DirectedGraph::node_list(self : DirectedGraph) -> Array[String]

    The nodes of the graph in insertion order.

    DirectedGraph::ordered_predecessors

    fn DirectedGraph::ordered_predecessors(self : DirectedGraph, name : String) -> Array[String]

    The predecessors of a node, sorted by their name.

    This is the port of dowhy.graph.get_ordered_predecessors. The order of the predecessors is not reliable otherwise, and the columns of a data frame are picked by the parents of a node.

    DirectedGraph::predecessors

    fn DirectedGraph::predecessors(self : DirectedGraph, name : String) -> Array[String]

    The parents of a node.

    The returned array is a copy, so a caller may modify it without changing the graph.

    DirectedGraph::remove_edge

    fn DirectedGraph::remove_edge(self : DirectedGraph, from : String, to : String) -> Unit

    Remove an edge from the graph.

    DirectedGraph::remove_node

    fn DirectedGraph::remove_node(self : DirectedGraph, name : String) -> Unit

    Remove the node with the given name and every edge that touches it.

    This is the port of networkx.DiGraph.remove_node. Removing a node that is not in the graph does nothing.

    DirectedGraph::subgraph

    fn DirectedGraph::subgraph(self : DirectedGraph, names : Array[String]) -> DirectedGraph

    The sub graph induced by the given nodes.

    DirectedGraph::successors

    fn DirectedGraph::successors(self : DirectedGraph, name : String) -> Array[String]

    The children of a node.

    The returned array is a copy, so a caller may modify it without changing the graph.

    DirectedGraph::to_dot

    fn DirectedGraph::to_dot(self : DirectedGraph) -> String

    The graph in Graphviz DOT format.

    DirectedGraph::topological_order

    fn DirectedGraph::topological_order(self : DirectedGraph) -> Array[String]

    A topological order of the graph.

    Returns an empty array when the graph has a cycle.

    DotEdge

    pub struct DotEdge {
    source : String
    target : String
    label : String?
    }

    An edge of a DOT string.

    DseparationAlgorithm

    pub enum DseparationAlgorithm {
    Default
    Naive
    }

    The algorithm of the checks of the adjustment sets.

    This is the port of the dseparation_algo argument of the upstream, which is the string "default" or "naive".

    DseparationAlgorithm::default

    The d-separation of the graph.

    DseparationAlgorithm::naive

    The naive check of the paths.

    add_edge

    fn add_edge(graph : DirectedGraph, from : String, to : String) -> Unit

    Add the edge between the two nodes, unless the graph would have a cycle.

    This is the port of dowhy.utils.graph_operations.add_edge: the edge is taken back when the graph is not acyclic with it.

    adjacency_matrix_to_adjacency_list

    fn adjacency_matrix_to_adjacency_list(matrix :
    Matrix
    , labels : Array[String]?) -> Map[String, Array[String]]

    The adjacency list of an adjacency matrix.

    This is the port of dowhy.utils.graph_operations.adjacency_matrix_to_adjacency_list. The keys are the labels of the nodes and the values are the labels of the children of the nodes, in the order of the columns of the matrix.

    The labels of the nodes are the numbers one, two and so on when the caller gives none, the way the upstream numbers them.

    adjacency_matrix_to_dot

    fn adjacency_matrix_to_dot(matrix :
    Matrix
    , labels : Array[String]?) -> String

    The DOT graph of an adjacency matrix.

    This is the port of dowhy.utils.graph_operations.adjacency_matrix_to_graph, which builds a graphviz.Digraph of the matrix. The port returns the source of that graph, the way the upstream reads it back with str_to_dot.

    Only the edges whose weight is larger than 0.01 in absolute value become edges of the graph, and the label of an edge is its weight.

    The upstream draws the edges from the column to the row of the matrix, the way its own loop over the indices of the matrix does; the port does the same.

    build_graph

    fn build_graph(action_nodes : Array[String], outcome_nodes : Array[String], common_cause_nodes : Array[String], instrument_nodes : Array[String], effect_modifier_nodes : Array[String], mediator_nodes : Array[String]) -> DirectedGraph

    Build a graph from the semantic role of the variables.

    check_valid_mediation_set

    fn check_valid_mediation_set(graph : DirectedGraph, nodes1 : Array[String], nodes2 : Array[String], candidate_nodes : Array[String], mediation_paths : Array[Array[String]]) -> Bool

    Whether the candidate set mediates the effect.

    This is the port of dowhy.graph.check_valid_mediation_set: the candidate set mediates the effect when it blocks one of the directed paths from the treatment to the outcome.

    convert_to_undirected_graph

    fn convert_to_undirected_graph(graph : DirectedGraph) -> DirectedGraph

    The graph of the edges of the graph, read in both directions.

    This is the port of dowhy.utils.graph_operations.convert_to_undirected_graph. The port has no undirected graph, so every edge of the graph becomes an edge in both directions.

    d_separated

    fn d_separated(graph : DirectedGraph, x : Array[String], y : Array[String], z : Array[String]) -> Bool

    Whether x and y are d-separated given z.

    Returns true when the two node sets are separated by the conditioning set.

    The traversal follows the classical "active path" characterisation: a path is active given z when every non collider on it is outside z and every collider on it is in z or has a descendant in z. The descendant test is what the ancestor set of z provides.

    daggity_fixture

    fn daggity_fixture() -> String

    The graph of the daggity web site, as the upstream writes it.

    daggity_to_dot

    fn daggity_to_dot(daggity : String) -> String

    The graph of a daggity string, in the DOT format.

    This is the port of dowhy.utils.graph_operations.daggity_to_dot, which turns the graph of the daggity web site into a DOT graph: every line becomes a statement, the dag keyword becomes digraph, the outcome, adjusted and exposure attributes are dropped and the latent attribute becomes the observed attribute of the node.

    del_edge

    fn del_edge(graph : DirectedGraph, from : String, to : String) -> Unit

    Remove the edge between the two nodes, unless the graph would fall apart.

    This is the port of dowhy.utils.graph_operations.del_edge: the edge is put back when the graph is not connected without it.

    do_surgery

    fn do_surgery(graph : DirectedGraph, node_names : Array[String], remove_outgoing_edges : Bool, remove_incoming_edges : Bool, target_node_names : Array[String], remove_only_direct_edges_to_target : Bool) -> DirectedGraph

    A graph with the edges of the given nodes removed.

    • remove_outgoing_edges drops every edge leaving the focal nodes;
    • remove_incoming_edges drops every edge entering the focal nodes;
    • remove_only_direct_edges_to_target restricts the removal to the edges that point at target_node_names.

    find_ancestor

    fn find_ancestor(graph : DirectedGraph, nodes : Array[String]) ->
    Set
    [String]

    The ancestors of the given nodes, the nodes themselves included.

    This is the port of dowhy.utils.graph_operations.find_ancestor.

    find_c_components

    fn find_c_components(graph : DirectedGraph, nodes : Array[String]) -> Array[Array[String]]

    The C-components of the graph.

    This is the port of dowhy.utils.graph_operations.find_c_components: the connected components of the graph of the edges that point in both directions.

    find_predecessor

    fn find_predecessor(graph : DirectedGraph, i : String, j : String) -> String?

    A predecessor of the second node on a path to the first one.

    This is the port of dowhy.utils.graph_operations.find_predecessor: the first parent of the second node whose path to the first node exists when the edges are read in both directions.

    get_all_directed_paths

    fn get_all_directed_paths(graph : DirectedGraph, nodes1 : Array[String], nodes2 : Array[String]) -> Array[Array[String]]

    The directed paths between two singleton node sets.

    get_backdoor_paths

    fn get_backdoor_paths(graph : DirectedGraph, nodes1 : Array[String], nodes2 : Array[String]) -> Array[Array[String]]

    The backdoor paths between two node sets.

    A path is a backdoor path when its first edge points into the treatment.

    get_instruments

    fn get_instruments(graph : DirectedGraph, treatment_nodes : Array[String], outcome_nodes : Array[String]) -> Array[String]

    The instruments of the treatment, following dowhy.graph.get_instruments.

    get_proper_backdoor_graph

    fn get_proper_backdoor_graph(graph : DirectedGraph, action_nodes : Array[String], outcome_nodes : Array[String]) -> DirectedGraph

    The proper backdoor graph of the given causal graph.

    get_proper_causal_path_nodes

    fn get_proper_causal_path_nodes(graph : DirectedGraph, action_nodes : Array[String], outcome_nodes : Array[String]) ->
    Set
    [String]

    The nodes that lie on a proper causal path from the actions to the outcomes, as defined by van der Zander et al.

    get_random_node_pair

    fn get_random_node_pair(count : Int, random :
    NumpyRandom
    ) -> (Int, Int)

    A pair of two different nodes.

    This is the port of dowhy.utils.graph_operations.get_random_node_pair. The upstream draws the two numbers from the global generator of numpy; the port draws them from the generator it is given, so the two numbers are the numbers of numpy for the seed of that generator.

    The upstream loops forever when there is only one node, because the second number can never differ from the first one; the port does the same.

    get_simple_ordered_tree

    fn get_simple_ordered_tree(count : Int) -> DirectedGraph

    The simple ordered tree of the given number of nodes.

    This is the port of dowhy.utils.graph_operations.get_simple_ordered_tree: the graph 0 -> 1 -> ..., whose nodes are numbered from zero.

    has_directed_path

    fn has_directed_path(graph : DirectedGraph, action_nodes : Array[String], outcome_nodes : Array[String]) -> Bool

    Whether every treatment has a directed path to an outcome and vice versa.

    induced_graph

    fn induced_graph(graph : DirectedGraph, nodes : Array[String]) -> DirectedGraph

    The graph induced by the given nodes.

    This is the port of dowhy.utils.graph_operations.induced_graph.

    is_blocked

    fn is_blocked(graph : DirectedGraph, path : Array[String], conditioned_nodes : Array[String]) -> Bool

    Whether a path is blocked by the given conditioning set.

    is_connected

    fn is_connected(graph : DirectedGraph) -> Bool

    Whether the graph is connected when its edges are read in both directions.

    This is the port of dowhy.utils.graph_operations.is_connected.

    parse_dot

    fn parse_dot(text : String) -> DirectedGraph

    The graph of a DOT string.

    The graph is directed, like the networkx.DiGraph the upstream builds.

    parse_dot_edges

    fn parse_dot_edges(text : String) -> Array[DotEdge]

    The edges of a DOT string, with the label of every edge.

    The edges keep the order of the statements of the DOT string.

    parse_gml

    fn parse_gml(text : String) -> DirectedGraph

    The graph of a GML string.

    The graph is directed, like the networkx.DiGraph the upstream builds.

    The edges of a GML graph name the id of their nodes, while the name of a node is its label, so the edges are resolved with the labels of the nodes the way networkx.parse_gml resolves them.

    str_to_dot

    fn str_to_dot(text : String) -> String

    The compact DOT graph of a DOT graph.

    This is the port of dowhy.utils.graph_operations.str_to_dot. The upstream turns every line of the graph into a statement of its own, drops the semicolon that follows the opening brace and the one that precedes the closing brace, and keeps the braces.

    The result is a graph the DOT reader of the port reads.