Structural deformable models
Public Types | Public Member Functions | Public Attributes | List of all members
Clusterer< D > Class Template Reference

#include <Clusterer.h>

Public Types

typedef vector< CElement< D > >::iterator eiterator
 
typedef vector< CElement< D > >::const_iterator const_eiterator
 

Public Member Functions

 Clusterer (dword nclasses=1, float min=0, float max=1)
 
void clearAccumulation ()
 
void initialize (dword nclasses, float min=0, float max=1)
 
dword classify (CElement< D > &elem)
 
dword classifyAll ()
 
void iterateClassification (dword maxit=10)
 

Public Attributes

vector< CElement< D > > m_Elements
 
vector< CElement< D > > m_Classes
 
vector< CElement< D > > m_ElemAcc
 

Detailed Description

template<int D>
class Clusterer< D >

Definition at line 83 of file Clusterer.h.

Member Typedef Documentation

template<int D>
typedef vector< CElement<D> >::const_iterator Clusterer< D >::const_eiterator

Definition at line 86 of file Clusterer.h.

template<int D>
typedef vector< CElement<D> >::iterator Clusterer< D >::eiterator

Definition at line 85 of file Clusterer.h.

Constructor & Destructor Documentation

template<int D>
Clusterer< D >::Clusterer ( dword  nclasses = 1,
float  min = 0,
float  max = 1 
)
inline

Definition at line 88 of file Clusterer.h.

88  {
89  initialize(nclasses, min, max);
90  };
void initialize(dword nclasses, float min=0, float max=1)
Definition: Clusterer.h:103

Member Function Documentation

template<int D>
dword Clusterer< D >::classify ( CElement< D > &  elem)
inline

Definition at line 118 of file Clusterer.h.

References CElement< D >::dist2(), CElement< D >::getNMembers(), and CElement< D >::setClassID().

118  {
119  float mind=numeric_limits<float>::max();
120  dword minid=0;
121  dword cid=0;
122  for(eiterator cv = m_Classes.begin();
123  cv != m_Classes.end(); cv++, cid++)
124  {
125  float d = elem.dist2(*cv);
126  if(d<mind) {
127  mind = d;
128  minid = cid;
129  }
130  }
131  CElement<D> &ae = m_ElemAcc[minid];
132  ae += elem;
133  ae.getNMembers()++;
134  elem.setClassID(minid);
135  return minid;
136  }
dword getNMembers() const
Definition: Clusterer.h:64
float dist2(const CElement< D > &rhs) const
Definition: Clusterer.h:52
vector< CElement< D > > m_ElemAcc
Definition: Clusterer.h:177
vector< CElement< D > > m_Classes
Definition: Clusterer.h:176
vector< CElement< D > >::iterator eiterator
Definition: Clusterer.h:85
void setClassID(dword cid)
Definition: Clusterer.h:67
unsigned long dword
Definition: simpletypes.h:6
template<int D>
dword Clusterer< D >::classifyAll ( )
inline

Definition at line 138 of file Clusterer.h.

138  {
139  dword reclass = 0;
141  for(eiterator e=m_Elements.begin();
142  e != m_Elements.end(); e++)
143  {
144  dword oldclass = e->getClassID();
145  if(oldclass != classify(*e))
146  reclass++;
147  }
148  for(eiterator ci=m_Classes.begin(), ca=m_ElemAcc.begin();
149  ci!=m_Classes.end(); ci++, ca++)
150  {
151  if(ca->getNMembers()) {
152  *ca *= 1.0f/ca->getNMembers();
153  *ci = *ca;
154  } else ci->getNMembers() = 0;
155  //cout << *ci << " members: " << ci->getNMembers() << endl;
156  }
157  cout << reclass << " re-classifications" << endl; //DEBUG
158  return reclass;
159  }
vector< CElement< D > > m_ElemAcc
Definition: Clusterer.h:177
vector< CElement< D > > m_Classes
Definition: Clusterer.h:176
vector< CElement< D > >::iterator eiterator
Definition: Clusterer.h:85
dword classify(CElement< D > &elem)
Definition: Clusterer.h:118
void clearAccumulation()
Definition: Clusterer.h:92
unsigned long dword
Definition: simpletypes.h:6
vector< CElement< D > > m_Elements
Definition: Clusterer.h:175
template<int D>
void Clusterer< D >::clearAccumulation ( )
inline

Definition at line 92 of file Clusterer.h.

92  {
93  dword cid=0;
94  for(eiterator cv = m_ElemAcc.begin();
95  cv != m_ElemAcc.end(); cv++, cid++)
96  {
97  *cv = 0;
98  cv->id = cid;
99  cv->getNMembers() = 0;
100  }
101  }
vector< CElement< D > > m_ElemAcc
Definition: Clusterer.h:177
vector< CElement< D > >::iterator eiterator
Definition: Clusterer.h:85
unsigned long dword
Definition: simpletypes.h:6
template<int D>
void Clusterer< D >::initialize ( dword  nclasses,
float  min = 0,
float  max = 1 
)
inline

Definition at line 103 of file Clusterer.h.

103  {
104  m_Classes.resize(nclasses);
105  m_ElemAcc.resize(nclasses);
106  dword cid=0;
107  for(eiterator cv = m_Classes.begin();
108  cv != m_Classes.end(); cv++, cid++)
109  {
110  cv->id = cid;
111  cv->getNMembers() = 0;
112  cv->randomize(min,max);
113  //cout << *cv << endl;
114  }
116  }
vector< CElement< D > > m_ElemAcc
Definition: Clusterer.h:177
vector< CElement< D > > m_Classes
Definition: Clusterer.h:176
vector< CElement< D > >::iterator eiterator
Definition: Clusterer.h:85
void clearAccumulation()
Definition: Clusterer.h:92
unsigned long dword
Definition: simpletypes.h:6
template<int D>
void Clusterer< D >::iterateClassification ( dword  maxit = 10)
inline

Definition at line 161 of file Clusterer.h.

Referenced by ImageWindow::onKeyPress().

161  {
162  int counter=0; //DEBUG
163  while(maxit>0) {
164  cout << "iteration " << (++counter) << endl; //DEBUG
165  if(classifyAll() == 0) break;
166  maxit--;
167  }
168  int cu=0;
169  for(eiterator ci=m_Classes.begin(); ci!=m_Classes.end(); ci++)
170  if(ci->getNMembers()) cu++;
171  cout << "number of classes used: " << cu << endl;
172  }
vector< CElement< D > > m_Classes
Definition: Clusterer.h:176
vector< CElement< D > >::iterator eiterator
Definition: Clusterer.h:85
dword classifyAll()
Definition: Clusterer.h:138

Member Data Documentation

template<int D>
vector< CElement<D> > Clusterer< D >::m_Classes

Definition at line 176 of file Clusterer.h.

Referenced by ImageWindow::onKeyPress().

template<int D>
vector< CElement<D> > Clusterer< D >::m_ElemAcc

Definition at line 177 of file Clusterer.h.

template<int D>
vector< CElement<D> > Clusterer< D >::m_Elements

Definition at line 175 of file Clusterer.h.

Referenced by ImageWindow::onKeyPress().


The documentation for this class was generated from the following file: