Skip to content
DeepForgeby svx
All problems
MediumProbabilitypr-040

MGF of Bernoulli

Problem

Moment generating function of a Bernoulli(p) random variable evaluated at t.

M(t) = (1 - p) + p * e^t.

Hint

Take the expectation of e^(tX) over X in {0, 1}.

Test cases

case 1
in: [0.5,0]
expected: 1
case 2
in: [0.5,1]
expected: 1.8591409142295225
case 3
in: [0.2,2]
expected: 2.2778112197861304
case 4
in: [0,3]
expected: 1
Starter codePython
import math


def mgf_bernoulli(p, t):
    # Your code here
    pass

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