splisosm.likelihood#

Likelihood functions and pvalue-approximation utilities.

Functions#

liu_sf(t, lambs[, dofs, deltas, kurtosis])

Compute p-values for weighted sums of chi-squared variables using the Liu approximation.

log_prob_fastdm(concentration, counts[, mask])

Compute optimized Dirichlet-multinomial log-likelihood.

log_prob_fastmult(probs, counts[, mask])

Compute optimized multinomial log-likelihood.

log_prob_fastmult_batched(probs, counts[, mask])

Compute batched optimized multinomial log-likelihood.

log_prob_fastmvn(locs, cov_eigvals, cov_eigvecs, data)

Compute multivariate normal log-likelihood with eigendecomposition.

log_prob_fastmvn_batched(locs, cov_eigvals, ...[, mask])

Compute batched multivariate normal log-likelihood with eigendecomposition.

Module Contents#

splisosm.likelihood.liu_sf(t, lambs, dofs=None, deltas=None, kurtosis=False)#

Compute p-values for weighted sums of chi-squared variables using the Liu approximation.

Let \(X = \sum_{i=1}^{d} \lambda_i * \chi^2(h_i, \delta_i)\) be a linear combination of d chi-squared random variables, each with degree of freedom \(h_i\) and noncentrality \(\delta_i\), this function approximates :math:Pr(X > t) using the Liu moment-matching approach [LTZ09].

Parameters:
  • t (numpy.typing.ArrayLike) – Shape (n,), observed test statistic.

  • lambs (numpy.typing.ArrayLike) – Shape (d,), weights of each chi-squared component.

  • dofs (Optional[numpy.typing.ArrayLike]) – Shape (d,), degrees of freedom for each component. Defaults to all ones.

  • deltas (Optional[numpy.typing.ArrayLike]) – Shape (d,), noncentrality parameters for each component. Defaults to all zeros.

  • kurtosis (bool) – If True, uses kurtosis matching proposed in [LWL12]; otherwise uses the original skewness matching [LTZ09].

Returns:

P-values of shape (n,) computed as Pr(X > t).

Return type:

ndarray

Notes

From limix/chiscore

splisosm.likelihood.log_prob_fastdm(concentration, counts, mask=None)#

Compute optimized Dirichlet-multinomial log-likelihood.

Parameters:
  • concentration (Tensor) – Isoform concentration tensor of shape (n_isos, n_spots).

  • counts (Tensor) – Isoform count tensor of shape (n_isos, n_spots).

  • mask (Optional[Tensor]) – Spot mask of shape (n_spots,). Entries with value 1 are treated as masked and are ignored when computing likelihood.

Returns:

Scalar log-likelihood.

Return type:

Tensor

splisosm.likelihood.log_prob_fastmult(probs, counts, mask=None)#

Compute optimized multinomial log-likelihood.

Parameters:
  • probs (Tensor) – Isoform ratio tensor of shape (n_isos, n_spots).

  • counts (Tensor) – Isoform count tensor of shape (n_isos, n_spots).

  • mask (Optional[Tensor]) – Spot mask of shape (n_spots,). Entries with value 1 are treated as masked and are ignored when computing likelihood.

Returns:

Scalar log-likelihood.

Return type:

Tensor

splisosm.likelihood.log_prob_fastmult_batched(probs, counts, mask=None)#

Compute batched optimized multinomial log-likelihood.

Parameters:
  • probs (Tensor) – Batched isoform ratio tensor of shape (batch_size, n_isos, n_spots).

  • counts (Tensor) – Batched isoform count tensor of shape (batch_size, n_isos, n_spots).

  • mask (Optional[Tensor]) – Mask tensor of shape (batch_size, n_spots). Entries with value 1 are treated as masked and are ignored when computing likelihood.

Returns:

Log-likelihood values of shape (batch_size,).

Return type:

Tensor

splisosm.likelihood.log_prob_fastmvn(locs, cov_eigvals, cov_eigvecs, data, mask=None)#

Compute multivariate normal log-likelihood with eigendecomposition.

Classes along the first axis are treated as independent, and the log-likelihood is computed as the sum of log-likelihoods for each class.

Parameters:
  • locs (Tensor) – Mean tensor of shape (n_classes, n_spots).

  • cov_eigvals (Tensor) – Covariance eigenvalues of shape (n_classes, n_spots) or (1, n_spots).

  • cov_eigvecs (Tensor) – Covariance eigenvectors of shape (n_classes, n_spots, n_spots) or (1, n_spots, n_spots).

  • data (Tensor) – Observation tensor of shape (n_classes, n_spots).

  • mask (Optional[Tensor]) – Spot mask of shape (n_spots,). Entries with value 1 are treated as masked and are ignored when computing likelihood.

Returns:

Scalar log-likelihood.

Return type:

Tensor

Raises:

ValueError – If covariance eigendecomposition shapes are incompatible with data.

splisosm.likelihood.log_prob_fastmvn_batched(locs, cov_eigvals, cov_eigvecs, data, mask=None)#

Compute batched multivariate normal log-likelihood with eigendecomposition.

Classes along the second axis are treated as independent, and the log-likelihood is computed as the sum of log-likelihoods for each class.

Parameters:
  • locs (Tensor) – Batched mean tensor of shape (batch_size, n_classes, n_spots).

  • cov_eigvals (Tensor) – Batched eigenvalue tensor of shape (batch_size, n_classes, n_spots).

  • cov_eigvecs (Tensor) – Batched eigenvector tensor of shape (batch_size, n_classes, n_spots, n_spots).

  • data (Tensor) – Batched observation of shape (batch_size, n_classes, n_spots).

  • mask (Tensor, optional) – Batched mask tensor of shape (batch_size, n_spots). Entries with value 1 are treated as masked and are ignored when computing likelihood.

Returns:

Log-likelihood values of shape (batch_size,).

Return type:

Tensor

Raises:

ValueError – If covariance decomposition shapes are incompatible with input sizes.