PLearn 0.1
|
#include <ScaledConditionalCDFSmoother.h>
Public Types | |
typedef ConditionalCDFSmoother | inherited |
Public Member Functions | |
ScaledConditionalCDFSmoother () | |
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 ScaledConditionalCDFSmoother * | 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 () |
Public Attributes | |
bool | preserve_relative_density |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declares this class' options. | |
Private Member Functions | |
void | build_ () |
This does the actual building. |
Definition at line 52 of file ScaledConditionalCDFSmoother.h.
Reimplemented from PLearn::ConditionalCDFSmoother.
Definition at line 64 of file ScaledConditionalCDFSmoother.h.
PLearn::ScaledConditionalCDFSmoother::ScaledConditionalCDFSmoother | ( | ) |
Definition at line 51 of file ScaledConditionalCDFSmoother.cc.
:ConditionalCDFSmoother(), preserve_relative_density(true) { }
string PLearn::ScaledConditionalCDFSmoother::_classname_ | ( | ) | [static] |
Declares name and deepCopy methods.
Reimplemented from PLearn::ConditionalCDFSmoother.
Definition at line 65 of file ScaledConditionalCDFSmoother.cc.
OptionList & PLearn::ScaledConditionalCDFSmoother::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::ConditionalCDFSmoother.
Definition at line 65 of file ScaledConditionalCDFSmoother.cc.
RemoteMethodMap & PLearn::ScaledConditionalCDFSmoother::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::ConditionalCDFSmoother.
Definition at line 65 of file ScaledConditionalCDFSmoother.cc.
Reimplemented from PLearn::ConditionalCDFSmoother.
Definition at line 65 of file ScaledConditionalCDFSmoother.cc.
Object * PLearn::ScaledConditionalCDFSmoother::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::ConditionalCDFSmoother.
Definition at line 65 of file ScaledConditionalCDFSmoother.cc.
StaticInitializer ScaledConditionalCDFSmoother::_static_initializer_ & PLearn::ScaledConditionalCDFSmoother::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::ConditionalCDFSmoother.
Definition at line 65 of file ScaledConditionalCDFSmoother.cc.
void PLearn::ScaledConditionalCDFSmoother::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::ConditionalCDFSmoother.
Definition at line 94 of file ScaledConditionalCDFSmoother.cc.
References PLearn::ConditionalCDFSmoother::build(), and build_().
{ inherited::build(); build_(); }
void PLearn::ScaledConditionalCDFSmoother::build_ | ( | ) | [private] |
This does the actual building.
Reimplemented from PLearn::ConditionalCDFSmoother.
Definition at line 89 of file ScaledConditionalCDFSmoother.cc.
Referenced by build().
{ }
string PLearn::ScaledConditionalCDFSmoother::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::ConditionalCDFSmoother.
Definition at line 65 of file ScaledConditionalCDFSmoother.cc.
void PLearn::ScaledConditionalCDFSmoother::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declares this class' options.
Reimplemented from PLearn::ConditionalCDFSmoother.
Definition at line 67 of file ScaledConditionalCDFSmoother.cc.
References PLearn::OptionBase::buildoption, PLearn::declareOption(), PLearn::ConditionalCDFSmoother::declareOptions(), and preserve_relative_density.
{ declareOption(ol, "preserve_relative_density", &ScaledConditionalCDFSmoother::preserve_relative_density, OptionBase::buildoption, "If true then the following formula is used inside each of the large intervals (t_0,t_1):\n" " S(y_t) = S(y_{t_0})+(PS(y_t)-PS(y_{t_0}))(RS(y_{t_0})-RS(y_{t_1}))/(PS(y_{t_1})-PS(y_{t_0})\n" "where S(y_t) is the smoothed survival function at position y_t, PS(y_t) is the prior\n" "survival function at y_t, and RS(y_t) is the rough survival function (which is to be\n" "smoothed) at y_t. Note that RS is only known at the extremes of the interval, y_{t_0}\n" "and y_{t_1}. Note that this formula has the property that within the interval, the\n" "density is the prior density, scaled by the ratio of the total density in the interval\n" "for the target rough curve with respect to the prior curve\n" "If false, then the following formula is used instead, using the same notation:\n" " S(y_t) = PS(y_t)(RS(y_{t_0})/PS(y_{t_0}) + (y_t - y_{t_0})(RS(y_{t_1})-RS(y_{t_0}))/(PS(y_{t_1}) (t_1 - t_0)))\n" "What is the justification for this second formula?\n" ); // Now call the parent class' declareOptions inherited::declareOptions(ol); }
static const PPath& PLearn::ScaledConditionalCDFSmoother::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::ConditionalCDFSmoother.
Definition at line 106 of file ScaledConditionalCDFSmoother.h.
:
// The source function is either f(i) = source_function[i] as a function of i
ScaledConditionalCDFSmoother * PLearn::ScaledConditionalCDFSmoother::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::ConditionalCDFSmoother.
Definition at line 65 of file ScaledConditionalCDFSmoother.cc.
OptionList & PLearn::ScaledConditionalCDFSmoother::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::ConditionalCDFSmoother.
Definition at line 65 of file ScaledConditionalCDFSmoother.cc.
OptionMap & PLearn::ScaledConditionalCDFSmoother::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::ConditionalCDFSmoother.
Definition at line 65 of file ScaledConditionalCDFSmoother.cc.
RemoteMethodMap & PLearn::ScaledConditionalCDFSmoother::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::ConditionalCDFSmoother.
Definition at line 65 of file ScaledConditionalCDFSmoother.cc.
void PLearn::ScaledConditionalCDFSmoother::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Transforms a shallow copy into a deep copy.
Reimplemented from PLearn::ConditionalCDFSmoother.
Definition at line 101 of file ScaledConditionalCDFSmoother.cc.
References PLearn::ConditionalCDFSmoother::makeDeepCopyFromShallowCopy().
{ inherited::makeDeepCopyFromShallowCopy(copies); }
real PLearn::ScaledConditionalCDFSmoother::smooth | ( | const Vec & | source_function, |
Vec & | smoothed_function, | ||
Vec | bin_positions = Vec() , |
||
Vec | dest_bin_positions = Vec() |
||
) | const [virtual] |
Reimplemented from PLearn::ConditionalCDFSmoother.
Definition at line 111 of file ScaledConditionalCDFSmoother.cc.
References PLearn::endl(), i, j, PLERROR, preserve_relative_density, PLearn::ConditionalCDFSmoother::prior_cdf, PLearn::TVec< T >::resize(), and PLearn::TVec< T >::size().
{ // put in 'survival_fn' the multiplicatively adjusted unconditional_survival_fn // such that the estimatedS values at yvalues match. In each segment // between prev_y and next_y. The adjustment ratio varies linearly from // estimatedS[prev_y]/unconditionalS[prev_y] to estimatedS[next_y]/unconditionalS[next_y]): // prev_ratio = estimatedS[prev_y]/unconditionalS[prev_y] // next_ratio = estimatedS[next_y]/unconditionalS[next_y] // adjustment = prev_ratio + (y-prev_y)*next_ratio/(next_y-prev_y) // s(y) = unconditional_s(y)*adjustment if (!prior_cdf) PLERROR("in ScaledConditionalCDFSmoother::smooth you need to supply a prior_cdf"); //assume source_function is a survival fn. if(bin_positions.size() != source_function.size()+1) PLERROR("in ScaledConditionalCDFSmoother::smooth you need to supply bin_positions"); if(dest_bin_positions.size() == 0) PLERROR("in ScaledConditionalCDFSmoother::smooth you need to supply dest_bin_positions"); smoothed_function.resize(dest_bin_positions.size()-1); int j= 0; for(int i= 0; i < source_function.size(); ++i) { Vec v0(1), v1(1);//prev_y, next_y v0[0]= bin_positions[i]; v1[0]= bin_positions[i+1]; real prev_ratio= source_function[i]/prior_cdf->survival_fn(v0); real next_ratio; if(i == source_function.size()-1) next_ratio= 0.0; else next_ratio= source_function[i+1]/prior_cdf->survival_fn(v1); cout << source_function[i] << '\t' << prev_ratio << '\t' << next_ratio << '\t' << v0[0] << '\t' << v1[0] << endl; real slope = !preserve_relative_density? 0 : ((source_function[i+1]-source_function[i])/(prior_cdf->survival_fn(v1)-prior_cdf->survival_fn(v0))); real absisse = !preserve_relative_density? 0 : (source_function[i] - slope * prior_cdf->survival_fn(v0)); while(j < smoothed_function.size() && dest_bin_positions[j+1] <= bin_positions[i+1]) { Vec v(1); v[0]= dest_bin_positions[j]; // the line below seems wrong, so I have fixed it -- YB // the reason it seems wrong is that smoothed_function[j_final] should be equal // to source_function[i+1], but it is not, currently. // smoothed_function[j]= prior_cdf->survival_fn(v) * (prev_ratio + (v[0]-v0[0])*next_ratio/(v1[0]-v0[0])); if (!preserve_relative_density) smoothed_function[j]= prior_cdf->survival_fn(v) * (prev_ratio + (v[0]-v0[0])*(next_ratio-prev_ratio)/(v1[0]-v0[0])); else // scale with bin number, i.e. warped with density smoothed_function[j]= absisse + slope * prior_cdf->survival_fn(v); cout << '\t' << v[0] << '\t' << prior_cdf->survival_fn(v) << '\t' << smoothed_function[j] << endl; ++j; } } /* //assume source_function is a survival fn. if(bin_positions.size() != source_function.size()+1) PLERROR("in ScaledConditionalCDFSmoother::smooth you need to supply bin_positions"); if(dest_bin_positions.size() == 0) PLERROR("in ScaledConditionalCDFSmoother::smooth you need to supply dest_bin_positions"); smoothed_function.resize(dest_bin_positions.size()-1); Vec f0(dest_bin_positions.size()-1); //new density int j= 0; real factor= 1.0; for(int i= 0; i < source_function.size(); ++i) { Vec v0(1), v1(1); v0[0]= bin_positions[i]; v1[0]= bin_positions[i+1]; real prior_prob= prior_cdf->survival_fn(v0) - prior_cdf->survival_fn(v1); real prob; if(i < source_function.size()-1) prob= (source_function[i]-source_function[i+1]); else prob= source_function[i]; if(0 < prior_prob && prob != 0.0) factor= prob / prior_prob; // else: use prev. factor //dummy-temp cout << v0[0] << '-' << v1[0] << ":\t" << prob << '/' << prior_prob << '=' << factor << endl; while(j < smoothed_function.size() && dest_bin_positions[j+1] <= bin_positions[i+1]) { Vec v(1); v[0]= (dest_bin_positions[j]+dest_bin_positions[j+1])/2; // smoothed_function[j]= factor * prior_cdf->survival_fn(v); f0[j]= factor * prior_cdf->density(v); //dummy-temp cout << '\t' << smoothed_function[j] << "= " << factor << " * " << prior_cdf->survival_fn(v) << endl; ++j; } } HistogramDistribution::calc_survival_from_density(f0, smoothed_function, dest_bin_positions); */ /* int j= 0; real factor= 1.0; for(int i= 0; i < source_function.size(); ++i) { Vec v0(1), v1(1); v0[0]= bin_positions[i]; v1[0]= bin_positions[i+1]; real prior_prob= prior_cdf->survival_fn(v0) - prior_cdf->survival_fn(v1); real prob; if(i < source_function.size()-1) prob= (source_function[i]-source_function[i+1]); else prob= source_function[i]; if(0 < prior_prob && prob != 0.0) factor= prob / prior_prob; // else: use prev. factor //dummy-temp cout << v0[0] << '-' << v1[0] << ":\t" << prob << '/' << prior_prob << '=' << factor << endl; while(j < smoothed_function.size() && dest_bin_positions[j+1] <= bin_positions[i+1]) { Vec v(1); v[0]= (dest_bin_positions[j]+dest_bin_positions[j+1])/2; smoothed_function[j]= factor * prior_cdf->survival_fn(v); //dummy-temp cout << '\t' << smoothed_function[j] << "= " << factor << " * " << prior_cdf->survival_fn(v) << endl; ++j; } } */ return 0.0; //dummy - FIXME - xsm }
Reimplemented from PLearn::ConditionalCDFSmoother.
Definition at line 106 of file ScaledConditionalCDFSmoother.h.
Definition at line 74 of file ScaledConditionalCDFSmoother.h.
Referenced by declareOptions(), and smooth().