/* Calculates the parameters of the optimization for the patellar tendon, based upon optimization method 1 (as described in the FreeBody user manual) */ void Muscle::mus_opt_pt_2(Segment **segment_data[]) { int points=this->pnts, segment_prox_point, segment_dist_point, frame=this->frame; int segment_most_prox=int (this->gblpnts[0][3]), segment_most_dist=int (this->gblpnts[points-1][3]); int num_segments=this->segments_spanned; Vec_DP v0(3), v1(3), v2(3), v3(3), v4(3), v5(3), v6(3), v7(3), r(3), Fnorm(3), Fnorm1(3), Fnorm2(3), opt_vec(3); for (int i=0; i<points-1; i++) { // This routine iterates for each muscle point segment_prox_point=int (this->gblpnts[i][3]); // Determine the location of each muscle point (what segment) segment_dist_point=int (this->gblpnts[i+1][3]); if ((segment_dist_point == segment_most_dist) && (segment_prox_point != segment_most_dist)) { for (int j=0; j<3; j++) { v0[j]=this->gblpnts[i][j]; v1[j]=this->gblpnts[i+1][j]; v2[j]=segment_data[frame][segment_dist_point]->rot_centre[j]; r[j]=v1[j]-v2[j]; Fnorm[j]=v0[j]-v1[j]; } Fnorm=MATHEMATICS::math_vecnorm(Fnorm); opt_vec=MATHEMATICS::math_crossprd(r,Fnorm); for (int j=0; j<3; j++) { this->opt_2[0][j]=Fnorm[j]; this->opt_2[3][j]=opt_vec[j]; } this->opt_2[0][3]=segment_most_dist; this->opt_2[3][3]=segment_most_dist; for (int j=0; j<3; j++) { this->opt_2[1][j]=-Fnorm[j]; } this->opt_2[1][3]=segment_most_prox; this->opt_2[2][3]=-1; this->opt_2[4][3]=-1; this->opt_2[5][3]=-1; } } return; }
int main(int argc, char *argv[]) { // tests(); // srand(time(10)); srand(10); if(argc < 4) { std::cout << "Input arguments:\n\t1: Filename for A matrix (as in A ~= WH)\n\t2: New desired dimension\n\t3: Max NMF iterations\n\t4: Max NNLS iterations\n\t5 (optional): delimiter (space is default)\n"; } else { std::string filename = argv[1]; int newDimension = atoi(argv[2]); int max_iter_nmf = atoi(argv[3]); int max_iter_nnls = atoi(argv[4]); char delimiter = (argc > 5) ? *argv[5] : ' '; DenseMatrix* A = readMatrix(filename,delimiter); A->copyColumnToRow(); printf("Sparsity of A: %f\n",sparsity(A)); DenseMatrix W = DenseMatrix(A->rows,newDimension); DenseMatrix H = DenseMatrix(newDimension,A->cols); NMF_Input input = NMF_Input(&W,&H,A,max_iter_nmf,max_iter_nnls); std::cout << "Starting NMF computation." << std::endl; std::clock_t start = std::clock(); double duration; // nmf_cpu(input); nmf_cpu_profile(input); duration = ( std::clock() - start ) / (double) CLOCKS_PER_SEC; std::cout << "NMF computation complete. Time: " << duration << " s." << std::endl; W.copyColumnToRow(); dtype AF = FrobeniusNorm(A); dtype WH_AF = Fnorm(W,H,*A); printf("Objective value: %f\n",WH_AF/AF); // DenseMatrix z1 = DenseMatrix(A->rows,newDimension); // DenseMatrix z2 = DenseMatrix(newDimension,A->cols); // printf("Calculated solution approximate Frobenius norm: %f\n",Fnorm(z1,z2,*A)); // printcolmajor(H.colmajor,H.rows,H.cols); if(A) delete A; } return 0; }