X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=trialSwap2.cpp;fp=trialSwap2.cpp;h=750c89ff2f6d10493be697d3f8d8932f0507648d;hb=597560b3c23f03d0069082cf096ce65e0c087519;hp=0000000000000000000000000000000000000000;hpb=6b2ac07f3e9ee57594d2358a3a25f9f700bd7362;p=mothur.git diff --git a/trialSwap2.cpp b/trialSwap2.cpp new file mode 100644 index 0000000..750c89f --- /dev/null +++ b/trialSwap2.cpp @@ -0,0 +1,1539 @@ +#include "trialswap2.h" + + +//The sum_of_squares, havel_hakimi and calc_c_score algorithms have been adapted from I. Miklos and J. Podani. 2004. Randomization of presence-absence matrices: comments and new algorithms. Ecology 85:86-92. + + +/**************************************************************************************************/ +int TrialSwap2::intrand(int n){ + try { + double z; + + z = (double)random() * (double)n / (double)RAND_MAX; + if(z>=n) + z=n-1; + if(z<0) + z=0; + return((int)floor(z)); + } + catch(exception& e) { + m->errorOut(e, "TrialSwap2", "intrand"); + exit(1); + } +} +/**************************************************************************************************/ +/* completely random matrix, all column and row totals are variable, matrix size is the same + * + * + */ +/**************************************************************************************************/ +int TrialSwap2::sim1(vector > &co_matrix){ + try { + vector randRow; + vector > tmpmatrix; + int nrows = co_matrix.size(); + int ncols = co_matrix[0].size(); + + //clear co_matrix + // for(i=0;icontrol_pressed) { break; } + + for(int j=0;j 0.5) { + randRow.push_back(1); + }else{ + randRow.push_back(0); + } + } + tmpmatrix.push_back(randRow); + randRow.clear(); + //cout << endl; + } + co_matrix = tmpmatrix; + + return 0; + } + catch(exception& e) { + m->errorOut(e, "TrialSwap2", "sim1"); + exit(1); + } +} +/**************************************************************************************************/ +/* + *row sums fixed, columns equiprobable + */ +void TrialSwap2::sim2(vector > &co_matrix) +{ + try { + + for(int i=0;icontrol_pressed) { break; } + random_shuffle( co_matrix[i].begin(), co_matrix[i].end() ); + } + } + catch(exception& e) { + m->errorOut(e, "TrialSwap2", "sim2"); + exit(1); + } +} +/**************************************************************************************************/ +int TrialSwap2::sim2plus(vector rowtotal, vector > &co_matrix) +{ + try { + int nrows = co_matrix.size(); + int ncols = co_matrix[0].size(); + double cellprob = 1.0/ncols; + vector cellprobvec; + vector tmprow; + vector > tmpmatrix; + //double randNum; + + double start = 0.0; + + for(int i=0; icontrol_pressed) { return 0; } + cellprobvec.push_back(start + cellprob); + start = cellprobvec[i]; + } + + for(int i=0; icontrol_pressed) { return 0; } + double randNum = rand() / double(RAND_MAX); + //cout << randNum << endl; + if(randNum <= cellprobvec[0]) + { + tmprow[0] = 1; + continue; + } + for(int j=1;j cellprobvec[j-1] && tmprow[j] != 1) + { + tmprow[j] = 1; + } + } + } + tmpmatrix.push_back(tmprow); + tmprow.clear(); + } + co_matrix = tmpmatrix; + tmpmatrix.clear(); + cellprobvec.clear(); + + return 0; + } + catch(exception& e) { + m->errorOut(e, "TrialSwap2", "sim2plus"); + exit(1); + } +} +/**************************************************************************************************/ +/* + * same as sim2 but using initmatrix which is the initial co-occurrence matrix before transposition + * may have to be changed depending on what matrix 'seed' is used. One way to use is to transpose + * every null matrix before using an index and use the random matrix as a seed for the next null. + */ +/**************************************************************************************************/ +void TrialSwap2::sim3(vector > &initmatrix) +{ + try { + for(int i=0;icontrol_pressed) { break; } + random_shuffle( initmatrix[i].begin(), initmatrix[i].end() ); + } + + } + catch(exception& e) { + m->errorOut(e, "TrialSwap2", "sim3"); + exit(1); + } +} +/**************************************************************************************************/ +/* + * + * + * + */ +/**************************************************************************************************/ +int TrialSwap2::sim4(vector columntotal, vector rowtotal, vector > &co_matrix) +{ + try { + vector colProb; + vector tmprow;//(ncols, 7); + vector > tmpmatrix; + vector range; + vector randNums; + int ncols = columntotal.size(); + int nrows = rowtotal.size(); + tmprow.clear(); + + double colSum = accumulate( columntotal.begin(), columntotal.end(), 0 ); + //cout << "col sum: " << colSum << endl; + for(int i=0;icontrol_pressed) { return 0; } + colProb.push_back(columntotal[i]/colSum); + } + + double start = 0.0; + + for(int i=0;icontrol_pressed) { return 0; } + range.push_back(start + colProb[i]); + start = range[i]; + } + + for(int i=0;icontrol_pressed) { return 0; } + + while ( accumulate( tmprow.begin(), tmprow.end(), 0 ) < rowtotal[i]) + { + if (m->control_pressed) { return 0; } + + double randNum = rand() / double(RAND_MAX); + if(randNum <= range[0]) + { + tmprow[0] = 1; + continue; + } + for(int j=1;j range[j-1] && tmprow[j] != 1) + { + tmprow[j] = 1; + } + + } + } + tmpmatrix.push_back(tmprow); + tmprow.clear(); + } + + co_matrix = tmpmatrix; + + return 0; + } + catch(exception& e) { + m->errorOut(e, "TrialSwap2", "sim4"); + exit(1); + } +} +/**************************************************************************************************/ +/* + * inverse of sim4, MUST BE TRANSPOSED BEFORE CO-OCCURRENCE ANALYSIS + * + * + */ +/**************************************************************************************************/ +int TrialSwap2::sim5(vector initcolumntotal,vector initrowtotal, vector > &initmatrix) +{ + try { + vector colProb; + vector tmprow;//(ncols, 7); + vector > tmpmatrix; + vector range; + vector randNums; + int ncols = initcolumntotal.size(); + int nrows = initrowtotal.size(); + + tmprow.clear(); + + double colSum = accumulate( initcolumntotal.begin(), initcolumntotal.end(), 0 ); + //cout << "col sum: " << colSum << endl; + for(int i=0;icontrol_pressed) { return 0; } + colProb.push_back(initcolumntotal[i]/colSum); + } + + double start = 0.0; + + for(int i=0;icontrol_pressed) { return 0; } + range.push_back(start + colProb[i]); + start = range[i]; + } + + for(int i=0;icontrol_pressed) { return 0; } + + while ( accumulate( tmprow.begin(), tmprow.end(), 0 ) < initrowtotal[i]) + { + if (m->control_pressed) { return 0; } + + double randNum = rand() / double(RAND_MAX); + if(randNum <= range[0]) + { + tmprow[0] = 1; + continue; + } + for(int j=1;j range[j-1] && tmprow[j] != 1) + { + tmprow[j] = 1; + } + + } + } + tmpmatrix.push_back(tmprow); + tmprow.clear(); + } + + initmatrix = tmpmatrix; + return 0; + } + catch(exception& e) { + m->errorOut(e, "TrialSwap2", "sim5"); + exit(1); + } +} +/**************************************************************************************************/ +/* + * + * + * + */ +/**************************************************************************************************/ +int TrialSwap2::sim6(vector columntotal, vector > &co_matrix) +{ + try { + vector > tmpmatrix; + vector colProb; + vector tmprow; + vector range; + int ncols = columntotal.size(); + int nrows = co_matrix.size(); + + int colSum = accumulate( columntotal.begin(), columntotal.end(), 0 ); + + for(int i=0;icontrol_pressed) { return 0; } + colProb.push_back(columntotal[i]/double (colSum)); + } + + double start = 0.0; + + for(int i=0;icontrol_pressed) { return 0; } + range.push_back(start + colProb[i]); + start = range[i]; + } + + for(int i=0;icontrol_pressed) { return 0; } + tmprow.assign(ncols, 0); + int tmprowtotal; + tmprowtotal = (rand() / double (RAND_MAX)) * 10; + while ( tmprowtotal > ncols) { + if (m->control_pressed) { return 0; } + tmprowtotal = (rand() / double (RAND_MAX)) * 10; + } + //cout << tmprowtotal << endl; + //cout << accumulate( tmprow.begin(), tmprow.end(), 0 ) << endl; + + while ( accumulate( tmprow.begin(), tmprow.end(), 0 ) < tmprowtotal) + { + if (m->control_pressed) { return 0; } + double randNum = rand() / double(RAND_MAX); + //cout << randNum << endl; + if(randNum <= range[0]) + { + tmprow[0] = 1; + continue; + } + for(int j=1;j range[j-1] && tmprow[j] != 1) + { + tmprow[j] = 1; + } + + } + + + } + + tmpmatrix.push_back(tmprow); + tmprow.clear(); + } + + co_matrix = tmpmatrix; + tmpmatrix.clear(); + + return 0; + } + catch(exception& e) { + m->errorOut(e, "TrialSwap2", "sim6"); + exit(1); + } +} +/**************************************************************************************************/ +/* + * MUST BE TRANSPOSED BEFORE CO-OCCURRENCE ANALYSIS + * + * + */ +/**************************************************************************************************/ +int TrialSwap2::sim7(vector initrowtotal, vector > &co_matrix) +{ + try { + vector > probmatrix; + vector > tmpmatrix; + vector colProb; + vector probrow; + vector tmprow; + vector range; + double nc; + int ncols = co_matrix[0].size(); int nrows = co_matrix.size(); + + tmpmatrix.assign(nrows, vector(ncols, 0.)); + + int rowsum = accumulate( initrowtotal.begin(), initrowtotal.end(), 0 ); + + nc = rowsum * ncols; + //cout << nc << endl; + + //assign null matrix based on probabilities + + double start = 0.0; // don't reset start -- probs should be from 0-1 thoughout the entire matrix + + for(int i=0;icontrol_pressed) { return 0; } + //cout << initrowtotal[i]/double(nc) << endl; + double cellprob = initrowtotal[i]/double(nc); + //cout << cellprob << endl; + for(int j=0;jcontrol_pressed) { return 0; } + done: + //cout << k << endl; + //tmprowsum = accumulate( tmprowtotal.begin(), tmprowtotal.end(), 0 ); + double randNum = rand() / double(RAND_MAX); + //cout << randNum << "+" << endl; + //special case for the first entry + if(randNum <= probmatrix[0][0] && tmpmatrix[0][0] != 1) + { + tmpmatrix[0][0] = 1; + k++; + //cout << k << endl; + continue; + } + + + for(int i=0;icontrol_pressed) { return 0; } + for(int j=0;j probmatrix[i][j-1] && tmpmatrix[i][j] != 1) + { + tmpmatrix[i][j] = 1; + k++; + //cout << k << endl; + goto done; + } + //else + //k = k-1; + } + + } + + } + + co_matrix = tmpmatrix; + return 0; + //build probibility matrix + /* for(int i=0;i ncols) + tmprowtotal = (rand() / double (RAND_MAX)) * 10; + //cout << tmprowtotal << endl; + //cout << accumulate( tmprow.begin(), tmprow.end(), 0 ) << endl; + + while ( accumulate( tmprow.begin(), tmprow.end(), 0 ) < tmprowtotal) + { + double randNum = rand() / double(RAND_MAX); + //cout << randNum << endl; + if(randNum <= range[0]) + { + tmprow[0] = 1; + continue; + } + for(int j=1;j range[j-1] && tmprow[j] != 1) + { + tmprow[j] = 1; + } + } + } + + tmpmatrix.push_back(tmprow); + tmprow.clear(); + } + + initmatrix = tmpmatrix; + */ + } + catch(exception& e) { + m->errorOut(e, "TrialSwap2", "sim7"); + exit(1); + } +} +/**************************************************************************************************/ +/* + * + * + * + */ +/**************************************************************************************************/ +int TrialSwap2::sim8(vector columntotal, vector rowtotal, vector > &co_matrix) +{ + try { + double prob; + double start = 0.0; + int ncols = columntotal.size(); int nrows = rowtotal.size(); + double probarray[nrows * ncols]; + double randnum; + int grandtotal; + int total = 0; + + //double colSum = accumulate( columntotal.begin(), columntotal.end(), 0 ); + double rowSum = accumulate( rowtotal.begin(), rowtotal.end(), 0 ); + + if (m->control_pressed) { return 0; } + + //cout << "rowsum: " << rowSum << endl; + + grandtotal = rowSum; + + //create probability matrix with each site being between 0 and 1 + for (int i=0;icontrol_pressed) { return 0; } + for (int j=0;jcontrol_pressed) { return 0; } + randnum = rand() / double(RAND_MAX); + //cout << "rand num: " << randnum << endl; + if((randnum <= probarray[0]) && (probarray[0] != 2) ) { + probarray[0] = 2; + total++; + continue; + } + for(int i=1;i<(nrows*ncols);i++) { + if (m->control_pressed) { return 0; } + if((randnum <= probarray[i]) && (randnum > probarray[i-1]) && (probarray[i] != 2) ) { + probarray[i] = 2; + total++; + break; + } + else + continue; + } + } + //cout << "prbarray" << endl; + //for(int i=0;i<(nrows*ncols);i++) + //cout << probarray[i] << " "; + //cout << endl; + for(int i=0;icontrol_pressed) { return 0; } + for(int j=0;jerrorOut(e, "TrialSwap2", "sim8"); + exit(1); + } +} +/**************************************************************************************************/ +int TrialSwap2::havel_hakimi(vector rowtotal,vector columntotal,vector > &co_matrix) +{ + try { + int nrows = co_matrix.size(); + int ncols = co_matrix[0].size(); + int i,j,k; + vector r1; r1.resize(nrows,0); + vector c; c.resize(ncols,0); + vector c1; c1.resize(ncols,0); + + + for(i=0;icontrol_pressed) { return 0; } + i=intrand(nrows); + while(r1[i]==0) { + if (m->control_pressed) { return 0; } + i=intrand(nrows); + } + r1[i]=0; + sho(c,c1,ncols); + for(j=0;jcontrol_pressed) { return 0; } + co_matrix[i][c1[j]]=1; + c[j]--; + if(c[j]<0) + m->mothurOut("Uhh! " + toString(c1[j]) + "\n"); + } + } + return 0; + } + catch(exception& e) { + m->errorOut(e, "TrialSwap2", "havel_hakimi"); + exit(1); + } +} +/**************************************************************************************************/ +int TrialSwap2::sho(vector c, vector c1, int k) +{ + try { + int i,j,temp; + + for(j=k-1;j>0;j--) + { + if (m->control_pressed) { return 0; } + for(i=0;icontrol_pressed) { return 0; } + i=intrand(k-1); + if(c[i]==c[i+1]) + { + temp=c[i]; + c[i]=c[i+1]; + c[i+1]=temp; + temp=c1[i]; + c1[i]=c1[i+1]; + c1[i+1]=temp; + } + } + return(0); + } + catch(exception& e) { + m->errorOut(e, "TrialSwap2", "sho"); + exit(1); + } +} +/**************************************************************************************************/ +double TrialSwap2::calc_c_score (vector > &co_matrix,vector rowtotal) +{ + try { + double cscore = 0.0; + double maxD; + double D; + double normcscore = 0.0; + int nonzeros = 0; + int ncols = co_matrix[0].size(); int nrows = rowtotal.size(); + vector > s(nrows, vector(nrows,0.0)); //only fill half the matrix + + for(int i=0;icontrol_pressed) { return 0; } + for(int k=0;kerrorOut(e, "TrialSwap2", "calc_c_score"); + exit(1); + } +} +/**************************************************************************************************/ +int TrialSwap2::calc_checker (vector > &co_matrix, vector rowtotal) +{ + try { + int cunits=0; + //int s[nrows][ncols]; + int ncols = co_matrix[0].size(); int nrows = rowtotal.size(); + vector > s(nrows, vector(nrows,0)); //only fill half the matrix + + for(int i=0;icontrol_pressed) { return 0; } + //s[i][j]=0; + for(int k=0;kerrorOut(e, "TrialSwap2", "calc_checker"); + exit(1); + } +} +/**************************************************************************************************/ +double TrialSwap2::calc_vratio (vector rowtotal, vector columntotal) +{ + try { + int nrows = rowtotal.size(); + int ncols = columntotal.size(); + int sumCol = accumulate(columntotal.begin(), columntotal.end(), 0 ); + // int sumRow = accumulate(rowtotal.begin(), rowtotal.end(), 0 ); + + double colAvg = (double) sumCol / (double) ncols; + // double rowAvg = (double) sumRow / (double) nrows; + + double p = 0.0; + + // double totalRowVar = 0.0; + double rowVar = 0.0; + double colVar = 0.0; + + for(int i=0;icontrol_pressed) { return 0; } + p = (double) rowtotal[i]/(double) ncols; + rowVar += p * (1.0-p); + } + + for(int i=0;icontrol_pressed) { return 0; } + colVar += pow(((double) columntotal[i]-colAvg),2); + } + + colVar = (1.0/(double)ncols) * colVar; + + return colVar/rowVar; + } + catch(exception& e) { + m->errorOut(e, "TrialSwap2", "calc_vratio"); + exit(1); + } + +} +/**************************************************************************************************/ +int TrialSwap2::calc_combo (vector > &initmatrix) +{ + try { + int initrows = initmatrix.size(); + int unique = 0; + int match = 0; + int matches = 0; + for(int i=0;icontrol_pressed) { return 0; } + if( (initmatrix[i] == initmatrix[j])) + { + match++; + matches++; + break; + } + } + + //on the last iteration of a previously matched row it will add itself because it doesn't match any following rows, so that combination is counted + if (match == 0) + unique++; + } + return unique; + } + catch(exception& e) { + m->errorOut(e, "TrialSwap2", "calc_combo"); + exit(1); + } +} +/**************************************************************************************************/ +int TrialSwap2::swap_checkerboards (vector > &co_matrix) +{ + try { + int ncols = co_matrix[0].size(); int nrows = co_matrix.size(); + int i, j, k, l; + i=intrand(nrows); + while((j = intrand(nrows) ) == i ) {;if (m->control_pressed) { return 0; }} + k=intrand(ncols); + while((l = intrand(ncols) ) == k ) {;if (m->control_pressed) { return 0; }} + //cout << co_matrix[i][k] << " " << co_matrix[j][l] << endl; + //cout << co_matrix[i][l] << " " << co_matrix[j][k] << endl; + //cout << co_matrix[i][l] << " " << co_matrix[j][k] << endl; + //cout << co_matrix[i][l] << " " << co_matrix[j][k] << endl; + 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]; + //cout << "swapped!" << endl; + } + //cout << "i: " << i << " j: " << j << " k: " << " l: " << l << endl; + return 0; + } + catch(exception& e) { + m->errorOut(e, "TrialSwap2", "swap_checkerboards"); + exit(1); + } +} +/**************************************************************************************************/ +double TrialSwap2::calc_pvalue_greaterthan (vector scorevec, double initialscore) +{ + try { + int runs = scorevec.size(); + double p = 0.0; + for( int i=0;icontrol_pressed) { return 0; } + if(scorevec[i]>=initialscore) + p++; + } + return p/(double)runs; + } + catch(exception& e) { + m->errorOut(e, "TrialSwap2", "calc_pvalue_greaterthan"); + exit(1); + } +} +/**************************************************************************************************/ +double TrialSwap2::calc_pvalue_lessthan (vector scorevec, double initialscore) +{ + try { + int runs = scorevec.size(); + double p = 0.0; + for( int i=0;icontrol_pressed) { return 0; } + if(scorevec[i]<=initialscore) + p++; + } + return p/(double)runs; + } + catch(exception& e) { + m->errorOut(e, "TrialSwap2", "calc_pvalue_lessthan"); + exit(1); + } +} +/**************************************************************************************************/ +double TrialSwap2::t_test (double initialscore, int runs, double nullMean, vector scorevec) +{ + try { + double t; + double sampleSD; + double sum = 0; + + for(int i=0;icontrol_pressed) { return 0; } + sum += pow((scorevec[i] - nullMean),2); + //cout << "scorevec[" << i << "]" << scorevec[i] << endl; + } + + m->mothurOut("nullMean: " + toString(nullMean)); m->mothurOutEndLine(); + + m->mothurOut("sum: " + toString(sum)); m->mothurOutEndLine(); + + sampleSD = sqrt( (1/runs) * sum ); + + m->mothurOut("samplSD: " + toString(sampleSD)); m->mothurOutEndLine(); + + t = (nullMean - initialscore) / (sampleSD / sqrt(runs)); + + return t; + } + catch(exception& e) { + m->errorOut(e, "TrialSwap2", "t_test"); + exit(1); + } +} +/**************************************************************************************************/ +int TrialSwap2::print_matrix(vector > &matrix, int nrows, int ncols) +{ + try { + m->mothurOut("matrix:"); m->mothurOutEndLine(); + + for (int i = 0; i < nrows; i++) + { + if (m->control_pressed) { return 0; } + for (int j = 0; j < ncols; j++) + { + m->mothurOut(toString(matrix[i][j])); + } + m->mothurOutEndLine(); + } + return 0; + } + catch(exception& e) { + m->errorOut(e, "TrialSwap2", "print_matrix"); + exit(1); + } +} +/**************************************************************************************************/ +int TrialSwap2::transpose_matrix (vector > &initmatrix, vector > &co_matrix)//, int nrows, int nocols) +{ + try { + int ncols = initmatrix.size(); int nrows = initmatrix[0].size(); + int tmpnrows = nrows; + //vector > tmpvec; + vector tmprow; + if(!co_matrix.empty()) + co_matrix.clear(); + for (int i=0;icontrol_pressed) { return 0; } + for (int j=0;jerrorOut(e, "TrialSwap2", "transpose_matrix"); + exit(1); + } +} +/**************************************************************************************************/ +int TrialSwap2::update_row_col_totals(vector > &co_matrix, vector &rowtotal, vector &columntotal) +{ + try { + //rowtotal.clear(); + //columntotal.clear(); + //generate (rowtotal.begin(), rowtotal.end(), 0); + //generate (columntotal.begin(), columntotal.end(), 0); + int nrows = co_matrix.size(); + int ncols = co_matrix[0].size(); + vector tmpcolumntotal(ncols, 0); + vector tmprowtotal(nrows, 0); + + int rowcount = 0; + + for (int i = 0; i < nrows; i++) + { + if (m->control_pressed) { return 0; } + for (int j = 0; j < ncols; j++) + { + if (co_matrix[i][j] == 1) + { + rowcount++; + tmpcolumntotal[j]++; + } + } + tmprowtotal[i] = rowcount; + rowcount = 0; + } + columntotal = tmpcolumntotal; + rowtotal = tmprowtotal; + /*cout << "rowtotal: "; + for(int i = 0; ierrorOut(e, "TrialSwap2", "update_row_col_totals"); + exit(1); + } +} +/**************************************************************************************************/ +/*int main(int argc, char *argv[]) +{ + srand (time(0)); + char* input_filename = argv[1]; + std::ifstream infile (input_filename); + + //skip the first line of headers + getline(infile, line); + //get the first line of data + getline(infile, line); + + nrows = 0; + ncols = 0; + + //int numspaces = 0; + char nextChar; + + for (int i=0; i > co_matrix;//[nrows][ncols]; + vector > initmatrix; + vector tmprow; + vector stats; + int tmpnrows = nrows; + + for (int row1=0; row1> tmp; + + for (int col=0; col> tmp; + //cout << tmp << endl; + if (atoi(tmp.c_str()) > 0) + tmprow.push_back(1); + else + tmprow.push_back(0); + } + if (accumulate( tmprow.begin(), tmprow.end(), 0 ) == 0) + { + tmpnrows--; + } + else + initmatrix.push_back(tmprow); + //add the row to the matrix + //initmatrix.push_back(tmprow); + tmprow.clear(); + //cout << tmprow << endl; + } + + infile3.close(); + nrows = tmpnrows; + + //print init matrix + /* cout << "original matrix:" << endl; + + for (int i = 0; i < nrows; i++) + { + for (int j = 0; j < ncols; j++) + { + cout << initmatrix[i][j]; + } + cout << endl; + } */ + + //for (i=0;i columntotal(ncols, 0); + vector initcolumntotal(ncols, 0); + vector initrowtotal(nrows, 0); + vector rowtotal(nrows, 0); + + transpose_matrix(initmatrix,co_matrix); + //remove degenerate rows and cols + + //cout << "transposed matrix:" << endl; + int rowcount = 0; + for (int i = 0; i < nrows; i++) + { + for (int j = 0; j < ncols; j++) + { + if (co_matrix[i][j] == 1) + { + rowcount++; + columntotal[j]++; + } + //cout << co_matrix[i][j]; + } + //cout << " row total: " << rowcount << endl; + //cout << endl; + rowtotal[i] = rowcount; + rowcount = 0; + } + + initcolumntotal = rowtotal; + initrowtotal = columntotal; + + cout << endl; + + runs = atol(argv[2]); + int metric = atol(argv[3]); + int nullModel = atol(argv[4]); + double initscore; + update_row_col_totals(co_matrix, rowtotal, columntotal, ncols, nrows); + //do initial metric: checker, c score, v ratio or combo + switch(metric) + { + case 1: + //c score + initscore = calc_c_score(co_matrix, rowtotal); + cout << "initial c score: " << initscore << endl; + //print_matrix(co_matrix, nrows, ncols); + break; + + case 2: + //checker + initscore = calc_checker(co_matrix, rowtotal); + cout << "initial checker score: " << initscore << endl; + break; + + case 3: + //v ratio + initscore = calc_vratio(nrows, ncols, rowtotal, columntotal); + cout << "initial v ratio: " << initscore << endl; + break; + + case 4: + //combo + initscore = calc_combo(initrows, initcols, initmatrix); + cout << "initial combo score: " << initscore << endl; + //set co_matrix equal to initmatrix because combo requires row comparisons + co_matrix = initmatrix; + break; + + case 5: + //test! + + //print_matrix(co_matrix, nrows, ncols); + //sim1(nrows, ncols, co_matrix); + //sim2(nrows, ncols, co_matrix); + //sim3(initrows, initcols, initmatrix); + //sim4(columntotal, rowtotal, co_matrix); + //sim5(initcolumntotal, initmatrix); + //sim6(columntotal, co_matrix); + //sim7(initcolumntotal, initmatrix); + sim8(columntotal, rowtotal, co_matrix); + //print_matrix(initmatrix, initrows, initcols); + //print_matrix(co_matrix, nrows, ncols); + + break; + + default: + cout << "no metric selected!" << endl; + return 1; + + } + + //matrix initialization + //havel_hakimi(nrows, ncols, rowtotal, columntotal, co_matrix); + //sum_of_square(nrows, ncols, rowtotal, columntotal, co_matrix); + //co-matrix is now a random matrix with the same row and column totals as the initial matrix + + //null matrix burn in + cout << "initializing null matrix..."; + for(int l=0;l<10000;l++) + { + //swap_checkerboards (co_matrix); + //if(l%10 == 0) + switch(nullModel) + { + case 1: + // + sim1(nrows, ncols, co_matrix); + break; + + case 2: + //sim2 + sim2(nrows, ncols, co_matrix); + //sim2plus(nrows, ncols, initrowtotal, co_matrix); + break; + + case 3: + //sim3 + sim3(initrows, initcols, initmatrix); + //transpose_matrix(initmatrix,co_matrix); + co_matrix = initmatrix; + break; + + case 4: + //sim4 + sim4(columntotal, rowtotal, co_matrix); + break; + + case 5: + //sim5 + sim5(initcolumntotal, initrowtotal, initmatrix); + transpose_matrix(initmatrix,co_matrix); + //co_matrix = initmatrix; + break; + + case 6: + sim6(columntotal, co_matrix); + break; + + case 7: + //sim7(ncols, nrows, initrowtotal, co_matrix); + //transpose_matrix(initmatrix,co_matrix); + //co_matrix = initmatrix; + break; + + case 8: + sim8(columntotal, rowtotal, co_matrix); + break; + + case 9: + //swap_checkerboards + swap_checkerboards (co_matrix); + break; + + default: + cout << "no null model selected!" << endl; + return 1; + } + } + cout << "done!" << endl; + + //generate null matrices and calculate the metrics + + cout << "run: " << endl; + for(int trial=0;trial