跳转到主要内容

Python中的参数可识别性分析

项目描述

identifiability - Python中的参数可识别性分析

此模块执行参数可识别性分析,基于轮廓似然计算和绘制置信区间。代码改编自 LMFIT,包括自定义函数以选择参数扫描的范围和绘制轮廓似然。显著性通过卡方分布来评估。可以使用 multiprocessing 模块并行执行优化运行。

安装

identifiability 是一个纯Python模块。可以使用以下命令安装最新开发版本:

$ pip install https://github.com/jmrohwer/identifiability/archive/refs/heads/main.zip

最新的稳定版本可在PyPI上获取

$ pip install identifiability

此模块可以与 PySCeS 结合使用,用于使用 CVODE 求解器进行模拟和动力学模型的参数估计。当使用 multiprocessing 并行执行可识别性分析时,需要额外的依赖项;这些依赖项可以安装如下:

$ pip install "identifiability[pyscesmp]"

基本用法

关于背景,请参阅 LMFIT文档 中的“置信区间计算”部分。

要开始可识别性分析,用户首先需要使用LMFIT执行参数估计。估计置信区间的方程序需要LMFIT 最小化器 对象和 最小化器结果 对象作为输入。

一个典型的流程将包括

>>> from identifiability import conf_interval
>>> c = conf_interval(
        mini, result, prob=0.95, limits=0.5, log=False, points=11, return_CIclass=True
    )
>>> print(c[0])  # OrderedDict of parameter names and corresponding confidence intervals
>>> c[1].plot_ci('a')   # plot confidence interval for parameter 'a'
>>> c[1].plot_all_ci()  # plot confidence intervals for all parameters

当使用LMFIT的模型包装器进行参数估计和模型拟合时,应将实例化的ModelResult对象传递两次给conf_interval()方法,而不是传递给MinimizerMinimizerResult(见上文)。在这种情况下,函数调用将是

>>> c = conf_interval(
        modelresult, modelresult, prob=0.95, limits=0.5, 
        log=False, points=11, return_CIclass=True
    )

一旦计算了轮廓似然,就可以使用相同的数据来计算不同概率的置信区间,从而避免计算轮廓似然的密集重新计算

>>> c[1].calc_all_ci(prob=0.8)

conf_interval方法的文档字符串

def conf_interval(
    minimizer,
    result,
    p_names=None,
    prob=0.95,
    limits=0.5,
    log=False,
    points=11,
    method='leastsq',
    return_CIclass=False,
    mp=True,
):
    """
    Calculate the confidence interval (CI) for parameters.

    The parameter for which the CI is calculated will be varied, while the
    remaining parameters are re-optimized to minimize the chi-square. The
    resulting chi-square is used to calculate the probability with a given
    statistic, i.e. chi-squared test.

    Parameters
    ----------
    minimizer : Minimizer or ModelResult
        The minimizer to use, holding objective function.
    result : MinimizerResult or ModelResult
        The result of running Minimizer.minimize() or Model.fit().
    p_names : list, optional
        Names of the parameters for which the CI is calculated. If None
        (default), the CI is calculated for every parameter.
    prob : float, optional
        The probability for the confidence interval (<1). If None,
        the default is 0.95 (95 % confidence interval).
    limits : float, optional
        The limits (as a fraction of the original parameter value) within which
        to vary the parameters for identifiability analysis (default is 0.5).
        If ``log=False``, the parameter is varied from p*limits to p*(2 - limits), 
        where p is the original value.
        If ``log=True``, the parameter is varied from p*limits to p/limits.
    log : bool, optional
        Whether to vary the parameter in a log (True) or a linear (False,
        default) scale.
    points : int, optional
        The number of points for which to calculate the profile likelihood over
        the given parameter range.
    method : str, optional
        The lmfit mimimize() method to use (default='leastsq')
    return_CIclass : bool, optional
        When true, return the instantiated ``ConfidenceInterval`` class to
        access its methods directly (default=False).
    mp : bool, optional
        Run the optimization in parallel using ``multiprocessing`` (default=True)

    Returns
    -------
    output : dict
        A dictionary containing a list of ``(lower, upper)``-tuples containing
        the confidence bounds for each parameter.
    ci : ``ConfidenceInterval`` instance, optional
        Instantiated ``ConfidenceInterval`` class to access the attached methods.
    """

© Johann M. Rohwer, 2023

项目详情


下载文件

下载适用于您平台的应用程序。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分发

identifiability-0.4.tar.gz (7.3 kB 查看哈希值)

上传时间

构建分发

identifiability-0.4-py3-none-any.whl (8.0 kB 查看哈希值)

上传时间 Python 3

支持者