|
| 1 | +--- |
| 2 | +Title: '.igammac()' |
| 3 | +Description: 'Computes the regularized upper incomplete gamma function.' |
| 4 | +Subjects: |
| 5 | + - 'Data Science' |
| 6 | + - 'Machine Learning' |
| 7 | +Tags: |
| 8 | + - 'AI' |
| 9 | + - 'Deep Learning' |
| 10 | + - 'Functions' |
| 11 | + - 'Machine Learning' |
| 12 | + - 'PyTorch' |
| 13 | +CatalogContent: |
| 14 | + - 'intro-to-py-torch-and-neural-networks' |
| 15 | + - 'paths/computer-science' |
| 16 | +--- |
| 17 | + |
| 18 | +The **`torch.igammac()`** function in PyTorch computes the upper regularized incomplete gamma function. This function is commonly used in probabilistic modeling, survival analysis, and statistical machine learning applications. `torch.igammac()` is an alias for `torch.special.gammaincc()`, meaning both functions compute the same values and can be used interchangeably. |
| 19 | + |
| 20 | +## Syntax |
| 21 | + |
| 22 | +```pseudo |
| 23 | +torch.igammac(input, other, \*, out=None) |
| 24 | +``` |
| 25 | + |
| 26 | +This is equivalent to: |
| 27 | + |
| 28 | +```pseudo |
| 29 | +torch.special.gammaincc(input, other, \*, out=None) |
| 30 | +``` |
| 31 | + |
| 32 | +**Parameters:** |
| 33 | + |
| 34 | +- `input` (Tensor): The first non-negative input tensor representing the shape parameter (${a}$). |
| 35 | +- `other` (Tensor): The second non-negative input tensor representing the integration limit (${x}$). |
| 36 | +- `out` (Tensor, optional): The output tensor. |
| 37 | + |
| 38 | +**Return value:** |
| 39 | + |
| 40 | +Returns a tensor containing the upper regularized incomplete gamma function values for each corresponding pair of elements in `input` and `other`. |
| 41 | + |
| 42 | +> **Note:** Supports broadcasting to a common shape and requires float inputs. The backward pass with respect to `input` is not currently supported. |
| 43 | +
|
| 44 | +## Example 1: Basic Element-Wise Computation |
| 45 | + |
| 46 | +In this example, `torch.igammac()` computes the upper regularized incomplete gamma function for corresponding elements of two 1D tensors: |
| 47 | + |
| 48 | +```py |
| 49 | +import torch |
| 50 | + |
| 51 | +a = torch.tensor([4.0]) |
| 52 | +x = torch.tensor([3.0, 4.0, 5.0]) |
| 53 | + |
| 54 | +result = torch.igammac(a, x) |
| 55 | +print("Upper incomplete gamma:", result) |
| 56 | + |
| 57 | +# Verify complementary relationship with igamma |
| 58 | +lower = torch.igamma(a, x) |
| 59 | +print("Sum of igamma and igammac:", lower + result) |
| 60 | +``` |
| 61 | + |
| 62 | +This code produces the following output: |
| 63 | + |
| 64 | +```shell |
| 65 | +Upper incomplete gamma: tensor([0.6472, 0.4335, 0.2650]) |
| 66 | +Sum of igamma and igammac: tensor([1., 1., 1.]) |
| 67 | +``` |
| 68 | + |
| 69 | +## Example 2: Survival Probabilities |
| 70 | + |
| 71 | +In this example, `torch.igammac()` calculates the survival probability (complement of CDF) for a gamma distribution at a given time point: |
| 72 | + |
| 73 | +```py |
| 74 | +import torch |
| 75 | + |
| 76 | +shape = torch.tensor([2.0, 3.0, 4.0]) |
| 77 | +time = torch.tensor([1.5]) |
| 78 | + |
| 79 | +survival_prob = torch.igammac(shape, time) |
| 80 | +cdf = torch.igamma(shape, time) |
| 81 | + |
| 82 | +print("Shape parameters:", shape) |
| 83 | +print("Time point:", time) |
| 84 | +print("Survival probabilities:", survival_prob) |
| 85 | +print("\nCDF values:", cdf) |
| 86 | +print("CDF + Survival:", cdf + survival_prob) |
| 87 | +``` |
| 88 | + |
| 89 | +The output of this code is: |
| 90 | + |
| 91 | +```shell |
| 92 | +Shape parameters: tensor([2., 3., 4.]) |
| 93 | +Time point: tensor([1.5]) |
| 94 | +Survival probabilities: tensor([0.4422, 0.7127, 0.8221]) |
| 95 | + |
| 96 | +CDF values: tensor([0.5578, 0.2873, 0.1779]) |
| 97 | +CDF + Survival: tensor([1., 1., 1.]) |
| 98 | +``` |
0 commit comments