00001 // $Id$ 00002 // Copyright (C) 2002 Klaas Gadeyne <first dot last at gmail dot com> 00003 // Copyright (C) 2008 Tinne De Laet <first dot last at mech dot kuleuven dot be> 00004 // 00005 // This program is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU Lesser General Public License as published by 00007 // the Free Software Foundation; either version 2.1 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU Lesser General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 // 00019 #ifndef GAUSSIAN_H 00020 #define GAUSSIAN_H 00021 00022 #include "pdf.h" 00023 00024 namespace BFL 00025 { 00027 class Gaussian: public Pdf<MatrixWrapper::ColumnVector> 00028 { 00029 private: 00030 MatrixWrapper::ColumnVector _Mu; 00031 MatrixWrapper::SymmetricMatrix _Sigma; 00032 00033 // variables to avoid recalculation of inverse 00034 mutable bool _Sigma_changed; 00035 mutable MatrixWrapper::SymmetricMatrix _Sigma_inverse; 00036 mutable double _sqrt_pow; 00037 mutable ColumnVector _diff; //needed in probabilityGet 00038 mutable ColumnVector _tempColumn; //needed in probabilityGet 00039 // variables to avoid allocation on the heap during resampling 00040 mutable ColumnVector _samples; 00041 mutable ColumnVector _sampleValue; 00042 mutable Matrix _Low_triangle; 00043 00044 public: 00046 00050 Gaussian (const MatrixWrapper::ColumnVector& Mu, const MatrixWrapper::SymmetricMatrix& Sigma); 00051 00053 Gaussian (int dimension = 0); 00054 00056 00058 virtual ~Gaussian(); 00059 00061 friend std::ostream& operator<< (std::ostream& os, const Gaussian& g); 00062 00064 virtual Gaussian* Clone() const; 00065 00066 // Redefinition of pure virtuals 00067 virtual Probability ProbabilityGet(const MatrixWrapper::ColumnVector& input) const; 00068 bool SampleFrom (vector<Sample<MatrixWrapper::ColumnVector> >& list_samples, 00069 const int num_samples, 00070 int method=DEFAULT, 00071 void * args=NULL) const; 00072 virtual bool SampleFrom (Sample<MatrixWrapper::ColumnVector>& one_sample, int method=DEFAULT, void * args=NULL) const; 00073 00074 virtual MatrixWrapper::ColumnVector ExpectedValueGet() const; 00075 virtual MatrixWrapper::SymmetricMatrix CovarianceGet() const; 00076 00077 // For a Gaussian this should be possible 00079 00082 void ExpectedValueSet (const MatrixWrapper::ColumnVector& mu); 00083 00085 00088 void CovarianceSet (const MatrixWrapper::SymmetricMatrix& cov); 00089 }; 00090 00091 } // end namespace 00092 #endif