Taking out deprecated functions, trying to eliminate DensePoint/DenseMatrix classes.

This commit is contained in:
Dongryeol Lee
2010-12-21 17:10:00 +00:00
parent 68d76ada11
commit dbbf0ec460
6 changed files with 72 additions and 38 deletions
@@ -12,12 +12,20 @@
namespace core {
namespace optimization {
template<typename FunctionType>
class TrustRegion {
private:
double max_radius_;
FunctionType *function_;
private:
void Evaluate_(const arma::vec &iterate);
void ObtainStepDirection_(
arma::vec *step_direction, double *step_direction_norm);
void ComputeCauchyPoint_(
double radius, const arma::vec &gradient,
const arma::mat &hessian, arma::vec *p);
@@ -35,6 +43,8 @@ class TrustRegion {
public:
TrustRegion();
double get_max_radius() const {
return max_radius_;
}
@@ -43,12 +53,7 @@ class TrustRegion {
max_radius_ = max_radius_in;
}
TrustRegion() {
max_radius_ = 10.0;
}
void Init() {
}
void Init(FunctionType &function_in);
void Optimize(int num_iterations, arma::vec *iterate);
};
@@ -12,7 +12,14 @@
namespace core {
namespace optimization {
void TrustRegion::ComputeSteihaugDirection_(
template<typename FunctionType>
TrustRegion<FunctionType>::TrustRegion() {
max_radius_ = 10.0;
function_ = NULL;
}
template<typename FunctionType>
void TrustRegion<FunctionType>::ComputeSteihaugDirection_(
double radius, const arma::vec &gradient, const arma::mat &hessian,
arma::vec *p, double *delta_m) {
@@ -117,7 +124,8 @@ void TrustRegion::ComputeSteihaugDirection_(
(*delta_m) = - arma::dot(gradient, *p) - 0.5 * quadratic_form2.at(0, 0);
}
void TrustRegion::ComputeCauchyPoint_(
template<typename FunctionType>
void TrustRegion<FunctionType>::ComputeCauchyPoint_(
double radius, const arma::vec &gradient,
const arma::mat &hessian, arma::vec *p) {
@@ -142,7 +150,8 @@ void TrustRegion::ComputeCauchyPoint_(
(*p) = (- tau * radius / gradient_norm) * gradient;
}
void TrustRegion::ComputeDoglegDirection_(
template<typename FunctionType>
void TrustRegion<FunctionType>::ComputeDoglegDirection_(
double radius, const arma::vec &gradient, const arma::mat &hessian,
arma::vec *p, double *delta_m) {
@@ -237,7 +246,8 @@ void TrustRegion::ComputeDoglegDirection_(
(*delta_m) = - arma::dot(gradient, *p) - 0.5 * quadratic_form2.at(0, 0);
}
void TrustRegion::TrustRadiusUpdate_(
template<typename FunctionType>
void TrustRegion<FunctionType>::TrustRadiusUpdate_(
double rho, double p_norm, double *current_radius) {
if(rho < 0.25) {
@@ -250,7 +260,29 @@ void TrustRegion::TrustRadiusUpdate_(
}
}
void TrustRegion::Optimize(int num_iterations, arma::vec *iterate) {
template<typename FunctionType>
void TrustRegion<FunctionType>::ObtainStepDirection_(
arma::vec *step_direction, double *step_direction_norm) {
}
template<typename FunctionType>
void TrustRegion<FunctionType>::Init(FunctionType &function_in) {
function_ = &function_in;
}
template<typename FunctionType>
void TrustRegion<FunctionType>::Optimize(
int num_iterations, arma::vec *iterate) {
// eta: The threshold for determining whether to take the step or
// not.
const double eta = 0.05;
// Initialize the starting iterate.
iterate->set_size(function_->num_dimensions());
iterate->fill(0.0);
// Whether to optimize until convergence.
bool optimize_until_convergence = (num_iterations <= 0);
@@ -259,10 +291,25 @@ void TrustRegion::Optimize(int num_iterations, arma::vec *iterate) {
double p_norm = 0;
double current_radius = 0.1;
int it_num;
// Step direction.
arma::vec p;
// The main optimization loop.
for(
it_num = 0; optimize_until_convergence ||
it_num < num_iterations; it_num++) {
// Obtain the step direction approximately.
ObtainStepDirection_(&p, &p_norm);
TrustRadiusUpdate_(rho, p_norm, &current_radius);
// If the decrease in the objective is sufficient enough, then
// accept the step. Otherwise, don't move.
if(rho > eta) {
}
}
}
};
@@ -157,14 +157,6 @@ class DenseMatrix {
}
}
void MakeColumnVector(int column_id, std::vector<double> *point_out) const {
point_out->resize(n_rows_);
const double *ptr = ptr_.get() + column_id * n_rows_;
for(int i = 0; i < n_rows_; ptr++, i++) {
(*point_out)[i] = (*ptr);
}
}
void MakeColumnVector(
int i, core::table::DensePoint *point_out) const {
point_out->Alias(
@@ -386,10 +386,6 @@ class Table {
direct_get_(point_id, point_out);
}
void get(int point_id, std::vector<double> *point_out) const {
direct_get_(point_id, point_out);
}
void get(int point_id, core::table::DensePoint *point_out) const {
direct_get_(point_id, point_out);
}
@@ -426,17 +422,6 @@ class Table {
}
}
void direct_get_(int point_id, std::vector<double> *entry) const {
if(this->IsIndexed() == false) {
data_.MakeColumnVector(point_id, entry);
}
else {
data_.MakeColumnVector(
IndexUtil<int>::Extract(
new_from_old_.get(), point_id), entry);
}
}
void direct_get_(
int point_id, core::table::DensePoint *entry) const {
if(this->IsIndexed() == false) {
@@ -26,6 +26,12 @@ class MixedLogitDCM {
public:
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(
@@ -29,7 +29,6 @@ void MixedLogitDCM<TableType>::Compute(
mlpack::mixed_logit_dcm::MixedLogitDCMResult *result_out) {
static const double C = 1.04;
static const double eta = 0.05;
// The maximum average integration sample size.
static const int R_MAX = 1000;
@@ -58,9 +57,9 @@ void MixedLogitDCM<TableType>::Compute(
theta.fill(0.0);
// The trust region optimizer.
core::optimization::TrustRegion trust_region;
trust_region.set_max_radius(core::math::LengthEuclidean(current_gradient));
trust_region.Optimize(-1, &theta);
// core::optimization::TrustRegion trust_region;
// trust_region.set_max_radius(core::math::LengthEuclidean(current_gradient));
// trust_region.Optimize(-1, &theta);
}
template<typename TableType>