mlpack  1.0.12
random_initializer.hpp
Go to the documentation of this file.
1 
15 #ifndef __MLPACK_METHODS_SPARSE_CODING_RANDOM_INITIALIZER_HPP
16 #define __MLPACK_METHODS_SPARSE_CODING_RANDOM_INITIALIZER_HPP
17 
18 #include <mlpack/core.hpp>
19 
20 namespace mlpack {
21 namespace sparse_coding {
22 
28 {
29  public:
39  static void Initialize(const arma::mat& data,
40  const size_t atoms,
41  arma::mat& dictionary)
42  {
43  // Create random dictionary.
44  dictionary.randn(data.n_rows, atoms);
45 
46  // Normalize each atom.
47  for (size_t j = 0; j < atoms; ++j)
48  dictionary.col(j) /= norm(dictionary.col(j), 2);
49  }
50 };
51 
52 }; // namespace sparse_coding
53 }; // namespace mlpack
54 
55 #endif
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: load.hpp:23
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...