PLearn 0.1
|
#include <StatsIterator.h>
Public Member Functions | |
virtual string | info () const |
Returns a bit more informative string about object (default returns classname()) | |
virtual void | init (int inputsize) |
Call this method once with the correct inputsize. | |
virtual void | update (const Vec &input) |
Then iterate over the data set and call this method for each row. | |
virtual bool | finish () |
virtual string | classname () const |
virtual OptionList & | getOptionList () const |
virtual OptionMap & | getOptionMap () const |
virtual RemoteMethodMap & | getRemoteMethodMap () const |
virtual SharpeRatioStatsIterator * | deepCopy (CopiesMap &copies) const |
virtual void | makeDeepCopyFromShallowCopy (CopiesMap &copies) |
Does the necessary operations to transform a shallow copy (this) into a deep copy by deep-copying all the members that need to be. | |
virtual void | oldwrite (ostream &out) const |
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 () |
Static Public Attributes | |
static StaticInitializer | _static_initializer_ |
Static Protected Member Functions | |
static void | declareOptions (OptionList &ol) |
Declare options (data fields) for the class. | |
Protected Attributes | |
Vec | nnonzero |
Vec | meansquared |
Vec | mean |
Private Types | |
typedef StatsIterator | inherited |
Compute the Sharpe ratio = mean(profit) / stdev(profit) where profit is assumed to be the "cost" given in input. Note that the mean and stdev are only computed over the instances where profit!=0 (because these represent the actual transactions that occured).
Definition at line 227 of file StatsIterator.h.
typedef StatsIterator PLearn::SharpeRatioStatsIterator::inherited [private] |
Reimplemented from PLearn::StatsIterator.
Definition at line 229 of file StatsIterator.h.
string PLearn::SharpeRatioStatsIterator::_classname_ | ( | ) | [static] |
Reimplemented from PLearn::StatsIterator.
Definition at line 358 of file StatsIterator.cc.
OptionList & PLearn::SharpeRatioStatsIterator::_getOptionList_ | ( | ) | [static] |
Reimplemented from PLearn::StatsIterator.
Definition at line 358 of file StatsIterator.cc.
RemoteMethodMap & PLearn::SharpeRatioStatsIterator::_getRemoteMethodMap_ | ( | ) | [static] |
Reimplemented from PLearn::StatsIterator.
Definition at line 358 of file StatsIterator.cc.
Reimplemented from PLearn::StatsIterator.
Definition at line 358 of file StatsIterator.cc.
Object * PLearn::SharpeRatioStatsIterator::_new_instance_for_typemap_ | ( | ) | [static] |
Reimplemented from PLearn::Object.
Definition at line 358 of file StatsIterator.cc.
StaticInitializer SharpeRatioStatsIterator::_static_initializer_ & PLearn::SharpeRatioStatsIterator::_static_initialize_ | ( | ) | [static] |
Reimplemented from PLearn::StatsIterator.
Definition at line 358 of file StatsIterator.cc.
string PLearn::SharpeRatioStatsIterator::classname | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 358 of file StatsIterator.cc.
void PLearn::SharpeRatioStatsIterator::declareOptions | ( | OptionList & | ol | ) | [static, protected] |
Declare options (data fields) for the class.
Redefine this in subclasses: call declareOption
(...) for each option, and then call inherited::declareOptions(options)
. Please call the inherited
method AT THE END to get the options listed in a consistent order (from most recently defined to least recently defined).
static void MyDerivedClass::declareOptions(OptionList& ol) { declareOption(ol, "inputsize", &MyObject::inputsize_, OptionBase::buildoption, "The size of the input; it must be provided"); declareOption(ol, "weights", &MyObject::weights, OptionBase::learntoption, "The learned model weights"); inherited::declareOptions(ol); }
ol | List of options that is progressively being constructed for the current class. |
Reimplemented from PLearn::StatsIterator.
Definition at line 397 of file StatsIterator.cc.
References PLearn::declareOption(), PLearn::OptionBase::learntoption, mean, meansquared, and nnonzero.
{ declareOption(ol, "mean", &SharpeRatioStatsIterator::mean, OptionBase::learntoption, " mean\n"); declareOption(ol, "meansquared", &SharpeRatioStatsIterator::meansquared, OptionBase::learntoption, " meansquared\n"); declareOption(ol, "nnonzero", &SharpeRatioStatsIterator::nnonzero, OptionBase::learntoption, " nnonzero\n"); inherited::declareOptions(ol); }
static const PPath& PLearn::SharpeRatioStatsIterator::declaringFile | ( | ) | [inline, static] |
Reimplemented from PLearn::StatsIterator.
Definition at line 241 of file StatsIterator.h.
: static void declareOptions(OptionList& ol);
SharpeRatioStatsIterator * PLearn::SharpeRatioStatsIterator::deepCopy | ( | CopiesMap & | copies | ) | const [virtual] |
Reimplemented from PLearn::StatsIterator.
Definition at line 358 of file StatsIterator.cc.
bool PLearn::SharpeRatioStatsIterator::finish | ( | ) | [virtual] |
Call this method when all the data has been shown (through update) If the method returns false, then a further pass through the data is required.
Implements PLearn::StatsIterator.
Definition at line 388 of file StatsIterator.cc.
References PLearn::mean(), PLearn::sqrt(), and PLearn::squareSubtract().
{ mean /= nnonzero; meansquared /= nnonzero; squareSubtract(meansquared, mean); result = mean/sqrt(meansquared); return true; }
OptionList & PLearn::SharpeRatioStatsIterator::getOptionList | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 358 of file StatsIterator.cc.
OptionMap & PLearn::SharpeRatioStatsIterator::getOptionMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 358 of file StatsIterator.cc.
RemoteMethodMap & PLearn::SharpeRatioStatsIterator::getRemoteMethodMap | ( | ) | const [virtual] |
Reimplemented from PLearn::Object.
Definition at line 358 of file StatsIterator.cc.
virtual string PLearn::SharpeRatioStatsIterator::info | ( | ) | const [inline, virtual] |
Returns a bit more informative string about object (default returns classname())
Reimplemented from PLearn::Object.
Definition at line 237 of file StatsIterator.h.
{ return "sharpe_ratio"; }
void PLearn::SharpeRatioStatsIterator::init | ( | int | inputsize | ) | [virtual] |
Call this method once with the correct inputsize.
Implements PLearn::StatsIterator.
Definition at line 367 of file StatsIterator.cc.
References PLearn::mean().
{ // We do not use resize on purpose, so // that the previous result Vec does not get overwritten meansquared = Vec(inputsize); mean = Vec(inputsize); nnonzero = Vec(inputsize); }
void PLearn::SharpeRatioStatsIterator::makeDeepCopyFromShallowCopy | ( | CopiesMap & | copies | ) | [virtual] |
Does the necessary operations to transform a shallow copy (this) into a deep copy by deep-copying all the members that need to be.
This needs to be overridden by every class that adds "complex" data members to the class, such as Vec
, Mat
, PP<Something>
, etc. Typical implementation:
void CLASS_OF_THIS::makeDeepCopyFromShallowCopy(CopiesMap& copies) { inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(complex_data_member1, copies); deepCopyField(complex_data_member2, copies); ... }
copies | A map used by the deep-copy mechanism to keep track of already-copied objects. |
Reimplemented from PLearn::StatsIterator.
Definition at line 360 of file StatsIterator.cc.
References PLearn::deepCopyField(), and PLearn::mean().
{ inherited::makeDeepCopyFromShallowCopy(copies); deepCopyField(mean, copies); deepCopyField(meansquared, copies); }
void PLearn::SharpeRatioStatsIterator::oldwrite | ( | ostream & | out | ) | const [virtual] |
Reimplemented from PLearn::StatsIterator.
Definition at line 411 of file StatsIterator.cc.
References PLearn::mean(), PLearn::write(), PLearn::writeField(), PLearn::writeFooter(), and PLearn::writeHeader().
{ writeHeader(out,"SharpeRatioStatsIterator"); inherited::write(out); writeField(out,"mean",mean); writeField(out,"meansquared",meansquared); writeField(out,"nnonzero",nnonzero); writeFooter(out,"SharpeRatioStatsIterator"); }
void PLearn::SharpeRatioStatsIterator::update | ( | const Vec & | input | ) | [virtual] |
Then iterate over the data set and call this method for each row.
Implements PLearn::StatsIterator.
Definition at line 376 of file StatsIterator.cc.
References i, in, PLearn::TVec< T >::length(), PLearn::mean(), and n.
{ int n=input.length(); for (int i=0;i<n;i++) { real in=input[i]; if (in!=0) nnonzero[i]++; mean[i] += in; meansquared[i] += in*in; } }
Reimplemented from PLearn::StatsIterator.
Definition at line 241 of file StatsIterator.h.
Vec PLearn::SharpeRatioStatsIterator::mean [protected] |
Definition at line 234 of file StatsIterator.h.
Referenced by declareOptions().
Vec PLearn::SharpeRatioStatsIterator::meansquared [protected] |
Definition at line 233 of file StatsIterator.h.
Referenced by declareOptions().
Vec PLearn::SharpeRatioStatsIterator::nnonzero [protected] |
Definition at line 232 of file StatsIterator.h.
Referenced by declareOptions().