planc
Parallel Lowrank Approximation with Non-negativity Constraints
ntf.cpp
Go to the documentation of this file.
1 /* Copyright Ramakrishnan Kannan 2017 */
2 
3 #include <armadillo>
4 #include <iostream>
5 #include "common/ncpfactors.hpp"
6 #include "common/ntf_utils.hpp"
8 #include "common/tensor.hpp"
9 #include "common/utils.h"
10 #include "ntf/ntfanlsbpp.hpp"
11 #include "ntf/ntfaoadmm.hpp"
12 #include "ntf/ntfhals.hpp"
13 #include "ntf/ntfmu.hpp"
14 #include "ntf/ntfnes.hpp"
15 
16 // ntf -d "2 3 4 5" -k 5 -t 20
17 
18 namespace planc {
19 
20 class NTFDriver {
21  public:
22  template <class NTFTYPE>
24  int test_modes = pc.num_modes();
25  UVEC dimensions(test_modes);
26  Tensor my_tensor(pc.dimensions());
27  std::string rand_prefix("rand_");
28  std::string filename = pc.input_file_name();
29  std::cout << "Input filename = " << filename << std::endl;
30  if (!filename.empty() &&
31  filename.compare(0, rand_prefix.size(), rand_prefix) != 0) {
32  my_tensor.read(pc.input_file_name());
33  my_tensor.print();
34  }
35  NTFTYPE ntfsolver(my_tensor, pc.lowrankk(), pc.lucalgo());
36  ntfsolver.num_it(pc.iterations());
37  ntfsolver.compute_error(pc.compute_error());
38  if (pc.dim_tree()) {
39  ntfsolver.dim_tree(true);
40  }
41  ntfsolver.computeNTF();
42  // ntfsolver.ncp_factors().print();
43  }
44  NTFDriver() {}
45 }; // class NTF Driver
46 
47 } // namespace planc
48 
49 int main(int argc, char* argv[]) {
50  planc::ParseCommandLine pc(argc, argv);
51  pc.parseplancopts();
52  planc::NTFDriver ntfd;
53  switch (pc.lucalgo()) {
54  case MU:
55  ntfd.callNTF<planc::NTFMU>(pc);
56  break;
57  case HALS:
58  ntfd.callNTF<planc::NTFHALS>(pc);
59  break;
60  case ANLSBPP:
61  ntfd.callNTF<planc::NTFANLSBPP>(pc);
62  break;
63  case AOADMM:
64  ntfd.callNTF<planc::NTFAOADMM>(pc);
65  break;
66  case NESTEROV:
67  ntfd.callNTF<planc::NTFNES>(pc);
68  break;
69  default:
70  ERR << "Wrong algorithm choice. Quitting.." << pc.lucalgo() << std::endl;
71  }
72 }
algotype lucalgo()
Returns the NMF algorithm to run. Passed as parameter –algo or -a.
Data is stored such that the unfolding is column major.
Definition: tensor.hpp:32
int num_modes()
Returns number of modes in tensors. For matrix it is two.
bool compute_error()
Returns whether to compute error not. Passed as parameter -e or –error.
int main(int argc, char *argv[])
Definition: ntf.cpp:49
int iterations()
Returns number of iterations. passed as -t or –iter.
Definition: utils.h:10
#define UVEC
Definition: utils.h:58
#define ERR
Definition: utils.h:28
void callNTF(planc::ParseCommandLine pc)
Definition: ntf.cpp:23
void parseplancopts()
parses the command line parameters
Definition: utils.h:10
UWORD lowrankk()
returns the low rank. Passed as parameter –lowrank or -k
std::string input_file_name()
Returns input file name. Passed as -i or –input.
ncp_factors contains the factors of the ncp every ith factor is of size n_i * k number of factors is ...
Definition: ncpfactors.hpp:20
Definition: utils.h:10
UVEC dimensions()
Returns vector of dimensions for every mode.
Definition: utils.h:10
bool dim_tree()
Enable dimension tree or not.
Definition: utils.h:10