celcomen.utils.helpers.calc_gex

celcomen.utils.helpers.calc_gex(sphex)

Converts a spherical gene expression matrix into a standard gene expression matrix.

The function takes a spherical expression matrix (sphex) and calculates the corresponding gene expression matrix (gex) using trigonometric functions such as sine and cosine. The last gene is computed using sine, and the others are computed using cosine, followed by multiplying by the sine of all preceding dimensions.

Parameters

sphextorch.Tensor

The spherical gene expression matrix. Expected shape is (n_samples, n_features - 1).

Returns

gextorch.Tensor

The computed gene expression matrix of shape (n_samples, n_features), where n_features is one more than in sphex. All NaN values are replaced with 0.

Examples

>>> sphex = torch.tensor([[0.5, 0.6], [0.3, 0.4]])
>>> gex = calc_gex(sphex)
>>> print(gex)
tensor([[0.8776, 0.5646, 0.4794],
        [0.9553, 0.5646, 0.2955]])