3 #ifndef COMMON_PARSECOMMANDLINE_HPP_ 4 #define COMMON_PARSECOMMANDLINE_HPP_ 28 std::string m_Afile_name;
29 std::string m_outputfile_name;
52 void parseArrayofString(
const char opt,
const char *input) {
53 std::stringstream ss(input);
56 if (this->m_num_modes == 0) {
57 while (getline(ss, s,
' ')) {
60 this->m_num_modes = i;
61 this->m_dimensions = arma::zeros<UVEC>(this->m_num_modes);
62 this->m_regularizers = arma::zeros<FVEC>(2 * this->m_num_modes);
63 this->m_proc_grids = arma::ones<UVEC>(this->m_num_modes);
68 while (getline(ss, s,
' ')) {
71 this->m_dimensions(i++) = ::atoi(s.c_str());
74 this->m_regularizers(i++) = ::atof(s.c_str());
77 this->m_proc_grids(i++) = ::atoi(s.c_str());
80 INFO <<
"wrong option::" << opt <<
"::values::" << input << std::endl;
93 this->m_num_modes = 0;
96 this->m_regW = arma::zeros<FVEC>(2);
97 this->m_regH = arma::zeros<FVEC>(2);
98 this->m_num_k_blocks = 1;
102 this->m_compute_error = 0;
103 this->m_input_normalization =
NONE;
104 this->m_dim_tree = 1;
109 while ((opt = getopt_long(this->m_argc, this->m_argv,
111 &long_index)) != -1) {
114 this->m_lucalgo =
static_cast<algotype>(atoi(optarg));
117 this->m_compute_error = atoi(optarg);
120 std::string temp = std::string(optarg);
121 this->m_Afile_name = temp;
125 this->m_k = atoi(optarg);
128 std::string temp = std::string(optarg);
129 this->m_outputfile_name = temp;
135 parseArrayofString(opt, optarg);
138 this->m_sparsity = atof(optarg);
141 this->m_num_it = atoi(optarg);
144 this->m_num_k_blocks = atoi(optarg);
147 std::string temp = std::string(optarg);
148 if (temp.compare(
"l2") == 0) {
150 }
else if (temp.compare(
"max") == 0) {
156 this->m_dim_tree = atoi(optarg);
159 std::cout <<
"failed while processing argument:" << optarg
166 if (this->m_num_modes == 2) {
167 this->m_globalm = this->m_dimensions(0);
168 this->m_globaln = this->m_dimensions(1);
169 this->m_regW(0) = this->m_regularizers(0);
170 this->m_regW(1) = this->m_regularizers(1);
171 this->m_regH(0) = this->m_regularizers(2);
172 this->m_regH(1) = this->m_regularizers(3);
173 this->m_pr = this->m_proc_grids(0);
174 this->m_pc = this->m_proc_grids(1);
181 std::cout <<
"a::" << this->m_lucalgo <<
"::i::" << this->m_Afile_name
182 <<
"::k::" << this->m_k <<
"::m::" << this->m_globalm
183 <<
"::n::" << this->m_globaln <<
"::t::" << this->m_num_it
184 <<
"::pr::" << this->m_pr <<
"::pc::" << this->m_pc
185 <<
"::error::" << this->m_compute_error <<
"::regW::" 186 <<
"l2::" << this->m_regW(0) <<
"::l1::" << this->m_regW(1)
188 <<
"l2::" << this->m_regH(0) <<
"::l1::" << this->m_regH(1)
189 <<
"::num_k_blocks::" << m_num_k_blocks
190 <<
"::dimensions::" << this->m_dimensions
191 <<
"::procs::" << this->m_proc_grids
192 <<
"::regularizers::" << this->m_regularizers
193 <<
"::input normalization::" << this->m_input_normalization
194 <<
"::dimtree::" << this->m_dim_tree << std::endl;
199 INFO <<
"distnmf usage:" << std::endl;
200 INFO <<
"for short arguments like -i do not use equals sign, eg -t 10" 202 <<
"for long arguments like --pr give key=value pair, eg --pr=4" 204 <<
"algorithm codes 0-MU2D, 1-HALS2D, 2-ANLSBPP2D, 3-NAIVEANLSBPP" 207 INFO <<
"Usage 1: mpirun -np 6 distnmf -a 0/1/2/3 -k 50" 208 <<
"-i rand_uniform/rand_normal/rand_lowrank --dimtree 1" 209 <<
"-d \"21600 14400\" -t 10 -p \"3 2\" " 210 <<
"--normalization \"l2\" " 211 <<
"-r \"0.0001 0 0 0.0001\" " << std::endl;
213 INFO <<
"Usage 2: mpirun -np 6 distnmf -a 0/1/2/3 -k 50 --dimtree 1" 214 <<
"-i Ainput -t 10 -p \"3 2\" " 215 <<
"--normalization \"max\" " 216 <<
"-r \"0.0001 0 0 0.0001\" " << std::endl;
218 INFO <<
"Usage 3: mpirun -np 6 distnmf -a 0/1/2/3 -k 50 --dimtree 1" 219 <<
"-i Ainput -o nmfoutput -t 10 -p \"3 2\" " 220 <<
"-r \"0.0001 0 0 0.0001\" " << std::endl;
223 INFO <<
"Usage 4: mpirun -np 6 distnmf -a 0/1/2/3 -k 50 --dimtree 1" 224 <<
"-i Ainput -o nmfoutput -t 10 -p \"3 2\" --sparsity=0.3" 225 <<
"-r \"0.0001 0 0 0.0001\" " << std::endl;
281 int pr() {
return m_pr; }
286 int pc() {
return m_pc; }
301 #endif // COMMON_PARSECOMMANDLINE_HPP_
FVEC regW()
L2 regularization as the first parameter and L1 as second for left lowrank factor W...
algotype lucalgo()
Returns the NMF algorithm to run. Passed as parameter –algo or -a.
std::string output_file_name()
Returns output file name.
int pc()
Returns the number of processor columns.
float sparsity()
Input parameter for generating sparse matrix. Passed as -s or –sparsity.
int num_modes()
Returns number of modes in tensors. For matrix it is two.
struct option plancopts[]
bool compute_error()
Returns whether to compute error not. Passed as parameter -e or –error.
int iterations()
Returns number of iterations. passed as -t or –iter.
FVEC regH()
L2 regularization as the first parameter and L1 as second for right lowrank factor H...
int pr()
Returns the number of processor rows.
void parseplancopts()
parses the command line parameters
UWORD lowrankk()
returns the low rank. Passed as parameter –lowrank or -k
ParseCommandLine(int argc, char **argv)
Constructor that takes the number of arguments and the command line parameters.
UVEC processor_grids()
Returns the process grid configuration.
UWORD globalm()
return global rows. Passed as parameter -d
std::string input_file_name()
Returns input file name. Passed as -i or –input.
void printConfig()
print the configuration received through the command line paramters
FVEC regularizers()
Returns the vector regularizers for all the modes.
ncp_factors contains the factors of the ncp every ith factor is of size n_i * k number of factors is ...
UVEC dimensions()
Returns vector of dimensions for every mode.
normtype input_normalization()
To column normalize the input matrix.
bool dim_tree()
Enable dimension tree or not.