|
PLearn 0.1
|
#include <LimitedGaussianSmoother.h>


Public Types | |
| typedef Smoother | inherited |
Public Member Functions | |
| LimitedGaussianSmoother () | |
| LimitedGaussianSmoother (real window_size_wrt_sigma_, real sigma_bin_) | |
| virtual void | build () |
| Post-constructor. | |
| 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 LimitedGaussianSmoother * | deepCopy (CopiesMap &copies) const |
| virtual real | smooth (const Vec &source_function, Vec &smoothed_function, Vec bin_positions=Vec(), Vec dest_bin_positions=Vec()) const |
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 () |
Static Public Attributes | |
| static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
| static void | declareOptions (OptionList &ol) |
| Declares this class' options. | |
Protected Attributes | |
| real | window_size_wrt_sigma |
| real | sigma_bin |
Private Member Functions | |
| void | build_ () |
| This does the actual building. | |
Definition at line 58 of file LimitedGaussianSmoother.h.
Reimplemented from PLearn::Smoother.
Definition at line 70 of file LimitedGaussianSmoother.h.
| PLearn::LimitedGaussianSmoother::LimitedGaussianSmoother | ( | ) |
Definition at line 46 of file LimitedGaussianSmoother.cc.
:Smoother() /* ### Initialise all fields to their default value */ { // ... // ### You may or may not want to call build_() to finish building the object // build_(); }
| PLearn::LimitedGaussianSmoother::LimitedGaussianSmoother | ( | real | window_size_wrt_sigma_, |
| real | sigma_bin_ | ||
| ) |
Definition at line 56 of file LimitedGaussianSmoother.cc.
:Smoother(), window_size_wrt_sigma(window_size_wrt_sigma_), sigma_bin(sigma_bin_) {}
| string PLearn::LimitedGaussianSmoother::_classname_ | ( | ) | [static] |
Declares name and deepCopy methods.
Reimplemented from PLearn::Smoother.
Definition at line 60 of file LimitedGaussianSmoother.cc.
| OptionList & PLearn::LimitedGaussianSmoother::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::Smoother.
Definition at line 60 of file LimitedGaussianSmoother.cc.
| RemoteMethodMap & PLearn::LimitedGaussianSmoother::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::Smoother.
Definition at line 60 of file LimitedGaussianSmoother.cc.
Reimplemented from PLearn::Smoother.
Definition at line 60 of file LimitedGaussianSmoother.cc.
| Object * PLearn::LimitedGaussianSmoother::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 60 of file LimitedGaussianSmoother.cc.
| StaticInitializer LimitedGaussianSmoother::_static_initializer_ & PLearn::LimitedGaussianSmoother::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::Smoother.
Definition at line 60 of file LimitedGaussianSmoother.cc.
| void PLearn::LimitedGaussianSmoother::build | ( | ) | [virtual] |
Post-constructor.
The normal implementation should call simply inherited::build(), then this class's build_(). This method should be callable again at later times, after modifying some option fields to change the "architecture" of the object.
Reimplemented from PLearn::Smoother.
Definition at line 91 of file LimitedGaussianSmoother.cc.
References PLearn::Smoother::build(), and build_().
{
inherited::build();
build_();
}

| void PLearn::LimitedGaussianSmoother::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::Smoother.
Definition at line 79 of file LimitedGaussianSmoother.cc.
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.
}

| string PLearn::LimitedGaussianSmoother::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 60 of file LimitedGaussianSmoother.cc.
| void PLearn::LimitedGaussianSmoother::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares this class' options.
Reimplemented from PLearn::Smoother.
Definition at line 62 of file LimitedGaussianSmoother.cc.
References PLearn::Smoother::declareOptions().
{
// ### Declare all of this object's options here
// ### For the "flags" of each option, you should typically specify
// ### one of OptionBase::buildoption, OptionBase::learntoption or
// ### OptionBase::tuningoption. Another possible flag to be combined with
// ### is OptionBase::nosave
// ### ex:
// declareOption(ol, "myoption", &LimitedGaussianSmoother::myoption, OptionBase::buildoption,
// "Help text describing this option");
// ...
// Now call the parent class' declareOptions
inherited::declareOptions(ol);
}

| static const PPath& PLearn::LimitedGaussianSmoother::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::Smoother.
Definition at line 113 of file LimitedGaussianSmoother.h.
| LimitedGaussianSmoother * PLearn::LimitedGaussianSmoother::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::Smoother.
Definition at line 60 of file LimitedGaussianSmoother.cc.
| OptionList & PLearn::LimitedGaussianSmoother::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 60 of file LimitedGaussianSmoother.cc.
| OptionMap & PLearn::LimitedGaussianSmoother::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 60 of file LimitedGaussianSmoother.cc.
| RemoteMethodMap & PLearn::LimitedGaussianSmoother::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 60 of file LimitedGaussianSmoother.cc.
| void PLearn::LimitedGaussianSmoother::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::Smoother.
Definition at line 98 of file LimitedGaussianSmoother.cc.
References PLearn::Smoother::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("LimitedGaussianSmoother::makeDeepCopyFromShallowCopy not fully (correctly) implemented yet!");
}

