// usage bestcuts #include #include #include "linklist.h" // global variables int ncoord, nlines, SoughtIdt; // basic run parameters double ulower[100] ; // maximal # of variables = 100 double llower[100] ; // min lower boundary limit double uupper[100] ; // max upper boundary limit double lupper[100] ; // min upper boundary limit double lstep[100] ; // lower boundary step double ustep[100] ; // upper boundary step Bool iscontinuous[100]; // is thi var. continuous double **Data ; // the array for holding data double bestvalues[100]; short nbest; double mark[4]; double purstep[3]; int d = 0 ; ofstream OutFile; // functions void ReadData ( char* DataName, double** &Data ) ; inline void TheLoop ( int c ) ; // c - recursion counter void panic (char*) ; int main (int argc, char* argv[]) { char* DataName = new char[100]; char* InfoName = new char[100]; char* OutName = new char[100]; ifstream InfoFile; unsigned int c = 0 ; // counter of recursion if (argc != 4) panic ("bestcuts "); DataName = argv[1]; // name of data file InfoName = argv[2]; // name of info file OutName = argv[3]; // name of output file InfoFile.open (InfoName, ios::nocreate ) ; // reading run parameters from info file. InfoFile >> mark[0] >> mark[1] >> mark[2] >> mark[3]; InfoFile >> purstep[0] >> purstep[1] >> purstep[2]; double dnt1, dnt2; for (dnt1 = 0; dnt1 < 3; dnt1++) { for (dnt2 = mark[cnt1] ; dnt2 <= mark[cnt1+1] ; dnt2 += purstep[cnt1]) { bestvalues[d][0] = dnt2 ; bestvalues[d++][1] = 0 ; } } d-- ; InfoFile >> ncoord ; // number of coords in data file, not incl. idt if (ncoord > 100) panic ("Too many coordinates. Maximal = 100"); InfoFile >> nlines ; // number of lines in DataFile if (ncoord*nlines > 5000000) panic ("Too big sample"); // max. RAM InfoFile >> SoughtIdt; // sought idt InfoFile >> suppresion; // suppression char letter; for (int cnt1 = 0; cnt1 < ncoord; cnt1++ ) // setting borders { InfoFile >> llower[cnt1]; InfoFile >> letter; if (letter == 'y' || letter == 'Y') iscontinuous[cnt1] = TRUE; else iscontinuous[cnt1] = FALSE; InfoFile >> ulower[cnt1]; InfoFile >> lupper[cnt1]; InfoFile >> uupper[cnt1]; InfoFile >> lstep[cnt1]; InfoFile >> ustep[cnt1]; } ReadData (DataName, Data); // setting the array Data OutFile.open (OutName) ; TheLoop (0); OutFile.close (); return 1; } // the main loop inline void TheLoop ( int c ) // c - recursion counter { double cup[100], clow[100]; unsigned int ntrue = 0, nfalse = 0 ; double efficiency, purity ; // loops over upper and lower cut on each variable for ( cup[c] = lupper[c] ; cup[c] <= uupper[c] ; cup[c] += ustep[c] ) { for ( clow[c] = llower[c]; clow[c] <= ulower[c]; clow[c] += lstep[c] ) { if ( c < ncoord-1 ) TheLoop (c+1) ; // next recursion step // else for ( int cnt1 = 0 ; cnt1 < nlines ; cnt1++ ) // loop over points { Bool match = TRUE; // does a point match cuts ? for (int cnt2 = 0; cnt2 < ncoord; cnt2++) //loop over coords { if ( Data[cnt1][cnt2] > cup[cnt2] || Data[cnt1][cnt2] < clow [cnt2] ) match = FALSE; } if (match && Data[cnt1][ncoord] == SoughtIdt) ntrue++; else if (match) nfalse++; } // ------------------------ writing output for ( int cnt3 = 0 ; cnt3 < ncoord ; cnt3++ ) OutFile << llower[cnt3] << " " << ulower[cnt3] << " " << lupper[cnt3] << " " << uupper[cnt3]; efficiency = ntrue / (double)nlines; purity = ntrue / ((double) ntrue + suppression * nfalse) ; while (int cnt = 1 ; purity < bests[cnt][0] && cnt bests[cnt][1]) bests[cnt][1] = efficiency; ntrue = nfalse = 0; // wrongly and truly found # of pts set 0 } } } // reading data file into memory. void ReadData (char* DataName, double** &Data) { ifstream DataFile; DataFile.open (DataName, ios::nocreate); Data = new double* [nlines]; for ( unsigned long cnt1 = 0 ; cnt1 < nlines; cnt1++ ) { Data[cnt1] = new double [ncoord]; for (int cnt2 = 0; cnt2 <= ncoord; cnt2++ ) { DataFile >> Data[cnt1][cnt2]; if ( DataFile.eof() ) panic ( "Unexpected data EOF in FindNeighbours" ); } } DataFile.close (); } void panic (char *phrase) { cout << phrase << endl ; exit (0); }