ridge_regression.h

00001 /* MLPACK 0.2
00002  *
00003  * Copyright (c) 2008, 2009 Alexander Gray,
00004  *                          Garry Boyer,
00005  *                          Ryan Riegel,
00006  *                          Nikolaos Vasiloglou,
00007  *                          Dongryeol Lee,
00008  *                          Chip Mappus, 
00009  *                          Nishant Mehta,
00010  *                          Hua Ouyang,
00011  *                          Parikshit Ram,
00012  *                          Long Tran,
00013  *                          Wee Chin Wong
00014  *
00015  * Copyright (c) 2008, 2009 Georgia Institute of Technology
00016  *
00017  * This program is free software; you can redistribute it and/or
00018  * modify it under the terms of the GNU General Public License as
00019  * published by the Free Software Foundation; either version 2 of the
00020  * License, or (at your option) any later version.
00021  *
00022  * This program is distributed in the hope that it will be useful, but
00023  * WITHOUT ANY WARRANTY; without even the implied warranty of
00024  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00025  * General Public License for more details.
00026  *
00027  * You should have received a copy of the GNU General Public License
00028  * along with this program; if not, write to the Free Software
00029  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00030  * 02110-1301, USA.
00031  */
00032 #ifndef RIDGE_REGRESSION_H_
00033 #define RIDGE_REGRESSION_H_
00034 
00035 #include "fastlib/fastlib.h"
00036 #include "mlpack/quicsvd/quicsvd.h"
00037 #include "ridge_regression_util.h"
00038 
00039 class RidgeRegression {
00040  public:
00041 
00042   RidgeRegression() {
00043   }
00044 
00045   void Init(fx_module *module, const Matrix &predictors, 
00046             const Matrix &predictions, 
00047             bool use_normal_equation_method = true);
00048 
00049   void Init(fx_module *module, const Matrix &input_data, index_t selector,
00050             bool use_normal_equation_method = true);
00051 
00069   void Init(fx_module *module, 
00070             const Matrix &input_data, 
00071             const GenVector<index_t> &predictor_indices,
00072             index_t &prediction_index, bool use_normal_equation_method = true);
00073 
00074   void Init(fx_module *module, 
00075             const Matrix &input_data, 
00076             const GenVector<index_t> &predictor_indices,
00077             const Matrix &prediction, bool use_normal_equation_method = true);
00078 
00079   void ReInitTargetValues(const Matrix &input_data, 
00080                           index_t target_value_index);
00081 
00082   void ReInitTargetValues(const Matrix &target_values_in);
00083 
00084   void Destruct();
00085 
00086   void SVDRegress(double lambda,
00087                   const GenVector<index_t> *predictor_indices = NULL);
00088 
00089   void CrossValidatedRegression(double lambda_min, double lambda_max,
00090                                 index_t num);
00091 
00092   void FeatureSelectedRegression
00093   (const GenVector<index_t> &predictor_indices, 
00094    const GenVector<index_t> &prune_predictor_indices, 
00095    const Matrix &original_target_training_values,
00096    GenVector<index_t> *output_predictor_indices);
00097 
00098   double ComputeSquareError();
00099 
00103   void Predict(const Matrix &dataset, Vector *new_predictions);
00104 
00105   void Predict(const Matrix &dataset, 
00106                const GenVector<index_t> &predictor_indices,
00107                Vector *new_predictions);
00108 
00109   void factors(Matrix *factors);
00110 
00111  private:
00112 
00113   fx_module *module_;
00114 
00117   Matrix predictors_;
00118 
00122   Matrix predictions_;
00123 
00128   Matrix covariance_;
00129 
00132   Matrix factors_;
00133 
00134   void ComputeLinearModel_(double lambda_sq, const Vector &singular_values, 
00135                            const Matrix &u, const Matrix &v_t,
00136                            int num_features);
00137   
00138   void BuildDesignMatrixFromIndexSet_
00139   (const Matrix &input_data, const double *predictions,
00140    const GenVector<index_t> *predictor_indices);
00141   
00142   void BuildCovariance_(const Matrix &input_data, 
00143                         const GenVector<index_t> *predictor_indices,
00144                         const double *predictions_in);
00145 
00146   void ExtractCovarianceSubset_
00147   (const Matrix &precomputed_covariance,
00148    const GenVector<index_t> *loo_current_predictor_indices,
00149    Matrix *precomputed_covariance_subset);
00150 
00151   void ExtractSubspace_(Matrix *u, Vector *singular_values, Matrix *v_t,
00152                         const GenVector<index_t> *predictor_indices);
00153 };
00154 
00155 #include "ridge_regression_impl.h"
00156 #endif
Generated on Mon Jan 24 12:04:38 2011 for FASTlib by  doxygen 1.6.3