35 #ifndef SHARK_MODELS_KERNELS_ABSTRACTKERNELFUNCTION_H 36 #define SHARK_MODELS_KERNELS_ABSTRACTKERNELFUNCTION_H 44 #ifdef SHARK_COUNT_KERNEL_LOOKUPS 45 #define INCREMENT_KERNEL_COUNTER( counter ) { counter++; } 47 #define INCREMENT_KERNEL_COUNTER( counter ) { } 64 template<
class InputTypeT>
115 return boost::shared_ptr<State>(
new EmptyState());
122 virtual double eval(ConstInputReference x1, ConstInputReference x2)
const{
133 inline double operator () (ConstInputReference x1, ConstInputReference x2)
const {
143 virtual void eval(ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix& result,
State& state)
const = 0;
148 virtual void eval(ConstBatchInputReference batchX1, ConstBatchInputReference batchX2, RealMatrix& result)
const {
150 eval(batchX1, batchX2, result, *state);
157 inline RealMatrix
operator () (ConstBatchInputReference batchX1, ConstBatchInputReference batchX2)
const{
159 eval(batchX1, batchX2, result);
167 ConstBatchInputReference batchX1,
168 ConstBatchInputReference batchX2,
169 RealMatrix
const& coefficients,
183 ConstBatchInputReference batchX1,
184 ConstBatchInputReference batchX2,
185 RealMatrix
const& coefficientsX2,
187 BatchInputType& gradient
198 double k12 =
eval(x1, x2);
199 return (2.0 - 2.0 * k12);
201 double k11 =
eval(x1, x1);
202 double k12 =
eval(x1, x2);
203 double k22 =
eval(x2, x2);
204 return (k11 - 2.0 * k12 + k22);
208 virtual RealMatrix
featureDistanceSqr(ConstBatchInputReference batchX1,ConstBatchInputReference batchX2)
const{
211 RealMatrix result=(*this)(batchX1,batchX2);
214 noalias(result) += 2.0;
217 RealVector kx2(sizeX2);
218 for(std::size_t i = 0; i != sizeX2;++i){
221 for(std::size_t j = 0; j != sizeX1;++j){
223 noalias(row(result,j)) += kx1 + kx2;