\section{P\+Spectrum\+String\+Kernel Class Reference}
\label{classmlpack_1_1kernel_1_1PSpectrumStringKernel}\index{P\+Spectrum\+String\+Kernel@{P\+Spectrum\+String\+Kernel}}


The p-\/spectrum string kernel.  


\subsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
\textbf{ P\+Spectrum\+String\+Kernel} (const std\+::vector$<$ std\+::vector$<$ std\+::string $>$ $>$ \&datasets, const size\+\_\+t p)
\begin{DoxyCompactList}\small\item\em Initialize the \doxyref{P\+Spectrum\+String\+Kernel}{p.}{classmlpack_1_1kernel_1_1PSpectrumStringKernel} with the given string datasets. \end{DoxyCompactList}\item 
const std\+::vector$<$ std\+::vector$<$ std\+::map$<$ std\+::string, int $>$ $>$ $>$ \& \textbf{ Counts} () const
\begin{DoxyCompactList}\small\item\em Access the lists of substrings. \end{DoxyCompactList}\item 
std\+::vector$<$ std\+::vector$<$ std\+::map$<$ std\+::string, int $>$ $>$ $>$ \& \textbf{ Counts} ()
\begin{DoxyCompactList}\small\item\em Modify the lists of substrings. \end{DoxyCompactList}\item 
{\footnotesize template$<$typename Vec\+Type $>$ }\\double \textbf{ Evaluate} (const Vec\+Type \&a, const Vec\+Type \&b) const
\begin{DoxyCompactList}\small\item\em Evaluate the kernel for the string indices given. \end{DoxyCompactList}\item 
size\+\_\+t \textbf{ P} () const
\begin{DoxyCompactList}\small\item\em Access the value of p. \end{DoxyCompactList}\item 
size\+\_\+t \& \textbf{ P} ()
\begin{DoxyCompactList}\small\item\em Modify the value of p. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
The p-\/spectrum string kernel. 

Given a length p, the p-\/spectrum kernel finds the contiguous subsequence match count between two strings. The kernel will take every possible substring of length p of one string and count how many times it appears in the other string.

The string kernel, when created, must be passed a reference to a series of string datasets (std\+::vector$<$std\+::vector$<$std\+::string$>$ $>$\&). This is because mlpack only supports datasets which are Armadillo matrices -- and a dataset of variable-\/length strings cannot be easily cast into an Armadillo matrix.

Therefore, once the \doxyref{P\+Spectrum\+String\+Kernel}{p.}{classmlpack_1_1kernel_1_1PSpectrumStringKernel} is created with a reference to the string datasets, a \char`\"{}fake\char`\"{} Armadillo data matrix must be created, which simply holds indices to the strings they represent. This \char`\"{}fake\char`\"{} matrix has two rows and n columns (where n is the number of strings in the dataset). The first row holds the index of the dataset (remember, the kernel can have multiple datasets), and the second row holds the index of the string. A fake matrix containing only strings from dataset 0 might look like this\+:

[[0 0 0 0 0 0 0 0 0] [0 1 2 3 4 5 6 7 8]]

This fake matrix is then given to the machine learning method, which will eventually call P\+Spectrum\+String\+Kernel\+::\+Evaluate(a, b), where a and b are two columns of the fake matrix. The string kernel will then map these fake columns back to the strings they represent, and then correctly evaluate the kernel.

Unfortunately, not every machine learning method will work with this kernel. Only machine learning methods which do not ever operate on the explicit representation of points can use this kernel. So, for instance, one cannot build a kd-\/tree on strings, because the Binary\+Space\+Tree$<$$>$ class will split the data according to the fake data matrix -- resulting in a meaningless tree. This kernel was originally written for the Fast\+M\+KS method; so, at the very least, it will work with that. 

Definition at line 65 of file pspectrum\+\_\+string\+\_\+kernel.\+hpp.



\subsection{Constructor \& Destructor Documentation}
\mbox{\label{classmlpack_1_1kernel_1_1PSpectrumStringKernel_a47cbfdf26b3615d6db222d23d4e644d4}} 
\index{mlpack\+::kernel\+::\+P\+Spectrum\+String\+Kernel@{mlpack\+::kernel\+::\+P\+Spectrum\+String\+Kernel}!P\+Spectrum\+String\+Kernel@{P\+Spectrum\+String\+Kernel}}
\index{P\+Spectrum\+String\+Kernel@{P\+Spectrum\+String\+Kernel}!mlpack\+::kernel\+::\+P\+Spectrum\+String\+Kernel@{mlpack\+::kernel\+::\+P\+Spectrum\+String\+Kernel}}
\subsubsection{P\+Spectrum\+String\+Kernel()}
{\footnotesize\ttfamily \textbf{ P\+Spectrum\+String\+Kernel} (\begin{DoxyParamCaption}\item[{const std\+::vector$<$ std\+::vector$<$ std\+::string $>$ $>$ \&}]{datasets,  }\item[{const size\+\_\+t}]{p }\end{DoxyParamCaption})}



Initialize the \doxyref{P\+Spectrum\+String\+Kernel}{p.}{classmlpack_1_1kernel_1_1PSpectrumStringKernel} with the given string datasets. 

For more information on this, see the general class documentation.


