Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In python! The formula is E(f(X)) = Xn i=1 p(x)f(x) ,

In python!

The formula is E(f(X)) = Xn i=1 p(x)f(x) , <-(summation of p(x)f(x))You are supposed to complete the function expect in the expect.py file. There are two input parameters of the function expect. (1) A dictionary representing the distribution of the random variable. The keys of dictionary are the possible values of random variable X and the values of the dictionary are the corresponding probability p(x). (2) A function. The function f accepts a scalar as input and returns a scalar. The return value of the function expect is a scalar, representing the expected value of f(X).

def main(): xDistributionExample1={1: 1/5, 2: 2/5, 3: 2/5} functionExample1=lambda x: x ** 2 print(expect(xDistributionExample1, functionExample1)) xDistributionExample2={1: 1/6, -1/2: 1/3, 1/3: 1/4, -1/4: 1/12, 1/5: 1/6} functionExample2=lambda x: 1/x print(expect(xDistributionExample2, functionExample2)) if __name__ == '__main__': main()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

In python! The formula is E(f(X)) = Xn i=1 p(x)f(x) ,

Answered: 1 week ago

Question

3. How has e-commerce transformed marketing?

Answered: 1 week ago