Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- template<typename Policy, typename Mapper, typename T>
- void Imputer(const arma::Mat<T> &input,
- arma::Mat<T> &output,
- Policy &&policy, //&& could accept const and non-const type
- const std::string &missValue,
- const Mapper &mapper,
- const size_t dimension,
- const bool tranpose = true)
- {
- size_t mappedValue = mapper.UnmapValue(missValue, dimension);
- if(transpose)
- {
- for (size_t i = 0; i < input.n_rows; ++i)
- {
- if (input(dimension, i) == mappedValue)
- {
- policy.Impute(input, output, dimension, i);
- // just for demo,
- // later imputation strategy can be implemented
- // so that user can replace it with mean, mode, etc.
- }
- }
- }
- else
- {
- //.....
- }
- }
- //I think the mapper could add one more template parameters to determine it should map missed value to specific value or not
- //Please give it a better name, most of the implementation details and api should same as the old DataSetInfo for backward
- //compatibility sake
- template<typename MapPolicy>
- class DatasetInfoRich
- {
- //......
- private:
- std::unordered_map<size_t, std::pair<boost::bimap<std::string, typename MapPolicy::map_type>,
- size_t>> maps;
- using PairType = boost::bimap<std::string, typename MapPolicy::map_type_t>::value_type;
- MapPolicy policy;
- };
- //When we want to insert value into the map, we could use the policy to map the string
- typename MapPolicy::map_type_t MapString(const &std::string, const size_t dimension)
- {
- return policy.MapString(string, dimension);
- }
- //Use typedef to provide backward compatibility
- using DatasetInfo = DataSetInfoRich<DefaultMapPolicy>;
Add Comment
Please, Sign In to add comment