iddn.bcd ======== .. py:module:: iddn.bcd .. autoapi-nested-parse:: Block coordinate descent for iDDN This module implements the block coordinate descent in [1]. Most methods are also Numba accelerated. For iddn_data with lots of samples, consider using `bcd_corr`. For iddn_data with lots of features, the `bcd_residual` is faster. [1] Fu, Yi, et al. "DDN3. 0: Determining significant rewiring of biological network structure with differential dependency networks." Bioinformatics (2024). Functions --------- .. autoapisummary:: iddn.bcd.bcd_residual iddn.bcd.bcd_corr iddn.bcd.solve2d Module Contents --------------- .. py:function:: bcd_residual(beta_in, X1, X2, y1_resi, y2_resi, cur_node, dep_nodes, lambda1, lambda2, threshold, max_iter=10000) BCD algorithm for iDDN using residual update strategy The algorithm allows warm start, which requires initial `beta_in`, `y1_resi`, and `y2_resi`. See `run_resi` on how to prepare these inputs. Denote `P` be the number features. N1 be the sample size for condition 1, and N2 for condition 2. :param beta_in: Initial beta. If initialization is not needed, use an array of all zeros :type beta_in: (2P) array_like :param X1: The iddn_data from condition 1 :type X1: (N1,P) array_like :param X2: The iddn_data from condition 2 :type X2: (N2,P) array_like :param y1_resi: The initial residual signal for condition 1. If warm start is not used, it is column CurrIdx of X1. :type y1_resi: (N1,1) array_like :param y2_resi: The initial residual signal for condition 2. If warm start is not used, it is column CurrIdx of X2. :type y2_resi: (N2,1) array_like :param cur_node: Index of the current node that serve as the response variable. :type cur_node: int :param dep_nodes: Nodes that point to current node will be 1. :type dep_nodes: (P) array_like :param lambda1: DDN parameter lambda1. :type lambda1: array_like :param lambda2: DDN parameter lambda2. :type lambda2: array_like :param threshold: Convergence threshold. :type threshold: float :param max_iter: Maximum number of iterations :type max_iter: int :returns: * **beta** (*ndarray, shape 2P*) -- Estimated beta for two conditions on node CurrIdx * **r** (*int*) -- Number of iterations taken * **betaerr** (*float*) -- The error term .. py:function:: bcd_corr(beta_in, cur_node, dep_nodes, lambda1, lambda2, corr_matrix_1, corr_matrix_2, threshold=1e-06, max_iter=100000) BCD algorithm for iDDN using correlation matrix update strategy This approach is more suitable for larger sample sizes. The algorithm allows warm start, which requires initial `beta_in`. Denote P be the number features. N1 be the sample size for condition 1, and N2 for condition 2. :param beta_in: Initial beta. If initialization is not needed, use an array of all zeros :type beta_in: array_like, length 2P :param cur_node: Index of the current node that serve as the response variable. :type cur_node: int :param dep_nodes: Nodes that point to current node will be 1. :type dep_nodes: (P) array_like :param lambda1: DDN parameter lambda1. :type lambda1: array_like :param lambda2: DDN parameter lambda2. :type lambda2: array_like :param corr_matrix_1: Correlation matrix for condition 1 :type corr_matrix_1: array_like, P by P :param corr_matrix_2: Correlation matrix for condition 2 :type corr_matrix_2: array_like, P by P :param threshold: Convergence threshold. :type threshold: float :param max_iter: Maximum number of iterations :type max_iter: int :returns: * **beta** (*ndarray, shape 2P*) -- Estimated beta for two conditions on node CurrIdx * **r** (*int*) -- Number of iterations taken * **delta_beta** (*float*) -- The error term .. py:function:: solve2d(rho1, rho2, lambda1, lambda2) Optimize for two variables corresponding to one node The details can be found in https://arxiv.org/abs/1203.3532 :param rho1: The rho from data1 :type rho1: float :param rho2: The rho from data2 :type rho2: float :param lambda1: DDN parameter lambda1 :type lambda1: float :param lambda2: DDN parameter lambda2 :type lambda2: float :returns: * **beta1** (*float*) -- Optimal coefficient for data1 * **beta2** (*float*) -- Optimal coefficient for data2