<commit_before># ifndef MICROCREDIT_MODEL_PARAMETERS_H
# define MICROCREDIT_MODEL_PARAMETERS_H

# include <Eigen/Dense>
# include <vector>
# include <iostream>

# include "variational_parameters.h"

using Eigen::MatrixXd;
using Eigen::VectorXd;
using Eigen::MatrixXi;
using Eigen::VectorXi;

using Eigen::Matrix;
using Eigen::Dynamic;

template <typename T> using VectorXT = Eigen::Matrix<T, Dynamic, 1>;
template <typename T> using MatrixXT = Eigen::Matrix<T, Dynamic, Dynamic>;

using std::vector;

//////////////////////////////////////
// VariationalParameters
//////////////////////////////////////

template <class T>
class VariationalParameters {
public:
  // Parameters:
  int n_g;    // The number of groups
  int k;      // The dimension of the means

  VectorParameter<T> e_mu;    // The vector of E(mu)
  PosDefMatrixParameter<T> e_mu2;   // E(mu mu^T)

  // Unlike the other parameters, use the natural parameters for lambda.
  PosDefMatrixParameter<T> lambda_v_par;   // lambda ~ Wishart(v_par, n_par)
  ScalarParameter<T> lambda_n_par;

  // A vector of per-group, E(tau), the observation noise precision
  vector<ScalarParameter<T>> e_tau_vec;
  vector<ScalarParameter<T>> e_log_tau_vec;  // E(log(tau))

  // Vectors of the per-group means.
  vector<VectorParameter<T>> e_mu_g_vec;  // E(mu_k)
  vector<PosDefMatrixParameter<T>> e_mu2_g_vec; // E(mu_k mu_k^T)

  // Methods:
  VariationalParameters(int k, int n_g): k(k), n_g(n_g) {
    e_mu = VectorParameter<T>(k, "e_mu");
    e_mu2 = PosDefMatrixParameter<T>(k, "e_mu2");

    lambda_v_par = PosDefMatrixParameter<T>(k, "lambda_v_par");
    lambda_n_par = ScalarParameter<T>("lambda_n_par");

    // Do the mu_g vectors
    e_mu_g_vec.resize(n_g);
    e_mu2_g_vec.resize(n_g);
    e_tau_vec.resize(n_g);
    e_log_tau_vec.resize(n_g);

    for (int g = 0; g < n_g; g++) {
      e_mu_g_vec[g] = VectorParameter<T>(k, "e_mu_g" + g);
      e_mu2_g_vec[g] = PosDefMatrixParameter<T>(k, "e_mu2_g" + g);
      e_tau_vec[g] = ScalarParameter<T>("e_tau_g" + g);
      e_log_tau_vec[g] = ScalarParameter<T>("e_log_tau_g" + g);
    }
  };


  VariationalParameters() {
    VariationalParameters(1, 1);
  }


  /////////////////
  template <typename Tnew>
  operator VariationalParameters<Tnew>() const {
    VariationalParameters<Tnew> vp = VariationalParameters<Tnew>(k, n_g);

    vp.e_mu = e_mu;
    vp.e_mu2 = e_mu2;

    vp.lambda_v_par = lambda_v_par;
    vp.lambda_n_par = lambda_n_par;

    for (int g = 0; g < n_g; g++) {
      vp.e_mu_g_vec[g] = e_mu_g_vec[g];
      vp.e_mu2_g_vec[g] = e_mu2_g_vec[g];

      vp.e_tau_vec[g] = e_tau_vec[g];
      vp.e_log_tau_vec[g] = e_log_tau_vec[g];
    }
    return vp;
  }
};


//////////////////////////////
// Priors

