Dirichlet functions in the Stochastic DuckDB extension
Function category
Dirichlet
5 functionsDirichlet — multivariate distribution over probability vectors that sum to 1. Priors for categorical and multinomial proportions.
Signature
dist_dirichlet_log_pdf(alpha: DOUBLE[], x: DOUBLE[]) → DOUBLE
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
alpha
|
Type
DOUBLE[]
|
Mode Positional | Description |
Argument
x
|
Type
DOUBLE[]
|
Mode Positional | Description |
Description
Computes the natural logarithm of the probability density function (PDF) of the Dirichlet distribution at x.
1
Example 1
SELECT dist_dirichlet_log_pdf([2.0, 3.0, 5.0], [0.2, 0.3, 0.5]);
Output
| dist_dirichlet_log_pdf(list_value(2.0, 3.0, 5.0), list_value(0.2, 0.3, 0.5)) |
|---|
| 2.1406542258478236 |
Related functions
- dist_dirichlet_sample() — Generates a random sample from the Dirichlet distribution with concentration parameters alpha
- dist_dirichlet_pdf() — Computes the probability density function (PDF) of the Dirichlet distribution at x, a list of values in [0, 1] that sums to 1
- dist_dirichlet_mean() — Returns the mean of each component of the Dirichlet distribution, alpha_i / sum(alpha)
- dist_dirichlet_variance() — Returns the variance of each component of the Dirichlet distribution
Signature
dist_dirichlet_mean(alpha: DOUBLE[]) → DOUBLE[]
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
alpha
|
Type
DOUBLE[]
|
Mode Positional | Description |
Description
Returns the mean of each component of the Dirichlet distribution, alpha_i / sum(alpha).
1
Component means of a Dirichlet
SELECT dist_dirichlet_mean([2.0, 3.0, 5.0]) AS mean;
Output
| mean |
|---|
| [0.2, 0.3, 0.5] |
Related functions
- dist_dirichlet_sample() — Generates a random sample from the Dirichlet distribution with concentration parameters alpha
- dist_dirichlet_pdf() — Computes the probability density function (PDF) of the Dirichlet distribution at x, a list of values in [0, 1] that sums to 1
- dist_dirichlet_variance() — Returns the variance of each component of the Dirichlet distribution
Signature
dist_dirichlet_pdf(alpha: DOUBLE[], x: DOUBLE[]) → DOUBLE
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
alpha
|
Type
DOUBLE[]
|
Mode Positional | Description |
Argument
x
|
Type
DOUBLE[]
|
Mode Positional | Description |
Description
Computes the probability density function (PDF) of the Dirichlet distribution at x, a list of values in [0, 1] that sums to 1.
1
Density at a point on the simplex
SELECT round(dist_dirichlet_pdf([2.0, 3.0, 5.0], [0.2, 0.3, 0.5]), 6) AS density;
Output
| density |
|---|
| 8.505 |
Related functions
- dist_dirichlet_sample() — Generates a random sample from the Dirichlet distribution with concentration parameters alpha
- dist_dirichlet_mean() — Returns the mean of each component of the Dirichlet distribution, alpha_i / sum(alpha)
- dist_dirichlet_variance() — Returns the variance of each component of the Dirichlet distribution
Signature
dist_dirichlet_sample(alpha: DOUBLE[]) → DOUBLE[]
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
alpha
|
Type
DOUBLE[]
|
Mode Positional | Description |
Description
Generates a random sample from the Dirichlet distribution with concentration parameters alpha. Returns a list of probabilities that sums to 1.
1
A Dirichlet sample is a probability vector
SELECT len(s) AS components, round(list_sum(s), 12) AS total
FROM (SELECT dist_dirichlet_sample([2.0, 3.0, 5.0]) AS s);
Output
| components | total |
|---|---|
| 3 | 1.0 |
Related functions
- dist_dirichlet_pdf() — Computes the probability density function (PDF) of the Dirichlet distribution at x, a list of values in [0, 1] that sums to 1
- dist_dirichlet_mean() — Returns the mean of each component of the Dirichlet distribution, alpha_i / sum(alpha)
- dist_dirichlet_variance() — Returns the variance of each component of the Dirichlet distribution
Signature
dist_dirichlet_variance(alpha: DOUBLE[]) → DOUBLE[]
Arguments (Positional)
| Argument | Type | Mode | Description |
|---|---|---|---|
Argument
alpha
|
Type
DOUBLE[]
|
Mode Positional | Description |
Description
Returns the variance of each component of the Dirichlet distribution.
1
Example 1
SELECT dist_dirichlet_variance([2.0, 3.0, 5.0]);
Output
| dist_dirichlet_variance(list_value(2.0, 3.0, 5.0)) |
|---|
| [0.014545454545454549, 0.01909090909090909, 0.022727272727272728] |
Related functions
- dist_dirichlet_sample() — Generates a random sample from the Dirichlet distribution with concentration parameters alpha
- dist_dirichlet_pdf() — Computes the probability density function (PDF) of the Dirichlet distribution at x, a list of values in [0, 1] that sums to 1
- dist_dirichlet_mean() — Returns the mean of each component of the Dirichlet distribution, alpha_i / sum(alpha)