Question: def grad ( beta , b , xTr , yTr , xTe, yTe, C , kerneltype, kpar = 1 ) : INPUT:

def grad(beta, b, xTr, yTr, xTe, yTe, C, kerneltype, kpar=1):
"""
INPUT:
beta : n dimensional vector that stores the linear combination coefficient
xTr : nxd dimensional matrix (training set, each row is an input vector)
yTr : n dimensional vector (training label, each entry is a label)
b : scalar (bias)
xTe : mxd dimensional matrix (test set, each row is an input vector)
yTe : m dimensional vector (test label, each entry is a label)
C : scalar (constant that controls the tradeoff between l2-regularizer and hinge-loss)
kerneltype: either 'linear','polynomial','rbf'
kpar : kernel parameter (inverse kernel width gamma in case of RBF, degree in case of polynomial)
OUTPUTS:
beta_grad : n dimensional vector (the gradient of the hinge loss with respect to the alphas)
bgrad : constant (the gradient of he hinge loss with respect to the bias, b)
"""
n, d = xTr.shape
beta_grad = np.zeros(n)
bgrad = np.zeros(1)
# compute the kernel values between xTr and xTr
kernel_train = computeK(kerneltype, xTr, xTr, kpar)
# compute the kernel values between xTe and xTr
kernel_test = computeK(kerneltype, xTe, xTr, kpar)
# # YOUR CODE HERE

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