mlpack 3.4.2
dictionary_encoding_policy.hpp
Go to the documentation of this file.
1
13#ifndef MLPACK_CORE_DATA_STRING_ENCODING_POLICIES_DICTIONARY_ENCODING_POLICY_HPP
14#define MLPACK_CORE_DATA_STRING_ENCODING_POLICIES_DICTIONARY_ENCODING_POLICY_HPP
15
16#include <mlpack/prereqs.hpp>
19
20namespace mlpack {
21namespace data {
22
33{
34 public:
38 static void Reset()
39 {
40 // Nothing to do.
41 }
42
55 template<typename MatType>
56 static void InitMatrix(MatType& output,
57 const size_t datasetSize,
58 const size_t maxNumTokens,
59 const size_t /* dictionarySize */)
60 {
61 output.zeros(maxNumTokens, datasetSize);
62 }
63
76 template<typename MatType>
77 static void Encode(MatType& output,
78 const size_t value,
79 const size_t line,
80 const size_t index)
81 {
82 output(index, line) = value;
83 }
84
96 template<typename ElemType>
97 static void Encode(std::vector<ElemType>& output, size_t value)
98 {
99 output.push_back(value);
100 }
101
109 static void PreprocessToken(const size_t /* line */,
110 const size_t /* index */,
111 const size_t /* value */)
112 { }
113
117 template<typename Archive>
118 void serialize(Archive& /* ar */, const unsigned int /* version */)
119 {
120 // Nothing to serialize.
121 }
122};
123
128template<>
130{
135 static const bool onePassEncoding = true;
136};
137
144template<typename TokenType>
147} // namespace data
148} // namespace mlpack
149
150#endif
DicitonaryEnocdingPolicy is used as a helper class for StringEncoding.
static void Reset()
Clear the necessary internal variables.
void serialize(Archive &, const unsigned int)
Serialize the class to the given archive.
static void PreprocessToken(const size_t, const size_t, const size_t)
The function is not used by the dictionary encoding policy.
static void InitMatrix(MatType &output, const size_t datasetSize, const size_t maxNumTokens, const size_t)
The function initializes the output matrix.
static void Encode(MatType &output, const size_t value, const size_t line, const size_t index)
The function performs the dictionary encoding algorithm i.e.
static void Encode(std::vector< ElemType > &output, size_t value)
The function performs the dictionary encoding algorithm i.e.
This class provides a dictionary interface for the purpose of string encoding.
The class translates a set of strings into numbers using various encoding algorithms.
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
The core includes that mlpack expects; standard C++ includes and Armadillo.
This is a template struct that provides some information about various encoding policies.
static const bool onePassEncoding
Indicates if the policy is able to encode the token at once without any information about other token...