params (pmrf.params)
- pmrf.params(tree, where: str | Sequence[str] | Callable[[Any], Any] = '*', *, free_only: bool = False) dict[str, TypeAliasForwardRef('Param')]
Returns the parameters of a model, or any collection of models, by name.
Parameters and modules can be given names upon construction. If no custom names are present, attribute paths are used. A named module collapses the path to its left into a namespace, and a named parameter collapses its path to the nearest named module or the root. Nested named modules are joined with
_. String dictionary keys that are identifiers become dotted names (components.cable.length); other keys keep the bracket form.Names see through freezing and wrappers such as
pmrf.modules.Tiedand a joint prior (pmrf.modules.Probabilistic), so attaching either keeps the names. The target of a tie is derived rather than stored, so it is not named.- Parameters:
tree (PyTree) – A model, or any collection of models and parameters.
where (str, Sequence[str] or Callable, default='*') – The parameters to return: a name, an fnmatch glob over names, a sequence of them, or a callable returning nodes of tree. An unknown name raises; a glob matching nothing selects nothing.
free_only (bool, default=False) – Only return free parameters: not fixed, and not frozen.
- Returns:
Names mapped to parameters. In a collection that is not a
pmrf.Module, a raw array leaf is returned as it is.- Return type:
dict[str, Param]
- Raises:
ValueError – If two parameters resolve to the same name, or where names an unknown one.
Examples
rc = Resistor(50.0, name='r') ** Capacitor(prf.Unconstrained(2.0, scale=1e-12), name='c') prf.params(rc) # {'r.R': Param(...), 'c.C': Param(...)} prf.params(rc, 'c.*') # {'c.C': Param(...)}