Model.join()#
- Model.join(model, by=None, copy=False, suffix=('.x', '.y'))[source]#
Joins a second model into this one.
- Parameters:
model (
Model) – The second model to join into this one.by (
Sequence[str] |None, default:None) – Sequence of variable names to join on.copy (
bool, default:False) – Whether to copy the second model before joining.suffix (
tuple[str,str], default:('.x', '.y')) – Suffixes to use for renaming of variables with duplicate names.
See also
Model.join_by_allAutomatically join by all overlapping names.
- Return type:
Self
Notes
If there are variables with duplicate names, the method’s behavior depends on
by:If the duplicate name is supplied in
by, then the variables fromself(i.e., the model on which the method is called) are used. They replace the respective variables in the second model.If the duplicate name is not supplied in
by, then the duplicate names are resolved by renaming the respective variables from both models usingsuffix.
The seed nodes of the second model are added to the calling model’s seed nodes.
Examples
Nothing supplied in
by, duplicate names are resolved by renaming:>>> import liesel.model as lsl >>> x1 = lsl.Var.new_obs(1.0, name="x") >>> x2 = lsl.Var.new_obs(1.0, name="x") >>> y = lsl.Var.new_calc(lambda x: x, x2, name="y") >>> m1 = lsl.Model(x1) >>> m2 = lsl.Model(x2, y) >>> m1.join(m2) Model(9 nodes, 3 vars) >>> list(m1.vars) ['x.y', 'x.x', 'y'] >>> list(m2.vars) [] >>> m1.seed_nodes_and_vars [Var(name="x.x"), Var(name="x.y"), Var(name="y")]
Joining on ‘x’:
>>> import liesel.model as lsl >>> x1 = lsl.Var.new_obs(1.0, name="x") >>> x2 = lsl.Var.new_obs(1.0, name="x") >>> y = lsl.Var.new_calc(lambda x: x, x2, name="y") >>> m1 = lsl.Model(x1) >>> m2 = lsl.Model(x2, y) >>> m1.join(m2, by=["x"]) Model(7 nodes, 2 vars) >>> list(m1.vars) ['x', 'y'] >>> list(m2.vars) [] >>> y.value_node[0] is x1 True >>> m1.seed_nodes_and_vars [Var(name="x"), Var(name="y")]