EssayGhost Assignment代写,Essay代写,网课代修,Quiz代考




您的位置: 主页 > 编程案例 > R语言代写 >
R语言代写 - ISTA 311 Programming assignment 2: Bayesian inference and the German| 代写R语言,代做R语言
发布时间:2021-08-03 23:36:47浏览次数:
Do not implementlikelihood, but for the purposes of writing yourupdatemethod, assume that it takes two parameters: a hypothesis and a piece of data, in that order. The hypothesis comes from the distribution, but the data may not.1.1.2 Simple Bayesian inference: the cookie problemDefine a subclass of theDistributionclass to solve the following version of the cookie problem.We have two bowls of cookies, which have a mixture of chocolate and vanilla cookies. We know the proportion of vanilla cookies in each bowl, but we dont know which bowl we are drawing from. We wish to estimate which bowl we are drawing fromYour subclass must:be calledCookiereplace the init method with a method that takes two parameterschoco1, choco2which represent the proportions of chocolate cookies in each bowl. Initialize the dictionary to {1: 0.5, 2: 0.5} representing a uniform prior distribution on the two bowls. Store the proportions as instance variables in your class so that yourlikelihoodmethod can use them.define alikelihoodmethod which takes two parameters: a hypothesis (i.e. one of the outcomes from the dictionary, representing Bowl 1 or Bowl 2, and a piece of evidence which is eitherv(vanilla) or c(chocolate).1.1.3 More inference: the German tank problemNow well solve a version of the German tank problem.You are given a text file that contains a collection of serial numbers: 2-5 numbers from each 100-number monthly block. Each number is on a line by itself to make it easy to read the numbers in from the file, but note that you will have to separate the numbers by their blocks yourself. Your task is to estimate the number of tanks that was produced each month.Implement aestimatetanksfunction, which takes the filename as a parameter and returns a list containing the estimated number of tanks produced each month.In order to do this, you should define a subclass of the Distribution class that has an appropriatelikelihood function for modeling this problem. Then, for each 100-number block, create an instance of your class, use the numbers from the file to update probabilities, and then use the result to produce asingle numberestimating the number of tanks produced in that month.The details of how you implement this estimation are up to you, because the test script only calls your estimatetanksfunction. As long asestimatetankstakes the filename as a parameter and returns a list of 24 numbers (intorfloat it doesnt matter) then the test script will be able to work with it. The correctness will be judged based on the accuracy of the estimates.The test script knows the true numbers of tanks that were used to generate the serial numbers in the text file. The script will display the RMS (root mean square) error in your collection of monthly estimates. Lower is better!This function is graded 50% on general correct functionality and 50% on the accuracy of your prediction. RMS error10 will receive 1 accuracy points; RMS error20 will receive 0 accuracy points; scoresinterpolate linearly between these endpoints, rounded up to a whole number. For reference, the simplest model for inference I implemented acheived RMS error of about 18.9, while a simple change improved it to about 13.7.In order to improve your accuracy, you can try experimenting with different priors or different ways to extract an estimate from the posterior distribution. However, priors must be generic, which is to say they should not be hand-tuned to the values in the test script.