// // Programmer: Craig Stuart Sapp // Creation Date: Thu Dec 25 22:45:39 PST 2008 // Last Modified: Thu Dec 25 22:45:43 PST 2008 // Filename: ...sig/examples/all/noisesequence.cpp // Web Address: http://sig.sapp.org/examples/museinfo/humdrum/noisesequence.cpp // Syntax: C++; museinfo // // Description: Create a dissimilarity plot between two sequences. // #include "humdrum.h" #include /* for qsort and bsearch functions */ #include /* for random number seeding */ #include // function declarations: void checkOptions (Options& opts, int argc, char** argv); void example (void); void usage (const char* command); double getMean (Array& data); double getSampleSD (double mean, Array& data); double pearsonCorrelation (int size, double* x, double* y); void printData (Array& a, Array& b, int counter); void getSequences (Array& a, Array& b, int seqlength, double noiseadd); // User interface variables: Options options; int seqlength = 100; // used with -l option double corrtarget = 0.0; // used with -r option double corrtolerance = 0.00001; // used with -t option int limit = 1000; // used with -L option int randomseed = 0; // used with -s option double noiseadd = 0.0; // used witn -n option ////////////////////////////////////////////////////////////////////////// int main(int argc, char** argv) { // process the command-line options checkOptions(options, argc, argv); if (randomseed <= 0) { randomseed = time(NULL); // time in seconds } srand48(randomseed); Array a; Array b; getSequences(a, b, seqlength, noiseadd); double corr = pearsonCorrelation(seqlength, a.getBase(), b.getBase()); int counter = 1; while (counter < limit) { if (fabs(corr - corrtarget) < corrtolerance) { break; } getSequences(a, b, seqlength, noiseadd); corr = pearsonCorrelation(seqlength, a.getBase(), b.getBase()); counter++; } printData(a, b, counter); return 0; } ////////////////////////////////////////////////////////////////////////// ////////////////////////////// // // getSequence -- // void getSequences(Array& a, Array& b, int seqlength, double noiseadd) { a.setSize(seqlength); a.allowGrowth(0); b.setSize(seqlength); b.allowGrowth(0); int i; for (i=0; i& a, Array& b, int counter) { int i; int size = a.getSize(); double corr = pearsonCorrelation(seqlength, a.getBase(), b.getBase()); cout << "!!!correlation:\t" << corr << "\n"; cout << "!!!randomseed:\t" << randomseed << "\n"; cout << "!!!target:\t" << corrtarget << "\n"; if (fabs(corr - corrtarget) > corrtolerance) { cout << "!!!status:\tFAILED to match tolerance\n"; } cout << "!!!tolerance:\t" << corrtolerance << "\n"; cout << "!!!attempts:\t" << counter << "\n"; cout << "!!!length:\t" << seqlength << "\n"; if (noiseadd != 0.0) { cout << "!!!noiseadd:\t" << noiseadd << "\n"; } cout << "**seq\t**seq\n"; for (i=0; i& data) { int size = data.getSize(); double sum = 0.0; double value; int i; for (i=0; i& data) { int size = data.getSize(); if (size <= 0) { return 0.0; } int i; double sum = 0.0; for (i=0; i