diff --git a/fastlib/trunk/contrib/dongryel/gp_regression/dictionary.h b/fastlib/trunk/contrib/dongryel/gp_regression/dictionary.h index 29452ddb1c..8cee5f3ffe 100644 --- a/fastlib/trunk/contrib/dongryel/gp_regression/dictionary.h +++ b/fastlib/trunk/contrib/dongryel/gp_regression/dictionary.h @@ -5,8 +5,8 @@ * @author Dongryeol Lee (dongryel@cc.gatech.edu) */ -#ifndef ML_GP_REGRESSION_DICTIONARY_H -#define ML_GP_REGRESSION_DICTIONARY_H +#ifndef MLPACK_GP_REGRESSION_DICTIONARY_H +#define MLPACK_GP_REGRESSION_DICTIONARY_H #include #include @@ -44,6 +44,8 @@ class Dictionary { public: + void inactive_indices(std::vector *inactive_indices_out) const; + Dictionary(const Dictionary &dictionary_in) { table_ = dictionary_in.table(); random_permutation_ = dictionary_in.random_permutation(); @@ -93,7 +95,7 @@ class Dictionary { void Init(const Matrix *table_in); void AddBasis( - int iteration_number, + int new_point_index, const Vector &new_column_vector, double self_value); diff --git a/fastlib/trunk/contrib/dongryel/gp_regression/dictionary_dev.h b/fastlib/trunk/contrib/dongryel/gp_regression/dictionary_dev.h index 6d0af531ea..379c639048 100644 --- a/fastlib/trunk/contrib/dongryel/gp_regression/dictionary_dev.h +++ b/fastlib/trunk/contrib/dongryel/gp_regression/dictionary_dev.h @@ -5,8 +5,8 @@ * @author Dongryeol Lee (dongryel@cc.gatech.edu) */ -#ifndef ML_GP_REGRESSION_DICTIONARY_DEV_H -#define ML_GP_REGRESSION_DICTIONARY_DEV_H +#ifndef MLPACK_GP_REGRESSION_DICTIONARY_DEV_H +#define MLPACK_GP_REGRESSION_DICTIONARY_DEV_H #include #include @@ -15,6 +15,19 @@ #include "dictionary.h" namespace ml { + +void Dictionary::inactive_indices( + std::vector *inactive_indices_out) const { + + // Scan the in_dictionary list and build the inactive index set. + inactive_indices_out->resize(0); + for (int i = 0; i < in_dictionary_.size(); i++) { + if (in_dictionary_[i] == false) { + inactive_indices_out->push_back(i); + } + } +} + void Dictionary::UpdateDictionary_( int new_point_index, const Vector &new_column_vector, diff --git a/fastlib/trunk/contrib/dongryel/gp_regression/sg_gp_regression.h b/fastlib/trunk/contrib/dongryel/gp_regression/sg_gp_regression.h index b152ee3bb8..81e7844715 100644 --- a/fastlib/trunk/contrib/dongryel/gp_regression/sg_gp_regression.h +++ b/fastlib/trunk/contrib/dongryel/gp_regression/sg_gp_regression.h @@ -30,6 +30,9 @@ class SparseGreedyGprModel { ml::Dictionary dictionary_for_error_; private: + + void QuadraticObjective_(const ml::Dictionary &dictionary_in) const; + template void ComputeKernelValues_( const CovarianceType &covariance_in, @@ -65,6 +68,9 @@ class SparseGreedyGprModel { class SparseGreedyGpr { private: + + const int random_subset_size_ = 60; + const Matrix *dataset_; const Vector *targets_; diff --git a/fastlib/trunk/contrib/dongryel/gp_regression/sg_gp_regression_dev.h b/fastlib/trunk/contrib/dongryel/gp_regression/sg_gp_regression_dev.h index 4fda8a37a8..3f9bffae35 100644 --- a/fastlib/trunk/contrib/dongryel/gp_regression/sg_gp_regression_dev.h +++ b/fastlib/trunk/contrib/dongryel/gp_regression/sg_gp_regression_dev.h @@ -14,6 +14,12 @@ namespace ml { namespace gp_regression { +void SparseGreedyGprModel::QuadraticObjective_( + const ml::Dictionary &dictionary_in) const { + + +} + void SparseGreedyGprModel::FillSquaredKernelMatrix_( int candidate_index, const Vector &kernel_values, @@ -76,6 +82,7 @@ void SparseGreedyGprModel::ComputeKernelValues_( Vector candidate_point; dataset_->MakeColumnVector(candidate_index, &candidate_point); + // Fill out the kernel values sequentially. for (int i = 0; i < dataset_->n_cols(); i++) { Vector point; dataset_->MakeColumnVector(i, &point); @@ -95,14 +102,19 @@ void SparseGreedyGprModel::AddOptimalPoint( // The optimal point information. int optimal_point_index = -1; - double optimum_value = std::numeric_limit::max(); + double optimum_value = std::numeric_limits::max(); // Loop over candidates and decide to add the optimal. for (int i = 0; i < candidate_indices.size(); i++) { // Make a copy of the dictionaries. - Dictionary dictionary_copy = dictionary_; - Dictionary dictionary_for_error_copy = dictionary_for_error_; + Dictionary dictionary_copy; + if (for_coeffs) { + dictionary_copy = dictionary_; + } + else { + dictionary_copy = dictionary_for_error_; + } // Candidate index for which the kernel values have to be computed. int candidate_index = candidate_indices[i]; @@ -117,12 +129,20 @@ void SparseGreedyGprModel::AddOptimalPoint( if (for_coeffs) { FillSquaredKernelMatrix_( candidate_index, kernel_values, &new_column_vector, &new_self_value); + dictionary_.AddBasis( + candidate_index, new_column_vector, new_self_value); + // Compute the objective function value for the coefficients. + QuadraticObjective_(dictionary_); } else { FillKernelMatrix_( candidate_index, kernel_values, &new_column_vector, &new_self_value); + dictionary_for_error_.AddBasis( + candidate_index, new_column_vector, new_self_value); + // Compute the objective function value for the error bar. + QuadraticObjective_(dictionary_for_error_); } } } @@ -191,9 +211,6 @@ void SparseGreedyGpr::Compute( double precision_in, SparseGreedyGprModel *model_out) { - // The maximum number of points to choose in each iteration. - const int max_num_points = 60; - // Initialize the model. model_out->Init(dataset_, targets_); @@ -214,15 +231,20 @@ void SparseGreedyGpr::Compute( // Choose a random subset from the inactive point set. ChooseRandomSubset_( - inactive_indices, max_num_points, &candidate_indices); + inactive_indices, random_subset_size_, &candidate_indices); ChooseRandomSubset_( - inactive_indices_for_error, max_num_points, &candidate_indices_for_error); + inactive_indices_for_error, random_subset_size_, + &candidate_indices_for_error); // Choose a random optimal point for both sets. model_out->AddOptimalPoint( covariance_in, noise_level_in, candidate_indices, false); model_out->AddOptimalPoint( covariance_in, noise_level_in, candidate_indices_for_error, true); + + // Update the list of inactive indices. + dictionary_.inactive_indices(&inactive_indices); + dictionary_for_error_.inactive_indices(&inactive_indices_for_error_); } while (Done_()); }