PLearn 0.1
|
#include <EmpiricalDistribution.h>
Public Member Functions | |
EmpiricalDistribution () | |
EmpiricalDistribution (int inputsize, bool random_sample_=true) | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual EmpiricalDistribution * | deepCopy (CopiesMap &copies) const |
void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Transforms a shallow copy into a deep copy. | |
virtual void | train (VMat training_set) |
trains the model | |
virtual double | log_density (const Vec &x) const |
return log of probability density log(p(x)) | |
virtual double | survival_fn (const Vec &x) const |
return survival fn = P(X>x) | |
virtual double | cdf (const Vec &x) const |
return survival fn = P(X<x) | |
virtual Vec | expectation () const |
return E[X] | |
virtual Mat | variance () const |
return Var[X] | |
virtual void | generate (Vec &x) const |
return a sample generated from the distribution. | |
Static Public Member Functions | |
static string | _classname_ () |
Declares name and deepCopy methods. | |
static OptionList & | _getOptionList_ () |
static RemoteMethodMap & | _getRemoteMethodMap_ () |
static Object * | _new_instance_for_typemap_ () |
static bool | _isa_ (const Object *o) |
static void | _static_initialize_ () |
static const PPath & | declaringFile () |
Public Attributes | |
bool | random_sample |
int | length |
int | current_sample_x |
int | current_sample_y |
bool | flip |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Protected Types | |
typedef Distribution | inherited |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares this class' options. | |
Protected Attributes | |
VMat | data |
Definition at line 42 of file EmpiricalDistribution.h.
typedef Distribution PLearn::EmpiricalDistribution::inherited [protected] |
Reimplemented from PLearn::Distribution.
Definition at line 48 of file EmpiricalDistribution.h.
PLearn::EmpiricalDistribution::EmpiricalDistribution | ( | ) |
Definition at line 54 of file EmpiricalDistribution.cc.
References PLearn::seed().
Definition at line 61 of file EmpiricalDistribution.cc.
References current_sample_x, current_sample_y, flip, PLearn::Learner::inputsize(), PLearn::Learner::inputsize_, and PLearn::seed().
:inherited(), random_sample(random_sample_) { inputsize_ = inputsize; current_sample_x = 0; current_sample_y = 0; flip = false; seed(); }
string PLearn::EmpiricalDistribution::_classname_ | ( | ) | [static] |
Declares name and deepCopy methods.
Reimplemented from PLearn::Distribution.
Definition at line 45 of file EmpiricalDistribution.cc.
OptionList & PLearn::EmpiricalDistribution::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::Distribution.
Definition at line 45 of file EmpiricalDistribution.cc.
RemoteMethodMap & PLearn::EmpiricalDistribution::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::Distribution.
Definition at line 45 of file EmpiricalDistribution.cc.
Reimplemented from PLearn::Distribution.
Definition at line 45 of file EmpiricalDistribution.cc.
Object * PLearn::EmpiricalDistribution::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Distribution.
Definition at line 45 of file EmpiricalDistribution.cc.
StaticInitializer EmpiricalDistribution::_static_initializer_ & PLearn::EmpiricalDistribution::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::Distribution.
Definition at line 45 of file EmpiricalDistribution.cc.
double PLearn::EmpiricalDistribution::cdf | ( | const Vec & | x | ) | const [virtual] |
return survival fn = P(X<x)
Reimplemented from PLearn::Distribution.
Definition at line 111 of file EmpiricalDistribution.cc.
References data, i, j, PLearn::VMat::length(), and PLearn::VMat::width().
{ double nbLower = 0; bool addOne; for(int i = 0; i<data.length(); i++){ addOne = true; for(int j = 0;j<data.width(); j++){ if(data(i,j) >= x[j]) addOne = false; } if(addOne) nbLower++; } return nbLower / ((double) data.length()); }
string PLearn::EmpiricalDistribution::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Distribution.
Definition at line 45 of file EmpiricalDistribution.cc.
void PLearn::EmpiricalDistribution::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares this class' options.
Reimplemented from PLearn::Distribution.
Definition at line 73 of file EmpiricalDistribution.cc.
References PLearn::Distribution::declareOptions().
{ inherited::declareOptions(ol); }
static const PPath& PLearn::EmpiricalDistribution::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::Distribution.
Definition at line 56 of file EmpiricalDistribution.h.
: static void declareOptions(OptionList& ol);
EmpiricalDistribution * PLearn::EmpiricalDistribution::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::Distribution.
Definition at line 45 of file EmpiricalDistribution.cc.
Vec PLearn::EmpiricalDistribution::expectation | ( | ) | const [virtual] |
return E[X]
Reimplemented from PLearn::Distribution.
Definition at line 128 of file EmpiricalDistribution.cc.
References PLearn::computeMean(), data, PLearn::Learner::inputsize_, and PLearn::mean().
{ Vec mean(inputsize_); computeMean(data, mean); return mean; }
void PLearn::EmpiricalDistribution::generate | ( | Vec & | x | ) | const [virtual] |
return a sample generated from the distribution.
Reimplemented from PLearn::Distribution.
Definition at line 145 of file EmpiricalDistribution.cc.
References current_sample_x, current_sample_y, data, flip, length, random_sample, PLearn::TVec< T >::resize(), PLearn::uniform_multinomial_sample(), and PLearn::VMat::width().
{ if(random_sample){ x.resize(data.width()); x << data(uniform_multinomial_sample(length)); } //Hack for generating all the possible combinations of two //examples. else{ if(!flip){ x.resize(data.width()); x << data(current_sample_x); flip = true; } else{ x.resize(data.width()); x << data(current_sample_y); current_sample_y++; flip = false; } if(current_sample_y == length){ current_sample_y = 0; current_sample_x++; } if(current_sample_x == length) current_sample_x = 0; } }
OptionList & PLearn::EmpiricalDistribution::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Distribution.
Definition at line 45 of file EmpiricalDistribution.cc.
OptionMap & PLearn::EmpiricalDistribution::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Distribution.
Definition at line 45 of file EmpiricalDistribution.cc.
RemoteMethodMap & PLearn::EmpiricalDistribution::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Distribution.
Definition at line 45 of file EmpiricalDistribution.cc.
double PLearn::EmpiricalDistribution::log_density | ( | const Vec & | x | ) | const [virtual] |
return log of probability density log(p(x))
Reimplemented from PLearn::Distribution.
Definition at line 88 of file EmpiricalDistribution.cc.
References PLERROR.
{ PLERROR("Density not implemented for EmpiricalDistribution"); return 0; }
void PLearn::EmpiricalDistribution::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::Distribution.
Definition at line 47 of file EmpiricalDistribution.cc.
References PLearn::deepCopyField().
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(data, copies); }
double PLearn::EmpiricalDistribution::survival_fn | ( | const Vec & | x | ) | const [virtual] |
return survival fn = P(X>x)
Reimplemented from PLearn::Distribution.
Definition at line 95 of file EmpiricalDistribution.cc.
References data, i, j, PLearn::VMat::length(), and PLearn::VMat::width().
{ double nbHigher = 0; bool addOne; for(int i = 0; i<data.length(); i++){ addOne = true; for(int j = 0;j<data.width(); j++){ if(data(i,j) <= x[j]) addOne = false; } if(addOne) nbHigher++; } return nbHigher / ((double) data.length()); }
void PLearn::EmpiricalDistribution::train | ( | VMat | training_set | ) | [virtual] |
trains the model
Reimplemented from PLearn::Distribution.
Definition at line 79 of file EmpiricalDistribution.cc.
References data, PLearn::Learner::inputsize_, PLearn::VMat::length(), length, PLERROR, PLearn::VMat::subMatColumns(), PLearn::Learner::targetsize_, and PLearn::VMat::width().
{ if(inputsize_ == 0) PLERROR("inputsize_ must be specified before training"); data = training_set.subMatColumns(0, inputsize_); targetsize_ = data.width()-inputsize_; length = training_set.length(); }
Mat PLearn::EmpiricalDistribution::variance | ( | ) | const [virtual] |
Reimplemented from PLearn::Distribution.
Definition at line 135 of file EmpiricalDistribution.cc.
References PLearn::computeMeanAndCovar(), data, PLearn::Learner::inputsize_, and PLearn::mean().
{ Vec mean(inputsize_); Mat covar(inputsize_,inputsize_); computeMeanAndCovar(data, mean, covar); return covar; }
Reimplemented from PLearn::Distribution.
Definition at line 56 of file EmpiricalDistribution.h.
Definition at line 92 of file EmpiricalDistribution.h.
Referenced by EmpiricalDistribution(), and generate().
Definition at line 93 of file EmpiricalDistribution.h.
Referenced by EmpiricalDistribution(), and generate().
VMat PLearn::EmpiricalDistribution::data [protected] |
Definition at line 46 of file EmpiricalDistribution.h.
Referenced by cdf(), expectation(), generate(), survival_fn(), train(), and variance().
bool PLearn::EmpiricalDistribution::flip [mutable] |
Definition at line 94 of file EmpiricalDistribution.h.
Referenced by EmpiricalDistribution(), and generate().
Definition at line 89 of file EmpiricalDistribution.h.
Referenced by generate(), and train().
Definition at line 86 of file EmpiricalDistribution.h.
Referenced by generate().