random_initializer.hpp
Go to the documentation of this file.
1 
13 #ifndef MLPACK_METHODS_SPARSE_CODING_RANDOM_INITIALIZER_HPP
14 #define MLPACK_METHODS_SPARSE_CODING_RANDOM_INITIALIZER_HPP
15 
16 #include <mlpack/prereqs.hpp>
17 
18 namespace mlpack {
19 namespace sparse_coding {
20 
26 {
27  public:
37  static void Initialize(const arma::mat& data,
38  const size_t atoms,
39  arma::mat& dictionary)
40  {
41  // Create random dictionary.
42  dictionary.randn(data.n_rows, atoms);
43 
44  // Normalize each atom.
45  for (size_t j = 0; j < atoms; ++j)
46  dictionary.col(j) /= norm(dictionary.col(j), 2);
47  }
48 };
49 
50 } // namespace sparse_coding
51 } // namespace mlpack
52 
53 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.
static void Initialize(const arma::mat &data, const size_t atoms, arma::mat &dictionary)
Initialize the dictionary randomly from a normal distribution, such that each atom has a norm of 1...
A DictionaryInitializer for use with the SparseCoding class.