mlpack  master
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)),
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)),
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.
89 
90 }; // class Imputer
91 
92 } // namespace data
93 } // namespace mlpack
94 
95 #endif
MapperType & Mapper()
Modify the given mapper (be careful!)
Definition: imputer.hpp:78
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
StrategyType & Strategy()
Modify the given given strategy (be careful!)
Definition: imputer.hpp:72
The core includes that mlpack expects; standard C++ includes and Armadillo.
const MapperType & Mapper() const
Get the mapper.
Definition: imputer.hpp:75
Definition: prereqs.hpp:56
MapperType mapper
Definition: imputer.hpp:85
Given a dataset of a particular datatype, replace user-specified missing value with a variable depend...
Definition: imputer.hpp:33
const StrategyType & Strategy() const
Get the strategy.
Definition: imputer.hpp:69
StrategyType strategy
Definition: imputer.hpp:82
test cpp RESULT_VARIABLE MEX_RESULT_TRASH OUTPUT_VARIABLE MEX_OUTPUT ERROR_VARIABLE MEX_ERROR_TRASH string(REGEX MATCH"Warning: You are using"MEX_WARNING"${MEX_OUTPUT}") if(MEX_WARNING) string(REGEX REPLACE".*using [a-zA-Z]* version \"([0-9.]*)[^\"]*\".*""\\1"OTHER_COMPILER_VERSION"$
Definition: CMakeLists.txt:18
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
Imputer(MapperType mapper, bool columnMajor=true)
Definition: imputer.hpp:36
Imputer(MapperType mapper, StrategyType strategy, bool columnMajor=true)
Definition: imputer.hpp:43