PLearn 0.1
Public Member Functions | Protected Attributes
PLearn::TopNI< T > Class Template Reference

#include <TopNI.h>

Collaboration diagram for PLearn::TopNI< T >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 TopNI ()
 Default constructor, you must then call init.
 TopNI (int the_N)
 N is the number of (value,index) pairs to remember.
void init (int the_N)
 N is the number of (value,point) pairs to remember.
void reset ()
void update (T value, int index)
 call this for each new value seen
void sort ()
const TVec< pair< T, int > > & getTopN ()
 call this at the end to get the the smallest N values with associated integer index

Protected Attributes

int N
TVec< pair< T, int > > topn
pair< T, int > * topnptr
 topn.data()
pair< T, int > * minpair

Detailed Description

template<class T>
class PLearn::TopNI< T >

This is a very simple class, that allows you to keep track of the top N values encountered among many and their associated integer index (or corresponding position). For keeping track of the bottom N values, see the companion class BottomNI.

Definition at line 62 of file TopNI.h.


Constructor & Destructor Documentation

template<class T>
PLearn::TopNI< T >::TopNI ( ) [inline]

Default constructor, you must then call init.

Definition at line 73 of file TopNI.h.

    {}
template<class T>
PLearn::TopNI< T >::TopNI ( int  the_N) [inline]

N is the number of (value,index) pairs to remember.

Definition at line 77 of file TopNI.h.

{ init(the_N); }

Member Function Documentation

template<class T>
const TVec< pair<T,int> >& PLearn::TopNI< T >::getTopN ( ) [inline]

call this at the end to get the the smallest N values with associated integer index

Definition at line 121 of file TopNI.h.

Referenced by PLearn::evaluateKernelTopN().

{ return topn; }

Here is the caller graph for this function:

template<class T>
void PLearn::TopNI< T >::init ( int  the_N) [inline]

N is the number of (value,point) pairs to remember.

< reserve space for N elements

< set length back to 0

< ptr for faster access

Definition at line 80 of file TopNI.h.

References N.

    {
        N = the_N;
        topn.resize(N); 
        topn.resize(0); 
        topnptr = topn.data(); 
    }
template<class T>
void PLearn::TopNI< T >::reset ( ) [inline]

Definition at line 88 of file TopNI.h.

References N.

{ init(N); }
template<class T>
void PLearn::TopNI< T >::sort ( ) [inline]

Definition at line 117 of file TopNI.h.

Referenced by PLearn::evaluateKernelTopN().

    { std::sort(topnptr, topnptr+topn.length(), greater<pair <T,int> >() ); }

Here is the caller graph for this function:

template<class T>
void PLearn::TopNI< T >::update ( value,
int  index 
) [inline]

call this for each new value seen

find the new minimum:

Definition at line 91 of file TopNI.h.

References n, and N.

Referenced by PLearn::evaluateKernelTopN().

    {
        int l=topn.length();
        if(l<N)
        {
            topn.append( pair<T,int>(value,index) );
            if (l==0 || value<minpair->first)
                minpair = &topnptr[l];
        }
        else if(value>minpair->first)
        {
            minpair->first = value;
            minpair->second = index;

            pair<T,int>* it = topnptr;
            int n = N;
            while(n--)
            {
                if(it->first<minpair->first)
                    minpair = it;
                ++it;
            }
        }
    }

Here is the caller graph for this function:


Member Data Documentation

template<class T>
pair<T,int>* PLearn::TopNI< T >::minpair [protected]

Definition at line 68 of file TopNI.h.

template<class T>
int PLearn::TopNI< T >::N [protected]

Definition at line 65 of file TopNI.h.

template<class T>
TVec< pair<T,int> > PLearn::TopNI< T >::topn [protected]

Definition at line 66 of file TopNI.h.

template<class T>
pair<T,int>* PLearn::TopNI< T >::topnptr [protected]

topn.data()

Definition at line 67 of file TopNI.h.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines