35 #ifndef SHARK_MODELS_KERNELS_LINEAR_KERNEL_H 36 #define SHARK_MODELS_KERNELS_LINEAR_KERNEL_H 45 template<
class InputType=RealVector>
63 {
return "LinearKernel"; }
73 return boost::shared_ptr<State>(
new EmptyState());
76 double eval(ConstInputReference x1, ConstInputReference x2)
const{
78 return inner_prod(x1, x2);
81 void eval(ConstBatchInputReference x1, ConstBatchInputReference x2, RealMatrix& result,
State& state)
const{
85 void eval(ConstBatchInputReference x1, ConstBatchInputReference x2, RealMatrix& result)
const{
87 result.resize(x1.size1(),x2.size1());
88 noalias(result) = prod(x1,trans(x2));
92 ConstBatchInputReference batchX1,
93 ConstBatchInputReference batchX2,
94 RealMatrix
const& coefficients,
98 SIZE_CHECK(batchX1.size2() == batchX2.size2());
102 ConstBatchInputReference batchX1,
103 ConstBatchInputReference batchX2,
104 RealMatrix
const& coefficientsX2,
106 BatchInputType& gradient
108 SIZE_CHECK(batchX1.size2() == batchX2.size2());
111 gradient.resize(batchX1.size1(),batchX1.size2());
113 noalias(gradient) = prod(coefficientsX2,batchX2);
117 return distanceSqr(x1,x2);
120 virtual RealMatrix
featureDistanceSqr(ConstBatchInputReference x1, ConstBatchInputReference x2)
const{
121 return distanceSqr(x1,x2);