Will continue after lunch.
This commit is contained in:
-12
@@ -17,23 +17,11 @@ namespace mlpack {
|
||||
namespace mixed_logit_dcm {
|
||||
template<typename IncomingTableType>
|
||||
class MixedLogitDCM {
|
||||
private:
|
||||
|
||||
double Normalization_(const core::table::DensePoint &beta);
|
||||
|
||||
public:
|
||||
typedef IncomingTableType TableType;
|
||||
|
||||
public:
|
||||
|
||||
int num_dimensions() const;
|
||||
|
||||
double Evaluate(const arma::vec &iterate) const;
|
||||
|
||||
void Gradient(const arma::vec &iterate, arma::vec *gradient_out) const;
|
||||
|
||||
void Hessian(const arma::vec &iterate, arma::mat *hessian_out) const;
|
||||
|
||||
TableType *attribute_table();
|
||||
|
||||
void Init(
|
||||
|
||||
+16
-44
@@ -12,28 +12,6 @@
|
||||
namespace mlpack {
|
||||
namespace mixed_logit_dcm {
|
||||
|
||||
template<typename TableType>
|
||||
int MixedLogitDCM<TableType>::num_dimensions() const {
|
||||
return table_.num_parameters();
|
||||
}
|
||||
|
||||
template<typename TableType>
|
||||
double MixedLogitDCM<TableType>::Evaluate(const arma::vec &iterate) const {
|
||||
//return table_.SimulatedLogLikelihood();
|
||||
}
|
||||
|
||||
template<typename TableType>
|
||||
void MixedLogitDCM<TableType>::Gradient(
|
||||
const arma::vec &iterate, arma::vec *gradient_out) const {
|
||||
//table_.SimulatedLoglikelihoodGradient(gradient_out);
|
||||
}
|
||||
|
||||
template<typename TableType>
|
||||
void MixedLogitDCM<TableType>::Hessian(
|
||||
const arma::vec &iterate, arma::mat *hessian_out) const {
|
||||
//table_.SimulatedLoglikelihoodHessian(hessian_out);
|
||||
}
|
||||
|
||||
template<typename TableType>
|
||||
void MixedLogitDCM<TableType>::Init(
|
||||
mlpack::mixed_logit_dcm::MixedLogitDCMArguments <
|
||||
@@ -60,10 +38,10 @@ void MixedLogitDCM<TableType>::Compute(
|
||||
static_cast<int>(
|
||||
table_.num_people() *
|
||||
arguments_in.initial_dataset_sample_rate_);
|
||||
std::vector<int> num_integration_samples(
|
||||
num_data_samples, std::max(
|
||||
int num_integration_samples =
|
||||
std::max(
|
||||
static_cast<int>(arguments_in.initial_integration_sample_rate_ * R_MAX),
|
||||
36));
|
||||
36);
|
||||
|
||||
// Compute the initial simulated log-likelihood, the gradient, and
|
||||
// the Hessian.
|
||||
@@ -73,26 +51,20 @@ void MixedLogitDCM<TableType>::Compute(
|
||||
//table_.SimulatedLoglikelihoodGradient(¤t_gradient);
|
||||
//table_.SimulatedLoglikelihoodHessian(¤t_hessian);
|
||||
|
||||
// Initialize the starting optimization parameter $\theta_0$.
|
||||
arma::vec theta;
|
||||
// Initialize the starting optimization parameter $\theta_0$ and its
|
||||
// associated sampling information.
|
||||
typedef mlpack::mixed_logit_dcm::DCMTable<TableType> DCMTableType;
|
||||
std::pair <
|
||||
arma::vec ,
|
||||
mlpack::mixed_logit_dcm::MixedLogitDCMSampling<DCMTableType> >
|
||||
iterate_sampling_pair;
|
||||
iterate_sampling_pair.first.set_size(
|
||||
arguments_in.distribution_->num_parameters());
|
||||
iterate_sampling_pair.first.zeros();
|
||||
iterate_sampling_pair.second.Init(
|
||||
&table_, num_data_samples, num_integration_samples);
|
||||
|
||||
|
||||
// The trust region optimizer.
|
||||
typedef MixedLogitDCM<TableType> FunctionType;
|
||||
core::optimization::TrustRegion<FunctionType> trust_region;
|
||||
if(arguments_in.trust_region_search_method_ == "cauchy") {
|
||||
trust_region.Init(
|
||||
*this, core::optimization::TrustRegionSearchMethod::CAUCHY);
|
||||
}
|
||||
else if(arguments_in.trust_region_search_method_ == "dogleg") {
|
||||
trust_region.Init(
|
||||
*this, core::optimization::TrustRegionSearchMethod::DOGLEG);
|
||||
}
|
||||
else {
|
||||
trust_region.Init(
|
||||
*this, core::optimization::TrustRegionSearchMethod::STEIHAUG);
|
||||
}
|
||||
trust_region.set_max_radius(arma::norm(current_gradient, 2));
|
||||
trust_region.Optimize(-1, &theta);
|
||||
}
|
||||
|
||||
template<typename TableType>
|
||||
|
||||
+24
-4
@@ -55,7 +55,7 @@ class MixedLogitDCMSampling {
|
||||
*/
|
||||
int num_active_people_;
|
||||
|
||||
std::vector<int> num_integration_samples_;
|
||||
arma::ivec num_integration_samples_;
|
||||
|
||||
private:
|
||||
|
||||
@@ -99,6 +99,20 @@ class MixedLogitDCMSampling {
|
||||
}
|
||||
}
|
||||
|
||||
void BuildSamples_() {
|
||||
for(int i = 0; i < num_active_people_; i++) {
|
||||
|
||||
// Get the index of the active person.
|
||||
int person_index = dcm_table_->shuffled_indices_for_person(i);
|
||||
|
||||
for(int j = simulated_choice_probabilities_[j].num_samples();
|
||||
j < num_integration_samples_[person_index]; j++) {
|
||||
|
||||
// Draw a beta from the parameter theta.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
double simulated_choice_probability(int person_index) const {
|
||||
@@ -271,11 +285,16 @@ class MixedLogitDCMSampling {
|
||||
void Init(
|
||||
DCMTableType *dcm_table_in,
|
||||
int num_active_people_in,
|
||||
const std::vector<int> &num_integration_samples_in) {
|
||||
int initial_num_integration_samples_in) {
|
||||
|
||||
dcm_table_ = dcm_table_in;
|
||||
num_active_people_ = num_active_people_in;
|
||||
num_integration_samples_ = num_integration_samples_in;
|
||||
num_integration_samples_.zeros(dcm_table_->num_people());
|
||||
for(int i = 0; i < num_active_people_; i++) {
|
||||
int person_index = dcm_table_->shuffled_indices_for_person(i);
|
||||
num_integration_samples_[person_index] =
|
||||
initial_num_integration_samples_in;
|
||||
}
|
||||
|
||||
// This vector maintains the running simulated choice
|
||||
// probabilities per person.
|
||||
@@ -295,13 +314,14 @@ class MixedLogitDCMSampling {
|
||||
simulated_loglikelihood_hessians_.resize(dcm_table_->num_people());
|
||||
|
||||
// Build up the samples.
|
||||
|
||||
BuildSamples_();
|
||||
}
|
||||
|
||||
void AddActivePeople(int num_additional_people) {
|
||||
num_active_people_ += num_additional_people;
|
||||
|
||||
// Build up additional samples for the new people.
|
||||
BuildSamples_();
|
||||
}
|
||||
|
||||
const std::vector <
|
||||
|
||||
Reference in New Issue
Block a user