find_named_node#
- pymc_marketing.mmm.counterfactual.find_named_node(roots, name, *, exclude=())[source]#
Find the one node of a graph that carries a given name.
Not every interesting quantity is a registered variable of a PyMC model: an MMM’s linear predictor is a
Deterministicunder a log link but only an anonymous intermediate carrying the namemuunder an identity link, so it has to be recovered from the graph instead of looked up. Recovering it that way is sound only while the name picks out a single node, and graph traversal is unordered, so taking the first match would bind to whichever node happened to come up first. Downstream that decides whether the increment’s completeness check compares the right two quantities, and a wrong binding is invisible: it either refuses a correct model or passes a broken one. So an ambiguous name is refused rather than guessed at.- Parameters:
- rootssequence of
Variable The nodes whose ancestors are searched. The roots themselves are part of the search, as
ancestors()yields them.- name
str The name to look for.
- excludeiterable of
Variable, optional Nodes that may not be returned, compared by identity. The observed variable belongs here whenever it could carry the requested name itself, as a target column named after the quantity being searched for would otherwise resolve to the observation.
- rootssequence of
- Returns:
VariableorNoneThe single node carrying name, or
Noneif the graph carries no such node.
- Raises:
ValueErrorIf more than one distinct node carries name, since no choice between them can be made reliably.
Notes
muno longer reaches this function from a stock model. It is registered as aDeterministicunder both links, so callers resolve it throughnamed_varsand never scan the graph for it. A custom effect whose unregistered intermediate happens to be namedmuis therefore shadowed by the model’s own node rather than colliding with it. This function still guards names that are not registered.A custom effect that registers a
Deterministicnamedmuis a different matter: PyMC enforces unique names, so under the identity link that combination now fails inbuild_modelwithVariable name mu already exists. It used to build, because the identity branch only setmu_var.name, which does not register. Such an effect has to be renamed.