void print_run_summary(sampler *samp){ /* Stop the global timer and print a small summary of the run. Input: sampler *samp Pointer to sampler structure which has been initialized. Sampling must be performed before running this routine. Output: Print a short summary of the run, including sample rate and acceptance rate. Print the the mean and standard deviation of all components sampled. */ double elapsed_sample = timestamp_diff_in_seconds(samp->time1, samp->time2); double elapsed_total = timestamp_diff_in_seconds(samp->time1_total, samp->time2_total); // -------------------------------------------------------------------------- // check output // -------------------------------------------------------------------------- printf("Time steps = %d\n", samp->M); printf("Total samples = %d\n", samp->M * samp->K); printf("ldim = %d\tgdim = %d\n", (int) samp->ldim[0], (int) samp->gdim[0]); printf("Total accepted = %lu\n", samp->accepted_total); printf("Acceptance rate = %f\n", (cl_float) samp->accepted_total / ((cl_float) (samp->M * samp->K)) ) ; printf("Time for kernel runs = %f\n", elapsed_sample); printf("Sample rate, kernel time only = %f million samples / s\n", samp->M * samp->K * 1e-6 / elapsed_sample); printf("Total time = %f\n", elapsed_total); printf("Sample rate, total time = %f million samples / s\n", samp->M * samp->K * 1e-6 / elapsed_total); printf("\n"); // Basic numerical estimate of mean and standard deviation of each component in the chain double mean, sigma; float *X = (float *) malloc(samp->total_samples * sizeof(float)); if(!X){ perror("Allocation failure basic stats"); abort(); } for(int i=0; i<samp->num_to_save; i++){ for(int j=0; j<samp->total_samples; j++) X[j] = samp->samples_host[i + j * (samp->num_to_save)]; compute_mean_stddev(X, &mean, &sigma, samp->total_samples); printf("Statistics for X_%d:\t", samp->indices_to_save_host[i]); printf("Mean = %f,\tsigma = %f\n", mean, sigma); } printf("\n"); free(X); }
bool cv_normalizer::determine_transform(const cv::Mat& image) { reset(); _LBANN_SILENT_EXCEPTION(image.empty(), "", false) if (!check_to_enable()) { return false; } normalization_type ntype = _none; if (m_unit_scale) { set_normalization_type(ntype, _u_scale); } if (m_mean_subtraction) { set_normalization_type(ntype, _mean_sub); } if (m_unit_variance) { set_normalization_type(ntype, _unit_var); } if (m_z_score) { set_normalization_type(ntype, _z_score); } ComputeType u_scale = 1.0; ComputeType largest = 1.0; //if (!m_z_score && m_unit_scale) { if (ntype < _z_score) { // !(m_z_score || (m_mean_subtraction && m_unit_variance)) switch(image.depth()) { case CV_8U: largest = std::numeric_limits<uint8_t>::max(); break; case CV_8S: largest = std::numeric_limits<int8_t>::max(); break; case CV_16U: largest = std::numeric_limits<uint16_t>::max(); break; case CV_16S: largest = std::numeric_limits<int16_t>::max(); break; case CV_32S: largest = std::numeric_limits<int32_t>::max(); break; default: return false; // Currently, do nothing for non-integral types. However, a set of scaling // paramters can be added to the argument list of this function. } u_scale = static_cast<ComputeType>(1.0)/largest; } std::vector<ComputeType> mean; std::vector<ComputeType> stddev; const normalization_type code_wo_uscale = mask_normalization_bits(ntype, _z_score); const auto NCh = static_cast<size_t>(image.channels()); if (code_wo_uscale != _none) { if (!compute_mean_stddev(image, mean, stddev) || (NCh != mean.size())) { return false; } #if 0 for (int ch = 0; ch < image.channels(); ++ch) { std::cout << "channel " << ch << "\tmean " << mean[ch] << "\tstddev " << stddev[ch] << std::endl; } #endif } m_trans.resize(NCh); switch (code_wo_uscale) { case _none: // Note that mean.size() is zero in this case for (size_t ch=0u; ch < NCh; ++ch) { m_trans[ch] = channel_trans_t(u_scale, 0.0); } break; case _mean_sub: for (size_t ch=0u; ch < NCh; ++ch) { m_trans[ch] = channel_trans_t(u_scale, - u_scale * mean[ch]); } break; case _unit_var: for (size_t ch=0u; ch < NCh; ++ch) { if (stddev[ch] > fabs(mean[ch])*(1e-7)) { m_trans[ch] = channel_trans_t(static_cast<ComputeType>(1.0)/stddev[ch], u_scale * mean[ch] - mean[ch]/stddev[ch]); } else { m_trans[ch] = channel_trans_t(u_scale, 0.0); } } break; case _z_score: for (size_t ch=0u; ch < NCh; ++ch) { if (stddev[ch] > fabs(mean[ch])*(1e-7)) { m_trans[ch] = channel_trans_t(static_cast<ComputeType>(1.0)/stddev[ch], - mean[ch]/stddev[ch]); } else { m_trans[ch] = channel_trans_t(0.0, 0.0); } } break; default: return false; } m_enabled = true; return true; }
void extractU_Shapelets(double **pd_Dataset, int* ds_len, int n_sample, int sLen, int app_no, char app[][100], char file[][100], char*outputname, int start_ts_id) { int sl; int i; int iter = 0; int cluster_id[n_sample]; double *ts; int ts_len; int cnt; int newsize; int k,j,l; int index, index2; double mean, stddev, range; /*Empty discriminatory ushapelets*/ double* ushapelet[n_sample]; int ushapelet_len[n_sample]; ts = pd_Dataset[start_ts_id]; ts_len = ds_len[start_ts_id]; printf("\nextractU_Shapelet\n"); memset(cluster_id, -1, n_sample *sizeof(int)); FILE *fp; fp = fopen(outputname, "a"); if(!fp) { perror(outputname); return; } fprintf(fp, "\n\n\nNew Clustering Batch------------------------------\n"); fprintf(fp,"************************\n"); fprintf(fp, "Iteration %d\n", iter); fprintf(fp, "Application %s\n Dataset path %s\n", app[start_ts_id], file[start_ts_id]); while(1) { cnt = 0; newsize = 0; for(sl=sLen-LOWER; sl <= sLen+UPPER && sl <= ts_len; sl+=STEP) { cnt += (ts_len - sl+1); // printf("sl = %d ts_len =%d cnt = %d\n", sl, ts_len, cnt); } double* p_subseq[cnt]; int ps_len[cnt]; double gap[cnt]; double dt[cnt]; for (k = 0, j= 0 ; k< n_sample; k++) { if(cluster_id[k] == -1) newsize++; } double* n_dataset[newsize]; int n_datalen[newsize]; int k,j; int old_id[n_sample]; memset(old_id, 0, newsize*sizeof(int)); /*create new unclustered data set*/ for (k = 0, j= 0 ; k< n_sample; k++) { if(cluster_id[k] == -1) { // copy the data set and len and keep a mapping n_dataset[j] = pd_Dataset[k]; n_datalen[j] = ds_len[k]; old_id[j] = k; j++; } } double dist[newsize]; /*index of the distance within threshold*/ int dataset_A[newsize];//--------Check: declared in both gobal and local int dataset_Alen;//--------Check: declared in both gobal and local memset(dataset_A, -1, newsize *sizeof(int)); /*********VERIFY*******/ if(ts_len < sLen) { printf(" The time series is too short to classify\n"); break; // break? } int cluster_no = app_no; /*****VERIFY END****/ cnt = 0; /*For all possible subsequences for a timeseries from the new dataset*/ for(sl=sLen-LOWER; sl <= sLen+UPPER && sl <= ts_len; sl+=STEP) { //printf("sl is %d ts_len -sl +1 is %d \n\n", sl, ts_len - sl + 1); for(i=0; i< ts_len - sl +1; i++) { p_subseq[cnt] = ts + i; ps_len[cnt] = sl; /*Compute the gap and threshold for each of the subsequence*/ gap[cnt] = computeGap(&dt[cnt], cluster_no, p_subseq[cnt], ps_len[cnt], n_dataset, newsize , n_datalen); //printf("i=%d sl=%d ps_len=%d cnt = %d\n", i, sl, ps_len[cnt], cnt); //printf("gap is %2.6f dt is %2.6f\n", gap[cnt], dt[cnt]); cnt++; } } /*Find the subsequence which gives the maximum gap for the dataset*/ printf("max gap is %d\n", cnt); index = max_index(gap, cnt); /*Add the discriminatory subsequence to the ushapelet list*/ printf("Discovered ushapelet gap is %2.6f dt is %2.6f index %d len %d\n", gap[index], dt[index], index, ps_len[index]); fprintf(fp, "Shapelet: "); for(k=0; k<ps_len[index]; k++) fprintf(fp,"%2.2f ", p_subseq[index][k]); printf("\n"); ushapelet[iter] = p_subseq[index]; ushapelet_len[iter] = ps_len[index]; fprintf(fp, "Shapelet len: %d\n",ps_len[index]); dataset_Alen = 0; j=0; for(l=0; l<newsize; l++) { /*Compute the minimum distance of the shapelet from each of the dataset */ dist[l]= computeDistance(p_subseq[index], ps_len[index], n_dataset[l], n_datalen[l]); /*If the computed distance is less than threshold then add to Dataset A*/ if (CompareDoubles2(dist[l], dt[index]) <= 0) { //printf("distance within threshold %2.2f %2.2f %d\n", dist[l], dt[index], l); dataset_A[j] = l; j++; dataset_Alen++; } } if(clustered(dataset_Alen, newsize)) break; else { mean = 0.0; stddev = 0.0; range = 0.0; /*Compute the mean standard deviation and range of the Dataset A*/ compute_mean_stddev(dataset_A, dataset_Alen, dist, newsize, &mean, &stddev); range = mean + stddev; //printf("%2.2f is the range mean %2.2f stddev %2.2f \n", range, mean, stddev); /*Exclude all the dataset within the range by marking it as clustered*/ for (k = 0, j= 0 ; k< newsize; k++) { if(CompareDoubles2(dist[k], range) <= 0) { //printf("Clustered dataset %d\n", old_id[k]); fprintf(fp, "Appname: %s Filename: %s\n", app[old_id[k]], file[old_id[k]]); cluster_id[old_id[k]] = iter; } } /*Find the dataset far away from the ushapelet*/ //printf("max distance is at %d\n", newsize); index2 = max_index(dist, newsize); ts = n_dataset[index2]; //printf("Finding next data set is at %d\n", index2); fprintf(fp,"************************\n"); fprintf(fp, "Iteration %d\n", iter+1); fprintf(fp, "Application %s\n Dataset path %s\n", app[old_id[index2]], file[old_id[index2]]); } ++iter; } fprintf(fp,"************************\n"); fprintf(fp, "Remaining set\n"); for( int z=0; z< n_sample; z++) { if(cluster_id[z]==-1) fprintf(fp, "Appname: %s Filename: %s\n", app[z], file[z]); } fclose(fp); printf("\n"); }