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

PLearn::PDistribution Class Reference

#include <PDistribution.h>

Inheritance diagram for PLearn::PDistribution:

Inheritance graph
[legend]
Collaboration diagram for PLearn::PDistribution:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 PDistribution ()
 Default constructor.

virtual void build ()
 simply calls inherited::build() then build_()

virtual void makeDeepCopyFromShallowCopy (map< const void *, void * > &copies)
 Transforms a shallow copy into a deep copy.

 PLEARN_DECLARE_OBJECT (PDistribution)
virtual int outputsize () const
 Returned value depends on outputs_def.

virtual void forget ()
 (Re-)initializes the PLearner in its fresh state (that state may depend on the 'seed' option) And sets 'stage' back to 0 (this is the stage of a fresh learner!)

virtual void train ()
 The role of the train method is to bring the learner up to stage==nstages, updating the train_stats collector with training costs measured on-line in the process.

virtual void computeOutput (const Vec &input, Vec &output) const
 Produce outputs according to what is specified in outputs_def.

virtual void computeCostsFromOutputs (const Vec &input, const Vec &output, const Vec &target, Vec &costs) const
 Computes negative log likelihood (NLL) assuming log-likelihood is first output.

void setConditionalFlags (TVec< int > &flags)
 Set the conditional flags.

virtual void setInput (const Vec &input) const
 Set the value for the input part of a conditional probability.

virtual void setTrainingSet (VMat training_set, bool call_forget=true)
 Overridden so that some stuff is updated according to the conditional flags when the training set is set.

virtual TVec< stringgetTestCostNames () const
 Return [ "NLL" ].

virtual TVec< stringgetTrainCostNames () const
 Return [ ].

virtual real log_density (const Vec &y) const
 Return log of probability density log(p(y | x)).

virtual real density (const Vec &y) const
 Return probability density p(y | x) (default version returns exp(log_density(y))).

virtual real survival_fn (const Vec &y) const
 Return survival function: P(Y>y | x).

virtual real cdf (const Vec &y) const
 Return cdf: P(Y<y | x).

virtual void expectation (Vec &mu) const
 Return E[Y | x].

virtual void variance (Mat &cov) const
 Return Var[Y | x].

virtual void resetGenerator (long g_seed) const
 Reset the random number generator used by generate() using the given seed.

virtual void generate (Vec &y) const
 Return a pseudo-random sample generated from the distribution.

void generateN (const Mat &Y) const
 X must be a N x inputsize() matrix.


Public Attributes

TVec< intconditional_flags
real lower_bound
real upper_bound
int n_curve_points
string outputs_def
Vec provide_input

Protected Member Functions

bool ensureFullJointDistribution (TVec< int > &old_flags)
 If the full joint distribution was already the one computed, return false and old_flags is of length 0.

void finishConditionalBuild ()
 Finish the build of a conditional distribution.

void resizeParts ()
 Resize input_part and target_part according to n_input and n_target.

void sortFromFlags (Vec &v)
 Sort a vector or a matrix according to the conditional flags currently defined.

void sortFromFlags (Mat &m, bool sort_columns=true, bool sort_rows=false)
bool splitCond (const Vec &input) const
 Split an input into the part corresponding to the 'real' input (in 'input_part'), and the target (in 'target_part').

virtual void updateFromConditionalSorting ()
 This method updates the internal data given a new sorting of the variables defined by the conditional flags.


Static Protected Member Functions

void declareOptions (OptionList &ol)
 Declares this class' options.


Protected Attributes

TVec< intcond_sort
int n_input
int n_margin
int n_target
bool already_sorted
 A boolean indicating whether the input, target and margin part are already sorted nicely, so we actually don't have to swap indices when given a new vector.

TVec< intcond_swap
 A vector indicating which indices need to be swapped when we have modified the conditional flags, in order to still have input, target, margin in this order.

real delta_curve
 The step when plotting the curve (upper case outputs_def).

bool full_joint_distribution
 A boolean indicating whether the distribution is only a full joint distribution (no conditional or marginalized variables).

Vec input_part
 Used to store the x part in p(y|x).

Vec target_part
 Used to store the y part in p(y|x).

