src/UCRDTW_kNN_serial.cpp
/// LB_Keogh 1: Create Envelop for the query
/// Note that because the query is known, envelop can be created once at the begenining.
///
/// Variable Explanation,
/// order : sorted indices for the query.
/// uo, lo: upper and lower envelops for the query, which already sorted.
/// t     : a circular array keeping the current data.
/// j     : index of the starting location in t
/// cb    : (output) current bound at each position. It will be used later for early abandoning in DTW.
LB_Keogh 1: Create Envelop for the query
Note that because the query is known, envelop can be created once at the begenining.

Variable Explanation,
order : sorted indices for the query.
uo, lo: upper and lower envelops for the query, which already sorted.
t     : a circular array keeping the current data.
j     : index of the starting location in t
cb    : (output) current bound at each position. It will be used later for early abandoning in DTW.
LB_Keogh 1 : Create Envelop for the query Note that because the query is known envelop can be created once at the begenining . Variable Explanation order : sorted indices for the query . uo lo : upper and lower envelops for the query which already sorted . t : a circular array keeping the current data . j : index of the starting location in t cb : ( output ) current bound at each position . It will be used later for early abandoning in DTW .
double lb_keogh_cumulative(int * order, double * t, double * uo, double * lo, double * cb, int j, int len, double mean,
        double std, double best_so_far = INF)
{
    double lb = 0;
    double x, d;
    for (int i = 0; i < len && lb < best_so_far; i++)
    {
        x = (t[(order[i]+j)] - mean) / std;
        d = 0;
        if (x > uo[i])
            d = dist(x,uo[i]);
        else if(x < lo[i])
            d = dist(x,lo[i]);
        lb += d;
        cb[order[i]] = d;
    }
    return lb;
}
double lb_keogh_cumulative ( int * order , double * t , double * uo , double * lo , double * cb , int j , int len , double mean , double std , double best_so_far = INF ) { double lb = 0 ; double x , d ; for ( int i = 0 ; i < len && lb < best_so_far ; i ++ ) { x = ( t [ ( order [ i ] + j ) ] - mean ) / std ; d = 0 ; if ( x > uo [ i ] ) d = dist ( x , uo [ i ] ) ; else if ( x < lo [ i ] ) d = dist ( x , lo [ i ] ) ; lb += d ; cb [ order [ i ] ] = d ; } return lb ; }
LB_Keogh 1: Create Envelop for the query
Note that because the query is known, envelop can be created once at the begenining.
LB_Keogh 1 : Create Envelop for the query Note that because the query is known envelop can be created once at the begenining .