35 #ifndef SHARK_MODELS_KERNELS_POINT_SET_KERNEL_H 36 #define SHARK_MODELS_KERNELS_POINT_SET_KERNEL_H 49 template<
class InputType=RealVector>
55 struct InternalState:
public State{
56 std::vector<boost::shared_ptr<State> > state;
59 state.resize(sizeX1 * sizeX2);
61 for(std::size_t i = 0; i != state.size();++i){
78 {
return "PointSetKernel<" +
m_base->
name() +
">"; }
94 InternalState* state =
new InternalState();
95 return boost::shared_ptr<State>(state);
102 double eval(ConstInputReference x1, ConstInputReference x2)
const{
103 RealMatrix response = (*m_base)(x1,x2);
105 return sum(response)/(response.size1() * response.size2());
109 void eval(ConstBatchInputReference
const& batchX1, ConstBatchInputReference
const& batchX2, RealMatrix& result,
State& state)
const{
110 InternalState& s = state.
toState<InternalState>();
114 s.resize(sizeX1,sizeX2,
m_base);
115 result.resize(sizeX1,sizeX2);
117 for(std::size_t i = 0; i != sizeX1; ++i){
118 for(std::size_t j = 0; j != sizeX2; ++j){
120 result(i,j) = sum(response)/(response.size1() * response.size2());
125 void eval(ConstBatchInputReference
const& batchX1, ConstBatchInputReference
const& batchX2, RealMatrix& result)
const{
128 result.resize(sizeX1,sizeX2);
131 for(std::size_t i = 0; i != sizeX1; ++i){
132 for(std::size_t j = 0; j != sizeX2; ++j){
134 result(i,j) = sum(response)/(response.size1() * response.size2());
140 ConstBatchInputReference
const& batchX1,
141 ConstBatchInputReference
const& batchX2,
142 RealMatrix
const& coefficients,
147 InternalState
const& s = state.
toState<InternalState>();
151 for(std::size_t i = 0; i != sizeX1; ++i){
152 for(std::size_t j = 0; j != sizeX2; ++j){
157 RealMatrix setCoeff(size1,size2, coefficients(i,j)/(size1 * size2));
160 noalias(gradient) += grad;