3 #ifndef NMF_BPPNMF_HPP_ 4 #define NMF_BPPNMF_HPP_ 15 #define ONE_THREAD_MATRIX_SIZE 2000 26 void updateOtherGivenOneMultipleRHS(
const T &input,
const MAT &given,
27 char worh,
MAT *othermat) {
31 MAT giventInput(this->k, input.n_cols);
33 giventGiven = given.t() * given;
36 giventInput = given.t() * input;
39 INFO <<
"starting " << worh <<
". Prereq for " << worh <<
" took=" << t2
40 <<
" NumThreads=" << numThreads <<
PRINTMATINFO(giventGiven)
43 #pragma omp parallel for schedule(dynamic) 44 for (
UINT i = 0; i < numThreads; i++) {
47 if (spanEnd > input.n_cols - 1) {
48 spanEnd = input.n_cols - 1;
52 if (spanStart <= spanEnd) {
53 if (spanStart == spanEnd) {
55 giventGiven, (
VEC)giventInput.col(spanStart),
true);
58 giventGiven, (
MAT)giventInput.cols(spanStart, spanEnd),
true);
61 INFO <<
"Scheduling " << worh <<
" start=" << spanStart
62 <<
", end=" << spanEnd <<
", tid=" << omp_get_thread_num()
69 INFO <<
"completed " << worh <<
" start=" << spanStart
70 <<
", end=" << spanEnd <<
", tid=" << omp_get_thread_num()
71 <<
" cpu=" << sched_getcpu() <<
" time taken=" << t2
72 <<
" num_iterations()=" << numIter << std::endl;
74 if (spanStart == spanEnd) {
76 (*othermat).row(i) = solVec;
78 (*othermat).rows(spanStart, spanEnd) =
85 double totalH2 =
toc();
86 INFO << worh <<
" total time taken :" << totalH2 << std::endl;
92 BPPNMF(
const T &A,
int lowrank) :
NMF<T>(A, lowrank) {
93 giventGiven = arma::zeros<MAT>(lowrank, lowrank);
100 int currentIteration = 0;
102 this->computeObjectiveErr();
106 this->collectStats(currentIteration);
109 MAT Wt = this->W.t();
110 MAT WtW = Wt * this->W;
111 MAT WtA = Wt * this->A;
114 #pragma omp parallel for 116 for (
UINT i = 0; i < this->n; i++) {
120 INFO <<
"Initialized subproblem and calling solveNNLS for " 121 <<
"H(" << i <<
"/" << this->n <<
")";
124 int numIter = subProblemforH->
solveNNLS();
130 INFO <<
"Comp H(" << i <<
"/" << this->n
131 <<
") of it=" << currentIteration <<
" time taken=" << t2
132 <<
" num_iterations()=" << numIter << std::endl;
136 INFO <<
"H: at it = " << currentIteration << std::endl << this->H;
143 MAT Ht = this->H.t();
144 MAT HtH = Ht * this->H;
148 #pragma omp parallel for 149 for (
UINT i = 0; i < this->m; i++) {
153 INFO <<
"Initialized subproblem and calling solveNNLS for " 154 <<
"W(" << i <<
"/" << this->m <<
")";
157 int numIter = subProblemforW->
solveNNLS();
164 INFO <<
"Comp W(" << i <<
"/" << this->n
165 <<
") of it=" << currentIteration <<
" time taken=" << t2
166 <<
" num_iterations()=" << numIter << std::endl;
172 INFO <<
"W: at it = " << currentIteration << std::endl << this->W;
182 unsigned int currentIteration = 0;
191 HALSNMF<T> tempHals(this->A, this->W, this->H);
198 INFO <<
" nnz = " << this->At.n_nonzero << std::endl;
204 this->collectStats(currentIteration);
205 this->stats(currentIteration + 1, 0) = currentIteration + 1;
208 updateOtherGivenOneMultipleRHS(this->At, this->H,
'W', &(this->W));
209 double totalW2 =
toc();
211 updateOtherGivenOneMultipleRHS(this->A, this->W,
'H', &(this->H));
212 double totalH2 =
toc();
216 this->stats(currentIteration + 1, 1) = totalH2;
217 this->stats(currentIteration + 1, 2) = totalW2;
219 this->stats(currentIteration + 1, 3) = totalW2 + totalH2;
221 INFO <<
"completed it=" << currentIteration
222 <<
" time taken = " << totalW2 + totalH2 << std::endl;
224 INFO <<
"error:it = " << currentIteration
225 <<
" bpperr =" << sqrt(this->objective_err) / this->normA
229 this->normalize_by_W();
231 this->collectStats(currentIteration);
232 INFO <<
"NMF Statistics:" << std::endl << this->stats << std::endl;
244 updateOtherGivenOneMultipleRHS(this->A, this->W,
'H', &(this->H));
252 #endif // NMF_BPPNMF_HPP_ MATTYPE getSolutionMatrix()
BPPNMF(const T &A, int lowrank)
void tic()
start the timer. easy to call as tic(); some code; double t=toc();
double getObjectiveError()
const unsigned int num_iterations() const
Returns the number of iterations.
MAT getRightLowRankFactor()
Returns the right low rank factor matrix H.
void num_iterations(const int it)
Sets number of iterations for the NMF algorithms.
void computeNMFSingleRHS()
VECTYPE getSolutionVector()
#define ONE_THREAD_MATRIX_SIZE
MAT getLeftLowRankFactor()
Returns the left low rank factor matrix W.
ncp_factors contains the factors of the ncp every ith factor is of size n_i * k number of factors is ...
void computeObjectiveError()
BPPNMF(const T &A, const MAT &llf, const MAT &rlf)