Question: The question asks for R function which gets vector as input and its output would be multiple and addition of that vector Submission returns matrices
The question asks for R function which gets vector as input and its output would be multiple and addition of that vector

Submission returns matrices of the exact dimension specified. . Data: All questions will use the following datastructures: rTrain ( Inx/ is a matrix of training data, where each row is a training point, and each column is a feature. - rest E Rmix) is a matrix of test data, where each row is a test point, and each column is a feature. y Train ( {1, ...,c}"x] is a vector of training labels - yTest E (1, ..., c)mxl is a (hidden) vector of test labels. 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(z), log p(y), loglp(r) * p(y)], where log[p(r) * p(y)] is computed as log p(r) + logp(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. 1. Logspace Multiplication [5 pts] Complete logProd=function(x) which takes as input a vector of numbers in logspace (i.e., I; = logpi), and returns the product of these numbers in logspace - i.e., logProd(x) = log II, pi- 2. Logspace Addition [5 pts] Complete logSum=function(x) which takes as input a vector of numbers in logspace (i.e., I; = log pi), and returns the sum of these numbers in logspace - i.e., logSum(x) = log ); pi
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
