00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef _etree_hh_
00021 #define _etree_hh_
00022
00023 #include<utility>
00024 #include<algorithm>
00025
00026 #include"node.hh"
00027 #include"datacache.hh"
00028
00036 class Etree {
00037
00038 private:
00039
00040 protected:
00041
00042 vector<Node> nodes;
00043 vector<int> fringe;
00044
00045 int dim;
00046 double round;
00047 double eta0;
00048 double sigma0;
00049 double tau1;
00050 double tau2;
00051 double bmuDecay;
00052
00053 int divisionThreshold;
00054 int divisionFactor;
00055
00056 double weightThreshold;
00057 double growingThreshold;
00058 int prevTreeSize;
00059
00060 DataCache *datavecs;
00061 vector<vector<int> > labels;
00062
00063 void Unserialize(istream &is);
00064
00065 void UpdateNode(int curnode, int prevnode, int BMU,const double *datavec,
00066 double distance);
00067 public:
00068 void Initialize();
00069 bool HasTreeGrown();
00070
00071 friend class VisualizerData;
00072
00073 Etree(DataCache *dc);
00074
00075 void SetParameters(int dT, int dF, double e0, double s0,
00076 double t1, double t2, double bdecay);
00077
00078
00079 int FindBMU(const double *datavec) const;
00080 double CalculateUpdateFactor(const double distance) const;
00081 void UpdateNodes(int BMU, const double *datavec);
00082 int TreeDistance(const int node1, const int node2) const;
00083 vector<int> FindTreePath(int nodenum) const;
00084 vector<pair<int, int> > GetSortedFringeDistances(const int nodenum) const;
00085 bool SetDataCache(DataCache &newcache);
00086 bool IsLeafNode(unsigned int i) const;
00087
00088
00089
00090
00091 void SingleIteration(const double *datavec);
00092 void SingleRound(bool exportData = false);
00093 void DecayBMUcounts();
00094 void KmeansAdjust();
00095 void TrunkReshape(int nodenum);
00096
00097 void ExportChildrenAsMatlab(string varname, ostream &os);
00098 void ExportShapeAsMatlab(ostream &os);
00099 friend ostream& operator<<(ostream &os, Etree &outtree);
00100 friend istream& operator>>(istream &is, Etree &intree);
00101 bool ReadFromDisk(string fname);
00102
00103
00104 int SubtreeSize(int node);
00105 int TotalNodes() { return nodes.size(); }
00106 int FringeSize() { return fringe.size(); }
00107 vector<int> NodesAtDepth(int depth);
00108 unsigned int MaxDepthNode() const;
00109 vector<int> GetDepthDistribution() const;
00110 int GetMaxDepth() const;
00111 void PrintNewickTree(ostream &out, const int curnodenum=0) const;
00112
00113
00114 void PrintTreeInfo(ostream &os) const;
00115 void PrintNodeInfo(int nodenum, ostream &os) const;
00116 void PrintNodeProto(int nodenum, ostream &os) const;
00117
00118
00119 void CreateIndex();
00120 void ClearIndex() { labels.clear(); }
00121 vector<int> GetIndexLabels(int i) const { return labels[i]; }
00122 vector<int> GetClassification(const double *queryvec) const;
00123 void PrintIndexStats(ostream &out) const;
00124
00125 };
00126
00127 #endif
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139