#include #include #include #include #include #include void panic (char *str); int main (int argc, char* argv[] ) { // help if (argc < 3) { cout << "Info file format" << endl ; cout << "# of points of noise. # pts of signal" << endl; cout << "dimensionality" << endl ; cout << "grad_11 grad_21 bord_11 bord_21" << endl; cout << "......." << endl ; cout << "grad_1n grad_2n bord_1n bord_2n" << endl; cout << "(first index refers to number of distribution, " << endl ; cout << "second - to that of coordinate)" << endl; panic ("grad "); } // reading data, opening files ifstream infofile (argv[1]); ofstream outfile (argv[2]); int n1, n2, d; double c1[200], c2[200], grad1[200], grad2[200], bord1[200], bord2[200]; infofile >> n1 >> n2 >> d; int cnt ; for (cnt=0 ; cnt < d ; cnt++) infofile >> grad1[cnt] >> grad2[cnt] >> bord1[cnt] >> bord2[cnt]; // -------------loop over points double coord[200]; // seeding rand int SEED; system ("date +%M%S > dummy") ; ifstream dum ("dummy" ) ; dum >> SEED; system ("rm dummy") ; srand (SEED); int cnd; // ------------- NOISE int npts1; for (npts1 = 0 ; npts1 < n1 ; ) { for (cnt = 0 ; cnt < d ; cnt++ ) coord[cnt] = 2.*rand()/RAND_MAX; for (cnd = 0 ; cnd < d ; cnd++ ) if ( (rand()+1.)/RAND_MAX > 1+(coord[cnd]-bord1[cnd])*grad1[cnd] ) { npts1++; for (cnt = 0 ; cnt < d ; cnt++ ) outfile << coord[cnt] << " " ; outfile << 0 << endl; break; } } // ++++++++++"SIGNAL" int out; for (int cnt2 = 0 ; cnt2 < n2 ; ) { for (cnt = 0 ; cnt < d ; cnt++ ) coord[cnt] = 2.*rand()/RAND_MAX; out = 0 ; for (cnd = 0 ; cnd < d ; cnd++ ) { if ((rand()+1.)/RAND_MAX > 1 -(coord[cnd]-bord2[cnd])*grad2[cnd]) { out=1; break; } } //cout << out << endl; if (out == 0) { cnt2++; for (cnt = 0 ; cnt < d ; cnt++ ) outfile << coord[cnt] << " " ; outfile << 1 << endl; } } } void panic (char *string) { cerr << string << endl; exit (0); }