Question: Part One: Compute K [Graded] In computek, you are going to calcuate the values of different kernel functions given inputs X and Z. You

Part One: Compute K [Graded] In computek, you are going to calcuate

the values of different kernel functions given inputs X and Z. You

will return K = K(X,Z). Kij = k(xi, Zj) where k(xi, z;)

= (x)(z;). This function takes in the parameter kerneltype to decide which

of the three different kernel functions to evaluate. To review, recall the  
 
 
 

Part One: Compute K [Graded] In computek, you are going to calcuate the values of different kernel functions given inputs X and Z. You will return K = K(X,Z). Kij = k(xi, Zj) where k(xi, z;) = (x)(z;). This function takes in the parameter kerneltype to decide which of the three different kernel functions to evaluate. To review, recall the following types of kernels: Linear: K(X, Z) = XTZ Polynomial: K(X, Z) = (XTZ + 1)d where kpar = d RBF: K(X, Z) = exp(-1x-||| -} where kpar = 1 Note: When calculating the RBF kernel, you can use the 12distance (X, Z) functions to calculate the pairwise 12 distance efficiently. def computek (kerneltype, X, Z, kpar=1): function K computek (kernel_type, X, Z) computes a matrix K such that Kij=k(x, z); for three different function linear, rbf or polynomial. Input: kerneltype: either 'linear', 'polynomial', 'rbf' X: n input vectors of dimension d (nxd); Z: m input vectors of dimension d (mxd); kpar: kernel parameter (inverse kernel width gamma in case of RBF, degree in case of polynomial) OUTPUT: K nxm kernel matrix assert kerneltype in ["linear","polynomial", "rbf"], "Kernel type %s not known." % kerneltype assert X.shape[1] K = None # YOUR CODE HERE == Z.shape[1], "Input dimensions do not match" raise NotImplementedError() return K

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 Economics Questions!