loggamma
loggamma is useful when you work with large inputs to the gamma function in statistical calculations, such as log-likelihood computations, Bayesian modeling, or custom anomaly scoring. Use it whenever gamma(x) would overflow to infinity.
Usage#
Syntax#
loggamma(x)Parameters#
| Name | Type | Required | Description |
|---|---|---|---|
x |
real | Yes | The input value. Must not be zero or a negative integer. |
Returns#
The natural logarithm of the absolute value of the gamma function of x.
Example#
Use loggamma to compute the log-gamma value of a duration in seconds without risking numeric overflow.
Query
['sample-http-logs']
| where req_duration_ms > 0
| extend duration_s = req_duration_ms / 1000.0
| extend loggamma_val = loggamma(duration_s)
| project _time, id, req_duration_ms, loggamma_valOutput
| _time | id | req_duration_ms | loggamma_val |
|---|---|---|---|
| 2024-11-14 10:00:00 | user-1 | 1000.0 | 0.0000 |
| 2024-11-14 10:01:00 | user-2 | 2000.0 | 0.0000 |
| 2024-11-14 10:02:00 | user-3 | 10000.0 | 16.1181 |
List of related functions#
- gamma: Returns the gamma function directly. Use it for small inputs where overflow isn't a concern.
- log: Returns the natural logarithm. Use it for general log-transformation without the gamma relationship.
- exp: Returns e^x. Use it to exponentiate
loggammaresults back to the original gamma scale when the values are small enough. - isfinite: Returns whether a value is finite. Use it to verify that
loggammaresults are valid for downstream calculations. - abs: Returns the absolute value. Note that
loggamma(x)equalslog(abs(gamma(x))), soabsis implicitly applied togamma(x)before the log.
Other query languages#
Splunk SPL users
Splunk SPL doesn't include a built-in loggamma() function. You typically implement it using external libraries or the Machine Learning Toolkit.
Splunk example
| eval loggamma_val = null()APL equivalent
['sample-http-logs']
| extend loggamma_val = loggamma(x)ANSI SQL users
Standard SQL does not define a LOGGAMMA() function. You need to implement it in application code or through database-specific extensions.
SQL example
-- No standard SQL equivalent; use application code
SELECT NULL AS loggamma_val FROM logsAPL equivalent
['sample-http-logs']
| extend loggamma_val = loggamma(x)