Esempio n. 1
0
void CDCStatsticsMethod::conduct_cdc_screening(std::vector<std::vector<double>> &x,
                                               std::vector<uint> &x_variable_index,
                                               std::vector<std::vector<double>> &distance_y,
                                               std::vector<std::vector<double>> &kernel, double index) {
    std::vector<uint> variable_sequence;
    std::vector<std::vector<double>> submatrix;
    std::vector<std::vector<double>> distance_x;
    ConditionDistanceCovarianceStats conditionDistanceCovarianceStats = ConditionDistanceCovarianceStats(distance_x,
                                                                                                         distance_y,
                                                                                                         kernel, 2);

    for (int i = (int) (x_variable_index.size() - 1); i >= 0; --i) {
        // extract variable index
        if (i != 0) {
            variable_sequence = generate_sequence(x_variable_index[i - 1] + 1, x_variable_index[i]);
        } else {
            variable_sequence = generate_sequence(0, x_variable_index[0]);
        }
        submatrix = extract_submatrix_byrow(x, variable_sequence);

        // compute statistics
        distance_x = Euclidean_distance_byrow(submatrix, index);
        conditionDistanceCovarianceStats.setDistance_x(distance_x);
        conditionDistanceCovarianceStats.compute_stats();
        this->cdc_statistic.push_back(conditionDistanceCovarianceStats.getCondition_distance_covariance_stats());
    }
    reverse(this->cdc_statistic.begin(), this->cdc_statistic.end());
}
Esempio n. 2
0
int main(int argc, char *argv[]) {

  int max_used_memory;
  int allocation_factor;
  int memory_required;

  SEQLIST *test_sequence;

  max_used_memory = 2000;
  allocation_factor = 11;

  printf("running with MAX_USED_MEMORY=%d and ALLOCATION_FACTOR=%d\n",
         max_used_memory, allocation_factor);

  test_sequence = generate_sequence(max_used_memory, allocation_factor);
  if (VERBOSE)
    seq_print(test_sequence);

  // check that allocation can actually do something.
  // This becomes upper bound on binary search.
  if (try_sequence(test_sequence, max_used_memory * allocation_factor * 2)) {

    // binary search for smallest MEMORY_SIZE which can accommodate
    memory_required = binary_search_required_memory(test_sequence,
      max_used_memory - 1, max_used_memory * allocation_factor * 2);

    // run it one more time at the identified size.
    // this makes sure that the data is set from a successful run.
    if (try_sequence(test_sequence, memory_required)) {
      // check if data contents are intact
      if (check_data(test_sequence)) {
        printf("Data integrity FAIL.\n");
      }
      else {
        printf("Data integrity PASS.\n");
      }

      // print statistics
      printf("Memory utilization: (%d/%d)=%f\n", max_used_memory, memory_required,
             ((double) max_used_memory / (double) memory_required));
    }
    else {
      printf("Consistency problem: binary_search_reqruired_memory "
             "returned %d, but final test failed\n", memory_required);
    }
  }
  else {
    printf("Requires more memory than the no-free case.\n");
  }
}
Esempio n. 3
0
int main(void)
{
  int size;

  printf("Please input the size: ");
  scanf("%d", &size);

  int *array = (int *) malloc (sizeof(int) * size);
  generate_sequence(array, size);

  print(array, size);
  putchar('\n');

  free(array);

  return 0;
}
Esempio n. 4
0
int main(int argc, char* argv[]) {

    set_test_name(argv[0]);

    HMM* hmm = malloc(sizeof(*hmm));
    hmm->num_states = 3;
    hmm->num_tokens = 2;
    hmm->state_distribution_total = malloc(3 * sizeof(*hmm->state_distribution_total));
    hmm->state_distribution = malloc(3 * sizeof(*hmm->state_distribution));
    hmm->tokens = malloc(2 * sizeof(*hmm->tokens));
    hmm->token_distribution_total = malloc(3 * sizeof(*hmm->token_distribution_total));
    hmm->token_distribution = malloc(3 * sizeof(*hmm->token_distribution));

    hmm->state_distribution_total[0] = 1;
    hmm->state_distribution_total[1] = 1;
    hmm->state_distribution_total[2] = 1;

    hmm->state_distribution[0] = malloc(4 * sizeof(*hmm->state_distribution[0]));
    hmm->state_distribution[0][0] = 0;
    hmm->state_distribution[0][1] = 1;
    hmm->state_distribution[0][2] = 0;
    hmm->state_distribution[0][3] = 0;

    hmm->state_distribution[1] = malloc(4 * sizeof(*hmm->state_distribution[1]));
    hmm->state_distribution[1][0] = 0;
    hmm->state_distribution[1][1] = 0;
    hmm->state_distribution[1][2] = 1;
    hmm->state_distribution[1][3] = 0;

    hmm->state_distribution[2] = malloc(4 * sizeof(*hmm->state_distribution[2]));
    hmm->state_distribution[2][0] = 0;
    hmm->state_distribution[2][1] = 0;
    hmm->state_distribution[2][2] = 0;
    hmm->state_distribution[2][3] = 1;

    hmm->tokens[0] = "a";
    hmm->tokens[1] = "the";

    hmm->token_distribution_total[0] = 0;
    hmm->token_distribution_total[1] = 1;
    hmm->token_distribution_total[2] = 1;

    hmm->token_distribution[0] = malloc(2 * sizeof(*hmm->token_distribution[0]));
    hmm->token_distribution[0][0] = 0;
    hmm->token_distribution[0][1] = 0;

    hmm->token_distribution[1] = malloc(2 * sizeof(*hmm->token_distribution[1]));
    hmm->token_distribution[1][0] = 1;
    hmm->token_distribution[1][1] = 0;

    hmm->token_distribution[2] = malloc(2 * sizeof(*hmm->token_distribution[2]));
    hmm->token_distribution[2][0] = 0;
    hmm->token_distribution[2][1] = 1;

    int expected_length = 2;
    char** expected_sequence = malloc(2 * sizeof(*expected_sequence));
    expected_sequence[0] = "a";
    expected_sequence[1] = "the";

    char** actual_sequence = malloc(5 * sizeof(*actual_sequence));

    // Test generating full-length (nonbinding max_length)
    assert_int_e(expected_length, generate_sequence(hmm, actual_sequence, 5));
    assert_stra_e(expected_sequence, actual_sequence, expected_length);

    expected_length = 1;
    expected_sequence[0] = "a";
    expected_sequence[1] = NULL;
    actual_sequence[0] = NULL;
    actual_sequence[1] = NULL;

    // Test binding max_length
    assert_int_e(expected_length, generate_sequence(hmm, actual_sequence, 1));
    assert_stra_e(expected_sequence, actual_sequence, expected_length);

    finish_test();

    return 0;

}