bool need_set_input
 A boolean indicating whether the input part has changed since last time, and thus if setInput() needs to be called.


Private Types

typedef PLearner inherited

Private Member Functions

void build_ ()
 This does the actual building.

void setConditionalFlagsWithoutUpdate (TVec< int > &flags)
 Set the conditional flags, but does not call updateFromConditionalSorting().


Private Attributes

Vec store_expect
 Global storage to save memory allocations.

Vec store_result
 Global storage to save memory allocations.

Mat store_cov

Member Typedef Documentation

typedef PLearner PLearn::PDistribution::inherited [private]
 

Reimplemented from PLearn::PLearner.

Reimplemented in PLearn::ConditionalDensityNet, PLearn::GaussianDistribution, PLearn::GaussianProcessRegressor, PLearn::GaussMix, PLearn::HistogramDistribution, PLearn::ManifoldParzen2, PLearn::PConditionalDistribution, PLearn::SpiralDistribution, PLearn::UnconditionalDistribution, and PLearn::UniformDistribution.

Definition at line 53 of file PDistribution.h.


Constructor & Destructor Documentation

PLearn::PDistribution::PDistribution  ) 
 

Default constructor.

Definition at line 50 of file PDistribution.cc.


Member Function Documentation

void PLearn::PDistribution::build  )  [virtual]
 

simply calls inherited::build() then build_()

Reimplemented from PLearn::PLearner.

Reimplemented in PLearn::ConditionalDensityNet, PLearn::GaussianProcessRegressor, PLearn::GaussMix, PLearn::HistogramDistribution, PLearn::ManifoldParzen2, PLearn::PConditionalDistribution, PLearn::SpiralDistribution, PLearn::UnconditionalDistribution, and PLearn::UniformDistribution.

Definition at line 147 of file PDistribution.cc.

References build_().

void PLearn::PDistribution::build_  )  [private]
 

This does the actual building.

Reimplemented from PLearn::PLearner.

Reimplemented in PLearn::ConditionalDensityNet, PLearn::GaussianProcessRegressor, PLearn::GaussMix, PLearn::HistogramDistribution, PLearn::ManifoldParzen2, PLearn::PConditionalDistribution, PLearn::SpiralDistribution, PLearn::UnconditionalDistribution, and PLearn::UniformDistribution.

Definition at line 156 of file PDistribution.cc.

References conditional_flags, delta_curve, lower_bound, n_curve_points, setConditionalFlagsWithoutUpdate(), and upper_bound.

Referenced by build().

real PLearn::PDistribution::cdf const Vec y  )  const [virtual]
 

Return cdf: P(Y<y | x).

Reimplemented in PLearn::ConditionalDensityNet, PLearn::GaussMix, PLearn::HistogramDistribution, PLearn::SpiralDistribution, and PLearn::UniformDistribution.

Definition at line 581 of file PDistribution.cc.

References PLERROR.

Referenced by computeOutput().

void PLearn::PDistribution::computeCostsFromOutputs const Vec input,
const Vec output,
const Vec target,
Vec costs
const [virtual]
 

Computes negative log likelihood (NLL) assuming log-likelihood is first output.

Implements PLearn::PLearner.

Reimplemented in PLearn::GaussianProcessRegressor.

Definition at line 259 of file PDistribution.cc.

References outputs_def, PLERROR, and PLearn::TVec< T >::resize().

void PLearn::PDistribution::computeOutput const Vec input,
Vec output
const [virtual]
 

Produce outputs according to what is specified in outputs_def.

Implements PLearn::PLearner.

Reimplemented in PLearn::GaussianProcessRegressor, and PLearn::PConditionalDistribution.

Definition at line 168 of file PDistribution.cc.

References cdf(), delta_curve, density(), expectation(), input_part, k, log_density(), lower_bound, n_curve_points, n_target, need_set_input, outputs_def, PLERROR, PLearn::TVec< T >::resize(), setInput(), splitCond(), PLearn::square(), store_cov, store_expect, store_result, PLearn::TVec< T >::subVec(), survival_fn(), target_part, PLearn::variance(), and PLearn::Vec.

void PLearn::PDistribution::declareOptions OptionList ol  )  [static, protected]
 

Declares this class' options.

