Guest User

Untitled

a guest
Jun 9th, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.72 KB | None | 0 0
  1. template<typename Policy, typename Mapper, typename T>
  2. void Imputer(const arma::Mat<T> &input,
  3.              arma::Mat<T> &output,
  4.              Policy &&policy, //&& could accept const and non-const type
  5.              const std::string &missValue,            
  6.              const Mapper &mapper,
  7.              const size_t dimension,
  8.              const bool tranpose = true)
  9. {
  10.   size_t mappedValue = mapper.UnmapValue(missValue, dimension);
  11.  
  12.   if(transpose)
  13.   {
  14.     for (size_t i = 0; i < input.n_rows; ++i)
  15.     {
  16.       if (input(dimension, i) == mappedValue)
  17.       {
  18.         policy.Impute(input, output, dimension, i);
  19.         // just for demo,
  20.         // later imputation strategy can be implemented
  21.         // so that user can replace it with mean, mode, etc.
  22.       }
  23.     }
  24.   }
  25.   else
  26.   {
  27.     //.....
  28.   }
  29. }
  30.  
  31. //I think the mapper could add one more template parameters to determine it should map missed value to specific value or not
  32. //Please give it a better name, most of the implementation details and api should same as the old DataSetInfo for backward
  33. //compatibility sake
  34. template<typename MapPolicy>
  35. class DatasetInfoRich
  36. {
  37. //......
  38. private:  
  39.   std::unordered_map<size_t, std::pair<boost::bimap<std::string, typename MapPolicy::map_type>,
  40.       size_t>> maps;
  41.   using PairType = boost::bimap<std::string, typename MapPolicy::map_type_t>::value_type;
  42.   MapPolicy policy;
  43. };
  44.  
  45. //When we want to insert value into the map, we could use the policy to map the string
  46. typename MapPolicy::map_type_t MapString(const &std::string, const size_t dimension)
  47. {
  48.   return policy.MapString(string, dimension);
  49. }
  50.  
  51. //Use typedef to provide backward compatibility
  52. using DatasetInfo = DataSetInfoRich<DefaultMapPolicy>;
Add Comment
Please, Sign In to add comment