12 #ifndef MLPACK_CORE_DATA_MAP_POLICIES_INCREMENT_POLICY_HPP 13 #define MLPACK_CORE_DATA_MAP_POLICIES_INCREMENT_POLICY_HPP 16 #include <unordered_map> 37 forceAllMappings(forceAllMappings) { }
40 using MappedType = size_t;
48 template<
typename T,
typename InputType>
51 std::vector<Datatype>& types)
53 if (types[dim] == Datatype::categorical)
61 types[dim] = Datatype::categorical;
66 std::stringstream token;
71 if (token.fail() || !token.eof())
72 types[dim] = Datatype::categorical;
89 template<
typename MapType,
typename T,
typename InputType>
91 const size_t dimension,
93 std::vector<Datatype>& types)
96 if (types[dimension] == Datatype::numeric && !forceAllMappings)
101 std::stringstream token;
106 if (!token.fail() && token.eof())
115 if (maps.count(dimension) == 0 ||
116 maps[dimension].first.count(input) == 0)
119 size_t numMappings = maps[dimension].first.size();
122 if (numMappings == 0)
123 types[dimension] = Datatype::categorical;
125 typedef typename std::pair<InputType, MappedType> PairType;
126 maps[dimension].first.insert(PairType(input, numMappings));
129 if (maps[dimension].second.count(numMappings) == 0)
131 maps[dimension].second.insert(std::make_pair(numMappings,
132 std::vector<InputType>()));
134 maps[dimension].second[numMappings].push_back(input);
136 return T(numMappings);
141 return maps[dimension].first.at(input);
147 bool forceAllMappings;
T MapString(const InputType &input, const size_t dimension, MapType &maps, std::vector< Datatype > &types)
Given the input and the dimension to which the it belongs, and the maps and types given by the Datase...
Definition: increment_policy.hpp:90
IncrementPolicy is used as a helper class for DatasetMapper.
Definition: increment_policy.hpp:33
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
static const bool NeedsFirstPass
We do need a first pass over the data to set the dimension types right.
Definition: increment_policy.hpp:43
The core includes that mlpack expects; standard C++ includes and Armadillo.
void MapFirstPass(const InputType &input, const size_t dim, std::vector< Datatype > &types)
Determine if the dimension is numeric or categorical.
Definition: increment_policy.hpp:49