Reimplemented from PLearn::PLearner.

Reimplemented in PLearn::ConditionalDensityNet, PLearn::GaussianDistribution, PLearn::GaussianProcessRegressor, PLearn::GaussMix, PLearn::HistogramDistribution, PLearn::PConditionalDistribution, PLearn::SpiralDistribution, PLearn::UnconditionalDistribution, and PLearn::UniformDistribution.

Definition at line 77 of file PDistribution.cc.

References PLearn::declareOption(), and PLearn::OptionList.

real PLearn::PDistribution::density const Vec y  )  const [virtual]
 

Return probability density p(y | x) (default version returns exp(log_density(y))).

Reimplemented in PLearn::HistogramDistribution.

Definition at line 575 of file PDistribution.cc.

References PLearn::exp(), and log_density().

Referenced by computeOutput().

bool PLearn::PDistribution::ensureFullJointDistribution TVec< int > &  old_flags  )  [protected]
 

If the full joint distribution was already the one computed, return false and old_flags is of length 0.

Otherwise, return true, conditional_flags is emptied (in order to compute the full joint distribution), with a backup in old_flags.

Definition at line 272 of file PDistribution.cc.

References conditional_flags, full_joint_distribution, PLearn::TVec< int >::length(), PLearn::TVec< T >::resize(), and setConditionalFlags().

void PLearn::PDistribution::expectation Vec mu  )  const [virtual]
 

Return E[Y | x].

Reimplemented in PLearn::ConditionalDensityNet, PLearn::GaussMix, PLearn::HistogramDistribution, PLearn::SpiralDistribution, and PLearn::UniformDistribution.

Definition at line 584 of file PDistribution.cc.

References PLERROR.

Referenced by computeOutput().

void PLearn::PDistribution::finishConditionalBuild  )  [protected]
 

Finish the build of a conditional distribution.

This method should be called at the end of the build_() method in a subclass. It will call updateFromConditionalSorting() and setInput() (if necessary).

Definition at line 291 of file PDistribution.cc.

References input_part, PLearn::TVec< T >::isNotEmpty(), PLearn::TVec< T >::length(), n_input, provide_input, setInput(), and updateFromConditionalSorting().

void PLearn::PDistribution::forget  )  [virtual]
 

(Re-)initializes the PLearner in its fresh state (that state may depend on the 'seed' option) And sets 'stage' back to 0 (this is the stage of a fresh learner!)

Implements PLearn::PLearner.

Reimplemented in PLearn::ConditionalDensityNet, PLearn::GaussianDistribution, PLearn::GaussianProcessRegressor, and PLearn::GaussMix.

Definition at line 568 of file PDistribution.cc.

References PLERROR.

void PLearn::PDistribution::generate Vec y  )  const [virtual]
 

Return a pseudo-random sample generated from the distribution.

Reimplemented in PLearn::ConditionalDensityNet, PLearn::GaussianDistribution, PLearn::GaussMix, PLearn::SpiralDistribution, and PLearn::UniformDistribution.

Definition at line 593 of file PDistribution.cc.

References PLERROR.

Referenced by generateN().

void PLearn::PDistribution::generateN const Mat Y  )  const
 

X must be a N x inputsize() matrix.

that will be filled. This will call generate N times to fill the N rows of the matrix.

Definition at line 321 of file PDistribution.cc.

References generate(), PLearn::PLearner::inputsize(), PLearn::TMat< T >::length(), PLERROR, and PLearn::TMat< T >::width().

TVec< string > PLearn::PDistribution::getTestCostNames  )  const [virtual]
 

Return [ "NLL" ].

Implements PLearn::PLearner.

Reimplemented in PLearn::GaussianProcessRegressor.

Definition at line 303 of file PDistribution.cc.

Referenced by PLearn::ConditionalDensityNet::getTrainCostNames().

TVec< string > PLearn::PDistribution::getTrainCostNames  )  const [virtual]
 

Return [ ].

Implements PLearn::PLearner.

Reimplemented in PLearn::ConditionalDensityNet, and PLearn::GaussianProcessRegressor.

Definition at line 311 of file PDistribution.cc.

real PLearn::PDistribution::log_density const Vec y  )  const [virtual]
 

