Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members

kmeans.h

00001 // Copyright (C) 1999 Jean-Marc Valin
00002 
00003 #ifndef KMEANS_H
00004 #define KMEANS_H
00005 
00006 #include "Vector.h"
00007 #include <iostream>
00008 #include "Object.h"
00009 #include "vq.h"
00010 
00011 namespace FD {
00012 
00013 class KMeans : public VQ {
00014 protected:
00015    //int length;
00016    std::vector<std::vector<float> > means;
00017    //std::vector<int> accum;
00018 
00019 public:
00020    explicit KMeans (float (*_dist)(const float *, const float*, int) = euclidian)
00021       : VQ(_dist)
00022    {}
00023 
00024    int nbClasses() const {return means.size();}
00025 
00026    const std::vector<float> &operator[] (int i) const;
00027 
00028    void split (const std::vector<float *> &data, int len);
00029 
00030    void bsplit ();
00031 
00032    void update (const std::vector<float *> &data, int len);
00033 
00034    void train (int codeSize, const std::vector<float *> &data, int len, bool binary=false);
00035 
00036    int getClassID (const float *v, float *dist_return = NULL) const;
00037    virtual void calcDist (const float *v, float *dist_return) const;
00038 
00039    void weightMeans (const Vector<float> &w, Vector<float> &out) const;
00040    
00041    void printOn(std::ostream &out=std::cout) const;
00042    void readFrom (std::istream &in=std::cin);
00043    friend std::istream &operator >> (std::istream &in, KMeans &mdl);
00044 };
00045 
00046 }//namespace FD
00047 
00048 #endif

Generated on Wed Oct 5 14:28:55 2005 for FlowDesigner by  doxygen 1.4.4