33 template<
typename MATRIX>
39 for (std::size_t i = 0; i < ref.
size1(); i++)
41 for (std::size_t j = 0; j < ref.
size2(); ++j)
43 diff =
std::max(diff, std::abs(res(i, j) - ref(i, j)));
55 for (std::size_t i = 0; i < v.
size1(); i++)
57 for (std::size_t j = 0; j < v.
size2(); ++j)
62 void test_nmf(std::size_t m, std::size_t k, std::size_t n);
64 void test_nmf(std::size_t m, std::size_t k, std::size_t n)
90 bool diff_ok = fabs(diff) <
EPS;
92 long iterations =
static_cast<long>(conf.
iters());
93 printf(
"%6s [%lux%lux%lu] diff = %.6f (%ld iterations)\n", diff_ok ?
"[[OK]]" :
"[FAIL]", m, k, n,
103 std::cout << std::endl;
104 std::cout <<
"------- Test NMF --------" << std::endl;
105 std::cout << std::endl;
112 std::cout << std::endl;
113 std::cout <<
"------- Test completed --------" << std::endl;
114 std::cout << std::endl;
Generic interface for matrix-vector and matrix-matrix products. See viennacl/linalg/vector_operations...
Configuration class for the nonnegative-matrix-factorization algorithm. Specify tolerances, maximum iteration counts, etc., here.
T max(const T &lhs, const T &rhs)
Maximum.
float matrix_compare(MATRIX &res, viennacl::matrix_base< ScalarType > &ref)
VectorT prod(std::vector< std::vector< T, A1 >, A2 > const &matrix, VectorT const &vector)
vcl_size_t max_iterations() const
Returns the maximum number of iterations for the NMF algorithm.
void test_nmf(std::size_t m, std::size_t k, std::size_t n)
size_type size2() const
Returns the number of columns.
size_type size1() const
Returns the number of rows.
vcl_size_t iters() const
Returns the number of iterations of the last NMF run using this configuration object.
void nmf(viennacl::matrix_base< ScalarType > const &V, viennacl::matrix_base< ScalarType > &W, viennacl::matrix_base< ScalarType > &H, viennacl::linalg::nmf_config const &conf)
The nonnegative matrix factorization (approximation) algorithm as suggested by Lee and Seung...
void fill_random(viennacl::matrix_base< ScalarType > &v)
ScalarType diff(ScalarType &s1, viennacl::scalar< ScalarType > &s2)
bool print_relative_error() const
Returns the flag specifying whether the relative tolerance should be printed in each iteration...
Provides a nonnegative matrix factorization implementation. Experimental.