Return log of probability density log(p(y | x)).

Reimplemented in PLearn::ConditionalDensityNet, PLearn::GaussianDistribution, PLearn::GaussianProcessRegressor, PLearn::GaussMix, PLearn::HistogramDistribution, PLearn::SpiralDistribution, and PLearn::UniformDistribution.

Definition at line 572 of file PDistribution.cc.

References PLERROR.

Referenced by computeOutput(), and density().

void PLearn::PDistribution::makeDeepCopyFromShallowCopy map< const void *, void * > &  copies  )  [virtual]
 

Transforms a shallow copy into a deep copy.

Reimplemented in PLearn::ConditionalDensityNet, PLearn::GaussianProcessRegressor, PLearn::GaussMix, PLearn::HistogramDistribution, PLearn::ManifoldParzen2, PLearn::PConditionalDistribution, PLearn::SpiralDistribution, PLearn::UnconditionalDistribution, and PLearn::UniformDistribution.

Definition at line 337 of file PDistribution.cc.

References cond_sort, cond_swap, conditional_flags, PLearn::deepCopyField(), input_part, provide_input, store_cov, store_expect, store_result, and target_part.

int PLearn::PDistribution::outputsize  )  const [virtual]
 

Returned value depends on outputs_def.

Implements PLearn::PLearner.

Reimplemented in PLearn::GaussianProcessRegressor.

Definition at line 354 of file PDistribution.cc.

References n_curve_points, n_target, and outputs_def.

PLearn::PDistribution::PLEARN_DECLARE_OBJECT PDistribution   ) 
 

void PLearn::PDistribution::resetGenerator long  g_seed  )  const [virtual]
 

Reset the random number generator used by generate() using the given seed.

Reimplemented in PLearn::ConditionalDensityNet, PLearn::GaussianDistribution, PLearn::GaussMix, PLearn::SpiralDistribution, and PLearn::UniformDistribution.

Definition at line 590 of file PDistribution.cc.

References PLERROR.

void PLearn::PDistribution::resizeParts  )  [protected]
 

Resize input_part and target_part according to n_input and n_target.

Definition at line 373 of file PDistribution.cc.

References input_part, n_input, n_target, PLearn::TVec< T >::resize(), and target_part.

Referenced by setConditionalFlagsWithoutUpdate().

void PLearn::PDistribution::setConditionalFlags TVec< int > &  flags  ) 
 

Set the conditional flags.

Definition at line 381 of file PDistribution.cc.

References setConditionalFlagsWithoutUpdate(), and updateFromConditionalSorting().

Referenced by ensureFullJointDistribution(), and setTrainingSet().

void PLearn::PDistribution::setConditionalFlagsWithoutUpdate TVec< int > &  flags  )  [private]
 

Set the conditional flags, but does not call updateFromConditionalSorting().

This method is called at build time so that flags information is available to subclasses during their build. The updateFromConditionalSorting() method should then be called when the subclass' build ends (this will be done in finishConditionalBuild()).

Definition at line 392 of file PDistribution.cc.

References already_sorted, PLearn::TVec< int >::append(), PLearn::TVec< T >::append(), cond_sort, cond_swap, conditional_flags, full_joint_distribution, PLearn::PLearner::inputsize(), PLearn::TVec< T >::isEmpty(), PLearn::TVec< int >::length(), PLearn::TVec< T >::length(), PLearn::max(), n_input, n_margin, n_target, PLERROR, PLearn::TVec< int >::resize(), PLearn::TVec< T >::resize(), resizeParts(), and PLearn::TVec< T >::subVec().

Referenced by build_(), and setConditionalFlags().

void PLearn::PDistribution::setInput const Vec input  )  const [virtual]
 

Set the value for the input part of a conditional probability.

This needs to be implemented in subclasses if there is something special to do (like precomputing some stuff).

Reimplemented in PLearn::ConditionalDensityNet, PLearn::GaussMix, PLearn::PConditionalDistribution, and PLearn::UnconditionalDistribution.

Definition at line 487 of file PDistribution.cc.

References input_part.

Referenced by computeOutput(), and finishConditionalBuild().

