PyTorch .igamma()
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
torch.igamma(input, other, *, out=None)
Or, alternatively:
torch.special.gammainc(input, other, *, out=None)
Parameters:
input(Tensor): The shape parameteraof the Gamma function.other(Tensor): The upper limitxof the integral.out(Tensor, optional): The output tensor to store results.
Return value:
Returns a tensor containing the lower regularized incomplete gamma function values for each corresponding pair of elements in input and other.
Example 1: Basic Element-Wise Computation
In this example, torch.igamma() computes the lower regularized incomplete gamma function for corresponding elements of two 1D tensors:
import torcha = 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:
tensor([0.2642, 0.3233, 0.3528])
Example 2: Gamma Distribution CDF
In this example, torch.igamma() calculates the cumulative distribution function (CDF) of a Gamma distribution with shape ${a}$ and rate 1:
import torcha = 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:
tensor([0.0000, 0.2642, 0.5940, 0.8009, 0.9084, 0.9596])
The .igamma() function 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.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn PyTorch on Codecademy
- Machine Learning Data Scientists solve problems at scale, make predictions, find patterns, and more! They use Python, SQL, and algorithms.
- Includes 27 Courses
- With Professional Certification
- Beginner Friendly.95 hours
- Learn how to use PyTorch to build, train, and test artificial neural networks in this course.
- Intermediate.3 hours