X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=trialSwap2.cpp;h=9959443c9ffbb0c411dfcd0fc6dd6920fbe6f5c8;hb=70491a12902e89b85cfa6b44a7b7fbe066ee2ac1;hp=c51a5b7c0be1d3048851325da8be9cb26b414949;hpb=5d5ce917adda39d712a4d5ac0932671db1426393;p=mothur.git diff --git a/trialSwap2.cpp b/trialSwap2.cpp index c51a5b7..9959443 100644 --- a/trialSwap2.cpp +++ b/trialSwap2.cpp @@ -50,9 +50,10 @@ double TrialSwap2::calc_c_score (vector > &co_matrix, vector ro } } - cscore = cscore/(double)(nrows*(nrows-1)/2); + //cscore = cscore/(double)(nrows*(nrows-1)/2); //not normalized //cout << "normalized c score: " << normcscore/nonzeros << endl; - + cscore = normcscore/(double)nonzeros; + return cscore; } catch(exception& e) { @@ -148,7 +149,7 @@ int TrialSwap2::calc_combo (int nrows, int ncols, vector > &nullmatr { try { //need to transpose so we can compare rows (row-major order) - int tmpnrows = nrows; + //int tmpnrows = nrows; vector > tmpmatrix; vector tmprow; @@ -192,23 +193,25 @@ int TrialSwap2::calc_combo (int nrows, int ncols, vector > &nullmatr } } /**************************************************************************************************/ -int TrialSwap2::swap_checkerboards (vector > &co_matrix, vector rowtotal, vector columntotal, int ncols, int nrows) +int TrialSwap2::swap_checkerboards (vector > &co_matrix, int ncols, int nrows) { try { - int ncols = co_matrix[0].size(); int nrows = co_matrix.size(); - int i, j, k, l; - i = m->getRandomIndex(nrows-1); - while((j = m->getRandomIndex(nrows-1) ) == i ) {;if (m->control_pressed) { return 0; }} - k = m->getRandomIndex(ncols-1); - while((l = m->getRandomIndex(ncols-1)) == k ) {;if (m->control_pressed) { return 0; }} - - if((co_matrix[i][k]*co_matrix[j][l]==1 && co_matrix[i][l]+co_matrix[j][k]==0)||(co_matrix[i][k]+co_matrix[j][l]==0 && co_matrix[i][l]*co_matrix[j][k]==1)) //checking for checkerboard value and swap - { - co_matrix[i][k]=1-co_matrix[i][k]; - co_matrix[i][l]=1-co_matrix[i][l]; - co_matrix[j][k]=1-co_matrix[j][k]; - co_matrix[j][l]=1-co_matrix[j][l]; - + //do 100 runs to make sure enough swaps are happening. This does NOT mean that there will be 1000 swaps, but that is the theoretical max. + for(int a=0;a<1000;a++){ + int i, j, k, l; + i = m->getRandomIndex(nrows-1); + while((j = m->getRandomIndex(nrows-1) ) == i ) {;if (m->control_pressed) { return 0; }} + k = m->getRandomIndex(ncols-1); + while((l = m->getRandomIndex(ncols-1)) == k ) {;if (m->control_pressed) { return 0; }} + + if((co_matrix[i][k]*co_matrix[j][l]==1 && co_matrix[i][l]+co_matrix[j][k]==0)||(co_matrix[i][k]+co_matrix[j][l]==0 && co_matrix[i][l]*co_matrix[j][k]==1)) //checking for checkerboard value and swap + { + co_matrix[i][k]=1-co_matrix[i][k]; + co_matrix[i][l]=1-co_matrix[i][l]; + co_matrix[j][k]=1-co_matrix[j][k]; + co_matrix[j][l]=1-co_matrix[j][l]; + + } } return 0; @@ -289,6 +292,34 @@ double TrialSwap2::t_test (double initialscore, int runs, double nullMean, vecto } } /**************************************************************************************************/ +double TrialSwap2::getSD (int runs, vector scorevec, double nullMean) +{ + try{ + double sum = 0; + for(int i=0;icontrol_pressed) { return 0; } + sum += pow((scorevec[i] - nullMean),2); + } + return sqrt( (1/double(runs)) * sum ); + } + catch(exception& e) { + m->errorOut(e, "TrialSwap2", "getSD"); + exit(1); + } +} +/**************************************************************************************************/ +double TrialSwap2::get_zscore (double sd, double nullMean, double initscore) +{ + try { + return (initscore - nullMean) / sd; + } + catch(exception& e) { + m->errorOut(e, "TrialSwap2", "get_zscore"); + exit(1); + } +} +/**************************************************************************************************/ int TrialSwap2::print_matrix(vector > &matrix, int nrows, int ncols) { try {