12 #ifndef MLPACK_CORE_DATA_MAP_POLICIES_MISSING_POLICY_HPP
13 #define MLPACK_CORE_DATA_MAP_POLICIES_MISSING_POLICY_HPP
16 #include <unordered_map>
17 #include <boost/bimap.hpp>
50 missingSet(std::move(missingSet))
82 template<
typename MapType,
typename T>
84 const size_t dimension,
86 std::vector<Datatype>& )
88 static_assert(std::numeric_limits<T>::has_quiet_NaN ==
true,
89 "Cannot use MissingPolicy with types where has_quiet_NaN() is false!");
92 std::stringstream token;
99 if (token.fail() || !token.eof() ||
100 missingSet.find(
string) != std::end(missingSet))
104 if (maps.count(dimension) == 0 ||
105 maps[dimension].first.left.count(
string) == 0)
108 typedef boost::bimap<std::string, MappedType>::value_type PairType;
109 maps[dimension].first.insert(PairType(
string,
110 std::numeric_limits<MappedType>::quiet_NaN()));
111 maps[dimension].second++;
114 return std::numeric_limits<T>::quiet_NaN();
139 template <
typename eT,
typename MapType>
142 arma::Mat<eT>& matrix,
144 std::vector<Datatype>& types)
147 static_assert(std::is_same<eT, double>::value,
"You must use double type "
148 " matrix in order to apply MissingPolicy");
150 std::stringstream token;
151 for (
size_t i = 0; i != tokens.size(); ++i)
153 token.str(tokens[i]);
154 token>>matrix.at(row, i);
157 if (token.fail() || missingSet.find(tokens[i]) != std::end(missingSet))
159 const eT val =
static_cast<eT
>(this->
MapString(tokens[i], row, maps,
161 matrix.at(row, i) = val;
171 std::set<std::string> missingSet;
void MapTokens(const std::vector< std::string > &tokens, size_t &row, arma::Mat< eT > &matrix, MapType &maps, std::vector< Datatype > &types)
MapTokens turns vector of strings into numeric variables and puts them into a given matrix...
The core includes that mlpack expects; standard C++ includes and Armadillo.
T MapString(const std::string &string, const size_t dimension, MapType &maps, std::vector< Datatype > &)
Given the string and the dimension to which it belongs by the user, and the maps and types given by t...
void MapFirstPass(const std::string &, const size_t)
There is nothing for us to do here, but this is required by the MapPolicy type.
static const bool NeedsFirstPass
This doesn't need a first pass over the data to set up.
MissingPolicy(std::set< std::string > missingSet)
Create the MissingPolicy object with the given missingSet.
MissingPolicy is used as a helper class for DatasetMapper.