void StateManager::PrintProb() { // calculate Pr(not even one omission) with equation (12) from CHARME // paper double l = pow(2, double (args->num_bits.value)); double m = NumStates; double n = min(m, /*the_states-> */ NumElts()); //gdp: approx cached algorithm double exp = (m + 1) * (harmonic(m + 1) - harmonic(m - n + 1)) - n; double pNO = pow(1 - 1 / l, (m + 1) * (harmonic(m + 1) - harmonic(m - n + 1)) - n); // print omission probabilities cout.precision(6); cout << "Omission Probabilities (caused by Hash Compaction):\n\n" << "\tPr[even one omitted state] <= " << 1 - pNO << "\n"; if (args->main_alg.mode == argmain_alg::Verify_bfs) cout << "\tPr[even one undetected error] <= " << 1 - pno << "\n" << "\tDiameter of reachability graph: " << currentLevel - 1 << "\n\n"; // remark: startstates had incremented the currentLevel counter else cout << "\n"; }
void StateManager::CheckLevel() // check if we are done with the level currently expanded { static double p = 1.0; // current bound on state omission probability static double l = pow(2, double(args->num_bits.value)); // l=2^b static double k = -1; // sum of the number of states - 1 static double m = NumStates; // size of the state table if (--statesCurrentLevel <= 0) // all the states of the current level have been expanded { // proceed to next level statesCurrentLevel = statesNextLevel; statesNextLevel = 0; // check if there are states in the following level if (statesCurrentLevel!=0) { currentLevel++; // calculate p_k with equation (2) from FORTE/PSTV paper for // the following level k += statesCurrentLevel; double pk = 1 - 2/l * (harmonic(m+1) - harmonic(m-k)) + ((2*m)+k*(m-k)) / (m*l*(m-k+1)); pno *= pk; } } }
void create_note(synth_note * sn, int note, int octave, float start_time, float len) { sn->note = note; sn->octave = octave; sn->start_time = start_time; sn->end_time = start_time + len; printf("Start Time: %f\n", sn->start_time); printf("End Time: %f\n", sn->end_time); //create sin waves sin_wave base; init(&base, 0.15, 0.0, get_frequency(note, octave)); create_envelope(&(sn->env), 0.1, len); sn->num_waves = 8; sn->waves = (sin_wave *) malloc(sizeof(sin_wave) * sn->num_waves); sn->waves[0] = base; harmonic(&(sn->waves[1]), &(sn->waves[0]), 2); harmonic(&(sn->waves[2]), &(sn->waves[0]), 3); harmonic(&(sn->waves[3]), &(sn->waves[0]), 4); harmonic(&(sn->waves[4]), &(sn->waves[0]), 5); harmonic(&(sn->waves[5]), &(sn->waves[0]), 6); harmonic(&(sn->waves[6]), &(sn->waves[0]), 7); harmonic(&(sn->waves[7]), &(sn->waves[0]), 8); }
int main(void) { double x, y; double result; printf("Enter two floating-point numbers (q to quit): _\b"); while (scanf("%lf %lf", &x, &y) == 2) { result = harmonic(x,y); printf("\nThe harmonic average value is %g\n", result); printf("\nEnter two floating-point numbers (q to quit): _\b"); } return 0; }
int main() { prepare(); int T; scanf("%d", &T); int ncase = 0; while (T--) { scanf("%d", &n); printf("Case %d: %.10lf\n", ++ncase, harmonic(n)); } return 0; }
int main() { /* double sum = 0; */ int i; int upto = 5; double log_val; double harmonic_val; int N; for (i = 0;i <= upto;i++) { N = (int) pow(10, i); log_val = log(N + 1); harmonic_val = harmonic(N); printf("%lf, %lf\n", log_val, harmonic_val); } return 0; }
void mean::entry() { sc_signed i(24); // Will hold input a sc_signed j(24); // Will hold input b sc_signed k(24); // Will hold input c sc_signed l(24); // Will hold input d sc_signed arith(24); // Arithmetic mean sc_signed geom(24); // Geometric mean sc_signed harmonic(24); // Harmonic mean while (true) { // read all inputs send_input.write(true); do { wait(); } while (data_available != true); i = in.read().to_int(); wait(); j = in.read().to_int(); wait(); k = in.read().to_int(); wait(); l = in.read().to_int(); send_input.write(false); // Calculate arithmetic mean arith = (i + j + k + l) / 4; // Calculate geometric mean calculate_geometric_mean(i, j, k, l, geom); // Calculate harmonic mean calculate_harmonic_mean(i, j, k, l, harmonic); // write all outputs do { wait(); } while (receiver_ready != true); data_ready.write(true); wait(); out.write(arith); wait(); out.write(geom); wait(); out.write(harmonic); wait(); data_ready.write(false); } } // end of entry function
void execute(const Param& tParam) { //printf("Backup BotID: %d\n",botID); /* assert Added by Soumyadeep */ // assert(state->oppNum > 2); //int attackBot = getattackbotID(); //int attackBot = tParam.BackupP.BotID; Vector2D<int> target = harmonic(); //target = cooperateWith(target , attackBot); SkillSet::addCircle(target.x, target.y, 50, 0x00); float lookat = looking_angle(target); sID = SkillSet::GoToPoint; sParam.GoToPointP.align = false; sParam.GoToPointP.finalslope = lookat; sParam.GoToPointP.x = target.x; sParam.GoToPointP.y = target.y; printf(" ( %d, %d )\n",target.x,target.y); skillSet->executeSkill(sID, sParam); }
void WorkerThread::createNewFilter() { // Free GPU memory from current filter and CUFFT cudaFree(_gabor_data); cudaFree(_gpu_image_0); cudaFree(_gpu_image_1); cufftDestroy(_fft_plan); float* gaussian_data; cudaMalloc((void**)&gaussian_data, sizeof(float) * _filter_pixels); int2 gaussian_size; gaussian_size.x = _filter_size; gaussian_size.y = _filter_size; int2 gaussian_center; gaussian_center.x = _filter_size / 2; gaussian_center.y = _filter_size / 2; gaussian(gaussian_data, _new_theta, _new_sigma, 1.0, gaussian_center, gaussian_size); float* harmonic_data; cudaMalloc((void**)&harmonic_data, sizeof(float) * _filter_pixels * 2); int2 harmonic_size; harmonic_size.x = _filter_size; harmonic_size.y = _filter_size; int2 harmonic_center; harmonic_center.x = _filter_size / 2; harmonic_center.y = _filter_size / 2; harmonic(harmonic_data, _new_theta, _new_lambda, _new_psi, harmonic_center, harmonic_size); float* host_harmonic = new float[_filter_size * _filter_size * 2]; cudaMalloc((void**)&_gabor_data, sizeof(float) * _filter_pixels * 2); int2 gabor_size; gabor_size.x = _filter_size; gabor_size.y = _filter_size; int2 gabor_center; gabor_center.x = _filter_size / 2; gabor_center.y = _filter_size / 2; multiplyRealComplex(gaussian_data, harmonic_data, _gabor_data, _filter_size * _filter_size); float* host_gabor_data = new float[_filter_pixels * 2]; cudaMemcpy(host_gabor_data, _gabor_data, sizeof(float) * _filter_pixels * 2, cudaMemcpyDeviceToHost); //pad the filter { float* data = host_gabor_data; float* target = _filter_image; memset(target, 0, sizeof(float) * _padded_pixels * 2); int padded_stride = 2 * _padded_size; int target_stride = 2 * _target_size; for (int i = 0; i < _target_size; ++i) { memcpy(target, data, sizeof(float) * target_stride); target += padded_stride; data += target_stride; } } // Copy gabor data into member for texture creation _filter_image_mutex.lock(); memcpy(_host_gabor_data, host_gabor_data, sizeof(float) * _filter_pixels * 2); _filter_image_mutex.unlock(); cudaFree(_gabor_data); cudaMalloc((void**)&_gabor_data, sizeof(float) * _padded_pixels * 2); cudaMalloc((void**)&_gpu_image_0, sizeof(float) * _padded_pixels * 2); cudaMalloc((void**)&_gpu_image_1, sizeof(float) * _padded_pixels * 2); cudaMemcpy(_gabor_data, _filter_image, sizeof(float) * _padded_pixels * 2, cudaMemcpyHostToDevice); cufftPlan2d(&_fft_plan, _padded_size, _padded_size, CUFFT_C2C); cufftExecC2C(_fft_plan, (cufftComplex*)(_gabor_data), (cufftComplex*)(_gabor_data), CUFFT_FORWARD); cudaMemcpy(_filter_image, _gabor_data, sizeof(float) * _padded_pixels * 2, cudaMemcpyDeviceToHost); // Free temporary GPU memory used for creation of filter cudaFree(gaussian_data); cudaFree(harmonic_data); delete host_harmonic; delete host_gabor_data; _should_create_new_filter = false; emit newFilterImage(); }
void WorkerThread::createInitialFilter() { float* gaussian_data; cudaMalloc((void**)&gaussian_data, sizeof(float) * _filter_pixels); int2 gaussian_size; gaussian_size.x = _filter_size; gaussian_size.y = _filter_size; int2 gaussian_center; gaussian_center.x = _filter_size / 2; gaussian_center.y = _filter_size / 2; gaussian(gaussian_data, 0.0, _sigma, 1.0, gaussian_center, gaussian_size); float* harmonic_data; cudaMalloc((void**)&harmonic_data, sizeof(float) * _filter_pixels * 2); int2 harmonic_size; harmonic_size.x = _filter_size; harmonic_size.y = _filter_size; int2 harmonic_center; harmonic_center.x = _filter_size / 2; harmonic_center.y = _filter_size / 2; harmonic(harmonic_data, 0, _lambda, 0.0, harmonic_center, harmonic_size); float* host_harmonic = new float[_filter_size * _filter_size * 2]; cudaMalloc((void**)&_gabor_data, sizeof(float) * _filter_pixels * 2); int2 gabor_size; gabor_size.x = _filter_size; gabor_size.y = _filter_size; int2 gabor_center; gabor_center.x = _filter_size / 2; gabor_center.y = _filter_size / 2; multiplyRealComplex(gaussian_data, harmonic_data, _gabor_data, _filter_size * _filter_size); float* host_gabor_data = new float[_filter_pixels * 2]; cudaMemcpy(host_gabor_data, _gabor_data, sizeof(float) * _filter_pixels * 2, cudaMemcpyDeviceToHost); //pad the filter { float* data = host_gabor_data; float* target = _filter_image; memset(target, 0, sizeof(float) * _padded_pixels * 2); int padded_stride = 2 * _padded_size; int target_stride = 2 * _target_size; for (int i = 0; i < _target_size; ++i) { memcpy(target, data, sizeof(float) * target_stride); target += padded_stride; data += target_stride; } } // Copy gabor data into member for texture creation _filter_image_mutex.lock(); memcpy(_host_gabor_data, host_gabor_data, sizeof(float) * _filter_pixels * 2); _filter_image_mutex.unlock(); cudaFree(_gabor_data); cudaMalloc((void**)&_gabor_data, sizeof(float) * _padded_pixels * 2); cudaMalloc((void**)&_gpu_image_0, sizeof(float) * _padded_pixels * 2); cudaMalloc((void**)&_gpu_image_1, sizeof(float) * _padded_pixels * 2); cudaMemcpy(_gabor_data, _filter_image, sizeof(float) * _padded_pixels * 2, cudaMemcpyHostToDevice); cufftPlan2d(&_fft_plan, _padded_size, _padded_size, CUFFT_C2C); cufftExecC2C(_fft_plan, (cufftComplex*)(_gabor_data), (cufftComplex*)(_gabor_data), CUFFT_FORWARD); cudaMemcpy(_filter_image, _gabor_data, sizeof(float) * _padded_pixels * 2, cudaMemcpyDeviceToHost); emit newFilterImage(); }
int StateManager::CheckLevel() // check if we are done with the level currently expanded { #ifdef HASHC static double p = 1.0; // current bound on state omission probability static double l = pow(2, double (args->num_bits.value)); // l=2^b static double k = -1; // sum of the number of states - 1 static double m = NumStates; // size of the state table #endif #if (DBG>10) //fprintf(stderr, "**CheckLevel(): statesCurrentLevel=%d, statesNextLevel=%d \n",statesCurrentLevel-1, statesNextLevel); #endif if (--statesCurrentLevel <= 0) // all the states of the current level have been expanded { //filter the level states & load the queue queue->CheckTable(); unsigned long deleted = queue->deletedstates(); statesNextLevel -= deleted; num_elts -= deleted; // proceed to next level statesCurrentLevel = statesNextLevel; statesNextLevel = 0; // check if there are states in the following level if (statesCurrentLevel != 0) { currentLevel++; //gdp: added to print begin level infos Reporter->print_level(); /* gdp: the following two test added for disk murphi */ if ((args->max_level.value > 0) && (currentLevel > args->max_level.value)) // stop exploration { Error.Notrace ("Reached depth %u exceedes max depth %u.\n\tStopping exploration", currentLevel, args->max_level.value); return (1); } #ifdef HASHC // calculate p_k with equation (2) from FORTE/PSTV paper for // the following level //k += statesCurrentLevel; k = min(m, k + statesCurrentLevel); //gdp: approx cached algorithm double pk = 1 - 2 / l * (harmonic(m + 1) - harmonic(m - k)) + ((2 * m) + k * (m - k)) / (m * l * (m - k + 1)); pno *= pk; #endif } } return (0); } /* CheckLevel() */
QString SGMXASScanConfiguration2013::detailedDescription() const{ return QString("XAS Scan from %1 to %2\nExit Slit: %3\nGrating: %4\nHarmonic: %5").arg(double(scanAxisAt(0)->regionAt(0)->regionStart())).arg(double(scanAxisAt(0)->regionAt(scanAxisAt(0)->regionCount()-1)->regionEnd())).arg(exitSlitGap(), 0, 'f', 1).arg(SGMBeamlineInfo::sgmInfo()->sgmGratingDescription(SGMBeamlineInfo::sgmGrating(grating()))).arg(SGMBeamlineInfo::sgmInfo()->sgmHarmonicDescription(SGMBeamlineInfo::sgmHarmonic(harmonic()))); }
int StateManager::CheckLevel() // check if we are done with the level currently expanded { #ifdef HASHC static double p = 1.0; // current bound on state omission probability static double l = pow(2, double (args->num_bits.value)); // l=2^b static double k = -1; // sum of the number of states - 1 static double m = NumStates; // size of the state table #endif if (--statesCurrentLevel <= 0) // all the states of the current level have been expanded { // proceed to next level statesCurrentLevel = statesNextLevel; statesNextLevel = 0; // check if there are states in the following level if (statesCurrentLevel != 0) { currentLevel++; //gdp: added to print begin level infos Reporter->print_level(); /* gdp: the following two tests added for cached murphi */ if ((args->max_level.value > 0) && (currentLevel > args->max_level.value)) // stop exploration { Error.Notrace ("Reached depth %u exceedes max depth %u.\n\tStopping exploration to prevent looping", currentLevel, args->max_level.value); return (1); } if ((args->max_collrate.value > 0) && (((double) NumOverwrites()) / ((double) NumElts()) > ((double) args->max_collrate.value / 100))) // stop exploration { Error.Notrace ("Collision rate %g exceeds max collision rate %g.\n\tStopping exploration to prevent looping.", ((double) NumOverwrites()) / ((double) NumElts()), ((double) args->max_collrate.value / 100)); return (2); } #ifdef HASHC // calculate p_k with equation (2) from FORTE/PSTV paper for // the following level //k += statesCurrentLevel; k = min(m, k + statesCurrentLevel); //gdp: approx cached algorithm double pk = 1 - 2 / l * (harmonic(m + 1) - harmonic(m - k)) + ((2 * m) + k * (m - k)) / (m * l * (m - k + 1)); pno *= pk; #endif } } return (0); } /* CheckLevel() */
int main() { harmonic(); return(0); }