Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In python! The formula is V ar(X) = E(((X E(X))2 ) You are supposed to complete the function getVariance in the expect.py file. You should

In python!

The formula is V ar(X) = E(((X E(X))2 ) You are supposed to complete the function getVariance in the expect.py file. You should follow the steps commented in the code and use the expect function. The getVariance function accepts a dictionary as input. The dictionary represents 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). The return value of the function getVariance is a scalar, representing the variance of X.

expect.py file:
def expect(xDistribution, function): ################################################## # Your code here ################################################## return expect ################################################## # Your code below each comment ################################################## def getVariance(xDistribution): #Step 1 - Calculate the expected value E(X) def getSquaredDistanceToMu(x): #Step 2 - Calculate (X-E(X))^2 return #Step 3 - Calculate Variance: Var(X)=E((X-E(X))^2) return 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

Step: 3

blur-text-image

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

Database Programming Languages 12th International Symposium Dbpl 2009 Lyon France August 2009 Proceedings Lncs 5708

Authors: Philippa Gardner ,Floris Geerts

2009th Edition

3642037925, 978-3642037924

More Books

Students also viewed these Databases questions

Question

Ensure continued excellence in people management.

Answered: 1 week ago

Question

Enhance the international team by recruiting the best people.

Answered: 1 week ago