class AbsSeq: public CHeapObj<mtInternal> { private: void init(double alpha);
protected:
int _num; // the number of elements in the sequence double _sum; // the sum of the elements in the sequence double _sum_of_squares; // the sum of squares of the elements in the sequence
double _davg; // decaying average double _dvariance; // decaying variance double _alpha; // factor for the decaying average / variance
// This is what we divide with to get the average. In a standard // number sequence, this should just be the number of elements in it. virtualdouble total() const { return (double) _num; };
virtualvoid add(double val); // adds a new element to the sequence void add(unsigned val) { add((double) val); } virtualdouble maximum() const = 0; // maximum element in the sequence virtualdouble last() const = 0; // last element added in the sequence
// the number of elements in the sequence
int num() const { return _num; } // the sum of the elements in the sequence double sum() const { return _sum; }
double avg() const; // the average of the sequence double variance() const; // the variance of the sequence double sd() const; // the standard deviation of the sequence
class TruncatedSeq: public AbsSeq { private:
enum PrivateConstants {
DefaultSeqLength = 10
}; void init(); protected: double *_sequence; // buffers the last L elements in the sequence
int _length; // this is L
int _next; // oldest slot in the array, i.e. next to be overwritten
public: // accepts a value for L
TruncatedSeq(int length = DefaultSeqLength, double alpha = DEFAULT_ALPHA_VALUE);
~TruncatedSeq(); virtualvoid add(double val); virtualdouble maximum() const; virtualdouble last() const; // the last value added to the sequence
double oldest() const; // the oldest valid value in the sequence double predict_next() const; // prediction based on linear regression
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.