MLPACK  1.0.11
random_initializer.hpp
Go to the documentation of this file.
1 
23 #ifndef __MLPACK_METHODS_SPARSE_CODING_RANDOM_INITIALIZER_HPP
24 #define __MLPACK_METHODS_SPARSE_CODING_RANDOM_INITIALIZER_HPP
25 
26 #include <mlpack/core.hpp>
27 
28 namespace mlpack {
29 namespace sparse_coding {
30 
36 {
37  public:
47  static void Initialize(const arma::mat& data,
48  const size_t atoms,
49  arma::mat& dictionary)
50  {
51  // Create random dictionary.
52  dictionary.randn(data.n_rows, atoms);
53 
54  // Normalize each atom.
55  for (size_t j = 0; j < atoms; ++j)
56  dictionary.col(j) /= norm(dictionary.col(j), 2);
57  }
58 };
59 
60 }; // namespace sparse_coding
61 }; // namespace mlpack
62 
63 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: load.hpp:31
A DictionaryInitializer for use with the SparseCoding class.
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...