void PLearn::PDistribution::setTrainingSet VMat  training_set,
bool  call_forget = true
[virtual]
 

Overridden so that some stuff is updated according to the conditional flags when the training set is set.

Reimplemented from PLearn::PLearner.

Definition at line 495 of file PDistribution.cc.

References conditional_flags, and setConditionalFlags().

void PLearn::PDistribution::sortFromFlags Mat m,
bool  sort_columns = true,
bool  sort_rows = false
[protected]
 

Definition at line 513 of file PDistribution.cc.

References cond_swap, k, PLearn::TVec< int >::length(), PLearn::TMat< T >::length(), PLearn::TMat< T >::resize(), sortFromFlags(), and PLearn::TMat< T >::width().

void PLearn::PDistribution::sortFromFlags Vec v  )  [protected]
 

Sort a vector or a matrix according to the conditional flags currently defined.

The indices are sorted as follows: input, target, margin. The vector (or matrix) is assumed to be sorted according to the previously defined flags.

Definition at line 504 of file PDistribution.cc.

References cond_swap, PLearn::TVec< int >::length(), PLearn::TVec< T >::length(), and PLearn::TVec< T >::resize().

Referenced by sortFromFlags().

bool PLearn::PDistribution::splitCond const Vec input  )  const [protected]
 

Split an input into the part corresponding to the 'real' input (in 'input_part'), and the target (in 'target_part').

Note that the 'margin' part is lost, since we don't need it. Return true iff the input part has changed since last time (this is false only it is absent from input, which can be seen from its length).

Definition at line 538 of file PDistribution.cc.

References already_sorted, cond_sort, input_part, PLearn::TVec< T >::length(), n_input, n_margin, n_target, PLERROR, PLearn::TVec< T >::subVec(), and target_part.

Referenced by computeOutput().

real PLearn::PDistribution::survival_fn const Vec y  )  const [virtual]
 

Return survival function: P(Y>y | x).

Reimplemented in PLearn::ConditionalDensityNet, PLearn::GaussMix, PLearn::HistogramDistribution, PLearn::SpiralDistribution, and PLearn::UniformDistribution.

Definition at line 578 of file PDistribution.cc.

References PLERROR.

Referenced by computeOutput().

void PLearn::PDistribution::train  )  [virtual]
 

The role of the train method is to bring the learner up to stage==nstages, updating the train_stats collector with training costs measured on-line in the process.

Implements PLearn::PLearner.

Reimplemented in PLearn::ConditionalDensityNet, PLearn::GaussianDistribution, PLearn::GaussianProcessRegressor, PLearn::GaussMix, PLearn::HistogramDistribution, and PLearn::ManifoldParzen2.

Definition at line 596 of file PDistribution.cc.

References PLERROR.

void PLearn::PDistribution::updateFromConditionalSorting  )  [protected, virtual]
 

This method updates the internal data given a new sorting of the variables defined by the conditional flags.

The default version does nothing: it should be implemented in each conditional subclass.

Reimplemented in PLearn::GaussMix, and PLearn::UnconditionalDistribution.

Definition at line 602 of file PDistribution.cc.

Referenced by finishConditionalBuild(), and setConditionalFlags().

void PLearn::PDistribution::variance Mat cov  )  const [virtual]
 

Return Var[Y | x].

Reimplemented in PLearn::ConditionalDensityNet, PLearn::GaussMix, PLearn::HistogramDistribution, PLearn::SpiralDistribution, and PLearn::UniformDistribution.

Definition at line 587 of file PDistribution.cc.

References PLERROR.


Member Data Documentation

bool PLearn::PDistribution::already_sorted [protected]
 

A boolean indicating whether the input, target and margin part are already sorted nicely, so we actually don't have to swap indices when given a new vector.

Definition at line 75 of file PDistribution.h.

Referenced by setConditionalFlagsWithoutUpdate(), and splitCond().

TVec<int> PLearn::PDistribution::cond_sort [protected]
 

Definition at line 65 of file PDistribution.h.

Referenced by makeDeepCopyFromShallowCopy(), setConditionalFlagsWithoutUpdate(), and splitCond().

TVec<int> PLearn::PDistribution::cond_swap [protected]
 

