imputer.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_CORE_DATA_IMPUTER_HPP
14 #define MLPACK_CORE_DATA_IMPUTER_HPP
15 
16 #include <mlpack/prereqs.hpp>
17 #include "dataset_mapper.hpp"
20 
21 namespace mlpack {
22 namespace data {
23 
32 template<typename T, typename MapperType, typename StrategyType>
33 class Imputer
34 {
35  public:
36  Imputer(MapperType mapper, bool columnMajor = true):
37  mapper(std::move(mapper)),
38  columnMajor(columnMajor)
39  {
40  // Nothing to initialize here.
41  }
42 
43  Imputer(MapperType mapper, StrategyType strategy, bool columnMajor = true):
44  strategy(std::move(strategy)),
45  mapper(std::move(mapper)),
46  columnMajor(columnMajor)
47  {
48  // Nothing to initialize here.
49  }
50 
60  void Impute(arma::Mat<T>& input,
61  const std::string& missingValue,
62  const size_t dimension)
63  {
64  T mappedValue = static_cast<T>(mapper.UnmapValue(missingValue, dimension));
65  strategy.Impute(input, mappedValue, dimension, columnMajor);
66  }
67 
69  const StrategyType& Strategy() const { return strategy; }
70 
72  StrategyType& Strategy() { return strategy; }
73 
75  const MapperType& Mapper() const { return mapper; }
76 
78  MapperType& Mapper() { return mapper; }
79 
80  private:
81  // StrategyType
82  StrategyType strategy;
83 
84  // DatasetMapperType<MapPolicy>
85  MapperType mapper;
86 
87  // save columnMajor as a member variable since it is rarely changed.
88  bool columnMajor;
89 }; // class Imputer
90 
91 } // namespace data
92 } // namespace mlpack
93 
94 #endif
const StrategyType & Strategy() const
Get the strategy.
Definition: imputer.hpp:69
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
Imputer(MapperType mapper, StrategyType strategy, bool columnMajor=true)
Definition: imputer.hpp:43
Given a dataset of a particular datatype, replace user-specified missing value with a variable depend...
Definition: imputer.hpp:33
StrategyType & Strategy()
Modify the given strategy.
Definition: imputer.hpp:72
void Impute(arma::Mat< T > &input, const std::string &missingValue, const size_t dimension)
Given an input dataset, replace missing values of a dimension with given imputation strategy...
Definition: imputer.hpp:60
MapperType & Mapper()
Modify the given mapper.
Definition: imputer.hpp:78
Imputer(MapperType mapper, bool columnMajor=true)
Definition: imputer.hpp:36
const MapperType & Mapper() const
Get the mapper.
Definition: imputer.hpp:75