ddn3.bcd
Block coordinate descent for DDN
This module implements the original block coordinate descent in [1], as well as various accelerated versions. Most methods are also Numba accelerated, except for bcd_org_old, which is left for comparison purposes.
For data with lots of samples, consider using bcd_corr. For data with lots of features, the bcd_residual is faster.
[1] Zhang, Bai, and Yue Wang. “Learning structural changes of Gaussian graphical models in controlled experiments.” UAI (2010).
Module Contents
Functions
|
The BCD algorithm in DDN 2.0. |
|
The BCD algorithm in DDN 2.0, with Numba acceleration and some simplification. |
|
BCD algorithm for DDN using residual update strategy |
|
BCD algorithm for DDN using correlation matrix update strategy |
|
Optimize for two variables corresponding to one node |
- ddn3.bcd.bcd_org_old(beta_in, y, X, lambda1, lambda2, n1=1, n2=1, threshold=1e-06, max_iter=100000)
The BCD algorithm in DDN 2.0.
See https://arxiv.org/abs/1203.3532 for details Denote P be the number features. N1 be the sample size for condition 1, and N2 for condition 2.
- Parameters:
beta_in (array_like, length 2P) – Initial beta. If initialization is not needed, use an array of all zeros
y (array_like, size (N1+N2) by 1) – The samples for the node serving as response.
X (array_like, size (N1+N2) by (P-2)) – The block diagonal matrix with all the predictive nodes. Each condition has P-1 nodes. The top left block has size N1(P-1), while the bottom right block has size N2(P-1). Other elements are all zeros.
lambda1 (float) – DDN parameter lambda1.
lambda2 (float) – DDN parameter lambda2.
n1 (int) – Sample size for condition 1, N1
n2 (int) – Sample size for condition 2, N2
threshold (float) – Convergence threshold.
max_iter (int) – Maximum number of iterations
- Returns:
beta (ndarray, shape 2P) – Estimated beta for two conditions on node CurrIdx
r (int) – Number of iterations taken
betaerr (float) – The error term
- ddn3.bcd.bcd_org(beta_in, y, X, lambda1, lambda2, n1=1, n2=1, threshold=1e-06, max_iter=100000)
The BCD algorithm in DDN 2.0, with Numba acceleration and some simplification.
See https://arxiv.org/abs/1203.3532 for details Denote P be the number features. N1 be the sample size for condition 1, and N2 for condition 2.
- Parameters:
beta_in (array_like, length 2P) – Initial beta. If initialization is not needed, use an array of all zeros
y (array_like, size (N1+N2) by 1) – The samples for the node serving as response.
X (array_like, size (N1+N2) by (P-2)) – The block diagonal matrix with all the predictive nodes. Each condition has P-1 nodes. The top left block has size N1(P-1), while the bottom right block has size N2(P-1). Other elements are all zeros.
lambda1 (float) – DDN parameter lambda1.
lambda2 (float) – DDN parameter lambda2.
n1 (int) – Sample size for condition 1, N1
n2 (int) – Sample size for condition 2, N2
threshold (float) – Convergence threshold.
max_iter (int) – Maximum number of iterations
- Returns:
beta (ndarray, shape 2P) – Estimated beta for two conditions on node CurrIdx
r (int) – Number of iterations taken
betaerr (float) – The error term
- ddn3.bcd.bcd_residual(beta_in, X1, X2, y1_resi, y2_resi, CurrIdx, lambda1, lambda2, threshold, max_iter=10000)
BCD algorithm for DDN 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.
- Parameters:
beta_in (array_like, length 2P) – Initial beta. If initialization is not needed, use an array of all zeros
X1 (array_like, shape N1 by P) – The data from condition 1
X2 (array_like, shape N2 by P) – The data from condition 2
y1_resi (array_like, shape N1 by 1) – The initial residual signal for condition 1. If warm start is not used, it is column CurrIdx of X1.
y2_resi (array_like, shape N2 by 1) – The initial residual signal for condition 2. If warm start is not used, it is column CurrIdx of X2.
CurrIdx (int) – Index of the current node that serve as the response variable.
lambda1 (float) – DDN parameter lambda1.
lambda2 (float) – DDN parameter lambda2.
threshold (float) – Convergence threshold.
max_iter (int) – Maximum number of iterations
- Returns:
beta (ndarray, shape 2P) – Estimated beta for two conditions on node CurrIdx
r (int) – Number of iterations taken
betaerr (float) – The error term
- ddn3.bcd.bcd_corr(beta_in, cur_node, lambda1, lambda2, corr_matrix_1, corr_matrix_2, threshold=1e-06, max_iter=100000)
BCD algorithm for DDN 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.
- Parameters:
beta_in (array_like, length 2P) – Initial beta. If initialization is not needed, use an array of all zeros
cur_node (int) – Index of the current node that serve as the response variable.
lambda1 (float) – DDN parameter lambda1.
lambda2 (float) – DDN parameter lambda2.
corr_matrix_1 (array_like, P by P) – Correlation matrix for condition 1
corr_matrix_2 (array_like, P by P) – Correlation matrix for condition 2
threshold (float) – Convergence threshold.
max_iter (int) – Maximum number of iterations
- 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
- ddn3.bcd.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
- Parameters:
rho1 (float) – The rho from data1
rho2 (float) – The rho from data2
lambda1 (float) – DDN parameter lambda1
lambda2 (float) – DDN parameter lambda2
- Returns:
beta1 (float) – Optimal coefficient for data1
beta2 (float) – Optimal coefficient for data2