\section{Bag\+Of\+Words\+Encoding\+Policy Class Reference}
\label{classmlpack_1_1data_1_1BagOfWordsEncodingPolicy}\index{Bag\+Of\+Words\+Encoding\+Policy@{Bag\+Of\+Words\+Encoding\+Policy}}


Definition of the \doxyref{Bag\+Of\+Words\+Encoding\+Policy}{p.}{classmlpack_1_1data_1_1BagOfWordsEncodingPolicy} class.  


\subsection*{Public Member Functions}
\begin{DoxyCompactItemize}
\item 
{\footnotesize template$<$typename Archive $>$ }\\void \textbf{ serialize} (Archive \&, const unsigned int)
\begin{DoxyCompactList}\small\item\em Serialize the class to the given archive. \end{DoxyCompactList}\end{DoxyCompactItemize}
\subsection*{Static Public Member Functions}
\begin{DoxyCompactItemize}
\item 
{\footnotesize template$<$typename Mat\+Type $>$ }\\static void \textbf{ Encode} (Mat\+Type \&output, const size\+\_\+t value, const size\+\_\+t line, const size\+\_\+t)
\begin{DoxyCompactList}\small\item\em The function performs the bag of words encoding algorithm i.\+e. \end{DoxyCompactList}\item 
{\footnotesize template$<$typename Elem\+Type $>$ }\\static void \textbf{ Encode} (std\+::vector$<$ std\+::vector$<$ Elem\+Type $>$$>$ \&output, const size\+\_\+t value, const size\+\_\+t line, const size\+\_\+t)
\begin{DoxyCompactList}\small\item\em The function performs the bag of words encoding algorithm i.\+e. \end{DoxyCompactList}\item 
{\footnotesize template$<$typename Mat\+Type $>$ }\\static void \textbf{ Init\+Matrix} (Mat\+Type \&output, const size\+\_\+t dataset\+Size, const size\+\_\+t, const size\+\_\+t dictionary\+Size)
\begin{DoxyCompactList}\small\item\em The function initializes the output matrix. \end{DoxyCompactList}\item 
{\footnotesize template$<$typename Elem\+Type $>$ }\\static void \textbf{ Init\+Matrix} (std\+::vector$<$ std\+::vector$<$ Elem\+Type $>$$>$ \&output, const size\+\_\+t dataset\+Size, const size\+\_\+t, const size\+\_\+t dictionary\+Size)
\begin{DoxyCompactList}\small\item\em The function initializes the output matrix. \end{DoxyCompactList}\item 
static void \textbf{ Preprocess\+Token} (size\+\_\+t, size\+\_\+t, size\+\_\+t)
\begin{DoxyCompactList}\small\item\em The function is not used by the bag of words encoding policy. \end{DoxyCompactList}\item 
static void \textbf{ Reset} ()
\begin{DoxyCompactList}\small\item\em Clear the necessary internal variables. \end{DoxyCompactList}\end{DoxyCompactItemize}


\subsection{Detailed Description}
Definition of the \doxyref{Bag\+Of\+Words\+Encoding\+Policy}{p.}{classmlpack_1_1data_1_1BagOfWordsEncodingPolicy} class. 

Bag\+Of\+Words is used as a helper class for \doxyref{String\+Encoding}{p.}{classmlpack_1_1data_1_1StringEncoding}. The encoder maps each dataset item to a vector of size N, where N is equal to the total unique number of tokens. The i-\/th coordinate of the output vector is equal to the number of times when the i-\/th token occurs in the corresponding dataset item. The order in which the tokens are labeled is defined by the dictionary used by the \doxyref{String\+Encoding}{p.}{classmlpack_1_1data_1_1StringEncoding} class. The encoder writes data either in the column-\/major order or in the row-\/major order depending on the output data type. 

Definition at line 35 of file bag\+\_\+of\+\_\+words\+\_\+encoding\+\_\+policy.\+hpp.



