| PLearn 0.1 | 
#include <UniformDistribution.h>


| Public Member Functions | |
| UniformDistribution () | |
| Default constructor. | |
| virtual void | build () | 
| Simply call inherited::build() then build_(). | |
| virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) | 
| Transform a shallow copy into a deep copy. | |
| virtual string | classname () const | 
| virtual OptionList & | getOptionList () const | 
| virtual OptionMap & | getOptionMap () const | 
| virtual RemoteMethodMap & | getRemoteMethodMap () const | 
| virtual UniformDistribution * | deepCopy (CopiesMap &copies) const | 
| virtual real | log_density (const Vec &x) const | 
| Return log of probability density log(p(x)). | |
| virtual real | survival_fn (const Vec &x) const | 
| Return survival fn = P(X>x). | |
| virtual real | cdf (const Vec &x) const | 
| Return survival fn = P(X<x). | |
| virtual void | expectation (Vec &mu) const | 
| Return E[X]. | |
| virtual void | variance (Mat &cov) const | 
| Return Var[X]. | |
| virtual void | resetGenerator (long g_seed) | 
| Reset the random number generator used by generate() using the given seed. | |
| virtual void | generate (Vec &x) const | 
| Return a pseudo-random sample generated from the distribution. | |
| Static Public Member Functions | |
| static string | _classname_ () | 
| 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 | |
| Vec | max | 
| Vec | min | 
| int | mesh_size | 
| int | n_dim | 
| Static Public Attributes | |
| static StaticInitializer | _static_initializer_ | 
| Static Protected Member Functions | |
| static void | declareOptions (OptionList &ol) | 
| Declare this class' options. | |
| Protected Attributes | |
| int | counter | 
| Private Types | |
| typedef UnconditionalDistribution | inherited | 
| Private Member Functions | |
| void | build_ () | 
| This does the actual building. | |
Definition at line 52 of file UniformDistribution.h.
| typedef UnconditionalDistribution PLearn::UniformDistribution::inherited  [private] | 
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 57 of file UniformDistribution.h.
| PLearn::UniformDistribution::UniformDistribution | ( | ) | 
Default constructor.
Definition at line 51 of file UniformDistribution.cc.
References max, min, and PLearn::TVec< T >::resize().
                                        :
    counter(0),
    mesh_size(-1),
    n_dim(-1)
{
    // Default = generate points uniformly in [0,1].
    min.resize(1);
    max.resize(1);
    min[0] = 0;
    max[0] = 1;
}

| string PLearn::UniformDistribution::_classname_ | ( | ) |  [static] | 
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 69 of file UniformDistribution.cc.
| OptionList & PLearn::UniformDistribution::_getOptionList_ | ( | ) |  [static] | 
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 69 of file UniformDistribution.cc.
| RemoteMethodMap & PLearn::UniformDistribution::_getRemoteMethodMap_ | ( | ) |  [static] | 
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 69 of file UniformDistribution.cc.
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 69 of file UniformDistribution.cc.
| Object * PLearn::UniformDistribution::_new_instance_for_typemap_ | ( | ) |  [static] | 
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 69 of file UniformDistribution.cc.
| StaticInitializer UniformDistribution::_static_initializer_ & PLearn::UniformDistribution::_static_initialize_ | ( | ) |  [static] | 
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 69 of file UniformDistribution.cc.
| void PLearn::UniformDistribution::build | ( | ) |  [virtual] | 
Simply call inherited::build() then build_().
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 102 of file UniformDistribution.cc.
References PLearn::UnconditionalDistribution::build(), and build_().
{
    inherited::build();
    build_();
}

