<commit_before>/** @file mixed_logit.test.cc
 *
 *  A "stress" test driver for mixed logit.
 *
 *  @author <NAME> (<EMAIL>)
 */

#include <numeric>
#include <time.h>
#include "core/table/table.h"
#include "core/tree/gen_metric_tree.h"
#include "mlpack/mixed_logit_dcm/constant_distribution.h"
#include "mlpack/mixed_logit_dcm/distribution.h"
#include "mlpack/mixed_logit_dcm/gaussian_distribution.h"
#include "mlpack/mixed_logit_dcm/mixed_logit_dcm_argument_parser.h"
#include "mlpack/mixed_logit_dcm/mixed_logit_dcm_dev.h"

namespace mlpack {
namespace mixed_logit_dcm {

int num_attributes_;
int num_people_;
std::vector<int> num_discrete_choices_;

class TestMixedLogitDCM {

  private:

    template<typename TableType>
    void GenerateRandomDataset_(
      TableType *random_attribute_dataset,
      TableType *random_decisions_dataset,
      TableType *random_num_alternatives_dataset) {

      // Find the total number of discrete choices.
      int total_num_attributes =
        std::accumulate(
          mlpack::mixed_logit_dcm::num_discrete_choices_.begin(),
          mlpack::mixed_logit_dcm::num_discrete_choices_.end(), 0);

      random_attribute_dataset->Init(
        mlpack::mixed_logit_dcm::num_attributes_, total_num_attributes);

      for(int j = 0; j < total_num_attributes; j++) {
        core::table::DensePoint point;
        random_attribute_dataset->get(j, &point);
        for(int i = 0; i < mlpack::mixed_logit_dcm::num_attributes_; i++) {
          point[i] = core::math::Random(0.1, 1.0);
        }
      }

      random_num_alternatives_dataset->Init(
        1, mlpack::mixed_logit_dcm::num_people_);
      for(int j = 0; j < mlpack::mixed_logit_dcm::num_people_; j++) {
        core::table::DensePoint point;
        random_num_alternatives_dataset->get(j, &point);

        // This is the number of discrete choices for the given
        // person.
        point[0] = mlpack::mixed_logit_dcm::num_discrete_choices_[j];
      }
      random_decisions_dataset->Init(
        1, mlpack::mixed_logit_dcm::num_people_);
      for(int j = 0; j < mlpack::mixed_logit_dcm::num_people_; j++) {
        core::table::DensePoint point;
        random_decisions_dataset->get(j, &point);

        // This is the discrete choice index of the given person.
        point[0] = core::math::RandInt(
                     mlpack::mixed_logit_dcm::num_discrete_choices_[j]) + 1;
      }
    }

  public:

    int StressTestMain() {
      for(int i = 0; i < 1; i++) {
        for(int k = 0; k < 2; k++) {

          // Randomly choose the number of attributes and the number
          // of people and the number of discrete choices per each
          // person.
          mlpack::mixed_logit_dcm::num_attributes_ = core::math::RandInt(3, 5);
          mlpack::mixed_logit_dcm::num_people_ = core::math::RandInt(50, 70);
          mlpack::mixed_logit_dcm::num_discrete_choices_.resize(
            mlpack::mixed_logit_dcm::num_people_);
          for(int j = 0; j < mlpack::mixed_logit_dcm::num_people_; j++) {
            mlpack::mixed_logit_dcm::num_discrete_choices_[j] =
              core::math::RandInt(3, 7);
          }

          switch(k) {
            case 0:

              // Test the constant distribution.
              StressTest<mlpack::mixed_logit_dcm::ConstantDistribution>();
              break;
            case 1:

              // Test the Gaussian distribution.
              StressTest<mlpack::mixed_logit_dcm::GaussianDistribution>();
              break;
          }
        }
      }
      return 0;
    }

