コード例 #1
0
ファイル: KMplex.cpp プロジェクト: tjuhh/NNDK
void KMplex::initialise(KEY& T, KEY& S)
{
    if(T.size() <= 2)
    {
        greedy(T, S);
        return;
    }

    KEY::iterator a;
    KEY::iterator b;
    double dab = 0.0;

    for(KEY::iterator t = T.begin(); t != T.end(); ++t)
        for(KEY::iterator tt = t + 1; tt != T.end(); ++tt)
        {
            if(D_[*t][*tt] > dab)
            {
                dab = D_[*t][*tt];
                a = t;
                b = tt;
            }
        }

    // Copy object indices a and b into sample key S
    S.push_back(*a);
    S.push_back(*b);

    // Remove object indices from key T
    T.erase(b);
    T.erase(a);
}
コード例 #2
0
ファイル: KMplex.cpp プロジェクト: tjuhh/NNDK
void KMplex::sample(KEY& T, KEY& S)
{
    if(T.size() <= 2)
    {
        greedy(T, S);
        return;
    }
    // NOTE: Cannot sample for two or less data, so copy any data to S

    // Indices of points a and b
    KEY::iterator a;
    KEY::iterator b;

    // Corresponding distances to points a and b, from c(S)
    double da = 0.0;
    double db = 0.0;
    for(KEY::iterator t = T.begin(); t != T.end(); ++t)
    {
        // Find shortest distance d(t,s)
        double d = large();
        for(KEY::iterator s = S.begin(); s != S.end(); ++s)
        {
            if(D_[*t][*s] < d)
                d = D_[*t][*s];
        }

        // Retain t if corresponds to first or second farthest from S
        if(d >= da)
        {
            b = a;		// Farthest object moves to second farthest
            db = da;
            a = t;		// New object t is farthest from s in S
            da = d;
        }
        else if(d >= db)	// New object t is second farthest from s in S
        {
            b = t;
            db = d;
        }
        else
        {
            ; 			// Do nothing
        }
    }

    // Indices a and b are moved to sample, S
    S.push_back(*a);
    S.push_back(*b);

    // Erase items a and b, starting with last in sequence
    if(a > b)
    {
        T.erase(a);
        T.erase(b);
    }
    else
    {
        T.erase(b);
        T.erase(a);
    }
}