A vector indicating which indices need to be swapped when we have modified the conditional flags, in order to still have input, target, margin in this order.

It is made of pairs (j,k) indicating that the new j-th variable must be the old k-th variable.

Definition at line 81 of file PDistribution.h.

Referenced by makeDeepCopyFromShallowCopy(), setConditionalFlagsWithoutUpdate(), and sortFromFlags().

TVec<int> PLearn::PDistribution::conditional_flags
 

Definition at line 104 of file PDistribution.h.

Referenced by build_(), ensureFullJointDistribution(), makeDeepCopyFromShallowCopy(), setConditionalFlagsWithoutUpdate(), and setTrainingSet().

real PLearn::PDistribution::delta_curve [protected]
 

The step when plotting the curve (upper case outputs_def).

Definition at line 84 of file PDistribution.h.

Referenced by build_(), and computeOutput().

bool PLearn::PDistribution::full_joint_distribution [protected]
 

A boolean indicating whether the distribution is only a full joint distribution (no conditional or marginalized variables).

Its value is deduced from the conditional flags.

Definition at line 89 of file PDistribution.h.

Referenced by ensureFullJointDistribution(), and setConditionalFlagsWithoutUpdate().

Vec PLearn::PDistribution::input_part [mutable, protected]
 

Used to store the x part in p(y|x).

Definition at line 91 of file PDistribution.h.

Referenced by computeOutput(), finishConditionalBuild(), makeDeepCopyFromShallowCopy(), resizeParts(), setInput(), and splitCond().

real PLearn::PDistribution::lower_bound
 

Definition at line 105 of file PDistribution.h.

Referenced by build_(), and computeOutput().

int PLearn::PDistribution::n_curve_points
 

Definition at line 106 of file PDistribution.h.

Referenced by build_(), computeOutput(), and outputsize().

int PLearn::PDistribution::n_input [protected]
 

Definition at line 66 of file PDistribution.h.

Referenced by finishConditionalBuild(), resizeParts(), setConditionalFlagsWithoutUpdate(), and splitCond().

int PLearn::PDistribution::n_margin [protected]
 

Definition at line 67 of file PDistribution.h.

Referenced by setConditionalFlagsWithoutUpdate(), and splitCond().

int PLearn::PDistribution::n_target [protected]
 

Definition at line 68 of file PDistribution.h.

Referenced by computeOutput(), outputsize(), resizeParts(), setConditionalFlagsWithoutUpdate(), and splitCond().

bool PLearn::PDistribution::need_set_input [mutable, protected]
 

A boolean indicating whether the input part has changed since last time, and thus if setInput() needs to be called.

Definition at line 96 of file PDistribution.h.

Referenced by computeOutput().

string PLearn::PDistribution::outputs_def
 

Definition at line 107 of file PDistribution.h.

Referenced by computeCostsFromOutputs(), computeOutput(), and outputsize().

Vec PLearn::PDistribution::provide_input
 

Definition at line 108 of file PDistribution.h.

Referenced by finishConditionalBuild(), and makeDeepCopyFromShallowCopy().

Mat PLearn::PDistribution::store_cov [mutable, private]
 

Definition at line 57 of file PDistribution.h.

Referenced by computeOutput(), and makeDeepCopyFromShallowCopy().

Vec PLearn::PDistribution::store_expect [mutable, private]
 

Global storage to save memory allocations.

Definition at line 56 of file PDistribution.h.

Referenced by computeOutput(), and makeDeepCopyFromShallowCopy().

Vec PLearn::PDistribution::store_result [mutable, private]
 

Global storage to save memory allocations.

Definition at line 56 of file PDistribution.h.

Referenced by computeOutput(), and makeDeepCopyFromShallowCopy().

Vec PLearn::PDistribution::target_part [mutable, protected]
 

Used to store the y part in p(y|x).

Definition at line 92 of file PDistribution.h.

Referenced by computeOutput(), makeDeepCopyFromShallowCopy(), resizeParts(), and splitCond().

real PLearn::PDistribution::upper_bound
 

Definition at line 105 of file PDistribution.h.

Referenced by build_().


The documentation for this class was generated from the following files:
Generated on Tue Aug 17 16:27:19 2004 for PLearn by doxygen 1.3.7