template <class T> class PriorParameters {
public:
  // Parameters:
  int k;      // The dimension of the means

  // mu ~ MNV(mu_mean, mu_info^-1)
  VectorParameter<T> mu_mean;
  PosDefMatrixParameter<T> mu_info;

  // lambda ~ LKJ(eta), scale ~ Gamma(alpha, beta)
  ScalarParameter<T> lambda_eta;
  ScalarParameter<T> lambda_alpha;
  ScalarParameter<T> lambda_beta;

  // tau ~ Gamma(alpha, beta)
  ScalarParameter<T> tau_alpha;
  ScalarParameter<T> tau_beta;

  // Optimization parameters for lambda<commit_msg>Use simpler types<commit_after># ifndef MICROCREDIT_MODEL_PARAMETERS_H
# define MICROCREDIT_MODEL_PARAMETERS_H

# include <Eigen/Dense>
# include <vector>
# include <iostream>

# include "variational_parameters.h"

using Eigen::MatrixXd;
using Eigen::VectorXd;
using Eigen::MatrixXi;
using Eigen::VectorXi;

using Eigen::Matrix;
using Eigen::Dynamic;

template <typename T> using VectorXT = Eigen::Matrix<T, Dynamic, 1>;
template <typename T> using MatrixXT = Eigen::Matrix<T, Dynamic, Dynamic>;

using std::vector;

//////////////////////////////////////
// VariationalParameters
//////////////////////////////////////

template <class T>
class VariationalParameters {
public:
  // Parameters:
  int n_g;    // The number of groups
  int k;      // The dimension of the means


  MultivatiateNormal<T> mu;

  // VectorParameter<T> e_mu;    // The vector of E(mu)
  // PosDefMatrixParameter<T> e_mu2;   // E(mu mu^T)

  // Unlike the other parameters, use the natural parameters for lambda.
  Wishart<T> lambda;
  // PosDefMatrixParameter<T> lambda_v_par;   // lambda ~ Wishart(v_par, n_par)
  // ScalarParameter<T> lambda_n_par;

  // A vector of per-group, E(tau), the observation noise precision
  vector<Gamma<T>> tau_vec;
  // vector<ScalarParameter<T>> e_tau_vec;
  // vector<ScalarParameter<T>> e_log_tau_vec;  // E(log(tau))

  // Vectors of the per-group means.
  vector<MultivatiateNormal<T>> mu_g_vec;
  // vector<VectorParameter<T>> e_mu_g_vec;  // E(mu_k)
  // vector<PosDefMatrixParameter<T>> e_mu2_g_vec; // E(mu_k mu_k^T)

  // Methods:
  VariationalParameters(int k, int n_g): k(k), n_g(n_g) {
    mu = MultivatiateNormal<T>(k);
    // e_mu = VectorParameter<T>(k, "e_mu");
    // e_mu2 = PosDefMatrixParameter<T>(k, "e_mu2");

    // lambda_v_par = PosDefMatrixParameter<T>(k, "lambda_v_par");
    // lambda_n_par = ScalarParameter<T>("lambda_n_par");
    lambda = Wishart<T>(k);

    // Do the mu_g vectors
    // e_mu_g_vec.resize(n_g);
    // e_mu2_g_vec.resize(n_g);
    // e_tau_vec.resize(n_g);
    // e_log_tau_vec.resize(n_g);
    mu_g_vec.resize(n_g);
    tau_vec.resize(n_g);

    for (int g = 0; g < n_g; g++) {
      mu_g_vec[g] = MultivatiateNormal<T>(k);
      tau_vec[g] = Gamma<T>();
    }
  };


  VariationalParameters() {
    VariationalParameters(1, 1);
  }


  /////////////////
  template <typename Tnew>
  operator VariationalParameters<Tnew>() const {
    VariationalParameters<Tnew> vp = VariationalParameters<Tnew>(k, n_g);

    // vp.e_mu = e_mu;
    // vp.e_mu2 = e_mu2;
    //
    // vp.lambda_v_par = lambda_v_par;
    // vp.lambda_n_par = lambda_n_par;
    //
    // for (int g = 0; g < n_g; g++) {
    //   vp.e_mu_g_vec[g] = e_mu_g_vec[g];
    //   vp.e_mu2_g_vec[g] = e_mu2_g_vec[g];
    //
    //   vp.e_tau_vec[g] = e_tau_vec[g];
    //   vp.e_log_tau_vec[g] = e_log_tau_vec[g];
    // }

    vp.mu = mu;

    vp.lambda = lambda;

    for (int g = 0; g < n_g; g++) {
      vp.mu_g_vec[g] = mu_g_vec[g];
      vp.tau_vec[g] = tau_vec[g];
    }
    return vp;
  }
};


//////////////////////////////
// Priors

template <class T> class PriorParameters {
public:
  // Parameters:
  int k;      // The dimension of the means

  // mu ~ MNV(mu_mean, mu_info^-1)
  VectorParameter<T> mu_mean;
  PosDefMatrixParameter<T> mu_info;

  // lambda ~ LKJ(eta), scale ~ Gamma(alpha, beta)
  ScalarParameter<T> lambda_eta;
  ScalarParameter<T> lambda_alpha;
  ScalarParameter<T> lambda_beta;

  // tau ~ Gamma(alpha, beta)
  ScalarParameter<T> tau_alpha;
  ScalarParameter<T> tau_beta;

  // Optimization parameters for lambda
{'fraction_non_alphanumeric': 0.17124394184168013, 'fraction_numerical': 0.004846526655896607, 'mean_word_length': 3.022445363260484, 'pattern_counts': {'":': 0, '<': 94, '<?xml version=': 0, '>': 89, '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': '414970', 'n_tokens_mistral': 2697, 'n_tokens_neox': 2566, 'n_words': 512}