\subsection{Member Function Documentation}
\mbox{\label{classmlpack_1_1data_1_1BagOfWordsEncodingPolicy_a0b7fe826d0b8cdb0e6a358ac5b811d6b}} 
\index{mlpack\+::data\+::\+Bag\+Of\+Words\+Encoding\+Policy@{mlpack\+::data\+::\+Bag\+Of\+Words\+Encoding\+Policy}!Encode@{Encode}}
\index{Encode@{Encode}!mlpack\+::data\+::\+Bag\+Of\+Words\+Encoding\+Policy@{mlpack\+::data\+::\+Bag\+Of\+Words\+Encoding\+Policy}}
\subsubsection{Encode()\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily static void Encode (\begin{DoxyParamCaption}\item[{Mat\+Type \&}]{output,  }\item[{const size\+\_\+t}]{value,  }\item[{const size\+\_\+t}]{line,  }\item[{const size\+\_\+t}]{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [static]}}



The function performs the bag of words encoding algorithm i.\+e. 

it writes the encoded token to the output. The encoder writes data in the column-\/major order.


\begin{DoxyTemplParams}{Template Parameters}
{\em Mat\+Type} & The output matrix type.\\
\hline
\end{DoxyTemplParams}

\begin{DoxyParams}{Parameters}
{\em output} & Output matrix to store the encoded results (sp\+\_\+mat or mat). \\
\hline
{\em value} & The encoded token. \\
\hline
{\em line} & The line number at which the encoding is performed. \\
\hline
{\em index} & The token index in the line. \\
\hline
\end{DoxyParams}


Definition at line 103 of file bag\+\_\+of\+\_\+words\+\_\+encoding\+\_\+policy.\+hpp.

\mbox{\label{classmlpack_1_1data_1_1BagOfWordsEncodingPolicy_a22d9c3ce9453668cfe0e91db4fadfc30}} 
\index{mlpack\+::data\+::\+Bag\+Of\+Words\+Encoding\+Policy@{mlpack\+::data\+::\+Bag\+Of\+Words\+Encoding\+Policy}!Encode@{Encode}}
\index{Encode@{Encode}!mlpack\+::data\+::\+Bag\+Of\+Words\+Encoding\+Policy@{mlpack\+::data\+::\+Bag\+Of\+Words\+Encoding\+Policy}}
\subsubsection{Encode()\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily static void Encode (\begin{DoxyParamCaption}\item[{std\+::vector$<$ std\+::vector$<$ Elem\+Type $>$$>$ \&}]{output,  }\item[{const size\+\_\+t}]{value,  }\item[{const size\+\_\+t}]{line,  }\item[{const size\+\_\+t}]{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [static]}}



The function performs the bag of words encoding algorithm i.\+e. 

it writes the encoded token to the output. The encoder writes data in the row-\/major order.

Overloaded function to accept vector$<$vector$<$\+Elem\+Type$>$$>$ as the output type.


\begin{DoxyTemplParams}{Template Parameters}
{\em Elem\+Type} & Type of the output values.\\
\hline
\end{DoxyTemplParams}

\begin{DoxyParams}{Parameters}
{\em output} & Output matrix to store the encoded results. \\
\hline
{\em value} & The encoded token. \\
\hline
{\em line} & The line number at which the encoding is performed. \\
\hline
{\em index} & The line token number at which the encoding is performed. \\
\hline
\end{DoxyParams}


Definition at line 128 of file bag\+\_\+of\+\_\+words\+\_\+encoding\+\_\+policy.\+hpp.

\mbox{\label{classmlpack_1_1data_1_1BagOfWordsEncodingPolicy_a4e2c846435f9d535401110a83555d2ca}} 
\index{mlpack\+::data\+::\+Bag\+Of\+Words\+Encoding\+Policy@{mlpack\+::data\+::\+Bag\+Of\+Words\+Encoding\+Policy}!Init\+Matrix@{Init\+Matrix}}
\index{Init\+Matrix@{Init\+Matrix}!mlpack\+::data\+::\+Bag\+Of\+Words\+Encoding\+Policy@{mlpack\+::data\+::\+Bag\+Of\+Words\+Encoding\+Policy}}
\subsubsection{Init\+Matrix()\hspace{0.1cm}{\footnotesize\ttfamily [1/2]}}
{\footnotesize\ttfamily static void Init\+Matrix (\begin{DoxyParamCaption}\item[{Mat\+Type \&}]{output,  }\item[{const size\+\_\+t}]{dataset\+Size,  }\item[{const size\+\_\+t}]{,  }\item[{const size\+\_\+t}]{dictionary\+Size }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [static]}}



The function initializes the output matrix. 

The encoder writes data in the column-\/major order.


\begin{DoxyTemplParams}{Template Parameters}
{\em Mat\+Type} & The output matrix type.\\
\hline
\end{DoxyTemplParams}

\begin{DoxyParams}{Parameters}
{\em output} & Output matrix to store the encoded results (sp\+\_\+mat or mat). \\
\hline
{\em dataset\+Size} & The number of strings in the input dataset. \\
\hline
{\em max\+Num\+Tokens} & The maximum number of tokens in the strings of the input dataset (not used). \\
\hline
{\em dictionary\+Size} & The size of the dictionary. \\
\hline
\end{DoxyParams}


Definition at line 59 of file bag\+\_\+of\+\_\+words\+\_\+encoding\+\_\+policy.\+hpp.

\mbox{\label{classmlpack_1_1data_1_1BagOfWordsEncodingPolicy_a44833b2c5967e5805ddfd5e0abbbd981}} 
\index{mlpack\+::data\+::\+Bag\+Of\+Words\+Encoding\+Policy@{mlpack\+::data\+::\+Bag\+Of\+Words\+Encoding\+Policy}!Init\+Matrix@{Init\+Matrix}}
\index{Init\+Matrix@{Init\+Matrix}!mlpack\+::data\+::\+Bag\+Of\+Words\+Encoding\+Policy@{mlpack\+::data\+::\+Bag\+Of\+Words\+Encoding\+Policy}}
\subsubsection{Init\+Matrix()\hspace{0.1cm}{\footnotesize\ttfamily [2/2]}}
{\footnotesize\ttfamily static void Init\+Matrix (\begin{DoxyParamCaption}\item[{std\+::vector$<$ std\+::vector$<$ Elem\+Type $>$$>$ \&}]{output,  }\item[{const size\+\_\+t}]{dataset\+Size,  }\item[{const size\+\_\+t}]{,  }\item[{const size\+\_\+t}]{dictionary\+Size }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [static]}}



The function initializes the output matrix. 

The encoder writes data in the row-\/major order.

Overloaded function to save the result in vector$<$vector$<$\+Elem\+Type$>$$>$.


\begin{DoxyTemplParams}{Template Parameters}
{\em Elem\+Type} & Type of the output values.\\
\hline
\end{DoxyTemplParams}

\begin{DoxyParams}{Parameters}
{\em output} & Output matrix to store the encoded results. \\
\hline
{\em dataset\+Size} & The number of strings in the input dataset. \\
\hline
{\em max\+Num\+Tokens} & The maximum number of tokens in the strings of the input dataset (not used). \\
\hline
{\em dictionary\+Size} & The size of the dictionary. \\
\hline
\end{DoxyParams}


Definition at line 82 of file bag\+\_\+of\+\_\+words\+\_\+encoding\+\_\+policy.\+hpp.

\mbox{\label{classmlpack_1_1data_1_1BagOfWordsEncodingPolicy_ae334c6e435725ce69cc696d5c18380cc}} 
\index{mlpack\+::data\+::\+Bag\+Of\+Words\+Encoding\+Policy@{mlpack\+::data\+::\+Bag\+Of\+Words\+Encoding\+Policy}!Preprocess\+Token@{Preprocess\+Token}}
\index{Preprocess\+Token@{Preprocess\+Token}!mlpack\+::data\+::\+Bag\+Of\+Words\+Encoding\+Policy@{mlpack\+::data\+::\+Bag\+Of\+Words\+Encoding\+Policy}}
\subsubsection{Preprocess\+Token()}
{\footnotesize\ttfamily static void Preprocess\+Token (\begin{DoxyParamCaption}\item[{size\+\_\+t}]{,  }\item[{size\+\_\+t}]{,  }\item[{size\+\_\+t}]{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [static]}}



The function is not used by the bag of words encoding policy. 


\begin{DoxyParams}{Parameters}
{\em line} & The line number at which the encoding is performed. \\
\hline
{\em index} & The token sequence number in the line. \\
\hline
{\em value} & The encoded token. \\
\hline
\end{DoxyParams}


Definition at line 144 of file bag\+\_\+of\+\_\+words\+\_\+encoding\+\_\+policy.\+hpp.

\mbox{\label{classmlpack_1_1data_1_1BagOfWordsEncodingPolicy_a77ad624cc83a2a71aa4d5ad991d811d7}} 
\index{mlpack\+::data\+::\+Bag\+Of\+Words\+Encoding\+Policy@{mlpack\+::data\+::\+Bag\+Of\+Words\+Encoding\+Policy}!Reset@{Reset}}
\index{Reset@{Reset}!mlpack\+::data\+::\+Bag\+Of\+Words\+Encoding\+Policy@{mlpack\+::data\+::\+Bag\+Of\+Words\+Encoding\+Policy}}
\subsubsection{Reset()}
{\footnotesize\ttfamily static void Reset (\begin{DoxyParamCaption}{ }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [static]}}



Clear the necessary internal variables. 



Definition at line 41 of file bag\+\_\+of\+\_\+words\+\_\+encoding\+\_\+policy.\+hpp.

\mbox{\label{classmlpack_1_1data_1_1BagOfWordsEncodingPolicy_aa5b3dd8336182f751ebec27167c22415}} 
\index{mlpack\+::data\+::\+Bag\+Of\+Words\+Encoding\+Policy@{mlpack\+::data\+::\+Bag\+Of\+Words\+Encoding\+Policy}!serialize@{serialize}}
\index{serialize@{serialize}!mlpack\+::data\+::\+Bag\+Of\+Words\+Encoding\+Policy@{mlpack\+::data\+::\+Bag\+Of\+Words\+Encoding\+Policy}}
\subsubsection{serialize()}
{\footnotesize\ttfamily void serialize (\begin{DoxyParamCaption}\item[{Archive \&}]{,  }\item[{const unsigned}]{int }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}



Serialize the class to the given archive. 



Definition at line 153 of file bag\+\_\+of\+\_\+words\+\_\+encoding\+\_\+policy.\+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.\+1/src/mlpack/core/data/string\+\_\+encoding\+\_\+policies/\textbf{ bag\+\_\+of\+\_\+words\+\_\+encoding\+\_\+policy.\+hpp}\end{DoxyCompactItemize}