| real PLearn::LimitedGaussianSmoother::smooth | ( | const Vec & | source_function, |
| Vec & | smoothed_function, | ||
| Vec | bin_positions = Vec(), |
||
| Vec | dest_bin_positions = Vec() |
||
| ) | const [virtual] |
Implements PLearn::Smoother.
Definition at line 113 of file LimitedGaussianSmoother.cc.
References PLearn::TVec< T >::fill(), PLearn::gauss_cum(), i, j, PLearn::TVec< T >::length(), PLearn::TVec< T >::resize(), sigma_bin, and window_size_wrt_sigma.
{
//parzen regressor?? kernel smoothing??
// smoothed_function[k] = sum_{j=max(0,k-window_size)}^{min(l-1,k+window_size)} w_{k,j} source_function[j]
// / sum_{j=max(0,k-window_size)}^{min(l-1,k+window_size)} w_{k,j}
// with w_{k,j} = phi(bin_positions[j+1];mu_k,sigma_k)-phi(bin_positions[j];mu_k,sigma_k)
// where mu_k = 0.5*(bin_positions[k+1]+bin_positions[k]),
// sigma_k = bin_positions[k+window_size]-bin_positions[k]
// where phi(x;mu,sigma) = cdf of normal(mu,sigma) at x,
// window_size = window_size_wrt_sigma * sigma_bin
// for dest_bin_positions != bin_positions: 2 methods:
// 1- trouver sigma_bin en fonction du voisinage
// d'une position dest. Somme ponderee avec
// gaussienne centree sur le pt. dest.
// 2- Un sigma_bin pour chaque bin_position (src).
// Une gaussienne centree sur sur ch. pos src.
//
smoothed_function.resize(source_function.length());
smoothed_function.fill(0.0);
real window_size= window_size_wrt_sigma * sigma_bin;
for(int i= 0; i < smoothed_function.length()-1; ++i)
{
int min_j= i-static_cast<int>(window_size), max_j= i+static_cast<int>(window_size);
if(min_j < 0) min_j= 0;
if(max_j > smoothed_function.length()) max_j= smoothed_function.length();
real sum_weights= 0.0;
real mu= 0.5*(bin_positions[i+1]+bin_positions[i]),
sigma= bin_positions[max_j-1]-bin_positions[i];
for(int j= min_j; j < max_j-1; ++j)
{
sum_weights+= gauss_cum(bin_positions[j+1], mu, sigma) -
gauss_cum(bin_positions[j], mu, sigma);
}
for(int j= min_j; j < max_j-1; ++j)
smoothed_function[i]+= ( gauss_cum(bin_positions[j+1], mu, sigma)
- gauss_cum(bin_positions[j], mu, sigma)
)
* source_function[j] / sum_weights;
}
return 0.0; //dummy - FIXME - xsm
/*
if(bin_positions.length() != 0 && source_function.length() != bin_positions.length()-1)
PLERROR("in LimitedGaussianSmoother::smooth There must be one more bin_positions than the "
"number of source_function points.");
//if no bin_positions given, assume positions are 0, 1, 2, ..., n
if(bin_positions.length() == 0)
{
int n= source_function.length()+1;
bin_positions.resize(n);
for(int i= 0; i < n; ++i)
bin_positions[i]= i;
}
//if no dest_bin_positions given, assume same as bin_positions
if(dest_bin_positions.length() == 0)
dest_bin_positions= bin_positions;
smoothed_function.resize(dest_bin_positions.length()-1);
smoothed_function.fill(0.0);
real window_size, mu, sigma, sum_weights;
int n= smoothed_function.length();
for(int i= 0; i < n; ++i)
{
sum_weights= 0.0;
int nj= source_function.length();
for(int j= 0; j < nj; ++j)
{
mu= 0.5*(bin_positions[i+1]+bin_positions[i]);
sigma= bin_positions[i+1]-bin_positions[i];
window_size= window_size_wrt_sigma * sigma;
real p1= mu - 0.5*window_size,
p2= mu + 0.5*window_size;
Vec::iterator it = find_if(options.begin(), options.end(),
bind2nd(mem_fun(&OptionBase::isOptionNamed), optionname));
}
/ *
int min_j= i-static_cast<int>(window_size), max_j= i+static_cast<int>(window_size);
if(min_j < 0) min_j= 0;
if(max_j > smoothed_function.length()) max_j= smoothed_function.length();
* /
real sum_weights= 0.0;
for(int j= min_j; j < max_j-1; ++j)
{
sum_weights+= gauss_cum(bin_positions[j+1], mu, sigma) -
gauss_cum(bin_positions[j], mu, sigma);
}
for(int j= min_j; j < max_j-1; ++j)
smoothed_function[i]+= ( gauss_cum(bin_positions[j+1], mu, sigma)
- gauss_cum(bin_positions[j], mu, sigma)
)
* source_function[j] / sum_weights;
}
*/
}

Reimplemented from PLearn::Smoother.
Definition at line 113 of file LimitedGaussianSmoother.h.
real PLearn::LimitedGaussianSmoother::sigma_bin [protected] |
Definition at line 65 of file LimitedGaussianSmoother.h.
Referenced by smooth().
Definition at line 65 of file LimitedGaussianSmoother.h.
Referenced by smooth().
1.7.4