ridge_regression.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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