Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members

GaussianProcessRegressor.h

Go to the documentation of this file.
00001 // -*- C++ -*- 00002 00003 // GaussianProcessRegressor.h 00004 // 00005 // Copyright (C) 2003 Yoshua Bengio 00006 // 00007 // Redistribution and use in source and binary forms, with or without 00008 // modification, are permitted provided that the following conditions are met: 00009 // 00010 // 1. Redistributions of source code must retain the above copyright 00011 // notice, this list of conditions and the following disclaimer. 00012 // 00013 // 2. Redistributions in binary form must reproduce the above copyright 00014 // notice, this list of conditions and the following disclaimer in the 00015 // documentation and/or other materials provided with the distribution. 00016 // 00017 // 3. The name of the authors may not be used to endorse or promote 00018 // products derived from this software without specific prior written 00019 // permission. 00020 // 00021 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00022 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00023 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00024 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00025 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00026 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00027 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00028 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00029 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 // 00032 // This file is part of the PLearn library. For more information on the PLearn 00033 // library, go to the PLearn Web site at www.plearn.org 00034 00035 00036 00037 00038 /* ******************************************************* 00039 * $Id: GaussianProcessRegressor.h,v 1.10 2004/07/21 16:30:55 chrish42 Exp $ 00040 ******************************************************* */ 00041 00042 00045 #ifndef GaussianProcessRegressor_INC 00046 #define GaussianProcessRegressor_INC 00047 00048 #include "PConditionalDistribution.h" 00049 #include <plearn/ker/Kernel.h> 00050 00051 namespace PLearn { 00052 using namespace std; 00053 00072 class GaussianProcessRegressor: public PConditionalDistribution 00073 { 00074 00075 public: 00076 typedef PConditionalDistribution inherited; 00077 // Build options 00078 00079 PP<Kernel> kernel; // kernel = prior covariance on functions 00080 int n_outputs; // dimension of the target variables 00081 Vec noise_sd; // output noise standard deviation, for each output dimension 00082 string Gram_matrix_normalization; // normalization method to apply to Gram matrix: 00083 // "none": no normalization 00084 // "centering_a_dot_product": this is the kernel PCA centering 00085 // K_{ij} <-- K_{ij} - mean_i(K_ij) - mean_j(K_ij) + mean_{ij}(K_ij) 00086 // "centering_a_distance": this is the MDS transformation of squared distances to dot products 00087 // K_{ij} <-- -0.5(K_{ij} - mean_i(K_ij) - mean_j(K_ij) + mean_{ij}(K_ij)) 00088 // "divisive": this is the spectral clustering and Laplacian eigenmaps normalization 00089 // K_{ij} <-- K_{ij}/sqrt(mean_i(K_ij) mean_j(K_ij)) 00090 // 00091 int max_nb_evectors; // if -1 compute all eigenvectors, o/w compute only that many principal eigenvectors 00092 00093 00094 // temporary fields that don't need to be saved = NON-OPTIONS 00095 00096 Mat alpha; // each row has the coefficients of K(x,x_j) in regression for i-th output 00097 mutable Vec Kxxi; // has K(x,x_i) for current input x 00098 mutable real Kxx; // has K(x,x) for current input x 00099 Mat K; // non-sparse Gram matrix 00100 Mat eigenvectors; // principal eigenvectors (in the rows!) 00101 Vec eigenvalues; // and corresponding eigenvalues 00102 Vec meanK; // meanK[j]=mean_i(K_{ij}) 00103 real mean_allK; 00104 00105 public: 00106 00107 GaussianProcessRegressor(); 00108 virtual ~GaussianProcessRegressor(); 00109 00111 virtual void makeDeepCopyFromShallowCopy(map<const void*, void*>& copies); 00112 00114 virtual void setInput(const Vec& input); 00115 virtual void setInput_const(const Vec& input) const; // same thing, but cheating (make believe it is const) 00116 00118 virtual double log_density(const Vec& x) const; 00119 00121 virtual Vec expectation() const; 00122 00124 virtual void expectation(Vec expected_y) const; 00125 00127 virtual Mat variance() const; 00128 virtual void variance(Vec diag_variances) const; 00129 00130 private: 00131 void build_(); 00132 00133 public: 00134 virtual void build(); 00135 00136 virtual void forget(); 00137 00138 virtual int outputsize() const; 00139 00142 virtual void train(); 00143 00144 virtual void computeOutput(const Vec& input, Vec& output) const; 00145 00150 virtual void computeCostsFromOutputs(const Vec& input, const Vec& output, 00151 const Vec& target, Vec& costs) const; 00152 00156 virtual void computeOutputAndCosts(const Vec& input, const Vec& target, 00157 Vec& output, Vec& costs) const; 00158 00162 virtual void computeCostsOnly(const Vec& input, const Vec& target, Vec& costs) const; 00163 00164 00166 virtual TVec<string> getTestCostNames() const; 00167 00170 virtual TVec<string> getTrainCostNames() const; 00171 00172 virtual int nTestCosts() const { return 2; } 00173 00174 virtual int nTrainCosts() const { return 2; } 00175 00177 int getTestCostIndex(const string& costname) const; 00178 00180 int getTrainCostIndex(const string& costname) const; 00181 00182 protected: 00183 static void declareOptions(OptionList& ol); 00184 00185 // covariance = K + sigma^2 I 00186 // multiply (K+sigma^2 I)^{-1} by vector v, put result in Cinv_v 00187 // TRICK USING PRINCIPAL E-VECTORS OF K: 00188 // Let C = sum_{i=1}^m lambda_i v_i v_i' + sigma I 00189 // with v_i orthonormal eigenvectors. Then, it can also be written 00190 // C = sum_{i=1}^m (lambda_i +sigma) v_i v_i' + sum_{i=m+1}^n sigma v_i v_i' 00191 // whose inverse is simply 00192 // inverse(C) = sum_{i=1}^m 1/(lambda_i +sigma) v_i v_i' + sum_{i=m+1}^n 1/sigma v_i v_i' 00193 // = sum_{i=1}^m (1/(lambda_i +sigma) - 1/sigma) v_i v_i' + 1/sigma I 00194 // set Cinv_v = inverse(C)*v, using given sigma in C 00195 void inverseCovTimesVec(real sigma, Vec v, Vec Cinv_v) const; 00196 // return u'*inverse(C)*u, using given sigma in C 00197 real QFormInverse(real sigma2, Vec u) const; 00198 00201 real BayesianCost(); 00202 00203 public: 00204 PLEARN_DECLARE_OBJECT(GaussianProcessRegressor); 00205 00206 }; 00207 00208 DECLARE_OBJECT_PTR(GaussianProcessRegressor); 00209 00210 } // end of namespace PLearn 00211 00212 #endif 00213 00214 00215 00216 00217

Generated on Tue Aug 17 15:53:58 2004 for PLearn by doxygen 1.3.7