Skip to content

Commit 8c3618c

Browse files
committed
add more to add_soft_bounds docstring
1 parent 680fee4 commit 8c3618c

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

src/diffpy/srfit/fitbase/recipeorganizer.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,21 +1167,22 @@ def add_soft_bounds(
11671167
11681168
Parameters
11691169
----------
1170-
param_or_eq : str or Parameter
1171-
The equation string or a Parameter object to restrain.
1170+
param_or_eq : str
1171+
The equation or parameter to restrain.
11721172
lower_bound : float, optional
11731173
The lower bound for the restraint evaluation (default is -inf).
11741174
upper_bound : float, optional
11751175
The upper bound for the restraint evaluation (default is inf).
11761176
sig : float, optional
11771177
The uncertainty associated with the bounds (default is 1).
1178+
Please see Notes for how this is used in the penalty calculation.
11781179
scaled : bool, optional
11791180
If True, the restraint penalty is scaled by the unrestrained
11801181
point-average chi^2 (chi^2/numpoints) (default is False).
11811182
params : dict, optional
1182-
The dictionary of Parameters, indexed by name, that are used in the
1183-
equation string but are not part of the RecipeOrganizer
1184-
(default is {}).
1183+
The dictionary of Parameters, indexed by name, that are used in
1184+
`param_or_eq` (if an equation string is used) but are not part
1185+
of the RecipeOrganizer (default is {}).
11851186
11861187
Returns
11871188
-------
@@ -1196,18 +1197,33 @@ def add_soft_bounds(
11961197
..
11971198
(max(0, lower_bound - val, val - upper_bound) / sig) ** 2
11981199
1199-
where `val` is the value of the evaluated equation.
1200+
where `val` is the value of the evaluated `param_or_eq`.
12001201
If `scaled` is True, this penalty is multiplied by
12011202
the average chi^2.
12021203
1204+
Examples
1205+
--------
1206+
Restraining the lattice parameters of an Ni lattice to be
1207+
approximately 7.4Å (2x the original lattice param)
1208+
can be done with the following code:
1209+
..
1210+
recipe.add_soft_bounds(
1211+
"a_ni + b_ni",
1212+
lower_bound=7.0,
1213+
upper_bound=7.5,
1214+
sig=0.1,
1215+
scaled=True,
1216+
params={"b_ni": Parameter("b_ni", 3.473)}
1217+
)
1218+
12031219
Raises
12041220
------
12051221
ValueError
1206-
If `func_params` contains a name that is already used
1222+
If `params` contains a name that is already used
12071223
for a Parameter.
12081224
ValueError
12091225
If `param_or_eq` depends on a Parameter that is not part of the
1210-
RecipeOrganizer and is not defined in `func_params`.
1226+
RecipeOrganizer and is not defined in `params`.
12111227
"""
12121228
if isinstance(param_or_eq, str):
12131229
eqstr = param_or_eq

0 commit comments

Comments
 (0)