Skip to content
DeepForgeby svx
All problems
MediumProbabilitypr-079

Beta PDF Value

Problem

Beta probability density with shape parameters alpha and beta at x:

f(x) = x^(alpha - 1) * (1 - x)^(beta - 1) / B(alpha, beta).

Return 0.0 when x is outside [0, 1] or a parameter is nonpositive; boundary points return 0.0.

Hint

Compute in log space and exponentiate to avoid overflow.

Test cases

case 1
in: [1,1,0.5]
expected: 1
case 2
in: [2,3,0.5]
expected: 1.4999999999999991
case 3
in: [2,2,0.5]
expected: 1.5
case 4
in: [0,1,0.5]
expected: 0
Starter codePython
import math


def beta_pdf_value(alpha, beta, x):
    # Your code here
    pass

4 test cases · run your code against them in the editor