Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed
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

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

The Equation Of Knowledge From Bayes Rule To A Unified Philosophy Of Science

Authors: Lê Nguyên Hoang

1st Edition

1000063275, 9781000063271

More Books

Students also viewed these Mathematics questions