Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please help code the following in python. Thank you. First, write a function that will compute the likelihood for a single x and y observation,
Please help code the following in python. Thank you.
First, write a function that will compute the likelihood for a single x and y observation, as a function of some estimate of ] def likelihood(theta_hat, x,y) : " "The likelihood function for a linear model with noise sampled from a Gausian distribution with zero mean and unit variance. Args: theta_hat (float): An estimate of the slope parameter. x (ndarray): A scalar that contains the input ralue. y (ndarray): A scalar that contains the corresponding measurement values to the input. Returns: ndarray: the likelihood values for the theta hat estimate " " sigma = 1 \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# \#\# Compute Gaussian likelihood below for single sample \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\# Let us first consider a single obersvation of x and y. Say, for simplicity, x=2.1 and y=3.7. Verify that, for this single observation, L(=1.0x=2.1,y=3.7)0.11 using your function above. [ ] \#\#\#\# Write your code When dealing with a set or vector of data points, as we are with our full dataset, we are concerned with their joint probability -- the likelihood that all data points are explained by our parameterization. Since we have assumed that the noise affects each output independently, we can factorize the likelihood, and write: L(x,y)=i=1NL(xi,yi), where we have N data points x=[x1,,xN] and y=[y1,,yN]. - In practice, such a product can be numerically unstable. Indeed, multiplying small values together can lead to arithmetic underflow. This problem can be circumvented by taking the logarithm of the likelihood because the logarithm transforms products into sums: logL(x,y)=i=1NlogL(xi,yi)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started