mimic.model_infer package¶
Submodules¶
mimic.model_infer.cLV module¶
- class mimic.model_infer.cLV.CompositionalLotkaVolterra(P=None, T=None, U=None, denom=None, pseudo_count=0.001)[source]¶
Bases:
object
Inference for compositional Lotka-Volterra.
\[\]rac{d}{dt} log( rac{pi_i(t)}{pi_D(t)}) = g_i + sum^D_{j=1} (A_{ij} pi_j(t)) + sum^P_{p=1} (B_{ip} u_p(t)
Parameters¶
P : A list of T_x by D dimensional numpy arrays of estimated relative abundances. T : A list of T_x by 1 dimensional numpy arrays giving the times of each observation x. U : An optional list of T_x by P numpy arrays of external perturbations for each x. denom : integer, id for taxa in denominator of log ratio pseudo_count : float, default=1e-3, a small number to replace zero counts
- predict(p0, times, u=None) ndarray [source]¶
Predict relative abundances from initial conditions.
Parameters¶
p0 : the initial observation, a D-dim numpy array times : a T by 1 numpy array of sample times u : a T by P numpy array of external perturbations
Returns¶
- y_preda T by D numpy array of predicted relative
abundances. Since we cannot predict initial conditions, the first entry is set to the array of -1.
- mimic.model_infer.cLV.choose_denom(P) int [source]¶
Pick a denominator for additive log-ratio transformation.
- mimic.model_infer.cLV.construct_alr(P, denom, pseudo_count=0.001) list[ndarray] [source]¶
Compute the additive log ratio transformation with a given choice of denominator. Assumes zeros have been replaced with nonzero values.
- mimic.model_infer.cLV.elastic_net_clv(X, P, U, T, Q_inv, alpha, r_A, r_g, r_B, tol=0.001, verbose=False, max_iter=10000) tuple[ndarray, ndarray, ndarray] [source]¶
- mimic.model_infer.cLV.estimate_elastic_net_regularizers_cv(X, P, U, T, denom, folds, no_effects=False, verbose=False) Tuple[float, float, float, float] | None [source]¶
- mimic.model_infer.cLV.estimate_relative_abundances(Y, pseudo_count=0.001) list[ndarray] [source]¶
Adds pseudo counts to avoid zeros and compute relative abundances
Parameters¶
- Ya list sequencing counts or observed concentrations
per sequence
- pseudo_countpseudo count, specific in relation to
the relative proportions of each taxon.
Returns¶
P : relative abundances with pseudo counts
- mimic.model_infer.cLV.estimate_ridge_regularizers_cv(X, P, U, T, denom, folds, no_effects=False, verbose=False) tuple[float, float, float] | None [source]¶
- mimic.model_infer.cLV.predict(x, p, u, times, A, g, B, denom) ndarray [source]¶
Make predictions from initial conditions
- mimic.model_infer.cLV.ridge_regression_clv(X, P, U, T, r_A=0, r_g=0, r_B=0) tuple[ndarray, ndarray, ndarray] [source]¶
Computes estimates of A, g, and B using least squares.
Parameters¶
X : a list of T x yDim-1 numpy arrays U : a list of T x uDim numpy arrays T : a list of T x 1 numpy arrays with the time of each observation
Returns¶
mimic.model_infer.infer_VAR_bayes module¶
- class mimic.model_infer.infer_VAR_bayes.infer_VAR(data=None, coefficients=None, intercepts=None, covariance_matrix=None, dataS=None)[source]¶
Bases:
BaseInfer
infer_VAR class for performing inference on VAR models.
This class provides methods for importing data, running inference on the VAR model, and performing posterior sampling and analysis.
- Args:
data (numpy.ndarray): The data to perform inference on.
- Methods:
- run_inference(method=’default’, **kwargs):
Runs the inference process for the VAR model.
- Returns:
None
- make_plot_stacked(dataX, dataS)[source]¶
Creates a stacked plot of abundance and metabolite data.
Args: dataX (numpy.ndarray): The abundance data. dataS (numpy.ndarray): The metabolite data.
Returns: None
- plot_heatmap(idata, matrices=None, true_values=None)[source]¶
Plots heatmaps of the inferred matrices.
Args: idata (arviz.InferenceData): The inference data. matrices (list of str): List of keys for matrices in idata.posterior to plot. true_values (list of numpy.ndarray): List of true matrices to compare with.
Returns: None
- posterior_analysis(data_filename=None, netcdf_filename=None, A=None, B=None)[source]¶
Performs posterior analysis and visualizes the results.
Args: data_filename (str, optional): The filename for the .npz data file. netcdf_filename (str, optional): The filename for the NetCDF file with inference results. A (numpy.ndarray, optional): The true matrix A to compare against. B (numpy.ndarray, optional): The true matrix B to compare against.
Returns: None
- run_inference(method='default', **kwargs)[source]¶
Runs the inference process for the VAR model.
- Args:
- method (str): Specifies which inference method to run.
Options are ‘default’, ‘large’, ‘xs’, ‘large_xs’. Default is ‘default’.
**kwargs: Additional keyword arguments to pass to the inference methods.
- Returns:
None
- set_parameters(data: ndarray | DataFrame | list | tuple | None = None, coefficients: ndarray | list | None = None, intercepts: ndarray | list | None = None, covariance_matrix: ndarray | list | None = None, dataS: ndarray | DataFrame | list | tuple | None = None, priors: Dict[str, Any] | None = None) None [source]¶
Sets the parameters for the infer_VAR instance.
Allows optional specification of all model parameters. Parameters not provided (None) are left unchanged.
- Parameters:
data (Optional[Union[np.ndarray, pd.DataFrame, list, tuple]]): The data to perform inference on. coefficients (Optional[Union[np.ndarray, list]]): Coefficients of the VAR model. intercepts (Optional[Union[np.ndarray, list]]): Intercepts of the VAR model. covariance_matrix (Optional[Union[np.ndarray, list]]): Covariance matrix of the VAR model. dataS (Optional[Union[np.ndarray, pd.DataFrame, list, tuple]]): The secondary data (e.g., metabolite data). priors (Optional[Dict[str, Any]]): A dictionary of prior distributions.
mimic.model_infer.infer_gMLV_lm module¶
- class mimic.model_infer.infer_gMLV_lm.Ridge1(alphas=None, num_species=3)[source]¶
Bases:
BaseEstimator
,RegressorMixin
Custom ridge regression class
- get_params(deep=True) dict [source]¶
Get parameters for this estimator.
Parameters¶
- deepbool, default=True
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Returns¶
- paramsdict
Parameter names mapped to their values.
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') Ridge1 ¶
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.Parameters¶
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weight
parameter inscore
.
Returns¶
- selfobject
The updated object.
- class mimic.model_infer.infer_gMLV_lm.Ridge2(alphas=None, num_species=3, num_pert=1)[source]¶
Bases:
BaseEstimator
,RegressorMixin
Custom ridge regression class
- get_params(deep=True) dict [source]¶
Get parameters for this estimator.
Parameters¶
- deepbool, default=True
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Returns¶
- paramsdict
Parameter names mapped to their values.
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') Ridge2 ¶
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.Parameters¶
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weight
parameter inscore
.
Returns¶
- selfobject
The updated object.
- mimic.model_infer.infer_gMLV_lm.do_bootstrapping(X, F, num_species, a0, a1, nt, nboots=100) None [source]¶
- mimic.model_infer.infer_gMLV_lm.do_final_fit_Ridge1(X, F, num_species, a0, a1) tuple[list[float], list[list[float]]] [source]¶
- mimic.model_infer.infer_gMLV_lm.do_final_fit_Ridge2(X, F, num_species, num_pert, a0, a1, a2) tuple[list[float], list[list[float]], list[list[float]]] [source]¶
- mimic.model_infer.infer_gMLV_lm.fit_alpha_Ridge1(X, F, num_species, n_a0, n_a1) tuple[float, float] [source]¶
- mimic.model_infer.infer_gMLV_lm.fit_alpha_Ridge2(X, F, num_species, num_pert, n_a0, n_a1, n_a2) tuple[float, float, float] [source]¶
- mimic.model_infer.infer_gMLV_lm.linearise_time_course_metabolites(sobs, yobs, times) tuple[ndarray, ndarray] [source]¶
- mimic.model_infer.infer_gMLV_lm.linearize_time_course(yobs, times) tuple[ndarray, ndarray] [source]¶
- mimic.model_infer.infer_gMLV_lm.linearize_time_course_16S(yobs, times) tuple[ndarray, ndarray] [source]¶
- mimic.model_infer.infer_gMLV_lm.linearize_time_course_16S_u(yobs, times, u) tuple[ndarray, ndarray] [source]¶
mimic.model_infer.multi_penalty_lasso module¶
- class mimic.model_infer.multi_penalty_lasso.MultiPenaltyLasso(alpha)[source]¶
Bases:
BaseEstimator
,RegressorMixin
Linear regression with non-uniform L1 regularizer.
Minimizes objective function:
1 / (2 * n_samples) * ||y - X * w||^2_2 + ||alpha * w||_1
where:
alpha = diag(alpha_1, alpha_2, ..., alpha_{num_samples})
and all alpha are non-zero
- get_params(deep=True) dict [source]¶
Get parameters for this estimator.
Parameters¶
- deepbool, default=True
If True, will return the parameters for this estimator and contained subobjects that are estimators.
Returns¶
- paramsdict
Parameter names mapped to their values.
- set_score_request(*, sample_weight: bool | None | str = '$UNCHANGED$') MultiPenaltyLasso ¶
Request metadata passed to the
score
method.Note that this method is only relevant if
enable_metadata_routing=True
(seesklearn.set_config()
). Please see User Guide on how the routing mechanism works.The options for each parameter are:
True
: metadata is requested, and passed toscore
if provided. The request is ignored if metadata is not provided.False
: metadata is not requested and the meta-estimator will not pass it toscore
.None
: metadata is not requested, and the meta-estimator will raise an error if the user provides it.str
: metadata should be passed to the meta-estimator with this given alias instead of the original name.
The default (
sklearn.utils.metadata_routing.UNCHANGED
) retains the existing request. This allows you to change the request for some parameters and not others.Added in version 1.3.
Note
This method is only relevant if this estimator is used as a sub-estimator of a meta-estimator, e.g. used inside a
Pipeline
. Otherwise it has no effect.Parameters¶
- sample_weightstr, True, False, or None, default=sklearn.utils.metadata_routing.UNCHANGED
Metadata routing for
sample_weight
parameter inscore
.
Returns¶
- selfobject
The updated object.