DFE parametrizations#
DFE parametrizations.
- class Parametrization(bounds: Dict[str, Tuple[float, float]] | None = None, scales: Dict[str, Literal['lin', 'log']] | None = None, x0: Dict[str, float] | None = None)[source]#
Bases:
Serializable,ABCBase class for DFE parametrizations.
Note that
get_pdf()is not required to be implemented, provided that the linearized mode of fastDFE is used (which is highly recommended).-
submodels:
Dict[str,Dict[str,float]] = {'dele': {}, 'full': {}}# The kind of submodels supported by holding some parameters fixed
- __init__(bounds: Dict[str, Tuple[float, float]] | None = None, scales: Dict[str, Literal['lin', 'log']] | None = None, x0: Dict[str, float] | None = None)[source]#
Initialize parametrization.
- Parameters:
bounds (
Optional[Dict[str,Tuple[float,float]]]) – Custom parameter bounds merging with defaultsscales (
Optional[Dict[str,Literal['lin','log']]]) – Custom scales merging with defaultsx0 (
Optional[Dict[str,float]]) – Custom initial parameters merging with defaults
-
bounds:
Dict[str,Tuple[float,float]] = {}# Default parameter bounds
-
scales:
Dict[str,Literal['lin','log']] = {}# Scales over which to optimize the parameters, either ‘log’ or ‘lin’
-
x0:
Dict[str,float] = {}# Default initial parameters
-
param_names:
List# argument names
- abstract get_pdf(**kwargs)[source]#
Get probability distribution function of DFE.
- Return type:
Callable[[ndarray],ndarray]- Returns:
Function that accepts an array of selection coefficients and returns their probability density
- abstract get_cdf(**kwargs)[source]#
Get probability distribution function of DFE.
- Return type:
Callable[[ndarray],ndarray]- Returns:
Function that accepts an array of selection coefficients and returns their cumulative probability
- plot(params: dict, intervals: Sequence = array([-inf, -100., -10., -1., 0., 1., inf]), file: str = None, show: bool = True, title: str = 'discretized DFE', ax: plt.Axes = None)[source]#
Plot the discretized DFE.
- Parameters:
params (
dict) – Parameters of the parametrizationintervals (
Sequence) – Intervals to use for discretization.file (
str) – File to save the plot to.show (
bool) – Whether to show the plot.title (
str) – Title of the plot.ax (plt.Axes) – Axes to use for the plot.
- Return type:
plt.Axes
- Returns:
Axes
- freeze(params: Dict[str, float])[source]#
Freeze parameters to create a DFE object.
- Parameters:
params (
Dict[str,float]) – Parameters of the parametrization- Return type:
- Returns:
DFE object
- classmethod from_file(file: str, classes=None)#
Load object from file.
- Parameters:
classes – Classes to be used for unserialization.
file (
str) – File to load from
- Return type:
Self
- classmethod from_json(json: str, classes=None)#
Unserialize object.
- Parameters:
classes – Classes to be used for unserialization
json (
str) – JSON string
- Return type:
Self
- to_file(file: str)#
Save object to file.
- Parameters:
file (
str) – File to save to
- to_json()#
Serialize object.
- Return type:
str- Returns:
JSON string
-
submodels:
- class GammaExpParametrization(bounds: Dict[str, Tuple[float, float]] | None = None, scales: Dict[str, Literal['lin', 'log']] | None = None, x0: Dict[str, float] | None = None)[source]#
Bases:
ParametrizationParametrization for mixture of a gamma and exponential distribution. This corresponds to model C in polyDFE.
We have the following probability density function:
\[\phi(S; S_d, b, p_b, S_b) = (1 - p_b) f_\Gamma(-S; S_d, b) \cdot \mathbf{1}_{\{S < 0\}} + p_b f_e(S; S_b) \cdot \mathbf{1}_{\{S \geq 0\}}\]where:
\(S_d\) is the mean of the DFE for \(S < 0\)
\(b\) is the shape of the gamma distribution
\(p_b\) is the probability that \(S \geq 0\)
\(S_b\) is the mean of the DFE for \(S \geq 0\)
\(f_\Gamma(x; m, b)\) is the density of the gamma distribution with mean \(m\) and shape \(b\)
\(f_e(x; m)\) is the density of the exponential distribution with mean \(m\)
\(\mathbf{1}_{\{A\}}\) denotes the indicator function, which is 1 if \(A\) is true, and 0 otherwise.
The DFE has often been observed to be multi-modal for negative selection coefficients. A gamma distribution provides a good amount of flexibility to accommodate this. Note that all \(S\) parameters are population-scaled selection coefficients, i.e. \(S = 4N_es\).
-
x0:
Dict[str,float] = {'S_b': 1, 'S_d': -1000, 'b': 0.4, 'p_b': 0.05}# Default initial parameters
-
bounds:
Dict[str,Tuple[float,float]] = {'S_b': (0.0001, 100), 'S_d': (-100000.0, -0.01), 'b': (0.01, 10), 'p_b': (0, 0.5)}# Default parameter bounds, using non-zero lower bounds for S_d and S_b due to log-scaled scales
-
scales:
Dict[str,Literal['lin','log']] = {'S_b': 'log', 'S_d': 'log', 'b': 'log', 'p_b': 'lin'}# Scales over which to optimize the parameters
-
submodels:
Dict[str,Dict[str,float]] = {'dele': {'S_b': 1, 'p_b': 0}, 'full': {}}# The kind of submodels supported by holding some parameters fixed
- static get_pdf(S_d: float, b: float, p_b: float, S_b: float, **kwargs)[source]#
Get PDF.
- Parameters:
S_d (
float) – Mean selection coefficient for deleterious mutationsb (
float) – Shape parameter for gamma distributionp_b (
float) – Probability of a beneficial mutationS_b (
float) – Mean selection coefficient for beneficial mutations
- Return type:
Callable[[ndarray],ndarray]- Returns:
Function that accepts an array of selection coefficients and returns their probability density
- static get_cdf(S_d: float, b: float, p_b: float, S_b: float, **kwargs)[source]#
Get CDF.
- Parameters:
S_d (
float) – Mean selection coefficient for deleterious mutationsb (
float) – Shape parameter for gamma distributionp_b (
float) – Probability of a beneficial mutationS_b (
float) – Mean selection coefficient for beneficial mutations
- Return type:
Callable[[ndarray],ndarray]- Returns:
Function that accepts an array of selection coefficients and returns their cumulative probability
- __init__(bounds: Dict[str, Tuple[float, float]] | None = None, scales: Dict[str, Literal['lin', 'log']] | None = None, x0: Dict[str, float] | None = None)#
Initialize parametrization.
- Parameters:
bounds (
Optional[Dict[str,Tuple[float,float]]]) – Custom parameter bounds merging with defaultsscales (
Optional[Dict[str,Literal['lin','log']]]) – Custom scales merging with defaultsx0 (
Optional[Dict[str,float]]) – Custom initial parameters merging with defaults
- freeze(params: Dict[str, float])#
Freeze parameters to create a DFE object.
- Parameters:
params (
Dict[str,float]) – Parameters of the parametrization- Return type:
- Returns:
DFE object
- classmethod from_file(file: str, classes=None)#
Load object from file.
- Parameters:
classes – Classes to be used for unserialization.
file (
str) – File to load from
- Return type:
Self
- classmethod from_json(json: str, classes=None)#
Unserialize object.
- Parameters:
classes – Classes to be used for unserialization
json (
str) – JSON string
- Return type:
Self
- plot(params: dict, intervals: Sequence = array([-inf, -100., -10., -1., 0., 1., inf]), file: str = None, show: bool = True, title: str = 'discretized DFE', ax: plt.Axes = None)#
Plot the discretized DFE.
- Parameters:
params (
dict) – Parameters of the parametrizationintervals (
Sequence) – Intervals to use for discretization.file (
str) – File to save the plot to.show (
bool) – Whether to show the plot.title (
str) – Title of the plot.ax (plt.Axes) – Axes to use for the plot.
- Return type:
plt.Axes
- Returns:
Axes
- to_file(file: str)#
Save object to file.
- Parameters:
file (
str) – File to save to
- to_json()#
Serialize object.
- Return type:
str- Returns:
JSON string
-
param_names:
List# argument names
- class DisplacedGammaParametrization(bounds: Dict[str, Tuple[float, float]] | None = None, scales: Dict[str, Literal['lin', 'log']] | None = None, x0: Dict[str, float] | None = None)[source]#
Bases:
ParametrizationParametrization for a reflected displaced gamma distribution.
We have the following probability density function:
\[\phi(S; \hat{S}, b, S_{max}) = f_\Gamma(S_{max} - S; S_{max} - \hat{S}, b) \cdot \mathbf{1}_{\{S \leq S_{max}\}}\]where:
\(\hat{S}\) is the mean of the DFE
\(b\) is the shape of the gamma distribution
\(S_{max}\) is the maximum value that \(S\) can take
\(f_\Gamma(x; m, b)\) is the density of the gamma distribution with mean \(m\) and shape \(b\)
\(\mathbf{1}_{\{A\}}\) denotes the indicator function, which is 1 if \(A\) is true, and 0 otherwise.
This parametrization uses a single gamma distribution for both positive and negative selection coefficients. This is a less flexible parametrization, which may produce results similar to the other models while requiring fewer parameters. Note that all \(S\) parameters are population-scaled selection coefficients, i.e. \(S = 4N_es\).
Warning
This model does not allow for a purely deleterious sub-parametrization, so
Inference.compare_nested_models()won’t work as expected.-
x0:
Dict[str,float] = {'S_max': 1, 'S_mean': -100, 'b': 1}# Default initial parameters
-
bounds:
Dict[str,Tuple[float,float]] = {'S_max': (0.001, 100), 'S_mean': (-100000, -0.01), 'b': (0.01, 10)}# Default parameter bounds
-
scales:
Dict[str,Literal['lin','log']] = {'S_max': 'log', 'S_mean': 'log', 'b': 'lin'}# Scales over which to optimize the parameters
-
submodels:
Dict[str,Dict[str,float]] = {'dele': {}, 'full': {}}# The kind of submodels supported by holding some parameters fixed
- static get_pdf(S_mean: float, b: float, S_max: float, **kwargs)[source]#
Get PDF.
- Return type:
Callable[[ndarray],ndarray]- Returns:
Function that accepts an array of selection coefficients and returns their probability density
- static get_cdf(S_mean: float, b: float, S_max: float, **kwargs)[source]#
Get CDF.
- Return type:
Callable[[ndarray],ndarray]- Returns:
Function that accepts an array of selection coefficients and returns their cumulative probability
- __init__(bounds: Dict[str, Tuple[float, float]] | None = None, scales: Dict[str, Literal['lin', 'log']] | None = None, x0: Dict[str, float] | None = None)#
Initialize parametrization.
- Parameters:
bounds (
Optional[Dict[str,Tuple[float,float]]]) – Custom parameter bounds merging with defaultsscales (
Optional[Dict[str,Literal['lin','log']]]) – Custom scales merging with defaultsx0 (
Optional[Dict[str,float]]) – Custom initial parameters merging with defaults
- freeze(params: Dict[str, float])#
Freeze parameters to create a DFE object.
- Parameters:
params (
Dict[str,float]) – Parameters of the parametrization- Return type:
- Returns:
DFE object
- classmethod from_file(file: str, classes=None)#
Load object from file.
- Parameters:
classes – Classes to be used for unserialization.
file (
str) – File to load from
- Return type:
Self
- classmethod from_json(json: str, classes=None)#
Unserialize object.
- Parameters:
classes – Classes to be used for unserialization
json (
str) – JSON string
- Return type:
Self
- plot(params: dict, intervals: Sequence = array([-inf, -100., -10., -1., 0., 1., inf]), file: str = None, show: bool = True, title: str = 'discretized DFE', ax: plt.Axes = None)#
Plot the discretized DFE.
- Parameters:
params (
dict) – Parameters of the parametrizationintervals (
Sequence) – Intervals to use for discretization.file (
str) – File to save the plot to.show (
bool) – Whether to show the plot.title (
str) – Title of the plot.ax (plt.Axes) – Axes to use for the plot.
- Return type:
plt.Axes
- Returns:
Axes
- to_file(file: str)#
Save object to file.
- Parameters:
file (
str) – File to save to
- to_json()#
Serialize object.
- Return type:
str- Returns:
JSON string
-
param_names:
List# argument names
- class GammaDiscreteParametrization(bounds: Dict[str, Tuple[float, float]] | None = None, scales: Dict[str, Literal['lin', 'log']] | None = None, x0: Dict[str, float] | None = None)[source]#
Bases:
ParametrizationParametrization for a mixture of a gamma and discrete distribution. This corresponds to polyDFE’s model B.
We have the following probability density function:
\[\phi(S; S_d, b, p_b, S_b) = (1 - p_b) f_{\Gamma}(S; S_d, b) \cdot \mathbf{1}_{\{S < 0\}} + p_b \cdot S_b \cdot \mathbf{1}_{\{0 \leq S \leq 1 / S_b\}}\]where:
\(S_d\) is the mean of the DFE for \(S < 0\)
\(b\) is the shape of the gamma distribution
\(p_b\) is the probability that \(S \geq 0\)
\(S_b\) is the shared selection coefficient of all positively selected mutations up to \(1/S_b\)
\(f_\Gamma(x; m, b)\) is the density of the gamma distribution with mean \(m\) and shape \(b\)
This parametrization is similar to
GammaExpParametrization, but uses a constant mass for positive selection coefficients. The results should be rather similar in most cases. Note that all \(S\) parameters are population-scaled selection coefficients, i.e. \(S = 4N_es\).-
x0:
Dict[str,float] = {'S_b': 1, 'S_d': -1000, 'b': 0.4, 'p_b': 0.05}# Default initial parameters
-
bounds:
Dict[str,Tuple[float,float]] = {'S_b': (0.0001, 100), 'S_d': (-100000.0, -0.01), 'b': (0.01, 10), 'p_b': (0, 0.5)}# default parameter bounds
-
scales:
Dict[str,Literal['lin','log']] = {'S_b': 'log', 'S_d': 'log', 'b': 'log', 'p_b': 'lin'}# scales over which to optimize the parameters
-
submodels:
Dict[str,Dict[str,float]] = {'dele': {'S_b': 1, 'p_b': 0}, 'full': {}}# The kind of submodels supported by holding some parameters fixed
- static get_pdf(S_d: float, b: float, p_b: float, S_b: float, **kwargs)[source]#
Get PDF.
- Parameters:
S_d (
float) – Mean of the DFE for S < 0b (
float) – Shape of the gamma distributionp_b (
float) – Probability that S > 0S_b (
float) – Shared selection coefficient of all positively selected mutations up to S_b
- Return type:
Callable[[ndarray],ndarray]- Returns:
Function that accepts an array of selection coefficients and returns their probability density
- static get_cdf(S_d: float, b: float, p_b: float, S_b: float, **kwargs)[source]#
Get CDF.
- Parameters:
S_d (
float) – Mean of the DFE for S < 0b (
float) – Shape of the gamma distributionp_b (
float) – Probability that S > 0S_b (
float) – Shared selection coefficient of all positively selected mutations up to S_b
- Return type:
Callable[[ndarray],ndarray]- Returns:
Function that accepts an array of selection coefficients and returns their cumulative probability
- __init__(bounds: Dict[str, Tuple[float, float]] | None = None, scales: Dict[str, Literal['lin', 'log']] | None = None, x0: Dict[str, float] | None = None)#
Initialize parametrization.
- Parameters:
bounds (
Optional[Dict[str,Tuple[float,float]]]) – Custom parameter bounds merging with defaultsscales (
Optional[Dict[str,Literal['lin','log']]]) – Custom scales merging with defaultsx0 (
Optional[Dict[str,float]]) – Custom initial parameters merging with defaults
- freeze(params: Dict[str, float])#
Freeze parameters to create a DFE object.
- Parameters:
params (
Dict[str,float]) – Parameters of the parametrization- Return type:
- Returns:
DFE object
- classmethod from_file(file: str, classes=None)#
Load object from file.
- Parameters:
classes – Classes to be used for unserialization.
file (
str) – File to load from
- Return type:
Self
- classmethod from_json(json: str, classes=None)#
Unserialize object.
- Parameters:
classes – Classes to be used for unserialization
json (
str) – JSON string
- Return type:
Self
- plot(params: dict, intervals: Sequence = array([-inf, -100., -10., -1., 0., 1., inf]), file: str = None, show: bool = True, title: str = 'discretized DFE', ax: plt.Axes = None)#
Plot the discretized DFE.
- Parameters:
params (
dict) – Parameters of the parametrizationintervals (
Sequence) – Intervals to use for discretization.file (
str) – File to save the plot to.show (
bool) – Whether to show the plot.title (
str) – Title of the plot.ax (plt.Axes) – Axes to use for the plot.
- Return type:
plt.Axes
- Returns:
Axes
- to_file(file: str)#
Save object to file.
- Parameters:
file (
str) – File to save to
- to_json()#
Serialize object.
- Return type:
str- Returns:
JSON string
-
param_names:
List# argument names
- class DiscreteParametrization(intervals: Sequence = array([-100000, -100, -10, -1, 0, 1, 1000]), bounds: Dict[str, Tuple[float, float]] | None = None, scales: Dict[str, Literal['lin', 'log']] | None = None, x0: Dict[str, float] | None = None)[source]#
Bases:
ParametrizationParametrization for a discrete distribution. This corresponds to polyDFE’s model D. By default we use 6 bins, but this can be changed by passing a different array to the constructor. The resulting parameter names are \(S_1, S_2, \dots, S_k\), where \(k\) is the number of bins.
That is, the probability density function is given by:
\(\phi(S; S_1, S_2, \dots, S_k) = \sum_{i=1}^{k} S_i/c_i \cdot \mathbf{1}_{\{S \in B_i\}}\) such that \(\sum_{i=1}^{k} S_i = 1,\)
where \(B_i\) and \(c_i\) are interval \(i\) and the width of interval \(i\), respectively.
This parametrization has the advantage of not imposing a shape on the DFE. For a reasonably fine parametrization, the number of parameters is larger than those of the other models, however. We generally also observe larger confidence intervals for this parametrization, and the optimization procedure may well be less efficient as we have to re-normalize the parameters to make sure they sum up to 1. Note that all \(S\) parameters are population-scaled selection coefficients, i.e. \(S = 4N_es\).
- __init__(intervals: Sequence = array([-100000, -100, -10, -1, 0, 1, 1000]), bounds: Dict[str, Tuple[float, float]] | None = None, scales: Dict[str, Literal['lin', 'log']] | None = None, x0: Dict[str, float] | None = None)[source]#
Constructor.
- Parameters:
intervals (
Sequence) – The intervals of the discrete distribution.bounds (
Optional[Dict[str,Tuple[float,float]]]) – Custom parameter bounds merging with defaultsscales (
Optional[Dict[str,Literal['lin','log']]]) – Custom scales merging with defaultsx0 (
Optional[Dict[str,float]]) – Custom initial parameters merging with defaults
-
intervals:
ndarray# Intervals
-
interval_sizes:
ndarray# Interval sizes
-
k:
int# Number of intervals, including the two infinite ones
-
params:
ndarray# All parameter names, including the fixed ones
-
param_names:
List[str]# Parameter names that are not fixed
-
fixed_params:
Dict[str,int]# Fixed parameters
-
x0:
Dict[str,float] = {}# Default initial parameters
-
bounds:
Dict[str,Tuple[float,float]] = {}# Default parameter bounds
-
scales:
Dict[str,Literal['lin','log']] = {}# Scales over which to optimize the parameters, either ‘log’ or ‘lin’
-
submodels:
Dict[str,Dict[str,float]] = {'dele': {}, 'full': {}}# Submodels
- get_pdf(**kwargs)[source]#
Get PDF.
- Parameters:
kwargs – Parameter values S1, S2, …, Sk
- Return type:
Callable[[ndarray],ndarray]- Returns:
Function that computes the PDF for given S values
- get_cdf(**kwargs)[source]#
Get CDF.
- Parameters:
kwargs – Parameter values S1, S2, …, Sk
- Return type:
Callable[[ndarray],ndarray]- Returns:
Function that computes the CDF for given S values
- freeze(params: Dict[str, float])#
Freeze parameters to create a DFE object.
- Parameters:
params (
Dict[str,float]) – Parameters of the parametrization- Return type:
- Returns:
DFE object
- classmethod from_file(file: str, classes=None)#
Load object from file.
- Parameters:
classes – Classes to be used for unserialization.
file (
str) – File to load from
- Return type:
Self
- classmethod from_json(json: str, classes=None)#
Unserialize object.
- Parameters:
classes – Classes to be used for unserialization
json (
str) – JSON string
- Return type:
Self
- plot(params: dict, intervals: Sequence = array([-inf, -100., -10., -1., 0., 1., inf]), file: str = None, show: bool = True, title: str = 'discretized DFE', ax: plt.Axes = None)#
Plot the discretized DFE.
- Parameters:
params (
dict) – Parameters of the parametrizationintervals (
Sequence) – Intervals to use for discretization.file (
str) – File to save the plot to.show (
bool) – Whether to show the plot.title (
str) – Title of the plot.ax (plt.Axes) – Axes to use for the plot.
- Return type:
plt.Axes
- Returns:
Axes
- to_file(file: str)#
Save object to file.
- Parameters:
file (
str) – File to save to
- to_json()#
Serialize object.
- Return type:
str- Returns:
JSON string
- class DiscreteFractionalParametrization(intervals: Sequence = array([-100000, -100, -10, -1, 0, 1, 1000]), bounds: Dict[str, Tuple[float, float]] | None = None, scales: Dict[str, Literal['lin', 'log']] | None = None, x0: Dict[str, float] | None = None)[source]#
Bases:
ParametrizationSame model as
DiscreteParametrization, but re-parametrized by \(\hat{S}_1, \hat{S}_2, \dots, \hat{S}_{k-1}\), so that the mass in the ith interval \(S_i\) is determined by the sum of masses to the left, i.e.\(S_i = \hat{S}_i \sum_{j<i} S_j, i = 1, \dots, k - 1\),
\(S_k = 1 - \sum_{j=1}^{k-1} S_j\).
This parametrization has the advantage of not imposing a shape on the DFE. For a reasonably fine parametrization, the number of parameters is larger than those of the other models, however. It is more easily optimized than
DiscreteParametrizationas it has one parameter less but its parameters are more difficult to interpret. One disadvantage with discrete parametrizations is that there may be gaps in the estimated DFE. Note that all \(S\) parameters are population-scaled selection coefficients, i.e. \(S = 4N_es\).- __init__(intervals: Sequence = array([-100000, -100, -10, -1, 0, 1, 1000]), bounds: Dict[str, Tuple[float, float]] | None = None, scales: Dict[str, Literal['lin', 'log']] | None = None, x0: Dict[str, float] | None = None)[source]#
Constructor.
- Parameters:
intervals (
Sequence) – The intervals of the discrete distribution.bounds (
Optional[Dict[str,Tuple[float,float]]]) – Custom parameter bounds merging with defaultsscales (
Optional[Dict[str,Literal['lin','log']]]) – Custom scales merging with defaultsx0 (
Optional[Dict[str,float]]) – Custom initial parameters merging with defaults
-
intervals:
ndarray# Intervals
-
interval_sizes:
ndarray# Interval sizes
-
k:
int# Number of intervals, including the two infinite ones
-
params:
ndarray# All parameter names, including fixed parameters
-
param_names:
List[str]# Parameter names that are not fixed
- fixed_params#
Fixed parameters
-
x0:
Dict[str,float] = {}# Default initial parameters
-
bounds:
Dict[str,Tuple[float,float]] = {}# Default parameter bounds
-
scales:
Dict[str,Literal['lin','log']] = {}# Scales over which to optimize the parameters, either ‘log’ or ‘lin’
-
submodels:
Dict[str,Dict[str,float]] = {'dele': {}, 'full': {}}# Submodels
- to_nominal(params: Dict[str, float])[source]#
Convert representation of fraction of total mass to the left to representation of fractions which sum to 1.
- Parameters:
params (
Dict[str,float]) – Parameter values S1, S2, …, Sk- Return type:
Dict[str,float]- Returns:
Converted parameters
- to_fractional(params: Dict[str, float])[source]#
Invert the to_nominal operation: Convert representation of fractions which sum to 1 back to representation of fraction of total mass to the left.
- Parameters:
params (
Dict[str,float]) – Converted parameters (nominal space)- Return type:
Dict[str,float]- Returns:
Original parameters (parameter space)
- get_pdf(**kwargs)[source]#
Get PDF.
- Parameters:
kwargs – Parameter values S1, S2, …, Sk-1
- Return type:
Callable[[ndarray],ndarray]- Returns:
Function that computes the PDF for given S values
- get_cdf(**kwargs)[source]#
Get CDF.
- Parameters:
kwargs – Parameter values S1, S2, …, Sk-1
- Return type:
Callable[[ndarray],ndarray]- Returns:
Function that computes the CDF for given S values
- freeze(params: Dict[str, float])#
Freeze parameters to create a DFE object.
- Parameters:
params (
Dict[str,float]) – Parameters of the parametrization- Return type:
- Returns:
DFE object
- classmethod from_file(file: str, classes=None)#
Load object from file.
- Parameters:
classes – Classes to be used for unserialization.
file (
str) – File to load from
- Return type:
Self
- classmethod from_json(json: str, classes=None)#
Unserialize object.
- Parameters:
classes – Classes to be used for unserialization
json (
str) – JSON string
- Return type:
Self
- plot(params: dict, intervals: Sequence = array([-inf, -100., -10., -1., 0., 1., inf]), file: str = None, show: bool = True, title: str = 'discretized DFE', ax: plt.Axes = None)#
Plot the discretized DFE.
- Parameters:
params (
dict) – Parameters of the parametrizationintervals (
Sequence) – Intervals to use for discretization.file (
str) – File to save the plot to.show (
bool) – Whether to show the plot.title (
str) – Title of the plot.ax (plt.Axes) – Axes to use for the plot.
- Return type:
plt.Axes
- Returns:
Axes
- to_file(file: str)#
Save object to file.
- Parameters:
file (
str) – File to save to
- to_json()#
Serialize object.
- Return type:
str- Returns:
JSON string
- class DFE(params: dict, model: Parametrization = None, bootstraps: DataFrame | None = None)[source]#
Bases:
SerializableFrozen parametrization of a DFE.
Wraps a
Parametrizationinstance together with fixed parameter values.- __init__(params: dict, model: Parametrization = None, bootstraps: DataFrame | None = None)[source]#
- Parameters:
params (
dict) – Frozen parameter values.model (
Parametrization) – Parametrization instance used to generate the DFE. Defaults toGammaExpParametrization.bootstraps (
Optional[DataFrame]) – Optional bootstrap DataFrame (same format as AbstractInference.bootstraps).
-
model:
Parametrization# Underlying parametrization model
-
params:
Dict[str,float]# Frozen parameters
-
bootstraps:
Optional[DataFrame]# Optional bootstrap samples
- get_bootstrap_dfes()[source]#
Get DFEs for all bootstrap samples.
- Return type:
List[DFE]- Returns:
List of DFE instances for each bootstrap sample.
- pdf(S: ndarray | float)[source]#
Evaluate the frozen PDF.
- Parameters:
S (
ndarray|float) – Selection coefficient(s)- Return type:
ndarray|float- Returns:
Probability density
- cdf(S: ndarray | float)[source]#
Evaluate the frozen CDF.
- Parameters:
S (
ndarray|float) – Selection coefficient(s)- Return type:
ndarray|float- Returns:
Cumulative probability
- discretize(bins: ndarray, warn_mass: bool = True, confidence_intervals: bool = True, ci_level: float = 0.05, bootstrap_type: Literal['percentile', 'bca'] = 'percentile', point_estimate: Literal['original', 'mean', 'median'] = 'mean')[source]#
Discretize the DFE with optional bootstrap confidence intervals.
- Parameters:
bins (
ndarray) – Intervals to use for discretization.warn_mass (
bool) – Whether to warn if mass is lost during discretization.confidence_intervals (
bool) – Whether to compute confidence intervals.ci_level (
float) – Confidence interval level (e.g., 0.05 for 95% CI).bootstrap_type (
Literal['percentile','bca']) – Type of bootstrap confidence intervals (‘percentile’ or ‘bca’).point_estimate (
Literal['original','mean','median']) – Whether to use ‘original’ MLE values, ‘mean’ or ‘median’ of bootstraps as point estimate.
- Return type:
Tuple[ndarray,Optional[ndarray]]- Returns:
Center values and (optionally) errors for each bin.
- classmethod from_file(file: str, classes=None)#
Load object from file.
- Parameters:
classes – Classes to be used for unserialization.
file (
str) – File to load from
- Return type:
Self
- classmethod from_json(json: str, classes=None)#
Unserialize object.
- Parameters:
classes – Classes to be used for unserialization
json (
str) – JSON string
- Return type:
Self
- to_file(file: str)#
Save object to file.
- Parameters:
file (
str) – File to save to
- to_json()#
Serialize object.
- Return type:
str- Returns:
JSON string
- static plot_many(dfes: Sequence[DFE], labels: Sequence[str] | None = None, intervals=array([-inf, -100., -10., -1., 0., 1., inf]), file=None, show=True, title='discretized DFE', ax=None, confidence_intervals: bool = True, ci_level: float = 0.05, bootstrap_type: Literal['percentile', 'bca'] = 'percentile', point_estimate: Literal['original', 'mean', 'median'] = 'mean', kwargs_legend: dict = {'prop': {'size': 8}})[source]#
Plot several DFE instances in a single discretized plot.
- Parameters:
dfes (
Sequence[DFE]) – Sequence of DFE instances to plot.labels (
Optional[Sequence[str]]) – Labels for the DFEs.intervals – Intervals to use for discretization.
file – File to save the plot to.
show – Whether to show the plot.
title – Title of the plot.
ax – Axes to use for the plot.
confidence_intervals (
bool) – Whether to plot confidence intervals.ci_level (
float) – Confidence interval level (e.g., 0.05 for 95% CI).bootstrap_type (
Literal['percentile','bca']) – Type of bootstrap confidence intervals (‘percentile’ or ‘bca’).point_estimate (
Literal['original','mean','median']) – Whether to use ‘original’ MLE values, ‘mean’ or ‘median’ of bootstraps as point estimate.kwargs_legend (
dict) – Additional keyword arguments for the legend.
- Returns:
Matplotlib Axes object.
- plot(intervals=array([-inf, -100., -10., -1., 0., 1., inf]), file=None, show=True, title='discretized DFE', ax=None, confidence_intervals: bool = True, ci_level: float = 0.05, bootstrap_type: Literal['percentile', 'bca'] = 'percentile', point_estimate: Literal['original', 'mean', 'median'] = 'mean', kwargs_legend: dict = {'prop': {'size': 8}})[source]#
Plot this DFE instance in a discretized plot.
- Parameters:
intervals – Intervals to use for discretization.
file – File to save the plot to.
show – Whether to show the plot.
title – Title of the plot.
ax – Axes to use for the plot.
confidence_intervals (
bool) – Whether to plot confidence intervals.ci_level (
float) – Confidence interval level (e.g., 0.05 for 95% CI).bootstrap_type (
Literal['percentile','bca']) – Type of bootstrap confidence intervals (‘percentile’ or ‘bca’).point_estimate (
Literal['original','mean','median']) – Whether to use ‘original’ MLE values, ‘mean’ or ‘median’ of bootstraps as point estimate.kwargs_legend (
dict) – Additional keyword arguments for the legend.
- Returns:
Matplotlib Axes object.