This site is best viewed in a browser that conforms to web standards.

Button
Button
Button
Button
Button

Button
Button
Button
Button

Turmsegler

Back to Article

Calculation

Experimental Time Series

Real Time Series

C++-Source



BOOL ivorix_rma (
          vector<double>& ivec,     // input  vector
          vector<double>& ovec,     // output vector
          unsigned long   span)     // time period or span of embedding
{
    ULONG   x       = 0;
    ULONG   y       = 0;
    double  sx      = 0;
    double  sxs     = 0;
    double  sy      = 0;
    double  sxy     = 0;
    double  icept   = 0;
    double  slope   = 0;
    double  p       = span;
    ULONG   e       = ivec.size();
    double  se      = 2.0 / (p / 3.0 + 1.0); // short exponent
    double  le      = 1.0 - se;              // long exponent

    if ( span == 0 || span >= e )
        return false;

    ovec.resize(ivec.size());

    // calculate the sum and the sum of squares
    // of the time series x-axis
    for ( x = 1; x <= span; x++ )
    {
        sx  += x;
        sxs += sqr(x);
    }

    ovec[0] = ivec[0];

    for ( y = 0; y < e; y++ )
    {
        slope  = 0;
        icept  = 0;

        if ( y >= span - 1 )
        {
            sy  = 0;
            sxy = 0;

            for ( x = 0; x < span; x++ )
            {
                sy  += ivec[y-x];
                sxy += ivec[y-x] * (span - x);
            }

            slope   = (sxy - ((sx * sy) / p)) / (sxs - (sqr(sx) / p));
            icept   = (sy - (slope * sx)) / p;
            ovec[y] = icept + p * slope;
            ovec[y] = (ovec[y] * se) + ivec[y-1] * le;
        }
        else
        {
            if ( y > 0 )
            {
                ovec[y] = ivec[y] * se + ovec[y-1] * le;
            }
        }
    }

    return true;
}

Back to Article