PLearn 0.1
|
00001 // -*- C++ -*-4 1999/10/29 20:41:34 dugas 00002 00003 // distr_math.h 00004 // Copyright (C) 2002 Pascal Vincent 00005 // 00006 // Redistribution and use in source and binary forms, with or without 00007 // modification, are permitted provided that the following conditions are met: 00008 // 00009 // 1. Redistributions of source code must retain the above copyright 00010 // notice, this list of conditions and the following disclaimer. 00011 // 00012 // 2. Redistributions in binary form must reproduce the above copyright 00013 // notice, this list of conditions and the following disclaimer in the 00014 // documentation and/or other materials provided with the distribution. 00015 // 00016 // 3. The name of the authors may not be used to endorse or promote 00017 // products derived from this software without specific prior written 00018 // permission. 00019 // 00020 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00021 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00022 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00023 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00024 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00025 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00026 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00027 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00028 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00029 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00030 // 00031 // This file is part of the PLearn library. For more information on the PLearn 00032 // library, go to the PLearn Web site at www.plearn.org 00033 00034 00035 /* ******************************************************* 00036 * $Id: distr_maths.h 9436 2008-09-04 18:48:55Z nouiz $ 00037 * This file is part of the PLearn library. 00038 ******************************************************* */ 00039 00040 00043 #ifndef distr_maths_INC 00044 #define distr_maths_INC 00045 00046 #include "TMat.h" 00047 00048 namespace PLearn { 00049 using namespace std; 00050 00051 // return log of Normal(x;mu, sigma2*I), i.e. density of a spherical Gaussian 00052 real log_of_normal_density(Vec x, Vec mu, real sigma2); 00053 inline real normal_density(Vec x, Vec mu, real sigma2) { return safeexp(log_of_normal_density(x,mu,sigma2)); } 00054 real log_rbf(Vec x, Vec mu, real sigma2); 00055 inline real rbf(Vec x, Vec mu, real sigma2) { return safeexp(log_rbf(x,mu,sigma2)); } 00056 00057 // return log of Normal(x;mu, diag(sigma2)), i.e. density of a diagonal Gaussian 00058 real log_of_normal_density(Vec x, Vec mu, Vec sigma2); 00059 inline real normal_density(Vec x, Vec mu, Vec sigma2) { return safeexp(log_of_normal_density(x,mu,sigma2)); } 00060 00061 // return log of Normal(x;mu, Sigma), i.e. density of a full Gaussian, 00062 // where the covariance Sigma is 00063 // Sigma = remainder_evalue*I + sum_i max(0,evalues[i]-remainder_evalue)*evectors(i)*evectors(i)' 00064 // The eigenvectors are in the ROWS of matrix evectors (because of easier row-wise access in Mat's). 00065 real log_of_normal_density(Vec x, Vec mu, Mat evectors, Vec evalues, real remainder_evalue=0); 00066 inline real normal_density(Vec x, Vec mu, Mat evectors, Vec evalues, real remainder_evalue=0) 00067 { return safeexp(log_of_normal_density(x,mu,evectors,evalues,remainder_evalue)); } 00068 real log_fullGaussianRBF(Vec x, Vec mu, Mat evectors, Vec evalues, real remainder_evalue=0); 00069 inline real fullGaussianRBF(Vec x, Vec mu, Mat evectors, Vec evalues, real remainder_evalue=0) 00070 { return safeexp(log_fullGaussianRBF(x,mu,evectors,evalues,remainder_evalue)); } 00071 00072 real logOfNormal(const Vec& x, const Vec& mu, const Mat& C); 00073 00077 real logPFittedGaussian(const Vec& x, const Mat& X, real lambda); 00078 00085 real logOfCompactGaussian(const Vec& x, const Vec& mu, 00086 const Vec& eigenvalues, const Mat& eigenvectors, 00087 real gamma=1e-6, bool add_gamma_to_eigenval=false); 00088 00089 00095 real beta_density(real x, real alpha, real beta); 00097 real log_beta_density(real x, real alpha, real beta); 00098 00099 // if (inverses) compute the eigendecomposition of C = inv(inv(A) + inv(B)) from eigendecompositions of A and B 00100 // else compute the eigendecomposition of C = A + B from eigendecompositions of A and B 00101 void addEigenMatrices(Mat A_evec, Vec A_eval, Mat B_evec, Vec B_eval, Mat C_evec, Vec C_eval, bool inverses=false); 00102 00112 void sums2Gaussian(real sum_w, Vec sum_wx, Mat sum_wx2, Vec mu, Mat cov_evectors, Vec cov_evalues, real min_variance); 00113 00114 } // end of namespace PLearn 00115 00116 #endif 00117 00118 00119 /* 00120 Local Variables: 00121 mode:c++ 00122 c-basic-offset:4 00123 c-file-style:"stroustrup" 00124 c-file-offsets:((innamespace . 0)(inline-open . 0)) 00125 indent-tabs-mode:nil 00126 fill-column:79 00127 End: 00128 */ 00129 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=79 :