Question: Write the function in R 4.1 Logspace Arithmetic [10 pts] When working with very small and very large numbers (such as probabilities), it is useful

Write the function in R

Write the function in R 4.1 Logspace Arithmetic [10 pts] When working

4.1 Logspace Arithmetic [10 pts] When working with very small and very large numbers (such as probabilities), it is useful to work in logspace to avoid numerical precision issues. In logspace, we keep track of the logs of numbers, instead of the numbers themselves. (We generally use natural logs for this). For example, if p(x) and p(y) are proba- bility values, instead of storing p(x) and p(y) and computing p(x) * p(y), we work in log space by storing log p(x), log p(y), log[p(x) * p(y)], where log[p(x) * p(y)] is computed as log p(c) + log p(y). The challenge is to add and multiply these numbers while remaining in logspace, without exponentialing. Note that if we exponentiale our numbers at any point in the calculation it completely defeats the purpose of working in log space. Hint: Alex Smola has an excellent post on his blog about this topic. 1. Logspace Multiplication [5 pts] Complete the function logProd(x) which takes as input a vector of numbers in logspace (i.e., I; = log p;), and returns the product of these numbers in logspace - i.e., logProd(x) = log II, pi- 2. Logspace Addition [5 pts] Complete the function logSum(x) which takes as input a vector of numbers in logspace (i.e., I; = log p;), and returns the sum of these numbers in logspace - i.e., logSum(x) = log _, pi- 5

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Mathematics Questions!