#include <PDistribution.h>
Inheritance diagram for PLearn::PDistribution:
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< string > | getTestCostNames () const |
Return [ "NLL" ]. | |
virtual TVec< string > | getTrainCostNames () 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< int > | conditional_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< int > | cond_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< int > | cond_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 |
|
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. |
|
Default constructor.
Definition at line 50 of file PDistribution.cc. |
|
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_(). |
|
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(). |
|
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(). |
|
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(). |
|
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. |
|
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. |
|
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(). |
|
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(). |
|
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(). |
|
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(). |
|
(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. |
|
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(). |
|
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(). |
|
Return [ "NLL" ].
Implements PLearn::PLearner. Reimplemented in PLearn::GaussianProcessRegressor. Definition at line 303 of file PDistribution.cc. Referenced by PLearn::ConditionalDensityNet::getTrainCostNames(). |
|
Return [ ].
Implements PLearn::PLearner. Reimplemented in PLearn::ConditionalDensityNet, and PLearn::GaussianProcessRegressor. Definition at line 311 of file PDistribution.cc. |
|
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(). |
|
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. |
|
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. |
|
|
|
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. |
|
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(). |
|
Set the conditional flags.
Definition at line 381 of file PDistribution.cc. References setConditionalFlagsWithoutUpdate(), and updateFromConditionalSorting(). Referenced by ensureFullJointDistribution(), and setTrainingSet(). |
|
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(). |
|
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(). |
|
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(). |
|
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(). |
|
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(). |
|
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(). |
|
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(). |
|
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. |
|
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(). |
|
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. |
|
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(). |
|
Definition at line 65 of file PDistribution.h. Referenced by makeDeepCopyFromShallowCopy(), setConditionalFlagsWithoutUpdate(), and splitCond(). |
|
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(). |
|
Definition at line 104 of file PDistribution.h. Referenced by build_(), ensureFullJointDistribution(), makeDeepCopyFromShallowCopy(), setConditionalFlagsWithoutUpdate(), and setTrainingSet(). |
|
The step when plotting the curve (upper case outputs_def).
Definition at line 84 of file PDistribution.h. Referenced by build_(), and computeOutput(). |
|
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(). |
|
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(). |
|
Definition at line 105 of file PDistribution.h. Referenced by build_(), and computeOutput(). |
|
Definition at line 106 of file PDistribution.h. Referenced by build_(), computeOutput(), and outputsize(). |
|
Definition at line 66 of file PDistribution.h. Referenced by finishConditionalBuild(), resizeParts(), setConditionalFlagsWithoutUpdate(), and splitCond(). |
|
Definition at line 67 of file PDistribution.h. Referenced by setConditionalFlagsWithoutUpdate(), and splitCond(). |
|
Definition at line 68 of file PDistribution.h. Referenced by computeOutput(), outputsize(), resizeParts(), setConditionalFlagsWithoutUpdate(), and splitCond(). |
|
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(). |
|
Definition at line 107 of file PDistribution.h. Referenced by computeCostsFromOutputs(), computeOutput(), and outputsize(). |
|
Definition at line 108 of file PDistribution.h. Referenced by finishConditionalBuild(), and makeDeepCopyFromShallowCopy(). |
|
Definition at line 57 of file PDistribution.h. Referenced by computeOutput(), and makeDeepCopyFromShallowCopy(). |
|
Global storage to save memory allocations.
Definition at line 56 of file PDistribution.h. Referenced by computeOutput(), and makeDeepCopyFromShallowCopy(). |
|
Global storage to save memory allocations.
Definition at line 56 of file PDistribution.h. Referenced by computeOutput(), and makeDeepCopyFromShallowCopy(). |
|
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(). |
|
Definition at line 105 of file PDistribution.h. Referenced by build_(). |