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

ConditionalGaussianDistribution.cc

Go to the documentation of this file.
00001 00002 00003 // -*- C++ -*- 00004 00005 // ConditionalGaussianDistribution.cc 00006 // 00007 // Copyright (C) *YEAR* *AUTHOR(S)* 00008 // ... 00009 // Copyright (C) *YEAR* *AUTHOR(S)* 00010 // 00011 // Redistribution and use in source and binary forms, with or without 00012 // modification, are permitted provided that the following conditions are met: 00013 // 00014 // 1. Redistributions of source code must retain the above copyright 00015 // notice, this list of conditions and the following disclaimer. 00016 // 00017 // 2. Redistributions in binary form must reproduce the above copyright 00018 // notice, this list of conditions and the following disclaimer in the 00019 // documentation and/or other materials provided with the distribution. 00020 // 00021 // 3. The name of the authors may not be used to endorse or promote 00022 // products derived from this software without specific prior written 00023 // permission. 00024 // 00025 // THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR 00026 // IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 00027 // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 00028 // NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 00029 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00030 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 00031 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 00032 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 00033 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00034 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00035 // 00036 // This file is part of the PLearn library. For more information on the PLearn 00037 // library, go to the PLearn Web site at www.plearn.org 00038 00039 #include "ConditionalGaussianDistribution.h" 00040 #include <plearn/math/plapack.h> 00041 #include <plearn/vmat/VMat_maths.h> 00042 #include <plearn/math/TMat.h> 00043 00044 namespace PLearn { 00045 using namespace std; 00046 00047 ConditionalGaussianDistribution::ConditionalGaussianDistribution() 00048 :inherited() 00049 { 00050 } 00051 00052 00053 PLEARN_IMPLEMENT_OBJECT(ConditionalGaussianDistribution, 00054 "ConditionalGaussianDistribution is a gaussian distribution " 00055 "in which the parameters could be learned or specified manually.", ""); 00056 00057 void ConditionalGaussianDistribution::declareOptions(OptionList& ol) 00058 { 00059 // ### Declare all of this object's options here 00060 // ### For the "flags" of each option, you should typically specify 00061 // ### one of OptionBase::buildoption, OptionBase::learntoption or 00062 // ### OptionBase::tuningoption. Another possible flag to be combined with 00063 // ### is OptionBase::nosave 00064 00065 declareOption(ol, "mean", &ConditionalGaussianDistribution::mean, OptionBase::buildoption, 00066 "The mean of the gaussian distribution \n" 00067 "Could be learned on a training set or specified by calling setInput"); 00068 00069 declareOption(ol, "covariance", &ConditionalGaussianDistribution::covariance, OptionBase::buildoption, 00070 "The covariance of the gaussian distribution \n" 00071 "Could be learned on a training set or specified manually"); 00072 00073 // Now call the parent class' declareOptions 00074 inherited::declareOptions(ol); 00075 } 00076 00077 void ConditionalGaussianDistribution::build() 00078 { 00079 inherited::build(); 00080 } 00081 00082 00083 void ConditionalGaussianDistribution::train(VMat training_set) 00084 { 00085 mean.resize(training_set.width()); 00086 covariance.resize(training_set.width(), training_set.width()); 00087 computeMeanAndCovar(training_set, mean, covariance); 00088 } 00089 00090 void ConditionalGaussianDistribution::makeDeepCopyFromShallowCopy(map<const void*, void*>& copies) 00091 { 00092 Learner::makeDeepCopyFromShallowCopy(copies); 00093 } 00094 00095 double ConditionalGaussianDistribution::log_density(const Vec& x) const 00096 { PLERROR("density not implemented yet for ConditionalGaussianDistribution"); return 0; } 00097 00098 double ConditionalGaussianDistribution::density(const Vec& x) const 00099 { return exp(log_density(x)); } 00100 00101 double ConditionalGaussianDistribution::survival_fn(const Vec& x) const 00102 { PLERROR("survival_fn not implemented yet for ConditionalGaussianDistribution"); return 0; } 00103 00104 double ConditionalGaussianDistribution::cdf(const Vec& x) const 00105 { PLERROR("cdf not implemented yet for ConditionalGaussianDistribution"); return 0; } 00106 00107 Vec ConditionalGaussianDistribution::expectation() const 00108 { 00109 return mean; 00110 } 00111 00112 Mat ConditionalGaussianDistribution::variance() const 00113 { 00114 return covariance; 00115 } 00116 00117 void ConditionalGaussianDistribution::generate(Vec& x) const 00118 { 00119 // WARNING! Function not found in lapack library for windows!! 00120 00121 #ifdef WIN32 00122 PLERROR("multivariate_normal for Vec not found in lapack library for windows!"); 00123 #else 00124 x = multivariate_normal(mean, covariance); 00125 #endif 00126 } 00127 00128 void ConditionalGaussianDistribution::setInput(const Vec& input) 00129 { 00130 mean.resize(input.size()); 00131 mean << input; 00132 } 00133 00134 } // end of namespace PLearn

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