data_dependent_random_initializer.hpp

Go to the documentation of this file.
00001 
00022 #ifndef __MLPACK_METHODS_SPARSE_CODING_DATA_DEPENDENT_RANDOM_INITIALIZER_HPP
00023 #define __MLPACK_METHODS_SPARSE_CODING_DATA_DEPENDENT_RANDOM_INITIALIZER_HPP
00024 
00025 #include <mlpack/core.hpp>
00026 
00027 namespace mlpack {
00028 namespace sparse_coding {
00029 
00035 class DataDependentRandomInitializer
00036 {
00037  public:
00047   static void Initialize(const arma::mat& data,
00048                          const size_t atoms,
00049                          arma::mat& dictionary)
00050   {
00051     // Set the size of the dictionary.
00052     dictionary.set_size(data.n_rows, atoms);
00053 
00054     // Create each atom.
00055     for (size_t i = 0; i < atoms; ++i)
00056     {
00057       // Add three atoms together.
00058       dictionary.col(i) = (data.col(math::RandInt(data.n_cols)) +
00059           data.col(math::RandInt(data.n_cols)) +
00060           data.col(math::RandInt(data.n_cols)));
00061 
00062       // Now normalize the atom.
00063       dictionary.col(i) /= norm(dictionary.col(i), 2);
00064     }
00065   }
00066 };
00067 
00068 }; // namespace sparse_coding
00069 }; // namespace mlpack
00070 
00071 #endif

Generated on 29 Sep 2016 for MLPACK by  doxygen 1.6.1