PLearn 0.1
|
#include <BottomNI.h>
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 |
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.
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) { }
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); }
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; }
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().
int PLearn::BottomNI< T >::nZeros | ( | ) | const [inline] |
Definition at line 124 of file BottomNI.h.
Referenced by PLearn::computeNearestNeighbors().
{return n_zeros;}
void PLearn::BottomNI< T >::reset | ( | ) | [inline] |
void PLearn::BottomNI< T >::sort | ( | ) | [inline] |
Definition at line 126 of file BottomNI.h.
Referenced by PLearn::computeNearestNeighbors(), PLearn::evaluateKernelBottomN(), and PLearn::BaseRegressorConfidence::train().
{ std::sort(bottomnptr, bottomnptr+bottomn.length()); }
void PLearn::BottomNI< T >::update | ( | T | value, |
int | index | ||
) | [inline] |
call this for each new value seen
find the new maximum:
Definition at line 96 of file BottomNI.h.
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; } } }
TVec< pair<T,int> > PLearn::BottomNI< T >::bottomn [protected] |
Definition at line 67 of file BottomNI.h.
pair<T,int>* PLearn::BottomNI< T >::bottomnptr [protected] |
bottomn.data()
Definition at line 68 of file BottomNI.h.
pair<T,int>* PLearn::BottomNI< T >::maxpair [protected] |
Definition at line 69 of file BottomNI.h.
int PLearn::BottomNI< T >::N [protected] |
Definition at line 66 of file BottomNI.h.
int PLearn::BottomNI< T >::n_zeros [protected] |
number of zeros
Definition at line 65 of file BottomNI.h.