pharmpy.parameter module¶
- class pharmpy.parameter.Parameter(name, init, lower=None, upper=None, fix=False, unit=1)[source]¶
Bases:
object
A single parameter
Example
>>> from pharmpy import Parameter >>> param = Parameter("TVCL", 0.005, lower=0) >>> param.fix = True
- Parameters
name (str) – Name of the parameter
init (number) – Initial estimate or simply the value of parameter.
fix (bool) – A boolean to indicate whether the parameter is fixed or not. Note that fixing a parameter will keep its bounds even if a fixed parameter is actually constrained to one single value. This is so that unfixing will take back the previous bounds.
lower (number) – The lower bound of the parameter. Default no bound. Must be less than the init.
upper (number) – The upper bound of the parameter. Default no bound. Must be greater than the init.
unit (str or unit expression) – Unit of parameter. Default to unitless
- property init¶
Initial parameter estimate or value
- is_close_to_bound(value=None, zero_limit=0.01, significant_digits=2)[source]¶
Check if parameter value is close to any bound
- Parameters
value (number) – value to check against parameter bounds. Defaults to checking against the parameter init
zero_limit (number) – maximum distance to 0 bounds
significant_digits (int) – maximum distance to non-zero bounds in number of significant digits
Examples
>>> from pharmpy import Parameter >>> par = Parameter("x", 1, lower=0, upper=10) >>> par.is_close_to_bound() False
>>> par.is_close_to_bound(0.005) True
>>> par.is_close_to_bound(0.005, zero_limit=0.0001) False
>>> par.is_close_to_bound(9.99) True
>>> par.is_close_to_bound(9.99, significant_digits=3) False
- property lower¶
Lower bound of the parameter
- property parameter_space¶
The parameter space set
A fixed parameter will be constrained to one single value and non-fixed parameters will be constrained to an interval possibly open in one or both ends.
Examples
>>> import sympy >>> from pharmpy import Parameter >>> par = Parameter("x", 1, lower=0, upper=10) >>> sympy.pprint(par.parameter_space) [0, 10]
>>> par.fix = True >>> sympy.pprint(par.parameter_space) {1}
- property symbol¶
Symbol representing the parameter
- unconstrain()[source]¶
Remove all constraints from this parameter
Example
>>> from pharmpy import Parameter >>> par = Parameter("x", 1, lower=0, upper=2) >>> par.unconstrain() >>> par Parameter("x", 1, lower=-oo, upper=oo, fix=False)
- property upper¶
Upper bound of the parameter
- class pharmpy.parameter.Parameters(params=None)[source]¶
Bases:
collections.abc.MutableSequence
A collection of parameters
Class representing a group of parameters. Usually all parameters in a model. This class give a ways of displaying, summarizing and manipulating more than one parameter at a time.
Specific parameters can be found using indexing on the parameter name
Example
>>> from pharmpy import Parameters, Parameter >>> par1 = Parameter("x", 0) >>> par2 = Parameter("y", 1) >>> pset = Parameters([par1, par2]) >>> pset["x"] Parameter("x", 0, lower=-oo, upper=oo, fix=False)
>>> "x" in pset True
>>> pset.append(Parameter("z", 0.1)) >>> len(pset) 3
>>> del pset["x"] >>> len(pset) 2
- property fix¶
Fixedness of parameters as dict
- property inits¶
Initial estimates of parameters as dict
- is_close_to_bound(values=None, zero_limit=0.01, significant_digits=2)[source]¶
Logical Series of whether values are close to the respective bounds
- Parameters
values (pd.Series) – Series of values with index a subset of parameter names. Default is to use all parameter inits
- Returns
pd.Series – Logical Series with same index as values
Example
>>> from pharmpy import Parameters, Parameter >>> par1 = Parameter("CL", 1, lower=0, upper=10) >>> par2 = Parameter("V", 10, lower=0, upper=100) >>> pset = Parameters([par1, par2]) >>> pset.is_close_to_bound() CL False V False dtype: bool
- property lower¶
Lower bounds of all parameters as a dictionary
- property names¶
List of all parameter names
- property nonfixed_inits¶
Dict of initial estimates for all non-fixed parameters
- property symbols¶
List of all parameter symbols
- to_dataframe()[source]¶
Create a dataframe with a summary of all Parameters
- Returns
DataFrame – A dataframe with one row per parameter. The columns are value, lower, upper and fix Row Index is the names
Example
>>> from pharmpy import Parameters, Parameter >>> par1 = Parameter("CL", 1, lower=0, upper=10) >>> par2 = Parameter("V", 10, lower=0, upper=100) >>> pset = Parameters([par1, par2]) >>> pset.to_dataframe() value lower upper fix CL 1 0 10 False V 10 0 100 False
- property upper¶
Upper bounds of all parameters as a dictionary