| void PLearn::UniformDistribution::build_ | ( | ) |  [private] | 
This does the actual building.
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 111 of file UniformDistribution.cc.
References PLearn::TVec< T >::append(), PLearn::UnconditionalDistribution::build(), i, PLearn::PLearner::inputsize_, PLearn::TVec< T >::length(), max, min, n_dim, PLASSERT, and PLERROR.
Referenced by build().
{
    // ### This method should do the real building of the object,
    // ### according to set 'options', in *any* situation.
    // ### Typical situations include:
    // ###  - Initial building of an object from a few user-specified options
    // ###  - Building of a "reloaded" object: i.e. from the complete set of all serialised options.
    // ###  - Updating or "re-building" of an object after a few "tuning" options have been modified.
    // ### You should assume that the parent class' build_() has already been called.
    // Check consistency of intervals.
    if (min.length() != max.length()) {
        PLERROR("In UniformDistribution::build_ - 'min' and 'max' should have the same size");
    }
    if (n_dim == -1)
        n_dim = min.length();
    if (n_dim != min.length()) {
        if (min.length() == 1) {
            real min_val = min[0];
            real max_val = max[0];
            for (int i = 0; i < n_dim - 1; i++) {
                min.append(min_val);
                max.append(max_val);
            }
        } else
            PLERROR("In UniformDistribution::build_ - The value of 'n_dim' "
                    "does not match the length of the 'min' vector");
    }
    PLASSERT( n_dim == min.length() );
    for (int i = 0; i < n_dim; i++) {
        if (min[i] > max[i]) {
            PLERROR("In UniformDistribution::build_ - 'min' should be always <= 'max'");
        }
    }
    inputsize_ = n_dim;
    // We need to re-build the parent classes, because the inputsize has
    // changed.
    inherited::build();
}


Return survival fn = P(X<x).
Reimplemented from PLearn::PDistribution.
Definition at line 156 of file UniformDistribution.cc.
References PLERROR.
{
    PLERROR("cdf not implemented for UniformDistribution"); return 0;
}
| string PLearn::UniformDistribution::classname | ( | ) | const  [virtual] | 
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 69 of file UniformDistribution.cc.
| void PLearn::UniformDistribution::declareOptions | ( | OptionList & | ol | ) |  [static, protected] | 
Declare this class' options.
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 74 of file UniformDistribution.cc.
References PLearn::OptionBase::buildoption, counter, PLearn::declareOption(), PLearn::UnconditionalDistribution::declareOptions(), PLearn::OptionBase::learntoption, max, mesh_size, min, and n_dim.
{
    declareOption(ol, "min", &UniformDistribution::min, OptionBase::buildoption,
        "The inferior bound for all intervals.");
    declareOption(ol, "max", &UniformDistribution::max, OptionBase::buildoption,
        "The superior bound for all intervals.");
    declareOption(ol, "mesh_size", &UniformDistribution::mesh_size, OptionBase::buildoption,
        "If set to a value > 0, this distribution will generate points deterministically\n"
        "so as to form a mesh of 'mesh_size'^d points equally spaced.");
    declareOption(ol, "n_dim", &UniformDistribution::n_dim,
                               OptionBase::buildoption,
        "Optionally, the number of dimensions. Provide this option only if\n"
        "you want to generate 'n_dim' dimensions all in [min,max] (in which\n"
        "case the length of 'min' and 'max' should be 1).");
    declareOption(ol, "counter", &UniformDistribution::counter, OptionBase::learntoption,
                  "Counts the number of points generated (necessary when 'mesh_size' is used).");
    // Now call the parent class' declareOptions().
    inherited::declareOptions(ol);
}

| static const PPath& PLearn::UniformDistribution::declaringFile | ( | ) |  [inline, static] | 
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 114 of file UniformDistribution.h.
| UniformDistribution * PLearn::UniformDistribution::deepCopy | ( | CopiesMap & | copies | ) | const  [virtual] | 
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 69 of file UniformDistribution.cc.
| void PLearn::UniformDistribution::expectation | ( | Vec & | mu | ) | const  [virtual] | 
Return E[X].
Reimplemented from PLearn::PDistribution.
Definition at line 164 of file UniformDistribution.cc.
References PLERROR.
{
    PLERROR("expectation not implemented for UniformDistribution");
}
| void PLearn::UniformDistribution::generate | ( | Vec & | x | ) | const  [virtual] | 
Return a pseudo-random sample generated from the distribution.
Reimplemented from PLearn::PDistribution.
Definition at line 172 of file UniformDistribution.cc.
References counter, i, max, mesh_size, min, n_dim, PLearn::PLearner::random_gen, and PLearn::TVec< T >::resize().
{
    x.resize(n_dim);
    if (mesh_size > 0) {
        int val = counter;
        int coord;
        for (int i = 0; i < n_dim; i++) {
            coord = val % mesh_size;
            val /= mesh_size;
            x[i] = min[i] + (max[i] - min[i]) * coord / real(mesh_size) + (max[i] - min[i]) / (2 * real(mesh_size));
        }
        counter++;
    } else {
        for (int i = 0; i < n_dim; i++) {
            x[i] = random_gen->bounded_uniform(min[i], max[i]);
        }
    }
}