\begin{DoxyParams}{Parameters}
{\em datasets} & Sets of string data. \\
\hline
{\em p} & The length of substrings to search. \\
\hline
\end{DoxyParams}


\subsection{Member Function Documentation}
\mbox{\label{classmlpack_1_1kernel_1_1PSpectrumStringKernel_ac234cd7efb1abfdc125c85a7ac055327}} 
\index{mlpack\+::kernel\+::\+P\+Spectrum\+String\+Kernel@{mlpack\+::kernel\+::\+P\+Spectrum\+String\+Kernel}!Counts@{Counts}}
\index{Counts@{Counts}!mlpack\+::kernel\+::\+P\+Spectrum\+String\+Kernel@{mlpack\+::kernel\+::\+P\+Spectrum\+String\+Kernel}}
\subsubsection{Counts()\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily const std\+::vector$<$std\+::vector$<$std\+::map$<$std\+::string, int$>$ $>$ $>$\& Counts (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}



Access the lists of substrings. 



Definition at line 93 of file pspectrum\+\_\+string\+\_\+kernel.\+hpp.

\mbox{\label{classmlpack_1_1kernel_1_1PSpectrumStringKernel_a6af5550e3efc25fc95bda59c318cc313}} 
\index{mlpack\+::kernel\+::\+P\+Spectrum\+String\+Kernel@{mlpack\+::kernel\+::\+P\+Spectrum\+String\+Kernel}!Counts@{Counts}}
\index{Counts@{Counts}!mlpack\+::kernel\+::\+P\+Spectrum\+String\+Kernel@{mlpack\+::kernel\+::\+P\+Spectrum\+String\+Kernel}}
\subsubsection{Counts()\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily std\+::vector$<$std\+::vector$<$std\+::map$<$std\+::string, int$>$ $>$ $>$\& Counts (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}



Modify the lists of substrings. 



Definition at line 96 of file pspectrum\+\_\+string\+\_\+kernel.\+hpp.

\mbox{\label{classmlpack_1_1kernel_1_1PSpectrumStringKernel_a18c0420cf974d5223049f21f796abc5f}} 
\index{mlpack\+::kernel\+::\+P\+Spectrum\+String\+Kernel@{mlpack\+::kernel\+::\+P\+Spectrum\+String\+Kernel}!Evaluate@{Evaluate}}
\index{Evaluate@{Evaluate}!mlpack\+::kernel\+::\+P\+Spectrum\+String\+Kernel@{mlpack\+::kernel\+::\+P\+Spectrum\+String\+Kernel}}
\subsubsection{Evaluate()}
{\footnotesize\ttfamily double Evaluate (\begin{DoxyParamCaption}\item[{const Vec\+Type \&}]{a,  }\item[{const Vec\+Type \&}]{b }\end{DoxyParamCaption}) const}



Evaluate the kernel for the string indices given. 

As mentioned in the class documentation, a and b should be 2-\/element vectors, where the first element contains the index of the dataset and the second element contains the index of the string. Therefore, if [2 3] is passed for a, the string used will be datasets[2][3] (datasets is of type std\+::vector$<$std\+::vector$<$std\+::string$>$ $>$\&).


\begin{DoxyParams}{Parameters}
{\em a} & Index of string and dataset for first string. \\
\hline
{\em b} & Index of string and dataset for second string. \\
\hline
\end{DoxyParams}
\mbox{\label{classmlpack_1_1kernel_1_1PSpectrumStringKernel_ad0b1284cb7df64984925548091781d48}} 
\index{mlpack\+::kernel\+::\+P\+Spectrum\+String\+Kernel@{mlpack\+::kernel\+::\+P\+Spectrum\+String\+Kernel}!P@{P}}
\index{P@{P}!mlpack\+::kernel\+::\+P\+Spectrum\+String\+Kernel@{mlpack\+::kernel\+::\+P\+Spectrum\+String\+Kernel}}
\subsubsection{P()\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily size\+\_\+t P (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}



Access the value of p. 



Definition at line 100 of file pspectrum\+\_\+string\+\_\+kernel.\+hpp.

\mbox{\label{classmlpack_1_1kernel_1_1PSpectrumStringKernel_a97c58660ce444396887bca51b1c831a9}} 
\index{mlpack\+::kernel\+::\+P\+Spectrum\+String\+Kernel@{mlpack\+::kernel\+::\+P\+Spectrum\+String\+Kernel}!P@{P}}
\index{P@{P}!mlpack\+::kernel\+::\+P\+Spectrum\+String\+Kernel@{mlpack\+::kernel\+::\+P\+Spectrum\+String\+Kernel}}
\subsubsection{P()\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily size\+\_\+t\& P (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}



Modify the value of p. 



Definition at line 102 of file pspectrum\+\_\+string\+\_\+kernel.\+hpp.



The documentation for this class was generated from the following file\+:\begin{DoxyCompactItemize}
\item 
/var/www/mlpack.\+ratml.\+org/mlpack.\+org/\+\_\+src/mlpack-\/3.\+3.\+0/src/mlpack/core/kernels/\textbf{ pspectrum\+\_\+string\+\_\+kernel.\+hpp}\end{DoxyCompactItemize}
