tie
- pmrf.parameters.tie(tree, target: str | ~typing.Sequence[str] | ~typing.Callable[[~typing.Any], ~typing.Any], source: str | ~typing.Sequence[str] | ~typing.Callable[[~typing.Any], ~typing.Any], fn: ~typing.Callable[[~typing.Any], ~typing.Any] = <function _identity>)
Returns a copy of a model in which one part is derived from another.
The target is removed from the model’s parameters and recomputed as
fn(source)every time the tree is resolved, so it follows the source throughupdate(), optimisation and sampling. A tie is not a replacement: useupdate()to replace a part once.fnreceives the source as the tie is applied, so a parameter arrives as its physical value. Tying a model that is already tied adds a tie; names refer to the untied model.A name resolves as it does for
update(): an exact name selects a parameter, or failing that a sub-model. A sub-model name, on either side, ties every parameter beneath it, pairing target and source by the suffix below the name and applying fn to each pair.- Parameters:
tree (PyTree) – A model, or any collection of models and parameters.
target (str, Sequence[str] or Callable) – The part to derive: a parameter name, a sub-model name, a sequence of names, or a callable returning nodes of tree.
source (str, Sequence[str] or Callable) – The part it is derived from, selected the same way.
fn (Callable, optional) – Maps the source to the target. Defaults to the identity.
- Returns:
A
pmrf.models.Wrappedif tree is apmrf.Model, so RF methods stay available; otherwise apmrf.modules.Tied, which is not a container. Read either back withresolve(), which applies the ties and returns the tree in its own shape with its parameters intact.- Return type:
PyTree
See also
resolveApply a tree’s ties, leaving its parameters as parameters.
- Raises:
ValueError – If a name is not found, if a sub-model name is ambiguous, if the two sub-models do not have matching parameter names beneath them, or if a target is under a joint prior, whose distribution must control it.
Examples
rc = Resistor(50.0, name='r') ** Capacitor(1e-12, name='c') tied = prf.tie(rc, 'r.R', 'c.C', fn=lambda C: C * 5e13) prf.params(tied) # {'c.C': Param(...)} prf.update(tied, {'c.C': 2e-12}).build().cascade[0].R # 100.0 parts = {'strip_a': MicrostripLine(...), 'strip_b': MicrostripLine(...)} tied = prf.tie(parts, 'strip_b', 'strip_a') # every parameter beneath prf.params(tied) # only `strip_a`'s