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

#include <BottomNI.h>

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

List of all members.

Public Member Functions

 BottomNI ()
 Default constructor, you must then call init.
 BottomNI (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
int nZeros () const
void sort ()
const TVec< pair< T, int > > & getBottomN ()
 call this at the end to get the the smallest N values with associated integer index

Protected Attributes

int n_zeros
 number of zeros
int N
TVec< pair< T, int > > bottomn
pair< T, int > * bottomnptr
 bottomn.data()
pair< T, int > * maxpair

Detailed Description

template<class T>
class PLearn::BottomNI< T >

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

Definition at line 62 of file BottomNI.h.


Constructor & Destructor Documentation

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

Default constructor, you must then call init.

Definition at line 74 of file BottomNI.h.

        : n_zeros(0), N(0), bottomnptr(0), maxpair(0)
    { }
template<class T>
PLearn::BottomNI< T >::BottomNI ( int  the_N) [inline]

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

Definition at line 79 of file BottomNI.h.

        : n_zeros(0), N(0), bottomnptr(0), maxpair(0)
    { init(the_N); }

Member Function Documentation

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

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

Definition at line 130 of file BottomNI.h.

Referenced by PLearn::computeNearestNeighbors(), PLearn::LocalizedFeaturesLayerVariable::computeSubsets(), PLearn::evaluateKernelBottomN(), and PLearn::BaseRegressorConfidence::train().

{ return bottomn; }

Here is the caller graph for this function:

template<class T>
void PLearn::BottomNI< 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 84 of file BottomNI.h.

References N.

Referenced by PLearn::LocalizedFeaturesLayerVariable::computeSubsets().

    {
        N = the_N;
        bottomn.resize(N); 
        bottomn.resize(0); 
        bottomnptr = bottomn.data(); 
        n_zeros=0;
    }

Here is the caller graph for this function:

template<class T>
int PLearn::BottomNI< T >::nZeros ( ) const [inline]

Definition at line 124 of file BottomNI.h.

Referenced by PLearn::computeNearestNeighbors().

{return n_zeros;}

Here is the caller graph for this function:

template<class T>
void PLearn::BottomNI< T >::reset ( ) [inline]

Definition at line 93 of file BottomNI.h.

References N.

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

Definition at line 126 of file BottomNI.h.

Referenced by PLearn::computeNearestNeighbors(), PLearn::evaluateKernelBottomN(), and PLearn::BaseRegressorConfidence::train().

Here is the caller graph for this function:

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

call this for each new value seen

find the new maximum:

Definition at line 96 of file BottomNI.h.

References n, and N.

Referenced by PLearn::computeNearestNeighbors(), PLearn::LocalizedFeaturesLayerVariable::computeSubsets(), PLearn::evaluateKernelBottomN(), and PLearn::BaseRegressorConfidence::train().

    {
        int l=bottomn.length();
        if(value==0)
            n_zeros++;
        if(l<N)
        {
            bottomn.append( pair<T,int>(value,index) );
            if (l==0 || value>maxpair->first)
                maxpair = &bottomnptr[l];
        }
        else if(value<maxpair->first)
        {
            maxpair->first = value;
            maxpair->second = index;

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

Here is the caller graph for this function:


Member Data Documentation

template<class T>
TVec< pair<T,int> > PLearn::BottomNI< T >::bottomn [protected]

Definition at line 67 of file BottomNI.h.

template<class T>
pair<T,int>* PLearn::BottomNI< T >::bottomnptr [protected]

bottomn.data()

Definition at line 68 of file BottomNI.h.

template<class T>
pair<T,int>* PLearn::BottomNI< T >::maxpair [protected]

Definition at line 69 of file BottomNI.h.

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

Definition at line 66 of file BottomNI.h.

template<class T>
int PLearn::BottomNI< T >::n_zeros [protected]

number of zeros

Definition at line 65 of file BottomNI.h.


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