mlpack  1.0.12
pspectrum_string_kernel.hpp
Go to the documentation of this file.
1 
18 #ifndef __MLPACK_CORE_KERNELS_PSPECTRUM_STRING_KERNEL_HPP
19 #define __MLPACK_CORE_KERNELS_PSPECTRUM_STRING_KERNEL_HPP
20 
21 #include <map>
22 #include <string>
23 #include <vector>
24 
25 #include <mlpack/core.hpp>
26 
27 namespace mlpack {
28 namespace kernel {
29 
67 {
68  public:
76  PSpectrumStringKernel(const std::vector<std::vector<std::string> >& datasets,
77  const size_t p);
78 
90  template<typename VecType>
91  double Evaluate(const VecType& a, const VecType& b) const;
92 
94  const std::vector<std::vector<std::map<std::string, int> > >& Counts() const
95  { return counts; }
97  std::vector<std::vector<std::map<std::string, int> > >& Counts()
98  { return counts; }
99 
101  size_t P() const { return p; }
103  size_t& P() { return p; }
104 
105  /*
106  * Returns a string representation of this object.
107  */
108  std::string ToString() const{
109  std::ostringstream convert;
110  convert << "PSpectrumStringKernel [" << this << "]" << std::endl;
111  convert << " p used: " << p << std::endl;
112  convert << " Dataset:" << datasets.size() << std::endl;
113  std::ostringstream convertb;
114  for (size_t ind=0; ind < datasets.size(); ind++)
115  convertb << datasets[ind].size();
116  convert << mlpack::util::Indent(convertb.str(),2);
117  return convert.str();
118  }
119  private:
121  const std::vector<std::vector<std::string> >& datasets;
122 
125  std::vector<std::vector<std::map<std::string, int> > > counts;
126 
128  size_t p;
129 };
130 
131 }; // namespace kernel
132 }; // namespace mlpack
133 
134 // Include implementation of templated Evaluate().
135 #include "pspectrum_string_kernel_impl.hpp"
136 
137 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: load.hpp:23
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.