Skip to contents

R6 class representing probability distributions for CCC analysis

An R6 class representing probability mass functions (PMF) with optimized operations for cell-cell communication analysis. Supports both discrete PMF arrays and normal distribution approximations.

Details

The Distribution class supports the following operations:

  • Addition: Sum of two independent random variables (FFT convolution)

  • Power: Sum of n i.i.d. random variables

  • Division: Average of n i.i.d. random variables

  • And (&): Special operation for L+R combination

Public fields

dtype

Distribution type: "normal" or "other"

loc

Location parameter (mean for normal)

scale

Scale parameter (sd for normal)

pmf_array

PMF array

is_align

Whether PMF is aligned to standard bins

is_normal_type

Whether distribution is normal type

is_analytic

Whether distribution has analytic CDF

is_complex_analytic

Whether from complex combination

cdf_analytic_func

Analytic CDF function (for normal)

min_cdf_non_zero

Lower bound of support

min_cdf_one

Upper bound of support

support_length

Length of support

ligand

Ligand distribution (for complex analytic)

receptor

Receptor distribution (for complex analytic)

mode

Distribution mode: "continuous" or "digit"

Methods


Method new()

Create a new Distribution object

Usage

Distribution$new(
  dtype = "other",
  loc = NULL,
  scale = NULL,
  samples = NULL,
  pmf_array = NULL,
  is_align = NULL,
  mode = "continuous",
  eps = 1e-04
)

Arguments

dtype

Type: "normal", "gaussian", or "other"

loc

Location parameter (mean)

scale

Scale parameter (sd)

samples

Sample data to construct PMF

pmf_array

Pre-computed PMF array

is_align

Whether PMF is aligned

mode

Distribution mode ("continuous" or "digit")

eps

Tolerance for PMF sum check

Returns

A new Distribution object


Method get_mean()

Get mean of distribution

Usage

Distribution$get_mean()

Returns

Mean value


Method get_std()

Get standard deviation

Usage

Distribution$get_std()

Returns

SD value


Method get_var()

Get variance

Usage

Distribution$get_var()

Returns

Variance value


Method get_pmf_array()

Get PMF array

Usage

Distribution$get_pmf_array()

Returns

PMF array


Method get_cdf_array()

Get CDF array

Usage

Distribution$get_cdf_array()

Returns

CDF array


Method add()

Add two distributions (convolution)

Usage

Distribution$add(other)

Arguments

other

Another Distribution object

Returns

New Distribution representing sum


Method power()

Sum of n i.i.d. copies

Usage

Distribution$power(n)

Arguments

n

Number of copies

Returns

New Distribution


Method divide()

Average of n i.i.d. copies

Usage

Distribution$divide(n)

Arguments

n

Number of copies

Returns

New Distribution


Method and_op()

Special "and" operation for L+R

Usage

Distribution$and_op(other)

Arguments

other

Another Distribution

Returns

New Distribution


Method mul_op()

Geometric mean of two distributions (sqrt(X*Y))

Usage

Distribution$mul_op(other)

Arguments

other

Another Distribution

Details

Uses pre-computed index matrix exactly as Python: For each product binsi*binsj, find which bin contains sqrt(product) The mapping is: if last_value < product <= value^2, then index = that bin

Returns

New Distribution representing sqrt(XY)


Method copy()

Copy the distribution

Usage

Distribution$copy()

Returns

A deep copy of this Distribution


Method print()

Print method

Usage

Distribution$print()


Method clone()

The objects of this class are cloneable with this method.

Usage

Distribution$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.