Model.add()

Contents

Model.add()#

Model.add(*args, copy=False, add_to_seeds=True)[source]#

Adds a variable number of variables or nodes to this model.

Parameters:
  • *args (Var | Node | Model) – Var or Node objects to add. Other Model instances are also accepted, in which case all nodes and variables from the supplied models are added to this model. Duplicate names are not allowed.

  • copy (bool, default: False) – If True, the supplied nodes, variables, and models are copied before adding them to this model.

  • add_to_seeds (bool, default: True) – If True, the supplied nodes and variables, and the seed nodes and variables of supplied models, are added to this model’s seed nodes and variables.

See also

Model.seed_nodes_and_vars

Seed nodes and variables.

Return type:

Self

Notes

If copy=False, any supplied model will be empty after adding its contents to the calling model.

Examples

Adding a variable:

>>> 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)
Model(7 nodes, 2 vars)
>>> list(m.vars)
['x2', 'x1']
>>> m.seed_nodes_and_vars
[Var(name="x1"), Var(name="x2")]

Adding a model:

>>> import liesel.model as lsl
>>> x1 = lsl.Var.new_obs(1.0, name="x1")
>>> x2 = lsl.Var.new_obs(1.0, name="x2")
>>> m1 = lsl.Model(x1)
>>> m2 = lsl.Model(x2)
>>> m1.add(m2)
Model(7 nodes, 2 vars)
>>> list(m1.vars)
['x2', 'x1']
>>> list(m2.vars)
[]
>>> m1.seed_nodes_and_vars
[Var(name="x1"), Var(name="x2")]