Пример #1
0
/* Select the Pivot Element .
	Strategy 1: Select a random sample of size O(logN) from the array and compute median 
				log to base 2 N is a good sampling choice as it scales well for smaller 
				and larger data sets alike
*/
int select_pivot(int low_idx, int high_idx)
{
    int i = 0;
    int N = floor_log2(high_idx - low_idx + 1); 		 
    int *random_indexes = calloc(N, sizeof(int));        
    // array
    double *random_elements = calloc(N, sizeof(double));        
    // array
    double final_median = 0;

    srand(time(NULL));          // Seed the RNG
    for (i = 0; i < N; i++) {
        random_indexes[i] = rand() % (high_idx - low_idx + 1) + low_idx;
        random_elements[i] = buf[random_indexes[i]];
    }
    final_median =
        (median_low(random_elements, N) +
         median_high(random_elements, N)) / 2;

    // Free allocated memory 
    free(random_indexes);
    free(random_elements);

    return final_median;
}
Пример #2
0
void scaling_norm(double *data, int rows, int cols, double trim, int baseline, int logscale){

  int i,j;

  double beta = 0.0;
  double mean_baseline = 0.0;
  double mean_treatment = 0.0;
  double med_intensity = 0.0;

  double *buffer;
  double *row_buffer;

  if (logscale){
    for (j=0; j < cols; j++){
      for(i=0; i < rows; i++){
	data[j*rows + i] = log(data[j*rows + i])/log(2.0);
      }
    }
  }



  if (baseline == -1){
    /* pick the array with median overall (total) intensity as baseline */
    buffer = Calloc(cols,double);
    for (j=0; j < cols; j++){
      for(i=0; i < rows; i++){
	buffer[j]+=data[j*rows + i];
      }
    }
    
    med_intensity = median_low(buffer, cols);
    for (j = 0; j < cols; j++){
      
      if (buffer[j] == med_intensity){
	baseline = j;
	break;
      }
    }
    Free(buffer);
    mean_baseline = mean_trim(&data[baseline*rows],rows,trim);
    
  } else if (baseline == -2){