Model.rebuild_graph()#
- Model.rebuild_graph(*vars_nodes_and_names)[source]#
Rebuilds the model graph by re-discovering the outputs of all supplied nodes and variables. Also accepts strings, which must be the names of nodes or variables currently in the model.
If no nodes or variables are supplied, uses the
seed_nodes_and_varssupplied to the model during initialization.- Return type:
Self
Examples
Here, a variable that was added manually but not added to the seed variables is dropped when rebuilding the graph:
>>> import liesel.model as lsl >>> x1 = lsl.Var.new_obs(1.0, name="x1") >>> x2 = lsl.Var.new_obs(1.0, name="x2") >>> m = lsl.Model(x1) >>> m.add(x2, add_to_seeds=False) Model(7 nodes, 2 vars) >>> list(m.vars) ['x2', 'x1'] >>> m.rebuild_graph() Model(5 nodes, 1 vars) >>> list(m.vars) ['x1']
Here, the model is empty after dropping the singletons, but gets restored when rebuilding, because the whole graph can be rediscovered from the seed nodes.
>>> x1 = lsl.Var.new_obs(1.0, name="x1") >>> x2 = lsl.Var.new_obs(1.0, name="x2") >>> m = lsl.Model(x1, x2) >>> m.drop_singletons() Model(3 nodes, 0 vars) >>> list(m.vars) [] >>> m.seed_nodes_and_vars [Var(name="x1"), Var(name="x2")] >>> m.rebuild_graph() Model(7 nodes, 2 vars) >>> list(m.vars) ['x2', 'x1']