| OptionList & PLearn::UniformDistribution::getOptionList | ( | ) | const  [virtual] | 
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 69 of file UniformDistribution.cc.
| OptionMap & PLearn::UniformDistribution::getOptionMap | ( | ) | const  [virtual] | 
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 69 of file UniformDistribution.cc.
| RemoteMethodMap & PLearn::UniformDistribution::getRemoteMethodMap | ( | ) | const  [virtual] | 
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 69 of file UniformDistribution.cc.
Return log of probability density log(p(x)).
Reimplemented from PLearn::PDistribution.
Definition at line 194 of file UniformDistribution.cc.
References i, max, min, n_dim, pl_log, and PLearn::sum().
{
    real sum = 0;
    for (int i = 0; i < n_dim; i++) {
        if (x[i] > max[i] || x[i] < min[i])
            return -INFINITY;
        sum += pl_log(max[i] - min[i]);
    }
    return -sum;
}

| void PLearn::UniformDistribution::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) |  [virtual] | 
Transform a shallow copy into a deep copy.
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 208 of file UniformDistribution.cc.
References PLearn::UnconditionalDistribution::makeDeepCopyFromShallowCopy(), and PLERROR.
{
    inherited::makeDeepCopyFromShallowCopy(copies);
    // ### Call deepCopyField on all "pointer-like" fields
    // ### that you wish to be deepCopied rather than
    // ### shallow-copied.
    // ### ex:
    // deepCopyField(trainvec, copies);
    // ### Remove this line when you have fully implemented this method.
    PLERROR("UniformDistribution::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!");
}

| void PLearn::UniformDistribution::resetGenerator | ( | long | g_seed | ) |  [virtual] | 
Reset the random number generator used by generate() using the given seed.
Reimplemented from PLearn::PDistribution.
Definition at line 225 of file UniformDistribution.cc.
References counter, and PLearn::PDistribution::resetGenerator().
{
    inherited::resetGenerator(g_seed);
    counter = 0;
}

Return survival fn = P(X>x).
Reimplemented from PLearn::PDistribution.
Definition at line 234 of file UniformDistribution.cc.
References PLERROR.
{
    PLERROR("survival_fn not implemented for UniformDistribution"); return 0;
}
| void PLearn::UniformDistribution::variance | ( | Mat & | cov | ) | const  [virtual] | 
Reimplemented from PLearn::PDistribution.
Definition at line 242 of file UniformDistribution.cc.
References PLERROR.
{
    PLERROR("variance not implemented for UniformDistribution");
}
Reimplemented from PLearn::UnconditionalDistribution.
Definition at line 114 of file UniformDistribution.h.
| int PLearn::UniformDistribution::counter  [mutable, protected] | 
Definition at line 65 of file UniformDistribution.h.
Referenced by declareOptions(), generate(), and resetGenerator().
Definition at line 75 of file UniformDistribution.h.
Referenced by build_(), declareOptions(), generate(), log_density(), and UniformDistribution().
Definition at line 77 of file UniformDistribution.h.
Referenced by declareOptions(), and generate().
Definition at line 76 of file UniformDistribution.h.
Referenced by build_(), declareOptions(), generate(), log_density(), and UniformDistribution().
Definition at line 78 of file UniformDistribution.h.
Referenced by build_(), declareOptions(), generate(), and log_density().
 1.7.4
 1.7.4