bioneuralnet.network.pysmccnet.core

Functions

binary_search(argu, sumabs)

Finds penalty parameter such that L1 norm of normalized argument equals sumabs.

l2n(vec)

Computes the L2 norm of a vector; returns 0.05 if norm is zero.

my_get_cors(xlist, ws, pair_cc, cc_coef)

PyTorch version of my_get_cors computing total weighted canonical correlations.

my_get_crit(xlist, ws, pair_cc, cc_coef)

PyTorch version of my_get_crit computing SmCCA objective on GPU.

my_multi_cca(xlist[, penalty, ws, niter, ...])

PyTorch version of my_multi_cca performing sparse multiple canonical correlation analysis (SmCCA) on GPU.

my_update_w(xlist, i, K, sumabsthis, ws, ...)

PyTorch version of my_update_w using hybrid GPU/CPU approach.

r_scale_torch(x)

Pytorch scaling using sample standard deviation.

soft(x, d)

Applies soft thresholding to input x with threshold d.

bioneuralnet.network.pysmccnet.core.my_get_cors(xlist: List[torch.Tensor], ws: List[torch.Tensor], pair_cc: ndarray | torch.Tensor, cc_coef: ndarray | torch.Tensor) float[source]

PyTorch version of my_get_cors computing total weighted canonical correlations.

Parameters:
  • xlist (List[torch.Tensor]) – List of input data matrices.

  • ws (List[torch.Tensor]) – List of weight vectors.

  • pair_cc (np.ndarray | torch.Tensor) – Matrix of pair indices.

  • cc_coef (np.ndarray | torch.Tensor) – Vector of scaling coefficients.

Returns:

Total weighted correlation value.

Return type:

float

bioneuralnet.network.pysmccnet.core.my_get_crit(xlist: List[torch.Tensor], ws: List[torch.Tensor], pair_cc: ndarray | torch.Tensor, cc_coef: ndarray | torch.Tensor) float[source]

PyTorch version of my_get_crit computing SmCCA objective on GPU.

Parameters:
  • xlist (List[torch.Tensor]) – List of input data matrices.

  • ws (List[torch.Tensor]) – List of weight vectors.

  • pair_cc (np.ndarray | torch.Tensor) – Matrix of pair indices.

  • cc_coef (np.ndarray | torch.Tensor) – Vector of scaling coefficients.

Returns:

Computed objective function value.

Return type:

float

bioneuralnet.network.pysmccnet.core.my_multi_cca(xlist: List[torch.Tensor], penalty: float | List[float] | ndarray | None = None, ws: List[torch.Tensor] | None = None, niter: int = 25, type: str = 'standard', ncomponents: int = 1, trace: bool = True, standardize: bool = True, cc_coef: List[float] | ndarray | torch.Tensor | None = None) Dict[str, Any][source]

PyTorch version of my_multi_cca performing sparse multiple canonical correlation analysis (SmCCA) on GPU.

Parameters:
  • xlist (List[torch.Tensor]) – List of data matrices (torch tensors on the target device).

  • penalty (float | List[float] | np.ndarray | None) – Penalty parameters for each omics layer.

  • ws (List[torch.Tensor] | None) – Initial weight vectors; if None, initialized via SVD.

  • niter (int) – Maximum number of iterations for convergence.

  • type (str) – Analysis type; currently supports “standard”.

  • ncomponents (int) – Number of canonical components to extract.

  • trace (bool) – If True, print iteration progress.

  • standardize (bool) – If True, standardize input data before analysis.

  • cc_coef (List | np.ndarray | torch.Tensor | None) – Scaling coefficients for between-omics pairs.

Returns:

Dictionary containing weights (‘ws’), initialization (‘ws_init’), and correlations (‘cors’).

Return type:

Dict[str, Any]

bioneuralnet.network.pysmccnet.core.my_update_w(xlist: List[torch.Tensor], i: int, K: int, sumabsthis: float, ws: List[torch.Tensor], ws_final: List[torch.Tensor], pair_cc: ndarray | torch.Tensor, cc_coef: ndarray | torch.Tensor | List[float], type: str = 'standard') torch.Tensor[source]

PyTorch version of my_update_w using hybrid GPU/CPU approach.

Parameters:
  • xlist (List[torch.Tensor]) – List of input data matrices.

  • i (int) – Index of the current omics layer to update.

  • K (int) – Number of latent components.

  • sumabsthis (float) – Sparsity penalty (L1 sum constraint) for this layer.

  • ws (List[torch.Tensor]) – Current weight vectors.

  • ws_final (List[torch.Tensor]) – Final weight vectors from previous components.

  • pair_cc (np.ndarray | torch.Tensor) – Matrix of pair indices.

  • cc_coef (np.ndarray | torch.Tensor | List[float]) – Scaling coefficients.

  • type (str) – Analysis type; currently supports ‘standard’.

Returns:

Updated weight vector for the i-th layer.

Return type:

torch.Tensor