mlpack  master
binarize.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_CORE_DATA_BINARIZE_HPP
14 #define MLPACK_CORE_DATA_BINARIZE_HPP
15 
16 #include <mlpack/prereqs.hpp>
17 
18 namespace mlpack {
19 namespace data {
20 
40 template<typename T>
41 void Binarize(const arma::Mat<T>& input,
42  arma::Mat<T>& output,
43  const double threshold)
44 {
45  output.copy_size(input);
46 
47  const int totalElems = static_cast<int>(input.n_elem);
48  const T *inPtr = input.memptr();
49  T *outPtr = output.memptr();
50 
51  #pragma omp parallel for
52  for (int i = 0; i < totalElems; ++i)
53  {
54  if (inPtr[i] > threshold)
55  outPtr[i] = 1;
56  else
57  outPtr[i] = 0;
58  }
59 }
60 
82 template<typename T>
83 void Binarize(const arma::Mat<T>& input,
84  arma::Mat<T>& output,
85  const double threshold,
86  const size_t dimension)
87 {
88  output = input;
89  const int totalCols = static_cast<int>(input.n_cols);
90 
91  #pragma omp parallel for
92  for (int i = 0; i < totalCols; ++i)
93  {
94  if (input(dimension, i) > threshold)
95  output(dimension, i) = 1;
96  else
97  output(dimension, i) = 0;
98  }
99 }
100 
101 } // namespace data
102 } // namespace mlpack
103 
104 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: binarize.hpp:18
The core includes that mlpack expects; standard C++ includes and Armadillo.
void Binarize(const arma::Mat< T > &input, arma::Mat< T > &output, const double threshold)
Given an input dataset and threshold, set values greater than threshold to 1 and values less than or ...
Definition: binarize.hpp:41