From 543b981ca87729df5c021549f072db5a1348ac27 Mon Sep 17 00:00:00 2001 From: ylevental Date: Wed, 22 Oct 2025 13:18:26 -0400 Subject: [PATCH 1/4] Add .igammac() term entry for PyTorch Tensor Operations (Issue #7793) --- .../terms/igammac/igammac.md | 190 ++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 content/pytorch/concepts/tensor-operations/terms/igammac/igammac.md diff --git a/content/pytorch/concepts/tensor-operations/terms/igammac/igammac.md b/content/pytorch/concepts/tensor-operations/terms/igammac/igammac.md new file mode 100644 index 00000000000..1cebc495c59 --- /dev/null +++ b/content/pytorch/concepts/tensor-operations/terms/igammac/igammac.md @@ -0,0 +1,190 @@ +--- + +Title: '.igammac()' + +Description: 'Computes the regularized upper incomplete gamma function.' + +Subjects: + +  - 'AI' + +  - 'Data Science' + +  - 'Machine Learning' + +Tags: + +  - 'AI' + +  - 'Deep Learning' + +  - 'Functions' + +  - 'Machine Learning' + +  - 'PyTorch' + +CatalogContent: + +  - 'intro-to-py-torch-and-neural-networks' + +  - 'paths/computer-science' + +--- + + + +In PyTorch, the `.igammac()` method is an alias for `torch.special.gammaincc()` and computes the regularized upper incomplete gamma function. This function is commonly used in probabilistic modeling, survival analysis, and statistical machine learning applications. + + + +\## Syntax + +```py + +torch.igammac(input, other, \*, out=None) + +``` + + + +This is equivalent to: + +```py + +torch.special.gammaincc(input, other, \*, out=None) + +``` + + + +\### Parameters + + + +\- `input` (Tensor): The first non-negative input tensor representing the shape parameter. + +\- `other` (Tensor): The second non-negative input tensor representing the integration limit. + + + +\### Keyword Arguments + + + +\- `out` (Tensor, optional): The output tensor. + + + +\### Return Value + + + +Returns a tensor containing the computed regularized upper incomplete gamma function values. The function computes the probability mass from `other` to infinity under the gamma distribution. + + + +\*\*Note:\*\* The function supports broadcasting to a common shape and requires float inputs. The backward pass with respect to `input` is not currently supported. + + + +\## Example + + + +The following example demonstrates the use of `.igammac()`: + +```py + +import torch + + + +\# Create input tensors + +a = torch.tensor(\[4.0]) + +x = torch.tensor(\[3.0, 4.0, 5.0]) + + + +\# Compute the regularized upper incomplete gamma + +result = torch.igammac(a, x) + + + +print("Upper incomplete gamma:", result) + + + +\# Verify complementary relationship + +lower = torch.igamma(a, x) + +sum\_result = lower + result + + + +print("Sum of igamma and igammac:", sum\_result) + +``` + + + +The above code produces the following output: + +``` + +Upper incomplete gamma: tensor(\[0.6472, 0.4335, 0.2650]) + +Sum of igamma and igammac: tensor(\[1., 1., 1.]) + +``` + + + +\## Codebyte Example + + + +The following codebyte demonstrates `.igammac()` in an interactive example: + +```codebyte/python + +import torch + + + +\# Example: Computing survival probabilities + +shape = torch.tensor(\[2.0, 3.0, 4.0]) + +time = torch.tensor(\[1.5]) + + + +\# Calculate the probability of surviving past time 1.5 + +survival\_prob = torch.igammac(shape, time) + + + +print("Shape parameters:", shape) + +print("Time point:", time) + +print("Survival probabilities:", survival\_prob) + + + +\# Show complementary relationship + +cdf = torch.igamma(shape, time) + +print("\\nCDF values:", cdf) + +print("CDF + Survival:", cdf + survival\_prob) + +``` + From 2bff068c1427088371202fc3b697b929d1f8cdff Mon Sep 17 00:00:00 2001 From: Yuval Levental Date: Wed, 22 Oct 2025 17:45:11 +0000 Subject: [PATCH 2/4] Fix YAML formatting issues --- .../terms/igammac/igammac.md | 67 +++---------------- 1 file changed, 10 insertions(+), 57 deletions(-) diff --git a/content/pytorch/concepts/tensor-operations/terms/igammac/igammac.md b/content/pytorch/concepts/tensor-operations/terms/igammac/igammac.md index 1cebc495c59..322d988d217 100644 --- a/content/pytorch/concepts/tensor-operations/terms/igammac/igammac.md +++ b/content/pytorch/concepts/tensor-operations/terms/igammac/igammac.md @@ -1,43 +1,23 @@ --- - Title: '.igammac()' - Description: 'Computes the regularized upper incomplete gamma function.' - Subjects: - -  - 'AI' - -  - 'Data Science' - -  - 'Machine Learning' - + - 'AI' + - 'Data Science' + - 'Machine Learning' Tags: - -  - 'AI' - -  - 'Deep Learning' - -  - 'Functions' - -  - 'Machine Learning' - -  - 'PyTorch' - + - 'AI' + - 'Deep Learning' + - 'Functions' + - 'Machine Learning' + - 'PyTorch' CatalogContent: - -  - 'intro-to-py-torch-and-neural-networks' - -  - 'paths/computer-science' - + - 'intro-to-py-torch-and-neural-networks' + - 'paths/computer-science' --- - - In PyTorch, the `.igammac()` method is an alias for `torch.special.gammaincc()` and computes the regularized upper incomplete gamma function. This function is commonly used in probabilistic modeling, survival analysis, and statistical machine learning applications. - - \## Syntax ```py @@ -46,8 +26,6 @@ torch.igammac(input, other, \*, out=None) ``` - - This is equivalent to: ```py @@ -56,42 +34,24 @@ torch.special.gammaincc(input, other, \*, out=None) ``` - - \### Parameters - - \- `input` (Tensor): The first non-negative input tensor representing the shape parameter. \- `other` (Tensor): The second non-negative input tensor representing the integration limit. - - \### Keyword Arguments - - \- `out` (Tensor, optional): The output tensor. - - \### Return Value - - Returns a tensor containing the computed regularized upper incomplete gamma function values. The function computes the probability mass from `other` to infinity under the gamma distribution. - - \*\*Note:\*\* The function supports broadcasting to a common shape and requires float inputs. The backward pass with respect to `input` is not currently supported. - - \## Example - - The following example demonstrates the use of `.igammac()`: ```py @@ -130,8 +90,6 @@ print("Sum of igamma and igammac:", sum\_result) ``` - - The above code produces the following output: ``` @@ -142,12 +100,8 @@ Sum of igamma and igammac: tensor(\[1., 1., 1.]) ``` - - \## Codebyte Example - - The following codebyte demonstrates `.igammac()` in an interactive example: ```codebyte/python @@ -187,4 +141,3 @@ print("\\nCDF values:", cdf) print("CDF + Survival:", cdf + survival\_prob) ``` - From f00a4db182e17d8ace4b1faf444975f0d914d5ac Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Fri, 24 Oct 2025 17:37:03 +0530 Subject: [PATCH 3/4] Revise igammac documentation for clarity and detail Updated the documentation for the `torch.igammac()` function to clarify its purpose, parameters, and examples. Improved formatting and consistency throughout the text. (The entire entry had backward slashes) --- .../terms/igammac/igammac.md | 122 ++++++------------ 1 file changed, 39 insertions(+), 83 deletions(-) diff --git a/content/pytorch/concepts/tensor-operations/terms/igammac/igammac.md b/content/pytorch/concepts/tensor-operations/terms/igammac/igammac.md index 322d988d217..6aae07bb294 100644 --- a/content/pytorch/concepts/tensor-operations/terms/igammac/igammac.md +++ b/content/pytorch/concepts/tensor-operations/terms/igammac/igammac.md @@ -16,128 +16,84 @@ CatalogContent: - 'paths/computer-science' --- -In PyTorch, the `.igammac()` method is an alias for `torch.special.gammaincc()` and computes the regularized upper incomplete gamma function. This function is commonly used in probabilistic modeling, survival analysis, and statistical machine learning applications. +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. -\## Syntax - -```py +## Syntax +```pseudo torch.igammac(input, other, \*, out=None) - ``` This is equivalent to: -```py - +```pseudo torch.special.gammaincc(input, other, \*, out=None) - ``` -\### Parameters - -\- `input` (Tensor): The first non-negative input tensor representing the shape parameter. +**Parameters:** -\- `other` (Tensor): The second non-negative input tensor representing the integration limit. +- `input` (Tensor): The first non-negative input tensor representing the shape parameter (${a}$). +- `other` (Tensor): The second non-negative input tensor representing the integration limit (${x}$). +- `out` (Tensor, optional): The output tensor. -\### Keyword Arguments +**Return value:** -\- `out` (Tensor, optional): The output tensor. +Returns a tensor containing the upper regularized incomplete gamma function values for each corresponding pair of elements in `input` and `other`. -\### Return Value +> **Note:** Supports broadcasting to a common shape and requires float inputs. The backward pass with respect to `input` is not currently supported. -Returns a tensor containing the computed regularized upper incomplete gamma function values. The function computes the probability mass from `other` to infinity under the gamma distribution. +## Example 1: Basic Element-Wise Computation -\*\*Note:\*\* The function supports broadcasting to a common shape and requires float inputs. The backward pass with respect to `input` is not currently supported. - -\## Example - -The following example demonstrates the use of `.igammac()`: +In this example, `torch.igammac()` computes the upper regularized incomplete gamma function for corresponding elements of two 1D tensors: ```py - import torch - - -\# Create input tensors - -a = torch.tensor(\[4.0]) - -x = torch.tensor(\[3.0, 4.0, 5.0]) - - - -\# Compute the regularized upper incomplete gamma +a = torch.tensor([4.0]) +x = torch.tensor([3.0, 4.0, 5.0]) result = torch.igammac(a, x) - - - print("Upper incomplete gamma:", result) - - -\# Verify complementary relationship - +# Verify complementary relationship with igamma lower = torch.igamma(a, x) - -sum\_result = lower + result - - - -print("Sum of igamma and igammac:", sum\_result) - +print("Sum of igamma and igammac:", lower + result) ``` -The above code produces the following output: +This code produces the following output: +```shell +Upper incomplete gamma: tensor([0.6472, 0.4335, 0.2650]) +Sum of igamma and igammac: tensor([1., 1., 1.]) ``` -Upper incomplete gamma: tensor(\[0.6472, 0.4335, 0.2650]) - -Sum of igamma and igammac: tensor(\[1., 1., 1.]) - -``` - -\## Codebyte Example - -The following codebyte demonstrates `.igammac()` in an interactive example: +## Example 2: Survival Probabilities -```codebyte/python +In this example, `torch.igammac()` calculates the survival probability (complement of CDF) for a gamma distribution at a given time point: +```py import torch +shape = torch.tensor([2.0, 3.0, 4.0]) +time = torch.tensor([1.5]) - -\# Example: Computing survival probabilities - -shape = torch.tensor(\[2.0, 3.0, 4.0]) - -time = torch.tensor(\[1.5]) - - - -\# Calculate the probability of surviving past time 1.5 - -survival\_prob = torch.igammac(shape, time) - - +survival_prob = torch.igammac(shape, time) +cdf = torch.igamma(shape, time) print("Shape parameters:", shape) - print("Time point:", time) +print("Survival probabilities:", survival_prob) +print("\nCDF values:", cdf) +print("CDF + Survival:", cdf + survival_prob) +``` -print("Survival probabilities:", survival\_prob) - - - -\# Show complementary relationship - -cdf = torch.igamma(shape, time) - -print("\\nCDF values:", cdf) +The output of this code is: -print("CDF + Survival:", cdf + survival\_prob) +```shell +Shape parameters: tensor([2., 3., 4.]) +Time point: tensor([1.5]) +Survival probabilities: tensor([0.4422, 0.7127, 0.8221]) +CDF values: tensor([0.5578, 0.2873, 0.1779]) +CDF + Survival: tensor([1., 1., 1.]) ``` From 04a23505ed0ee726d5fe2debe37f46991ace700d Mon Sep 17 00:00:00 2001 From: Daksha Deep Date: Wed, 29 Oct 2025 18:05:30 +0530 Subject: [PATCH 4/4] Update igammac.md --- .../pytorch/concepts/tensor-operations/terms/igammac/igammac.md | 1 - 1 file changed, 1 deletion(-) diff --git a/content/pytorch/concepts/tensor-operations/terms/igammac/igammac.md b/content/pytorch/concepts/tensor-operations/terms/igammac/igammac.md index 6aae07bb294..9d663dc0c6e 100644 --- a/content/pytorch/concepts/tensor-operations/terms/igammac/igammac.md +++ b/content/pytorch/concepts/tensor-operations/terms/igammac/igammac.md @@ -2,7 +2,6 @@ Title: '.igammac()' Description: 'Computes the regularized upper incomplete gamma function.' Subjects: - - 'AI' - 'Data Science' - 'Machine Learning' Tags: