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
00033
00034
00035
00036
00037
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
00060
00061
00062
00063
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
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
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 }