<commit_before>#include "MixtureModelClustering.h"

MixtureModelClustering::MixtureModelClustering(EMatrix *ematrix, int min_obs,
    int num_jobs, int job_index, char **method, int num_methods,
    char * criterion, int max_clusters, double threshold,
    geneFilter *set1, geneFilter *set2)
  : PairWiseClustering(ematrix, min_obs, num_jobs, job_index) {

  // Initialize some values.
  this->max_clusters = max_clusters;
  this->criterion = criterion;
  this->method = method;
  this->num_methods = num_methods;
  this->threshold = threshold;
  this->set1 = set1;
  this->set2 = set2;

  // Make sure the mixture module criterion are good
  bool $mmc_is_good = false;
  if (strcmp(criterion, "BIC") == 0) {
    $mmc_is_good = true;
  }
  else if (strcmp(criterion, "ICL") == 0) {
    $mmc_is_good = true;
  }
  else if (strcmp(criterion, "NEC") == 0) {
    $mmc_is_good = true;
  }
  else if (strcmp(criterion, "CV") == 0) {
    $mmc_is_good = true;
  }
  else if (strcmp(criterion, "DCV") == 0) {
    $mmc_is_good = true;
  }
  if (!$mmc_is_good) {
    fprintf(stderr, "Error: The mixture model criterion must be one of: BIC, ICL, NEC, CV, DCV (--criterion option).\n");
    exit(-1);
  }
  if (max_clusters < 2 || max_clusters > 10 ){
    fprintf(stderr, "Error: Please select a maximum cluters between 2 and 10. (--max_clusters option).\n");
    exit(-1);
  }
}

/**
 *
 */
MixtureModelClustering::~MixtureModelClustering() {

}


/**
 *
 */
void MixtureModelClustering::run() {
  // Register signal and signal handler
  // signal(SIGINT, signal_callback_handler);

  // variables used for timing of the code.
  time_t start_time = time(0);
  time_t now;

  // If KINC is being rung using MPI then those values take precedence.
//  if (mpi_num_procs > 1) {
//    num_jobs = mpi_num_procs;
//    job_index = mpi_id;
//  }

  // Calculate the total number of comparisons and how many will be
  // performed by this process. We subtract 1 from the first params->rows
  // because we do not calculate the diagonal.
  long long int num_rows = ematrix->getNumGenes();
  long long int total_comps  = (num_rows * (num_rows - 1)) / 2;
  long long int comps_per_process = total_comps / num_jobs;
  long long int comp_start = 0;
  long long int comp_stop = total_comps;

  if (job_index > 0) {
    comp_start = (job_index - 1) * comps_per_process;
    comp_stop = (job_index - 1) * comps_per_process + comps_per_process;
  }
  // If this is the last process and there are some remainder comparisons
  // then we need to add them to the stop
  if (job_index == num_jobs) {
    comp_stop = total_comps;
  }
  printf("  Job %d of %d. \n", job_index, num_jobs);
  printf("  Performing (%lld x %lld)/2 comparisons: %lld to %lld (%lld) of %lld\n", num_rows, num_rows-1, comp_start, comp_stop, comp_stop - comp_start, total_comps);
  fflush(stdout);

  // Create the writer object to write out the clusters.
  PairWiseClusterWriter * pwcw = new PairWiseClusterWriter(method, num_methods,
      ematrix->getFilePrefix(), job_index, ematrix->getNumSamples());

  // Provide a message to the user indicating where the calculations will start.
  if (pwcw->getRecoveryX() > 0 || pwcw->getRecoveryY() > 0) {<commit_msg>Fixed a bug in comps per job if filtering is used<commit_after>#include "MixtureModelClustering.h"

MixtureModelClustering::MixtureModelClustering(EMatrix *ematrix, int min_obs,
    int num_jobs, int job_index, char **method, int num_methods,
    char * criterion, int max_clusters, double threshold,
    geneFilter *set1, geneFilter *set2)
  : PairWiseClustering(ematrix, min_obs, num_jobs, job_index) {

  // Initialize some values.
  this->max_clusters = max_clusters;
  this->criterion = criterion;
  this->method = method;
  this->num_methods = num_methods;
  this->threshold = threshold;
  this->set1 = set1;
  this->set2 = set2;

  // Make sure the mixture module criterion are good
  bool $mmc_is_good = false;
  if (strcmp(criterion, "BIC") == 0) {
    $mmc_is_good = true;
  }
  else if (strcmp(criterion, "ICL") == 0) {
    $mmc_is_good = true;
  }
  else if (strcmp(criterion, "NEC") == 0) {
    $mmc_is_good = true;
  }
  else if (strcmp(criterion, "CV") == 0) {
    $mmc_is_good = true;
  }
  else if (strcmp(criterion, "DCV") == 0) {
    $mmc_is_good = true;
  }
  if (!$mmc_is_good) {
    fprintf(stderr, "Error: The mixture model criterion must be one of: BIC, ICL, NEC, CV, DCV (--criterion option).\n");
    exit(-1);
  }
  if (max_clusters < 2 || max_clusters > 10 ){
    fprintf(stderr, "Error: Please select a maximum cluters between 2 and 10. (--max_clusters option).\n");
    exit(-1);
  }
}

/**
 *
 */
MixtureModelClustering::~MixtureModelClustering() {

}


/**
 *
 */
void MixtureModelClustering::run() {
  // Register signal and signal handler
  // signal(SIGINT, signal_callback_handler);

  // variables used for timing of the code.
  time_t start_time = time(0);
  time_t now;

  // If KINC is being rung using MPI then those values take precedence.
//  if (mpi_num_procs > 1) {
//    num_jobs = mpi_num_procs;
//    job_index = mpi_id;
//  }

  // Calculate the total number of comparisons and how many will be
  // performed by this process. We subtract 1 from the first params->rows
  // because we do not calculate the diagonal.
  long long int num_rows = ematrix->getNumGenes();
  long long int total_comps  = (num_rows * (num_rows - 1)) / 2;

  // Adjust the totals above if we have a filter on the genes
  if (set1->num_genes > 0) {
    total_comps  = (set1->num_genes * (num_rows - 1));
  }
  if (set2->num_genes > 0) {
    total_comps  = (set1->num_genes * set2->num_genes);
  }

  long long int comps_per_process = total_comps / num_jobs;
  long long int comp_start = 0;
  long long int comp_stop = total_comps;



  if (job_index > 0) {
    comp_start = (job_index - 1) * comps_per_process;
    comp_stop = (job_index - 1) * comps_per_process + comps_per_process;
  }
  // If this is the last process and there are some remainder comparisons
  // then we need to add them to the stop
  if (job_index == num_jobs) {
    comp_stop = total_comps;
  }
  printf("  Job %d of %d. \n", job_index, num_jobs);
  printf("  Performing %lld to %lld (%lld) of %lld\n", comp_start, comp_stop, comp_stop - comp_start, total_comps);
  fflush(stdout);

  // Create the writer object to write out the clusters.
  PairWiseClusterWriter * pwcw = new PairWiseClusterWriter(method, num_methods,
      ematrix->getFilePrefix(), job_index, ematrix->getNumSamples());

  // Provide a message to the user indicating where the calculations will start.
  if (pwcw->getRecoveryX() > 0 || pwcw->getRecoveryY() > 0) {
{'fraction_non_alphanumeric': 0.12307692307692308, 'fraction_numerical': 0.010558069381598794, 'mean_word_length': 3.462314939434724, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 46, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3393998', 'n_tokens_mistral': 2458, 'n_tokens_neox': 2314, 'n_words': 685}