    template<typename DistributionType>
    int StressTest() {

      typedef core::table::Table <
      core::tree::GenMetricTree <
      core::tree::AbstractStatistic > > TableType;

      // The list of arguments.
      std::vector< std::string > args;

      // Push in the reference dataset name.
      std::string attributes_in("random_attributes.csv");
      args.push_back(std::string("--attributes_in=") + attributes_in);

      // Push in the decision set info name.
      std::string decisions_in(
        "random_decisions.csv");
      args.push_back(
        std::string("--decisions_in=") +
        decisions_in);

      // Push in the number of alternatives.
      std::string num_alternatives_in("random_num_alternatives.csv");
      args.push_back(
        std::string("--num_alternatives_in=") +
        num_alternatives_in);

      // Print out the header of the trial.
      std::cout << "\n==================\n";
      std::cout << "Test trial begin\n";
      std::cout << "Number of attributes: " <<
                mlpack::mixed_logit_dcm::num_attributes_ << "\n";
      std::cout << "Number of people: " <<
                mlpack::mixed_logit_dcm::num_people_ << "\n";

      // Generate the random dataset and save it.<commit_msg>Getting there.<commit_after>/** @file mixed_logit.test.cc
 *
 *  A "stress" test driver for mixed logit.
 *
 *  @author <NAME> (<EMAIL>)
 */

#include <numeric>
#include <time.h>
#include "core/table/table.h"
#include "core/tree/gen_metric_tree.h"
#include "mlpack/mixed_logit_dcm/constant_distribution.h"
#include "mlpack/mixed_logit_dcm/distribution.h"
#include "mlpack/mixed_logit_dcm/gaussian_distribution.h"
#include "mlpack/mixed_logit_dcm/mixed_logit_dcm_argument_parser.h"
#include "mlpack/mixed_logit_dcm/mixed_logit_dcm_dev.h"

namespace mlpack {
namespace mixed_logit_dcm {

int num_attributes_;
int num_people_;
std::vector<int> num_discrete_choices_;

class TestMixedLogitDCM {

  private:

    template<typename TableType>
    void GenerateRandomDataset_(
      TableType *random_attribute_dataset,
      TableType *random_decisions_dataset,
      TableType *random_num_alternatives_dataset) {

      // Find the total number of discrete choices.
      int total_num_attributes =
        std::accumulate(
          mlpack::mixed_logit_dcm::num_discrete_choices_.begin(),
          mlpack::mixed_logit_dcm::num_discrete_choices_.end(), 0);

      random_attribute_dataset->Init(
        mlpack::mixed_logit_dcm::num_attributes_, total_num_attributes);

      for(int j = 0; j < total_num_attributes; j++) {
        core::table::DensePoint point;
        random_attribute_dataset->get(j, &point);
        for(int i = 0; i < mlpack::mixed_logit_dcm::num_attributes_; i++) {
          point[i] = core::math::Random(0.1, 1.0);
        }
      }

      random_num_alternatives_dataset->Init(
        1, mlpack::mixed_logit_dcm::num_people_);
      for(int j = 0; j < mlpack::mixed_logit_dcm::num_people_; j++) {
        core::table::DensePoint point;
        random_num_alternatives_dataset->get(j, &point);

        // This is the number of discrete choices for the given
        // person.
        point[0] = mlpack::mixed_logit_dcm::num_discrete_choices_[j];
      }
      random_decisions_dataset->Init(
        1, mlpack::mixed_logit_dcm::num_people_);
      for(int j = 0; j < mlpack::mixed_logit_dcm::num_people_; j++) {
        core::table::DensePoint point;
        random_decisions_dataset->get(j, &point);

        // This is the discrete choice index of the given person.
        point[0] = core::math::RandInt(
                     mlpack::mixed_logit_dcm::num_discrete_choices_[j]) + 1;
      }
    }

  public:

    int StressTestMain() {
      for(int i = 0; i < 1; i++) {
        for(int k = 0; k < 3; k++) {

          // Randomly choose the number of attributes and the number
          // of people and the number of discrete choices per each
          // person.
          mlpack::mixed_logit_dcm::num_attributes_ = core::math::RandInt(3, 5);
          mlpack::mixed_logit_dcm::num_people_ = core::math::RandInt(50, 70);
          mlpack::mixed_logit_dcm::num_discrete_choices_.resize(
            mlpack::mixed_logit_dcm::num_people_);
          for(int j = 0; j < mlpack::mixed_logit_dcm::num_people_; j++) {
            mlpack::mixed_logit_dcm::num_discrete_choices_[j] =
              core::math::RandInt(3, 7);
          }

          switch(k) {
            case 0:

              // Test the constant distribution.
              StressTest <
              mlpack::mixed_logit_dcm::ConstantDistribution > (
                std::string("constant"));
              break;
            case 1:

              // Test the diagonal Gaussian distribution.
              StressTest <
              mlpack::mixed_logit_dcm::DiagonalGaussianDistribution > (
                std::string("diag_gaussian"));
              break;
            case 2:

              // Test the full Gaussian distribution.
              StressTest <
              mlpack::mixed_logit_dcm::GaussianDistribution > (
                std::string("full_gaussian"));
              break;
          }
        }
      }
      return 0;
    }

    template<typename DistributionType>
    int StressTest(const std::string &distribution_name) {

      typedef core::table::Table <
      core::tree::GenMetricTree <
      core::tree::AbstractStatistic > > TableType;

      // The list of arguments.
      std::vector< std::string > args;

      // Push in the distribution type.
      args.push_back(std::string("--distribution_in=") + distribution_name);

      // Push in the reference dataset name.
      std::string attributes_in("random_attributes.csv");
      args.push_back(std::string("--attributes_in=") + attributes_in);

      // Push in the decision set info name.
      std::string decisions_in(
        "random_decisions.csv");
      args.push_back(
        std::string("--decisions_in=") +
        decisions_in);

      // Push in the number of alternatives.
      std::string num_alternatives_in("random_num_alternatives.csv");
      args.push_back(
        std::string("--num_alternatives_in=") +
        num_alternatives_in);

      // Print out the header of the trial.
      std::cout << "\n==================\n";
      std::cout << "Test trial begin\n";
      std::cout << "Number of attributes: " <<
                mlpack::mixed_logit_dcm::num_attributes_ << "\n";
      std::cout << "Number of people: " <<
                mlpack::mixed_logit_dcm::num_people_ << "\n";

      // Generate the random dataset and save it.
{'fraction_non_alphanumeric': 0.12454393057883838, 'fraction_numerical': 0.006015185879104625, 'mean_word_length': 2.6574107464839525, 'pattern_counts': {'":': 0, '<': 74, '<?xml version=': 0, '>': 40, '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': '3528298', 'n_tokens_mistral': 3341, 'n_tokens_neox': 3149, 'n_words': 615}