41 #ifndef SHARK_MODELS_KERNELEXPANSION_H 42 #define SHARK_MODELS_KERNELEXPANSION_H 66 template<
class InputType>
102 {
return "KernelExpansion"; }
132 return m_b.size() != 0;
158 double const&
offset(std::size_t cls)
const{
180 std::vector<std::size_t> svIndices;
181 for (std::size_t i=0; i != ic; ++i){
182 if (blas::norm_1(row(
m_alpha, i)) > 0.0){
183 svIndices.push_back(i);
190 RealMatrix a(svIndices.size(),
m_alpha.size2());
191 for (std::size_t i=0; i!= svIndices.size(); ++i){
192 noalias(row(a,i)) = row(
m_alpha,svIndices[i]);
213 noalias(to_vector(
m_alpha)) = subrange(newParameters, 0, numParams);
215 noalias(
m_b) = subrange(newParameters, numParams, numParams +
m_b.size());
230 return boost::shared_ptr<State>(
new EmptyState());
234 void eval(BatchInputType
const& patterns, BatchOutputType& output)
const{
235 std::size_t numPatterns =
batchSize(patterns);
238 output.resize(numPatterns,
m_alpha.size2());
240 output = repeat(
m_b,numPatterns);
244 std::size_t batchStart = 0;
251 RealMatrix kernelEvaluations = (*mep_kernel)(
m_basis.
batch(i),patterns);
254 auto batchAlpha = subrange(
m_alpha,batchStart,batchEnd,0,
m_alpha.size2());
255 noalias(output) += prod(trans(kernelEvaluations),batchAlpha);
259 void eval(BatchInputType
const& patterns, BatchOutputType& outputs,
State & state)
const{
260 eval(patterns, outputs);
274 archive >> (*mep_kernel);
284 archive << const_cast<KernelType const&>(*mep_kernel);
311 template<
class InputType>
326 {
return "KernelClassifier"; }