MLPACK  1.0.11
pspectrum_string_kernel.hpp
Go to the documentation of this file.
1 
26 #ifndef __MLPACK_CORE_KERNELS_PSPECTRUM_STRING_KERNEL_HPP
27 #define __MLPACK_CORE_KERNELS_PSPECTRUM_STRING_KERNEL_HPP
28 
29 #include <map>
30 #include <string>
31 #include <vector>
32 
33 #include <mlpack/core.hpp>
34 
35 namespace mlpack {
36 namespace kernel {
37 
75 {
76  public:
84  PSpectrumStringKernel(const std::vector<std::vector<std::string> >& datasets,
85  const size_t p);
86 
98  template<typename VecType>
99  double Evaluate(const VecType& a, const VecType& b) const;
100 
102  const std::vector<std::vector<std::map<std::string, int> > >& Counts() const
103  { return counts; }
105  std::vector<std::vector<std::map<std::string, int> > >& Counts()
106  { return counts; }
107 
109  size_t P() const { return p; }
111  size_t& P() { return p; }
112 
113  /*
114  * Returns a string representation of this object.
115  */
116  std::string ToString() const{
117  std::ostringstream convert;
118  convert << "PSpectrumStringKernel [" << this << "]" << std::endl;
119  convert << " p used: " << p << std::endl;
120  convert << " Dataset:" << datasets.size() << std::endl;
121  std::ostringstream convertb;
122  for (size_t ind=0; ind < datasets.size(); ind++)
123  convertb << datasets[ind].size();
124  convert << mlpack::util::Indent(convertb.str(),2);
125  return convert.str();
126  }
127  private:
129  const std::vector<std::vector<std::string> >& datasets;
130 
133  std::vector<std::vector<std::map<std::string, int> > > counts;
134 
136  size_t p;
137 };
138 
139 }; // namespace kernel
140 }; // namespace mlpack
141 
142 // Include implementation of templated Evaluate().
143 #include "pspectrum_string_kernel_impl.hpp"
144 
145 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: load.hpp:31
const std::vector< std::vector< std::string > > & datasets
The datasets.
const std::vector< std::vector< std::map< std::string, int > > > & Counts() const
Access the lists of substrings.
double Evaluate(const VecType &a, const VecType &b) const
Evaluate the kernel for the string indices given.
PSpectrumStringKernel(const std::vector< std::vector< std::string > > &datasets, const size_t p)
Initialize the PSpectrumStringKernel with the given string datasets.
size_t p
The value of p to use in calculation.
std::string Indent(std::string input, const size_t howManyTabs=1)
A utility function that replaces all all newlines with a number of spaces depending on the indentatio...
std::vector< std::vector< std::map< std::string, int > > > counts
Mappings of the datasets to counts of substrings.
std::vector< std::vector< std::map< std::string, int > > > & Counts()
Modify the lists of substrings.
size_t P() const
Access the value of p.