From 4021a5d22b9fdb13e9eecbceb5d385c90db05708 Mon Sep 17 00:00:00 2001 From: SrikartikMateti Date: Thu, 23 Oct 2025 21:15:22 +0530 Subject: [PATCH 1/4] Adding igamma --- .../tensor-operations/terms/igamma/igamma.md | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 content/pytorch/concepts/tensor-operations/terms/igamma/igamma.md diff --git a/content/pytorch/concepts/tensor-operations/terms/igamma/igamma.md b/content/pytorch/concepts/tensor-operations/terms/igamma/igamma.md new file mode 100644 index 00000000000..623cc63aa7c --- /dev/null +++ b/content/pytorch/concepts/tensor-operations/terms/igamma/igamma.md @@ -0,0 +1,81 @@ +--- +Title: '.igamma' +Description: 'Computes the lower regularized incomplete gamma function.' +Subjects: + - 'Computer Science' + - 'Data Science' + - 'Machine Learning' +Tags: + - 'AI' + - 'Deep Learning' + - 'Methods' + - 'PyTorch' + - 'Tensor' +CatalogContent: + - 'intro-to-py-torch-and-neural-networks' + - 'paths/data-science' +--- + +The torch.igamma() function in PyTorch computes the lower regularized incomplete gamma function, a special mathematical function often used in probability, statistics, and machine learning. +It returns a [tensor](https://www.codecademy.com/resources/docs/pytorch/tensors) containing the computed values for each element pair in the input tensors. + +## Syntax + +```pseudo +torch.igamma(input, other, *, out=None) +``` + +**Parameters:** +input (Tensor): The shape parameter 𝑎 a of the gamma function. +other (Tensor): The upper limit 𝑥 of the integral. +out (Tensor, optional): The output tensor. + +**Return value:** + +The `.igamma` property returns a tensor containing the result of the lower regularized incomplete gamma function for each pair of elements in input and other + +## Example 1 + +The following example demonstrates how to use the `torch.igamma()` function to compute the lower regularized incomplete gamma values: + +```py +import torch + +a = torch.tensor([2.0, 3.0, 4.0]) +x = torch.tensor([1.0, 2.0, 3.0]) + +result = torch.igamma(a, x) +print(result) +``` + +This example produces the following output: + +```shell +tensor([0.2642, 0.3233, 0.3528]) +``` + +## Example 2 + +The CDF of a Gamma distribution with shape 𝑎 a and rate 1 can be computed using torch.igamma: + +```py +import torch + +a = torch.tensor([2.0]) +x = torch.linspace(0, 5, 6) +gamma_cdf = torch.igamma(a, x) + +print(gamma_cdf) +``` + +The output of this code is: + +```shell +tensor([0.0000, 0.2642, 0.5940, 0.8009, 0.9084, 0.9596]) +``` + +The `.igamma` property is useful for: + +- Computing CDFs of Gamma, Chi-square, or Exponential distributions. +- Performing Bayesian statistical modeling (priors and posteriors). +- Implementing neural network activations and loss functions involving special functions. From a92fa94a1b2a81246edc61117385e15ec8067245 Mon Sep 17 00:00:00 2001 From: Mamta Wardhani Date: Fri, 24 Oct 2025 17:16:07 +0530 Subject: [PATCH 2/4] minor content fixes --- .../tensor-operations/terms/igamma/igamma.md | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/content/pytorch/concepts/tensor-operations/terms/igamma/igamma.md b/content/pytorch/concepts/tensor-operations/terms/igamma/igamma.md index 623cc63aa7c..1e3621a3287 100644 --- a/content/pytorch/concepts/tensor-operations/terms/igamma/igamma.md +++ b/content/pytorch/concepts/tensor-operations/terms/igamma/igamma.md @@ -1,6 +1,6 @@ --- -Title: '.igamma' -Description: 'Computes the lower regularized incomplete gamma function.' +Title: '.igamma()' +Description: 'Computes the lower regularized incomplete gamma function for tensor inputs.' Subjects: - 'Computer Science' - 'Data Science' @@ -16,8 +16,7 @@ CatalogContent: - 'paths/data-science' --- -The torch.igamma() function in PyTorch computes the lower regularized incomplete gamma function, a special mathematical function often used in probability, statistics, and machine learning. -It returns a [tensor](https://www.codecademy.com/resources/docs/pytorch/tensors) containing the computed values for each element pair in the input tensors. +The **`torch.igamma()`** function in PyTorch computes the lower regularized incomplete gamma function, a special mathematical function often used in probability, statistics, and machine learning. `torch.igamma()` is an alias for `torch.special.gammainc()`. This means both functions compute the regularized lower incomplete gamma function and can be used interchangeably. ## Syntax @@ -25,18 +24,25 @@ It returns a [tensor](https://www.codecademy.com/resources/docs/pytorch/tensors) torch.igamma(input, other, *, out=None) ``` +Or, alternatively: + +```pseudo +torch.special.gammainc(input, other, *, out=None) +``` + **Parameters:** -input (Tensor): The shape parameter 𝑎 a of the gamma function. -other (Tensor): The upper limit 𝑥 of the integral. -out (Tensor, optional): The output tensor. + +- `input` (Tensor): The shape parameter ${a\}$ of the gamma function. +- `other` (Tensor): The upper limit ${x\}$ of the integral. +- `out` (Tensor, optional): The output tensor. **Return value:** -The `.igamma` property returns a tensor containing the result of the lower regularized incomplete gamma function for each pair of elements in input and other +Returns a tensor containing the lower regularized incomplete gamma function values for each corresponding pair of elements in `input` and `other`. -## Example 1 +## Example 1: Basic Element-Wise Computation -The following example demonstrates how to use the `torch.igamma()` function to compute the lower regularized incomplete gamma values: +In this example, `torch.igamma()` computes the lower regularized incomplete gamma function for corresponding elements of two 1D tensors: ```py import torch @@ -54,9 +60,9 @@ This example produces the following output: tensor([0.2642, 0.3233, 0.3528]) ``` -## Example 2 +## Example 2: Gamma Distribution CDF -The CDF of a Gamma distribution with shape 𝑎 a and rate 1 can be computed using torch.igamma: +In this example, `torch.igamma()` calculates the cumulative distribution function (CDF) of a Gamma distribution with shape ${a\}$ and rate 1: ```py import torch @@ -74,7 +80,7 @@ The output of this code is: tensor([0.0000, 0.2642, 0.5940, 0.8009, 0.9084, 0.9596]) ``` -The `.igamma` property is useful for: +The `.igamma()` function is useful for: - Computing CDFs of Gamma, Chi-square, or Exponential distributions. - Performing Bayesian statistical modeling (priors and posteriors). From 764be921dd5c72d99ce65fc9a41a933ff683fb6b Mon Sep 17 00:00:00 2001 From: Daksha Deep Date: Tue, 28 Oct 2025 14:44:45 +0530 Subject: [PATCH 3/4] Update igamma.md --- .../pytorch/concepts/tensor-operations/terms/igamma/igamma.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/pytorch/concepts/tensor-operations/terms/igamma/igamma.md b/content/pytorch/concepts/tensor-operations/terms/igamma/igamma.md index 1e3621a3287..446fba7a0c4 100644 --- a/content/pytorch/concepts/tensor-operations/terms/igamma/igamma.md +++ b/content/pytorch/concepts/tensor-operations/terms/igamma/igamma.md @@ -1,6 +1,6 @@ --- Title: '.igamma()' -Description: 'Computes the lower regularized incomplete gamma function for tensor inputs.' +Description: 'Computes the lower incomplete gamma function for tensor inputs.' Subjects: - 'Computer Science' - 'Data Science' From a0ab308f9dad4c1226cce6cd9314893652e7e7d2 Mon Sep 17 00:00:00 2001 From: Daksha Deep Date: Tue, 28 Oct 2025 14:47:38 +0530 Subject: [PATCH 4/4] Update igamma.md --- .../concepts/tensor-operations/terms/igamma/igamma.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/content/pytorch/concepts/tensor-operations/terms/igamma/igamma.md b/content/pytorch/concepts/tensor-operations/terms/igamma/igamma.md index 446fba7a0c4..fc92876a068 100644 --- a/content/pytorch/concepts/tensor-operations/terms/igamma/igamma.md +++ b/content/pytorch/concepts/tensor-operations/terms/igamma/igamma.md @@ -32,9 +32,9 @@ torch.special.gammainc(input, other, *, out=None) **Parameters:** -- `input` (Tensor): The shape parameter ${a\}$ of the gamma function. -- `other` (Tensor): The upper limit ${x\}$ of the integral. -- `out` (Tensor, optional): The output tensor. +- `input` (Tensor): The shape parameter `a` of the Gamma function. +- `other` (Tensor): The upper limit `x` of the integral. +- `out` (Tensor, optional): The output tensor to store results. **Return value:**