PLearn 0.1
|
#include <VMatrixFromDistribution.h>
Public Member Functions | |
VMatrixFromDistribution () | |
virtual void | build () |
Simply calls inherited::build() then build_(). | |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Transforms a shallow copy into a deep copy. | |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual VMatrixFromDistribution * | deepCopy (CopiesMap &copies) const |
virtual real | get (int i, int j) const |
This method must be implemented in all subclasses. | |
virtual void | getSubRow (int i, int j, Vec v) const |
It is suggested that this method be implemented in subclasses to speed up accesses (default version repeatedly calls get(i,j) which may have a significant overhead). | |
virtual void | getRow (int i, Vec v) const |
These methods do not usually need to be overridden in subclasses (default versions call getSubRow, which should do just fine) | |
virtual void | getColumn (int i, Vec v) const |
Copies column i into v (which must have appropriate length equal to the VMat's length). | |
virtual void | getMat (int i, int j, Mat m) const |
Copies the submatrix starting at i,j into m (which must have appropriate length and width). | |
virtual Mat | toMat () const |
Returns a Mat with the same data as this VMat. | |
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 | |
PP< PDistribution > | distr |
string | mode |
int32_t | generator_seed |
int | nsamples |
Vec | mins |
Vec | maxs |
int | samples_per_dim |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares this class' options. | |
Protected Attributes | |
Mat | data |
Will hold the data sampled from the distribution. | |
Private Types | |
typedef VMatrix | inherited |
Private Member Functions | |
void | build_ () |
This does the actual building. |
Definition at line 50 of file VMatrixFromDistribution.h.
typedef VMatrix PLearn::VMatrixFromDistribution::inherited [private] |
Reimplemented from PLearn::VMatrix.
Definition at line 55 of file VMatrixFromDistribution.h.
PLearn::VMatrixFromDistribution::VMatrixFromDistribution | ( | ) |
Definition at line 47 of file VMatrixFromDistribution.cc.
References samples_per_dim.
:mode("sample"), generator_seed(0), nsamples(0) /* ### Initialize all fields to their default value */ { samples_per_dim = 10; }
string PLearn::VMatrixFromDistribution::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::VMatrix.
Definition at line 57 of file VMatrixFromDistribution.cc.
OptionList & PLearn::VMatrixFromDistribution::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::VMatrix.
Definition at line 57 of file VMatrixFromDistribution.cc.
RemoteMethodMap & PLearn::VMatrixFromDistribution::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::VMatrix.
Definition at line 57 of file VMatrixFromDistribution.cc.
Reimplemented from PLearn::VMatrix.
Definition at line 57 of file VMatrixFromDistribution.cc.
Object * PLearn::VMatrixFromDistribution::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 57 of file VMatrixFromDistribution.cc.
StaticInitializer VMatrixFromDistribution::_static_initializer_ & PLearn::VMatrixFromDistribution::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::VMatrix.
Definition at line 57 of file VMatrixFromDistribution.cc.
void PLearn::VMatrixFromDistribution::build | ( | ) | [virtual] |
Simply calls inherited::build() then build_().
Reimplemented from PLearn::VMatrix.
Definition at line 154 of file VMatrixFromDistribution.cc.
References PLearn::VMatrix::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::VMatrixFromDistribution::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::VMatrix.
Definition at line 90 of file VMatrixFromDistribution.cc.
References data, distr, generator_seed, i, PLearn::VMatrix::inputsize_, j, PLearn::VMatrix::length_, maxs, mins, mode, nsamples, PLERROR, PLearn::pow(), PLearn::TMat< T >::resize(), samples_per_dim, PLearn::VMatrix::targetsize_, PLearn::VMatrix::weightsize_, PLearn::TMat< T >::width(), and PLearn::VMatrix::width_.
Referenced by build().
{ if(distr) { if(mode=="sample") { length_ = nsamples; width_ = distr->getNPredicted(); inputsize_ = width_; targetsize_ = 0; weightsize_ = 0; data.resize(length_, width_); distr->resetGenerator(generator_seed); distr->generateN(data); } else if(mode=="density" || mode=="log_density") { length_ = (int)pow(double(samples_per_dim),double(distr->inputsize())); width_ = distr->inputsize()+1; inputsize_ = distr->inputsize(); targetsize_ = 0; weightsize_ = 1; data.resize(length_, width_); Vec v(data.width()); int k=0; switch(distr->inputsize()) { case 1: for(int j=0;j<samples_per_dim;j++) { v[0] = mins[0] + ((real)j / (samples_per_dim-1)) * (maxs[0]-mins[0]); if(mode=="density") v[1] = distr->density(v.subVec(0,1)); else // log_density v[1] = distr->log_density(v.subVec(0,1)); data(k++)<<v; } break; case 2: for(int i=0;i<samples_per_dim;i++) { v[0] = mins[0] + ((real)i / (samples_per_dim-1)) * (maxs[0]-mins[0]); for(int j=0;j<samples_per_dim;j++) { v[1] = mins[1] + ((real)j / (samples_per_dim-1)) * (maxs[1]-mins[1]); if(mode=="density") v[2] = distr->density(v.subVec(0,2)); else // log_density v[2] = distr->log_density(v.subVec(0,2)); data(k++)<<v; } } break; default: PLERROR("density and log_density modes only supported for distribution of dimension 1 or 2");break; } } else PLERROR("In VMatrixFromDistribution: invalid mode: %s",mode.c_str()); } }
string PLearn::VMatrixFromDistribution::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 57 of file VMatrixFromDistribution.cc.
void PLearn::VMatrixFromDistribution::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares this class' options.
Reimplemented from PLearn::VMatrix.
Definition at line 59 of file VMatrixFromDistribution.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::VMatrix::declareOptions(), distr, generator_seed, maxs, mins, mode, nsamples, and samples_per_dim.
{ declareOption(ol, "distr", &VMatrixFromDistribution::distr, OptionBase::buildoption, "The distribution this matrix will be generated from\n"); declareOption(ol, "mode", &VMatrixFromDistribution::mode, OptionBase::buildoption, "mode can be one of:\n" " \"sample\" : will draw nsamples from the distribution initializing the generator with the generator_seed \n" " \"density\" : for 1d or 2d distributions, will report the density along a grid of samples_per_dim \n" " gridpoints per dimension. The resulting matrix will contain rows of the form [ coordinates density ] \n" " \"log_density\" : same as density, but reports the log of the density instead. \n" ); declareOption(ol, "generator_seed", &VMatrixFromDistribution::generator_seed, OptionBase::buildoption, "The initial generator_seed to initialize the distribution's generator"); declareOption(ol, "nsamples", &VMatrixFromDistribution::nsamples, OptionBase::buildoption, "number of samples to draw"); declareOption(ol, "samples_per_dim", &VMatrixFromDistribution::samples_per_dim, OptionBase::buildoption, "number of samples on each dimensions of the grid"); declareOption(ol, "mins", &VMatrixFromDistribution::mins, OptionBase::buildoption, "the minimum of the grid on each dimensions"); declareOption(ol, "maxs", &VMatrixFromDistribution::maxs, OptionBase::buildoption, "the maximum of the grid on each dimensions"); inherited::declareOptions(ol); }
static const PPath& PLearn::VMatrixFromDistribution::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::VMatrix.
Definition at line 109 of file VMatrixFromDistribution.h.
VMatrixFromDistribution * PLearn::VMatrixFromDistribution::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::VMatrix.
Definition at line 57 of file VMatrixFromDistribution.cc.
This method must be implemented in all subclasses.
Returns element (i,j).
Implements PLearn::VMatrix.
Definition at line 165 of file VMatrixFromDistribution.cc.
References data.
{ return data(i,j); }
Copies column i into v (which must have appropriate length equal to the VMat's length).
Reimplemented from PLearn::VMatrix.
Definition at line 168 of file VMatrixFromDistribution.cc.
References PLearn::TMat< T >::column(), and data.
{ v << data.column(i); }
Copies the submatrix starting at i,j into m (which must have appropriate length and width).
Reimplemented from PLearn::VMatrix.
Definition at line 177 of file VMatrixFromDistribution.cc.
References data, PLearn::TMat< T >::length(), PLearn::TMat< T >::subMat(), and PLearn::TMat< T >::width().
OptionList & PLearn::VMatrixFromDistribution::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 57 of file VMatrixFromDistribution.cc.
OptionMap & PLearn::VMatrixFromDistribution::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 57 of file VMatrixFromDistribution.cc.
RemoteMethodMap & PLearn::VMatrixFromDistribution::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 57 of file VMatrixFromDistribution.cc.
These methods do not usually need to be overridden in subclasses (default versions call getSubRow, which should do just fine)
Copies row i into v (which must have appropriate length equal to the VMat's width).
Reimplemented from PLearn::VMatrix.
Definition at line 174 of file VMatrixFromDistribution.cc.
References data.
{ v << data(i); }
It is suggested that this method be implemented in subclasses to speed up accesses (default version repeatedly calls get(i,j) which may have a significant overhead).
Fills v with the subrow i lying between columns j (inclusive) and j+v.length() (exclusive).
Reimplemented from PLearn::VMatrix.
Definition at line 171 of file VMatrixFromDistribution.cc.
References data, and PLearn::TVec< T >::length().
{ v << data(i).subVec(j,v.length()); }
void PLearn::VMatrixFromDistribution::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::VMatrix.
Definition at line 160 of file VMatrixFromDistribution.cc.
References PLearn::VMatrix::makeDeepCopyFromShallowCopy().
{ inherited::makeDeepCopyFromShallowCopy(copies); }
Mat PLearn::VMatrixFromDistribution::toMat | ( | ) | const [virtual] |
Returns a Mat with the same data as this VMat.
The default version of this method calls toMatCopy(). However this method will typically be overrided by subclasses (such as MemoryVMatrix) whose internal representation is already a Mat in order to return this Mat directly to avoid a new memory allocation and copy of elements. In this case, and in this case only, modifying the elements of the returned Mat will logically result in modified elements in the original VMatrix view of it. If you want to be sure that altering the content of the returned Mat won't modify the data contained in the VMatrix, you should call toMatCopy() instead.
Reimplemented from PLearn::VMatrix.
Definition at line 180 of file VMatrixFromDistribution.cc.
References data.
{ return data; }
Reimplemented from PLearn::VMatrix.
Definition at line 109 of file VMatrixFromDistribution.h.
Mat PLearn::VMatrixFromDistribution::data [protected] |
Will hold the data sampled from the distribution.
Definition at line 60 of file VMatrixFromDistribution.h.
Referenced by build_(), get(), getColumn(), getMat(), getRow(), getSubRow(), and toMat().
Definition at line 68 of file VMatrixFromDistribution.h.
Referenced by build_(), and declareOptions().
Definition at line 72 of file VMatrixFromDistribution.h.
Referenced by build_(), and declareOptions().
Definition at line 76 of file VMatrixFromDistribution.h.
Referenced by build_(), and declareOptions().
Definition at line 76 of file VMatrixFromDistribution.h.
Referenced by build_(), and declareOptions().
Definition at line 69 of file VMatrixFromDistribution.h.
Referenced by build_(), and declareOptions().
Definition at line 73 of file VMatrixFromDistribution.h.
Referenced by build_(), and declareOptions().
Definition at line 77 of file VMatrixFromDistribution.h.
Referenced by build_(), declareOptions(), and VMatrixFromDistribution().