19 for(
int i=0; i<D; i++)
val[i]=rhs[i];
23 for(
int i=0; i<D; i++)
val[i]=rhs.
val[i];
29 for(
int i=0; i<D; i++)
val[i]=v;
33 for(
int i=0; i<D; i++)
val[i]+=rhs.
val[i];
37 for(
int i=0; i<D; i++)
val[i]*=rhs.
val[i];
41 for(
int i=0; i<D; i++)
val[i]*=v;
45 for(
int i=0; i<D; i++)
val[i]/=v;
49 for(
int i=0; i<D; i++)
val[i]=
frand(max-min)+min;
54 for(
int i=0; i<D; i++) {
55 register float cd =
val[i]-rhs.
val[i];
68 friend ostream& operator<<(ostream& os, const CElement<D> &rhs) {
69 for(
int i=0; i<D; i++) {
85 typedef typename vector< CElement<D> >::iterator
eiterator;
89 initialize(nclasses, min, max);
94 for(eiterator cv = m_ElemAcc.begin();
95 cv != m_ElemAcc.end(); cv++, cid++)
99 cv->getNMembers() = 0;
104 m_Classes.resize(nclasses);
105 m_ElemAcc.resize(nclasses);
107 for(eiterator cv = m_Classes.begin();
108 cv != m_Classes.end(); cv++, cid++)
111 cv->getNMembers() = 0;
112 cv->randomize(min,max);
119 float mind=numeric_limits<float>::max();
122 for(eiterator cv = m_Classes.begin();
123 cv != m_Classes.end(); cv++, cid++)
125 float d = elem.
dist2(*cv);
141 for(eiterator e=m_Elements.begin();
142 e != m_Elements.end(); e++)
144 dword oldclass = e->getClassID();
145 if(oldclass != classify(*e))
148 for(eiterator ci=m_Classes.begin(), ca=m_ElemAcc.begin();
149 ci!=m_Classes.end(); ci++, ca++)
151 if(ca->getNMembers()) {
152 *ca *= 1.0f/ca->getNMembers();
154 }
else ci->getNMembers() = 0;
157 cout << reclass <<
" re-classifications" << endl;
164 cout <<
"iteration " << (++counter) << endl;
165 if(classifyAll() == 0)
break;
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;
dword getNMembers() const
float dist2(const CElement< D > &rhs) const
vector< CElement< D > > m_ElemAcc
void iterateClassification(dword maxit=10)
CElement< D > & operator=(const vector< float > &rhs)
vector< CElement< D > > m_Classes
CElement(const vector< float > &rhs)
CElement< D > & operator=(float v)
vector< CElement< D > >::iterator eiterator
void initialize(dword nclasses, float min=0, float max=1)
Clusterer(dword nclasses=1, float min=0, float max=1)
dword classify(CElement< D > &elem)
CElement< D > & operator=(const CElement &rhs)
void setClassID(dword cid)
CElement< D > & operator+=(const CElement< D > &rhs)
vector< CElement< D > >::const_iterator const_eiterator
CElement< D > & randomize(float min=0, float max=1)
vector< CElement< D > > m_Elements
CElement< D > & operator*=(float v)
CElement< D > & operator/=(float v)
float dist(const CElement< D > &rhs) const
CElement< D > & operator*=(const CElement< D > &rhs)
DMatrix< T > & sqrt(DMatrix< T > &mat)