Main Page | Class List | File List | Class Members | File Members

etree.hh

00001 /*
00002 The Evolving Tree
00003 Copyright (C) 2004 Jussi Pakkanen, Petri Turkulainen
00004  
00005 This program is free software; you can redistribute it and/or
00006 modify it under the terms of the GNU General Public License
00007 as published by the Free Software Foundation; either version 2
00008 of the License, or (at your option) any later version.
00009  
00010 This program is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014  
00015 You should have received a copy of the GNU General Public License
00016 along with this program; if not, write to the Free Software
00017 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
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   // Helper functions.
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   //const vector<double *> MapData(int node);
00089 
00090   // Updating functions.
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   // Functions that print tree status info.
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   // Statistics calculators and printers.
00114   void PrintTreeInfo(ostream &os) const;
00115   void PrintNodeInfo(int nodenum, ostream &os) const;
00116   void PrintNodeProto(int nodenum, ostream &os) const;
00117 
00118   // Functions dealing with the index.
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 

Generated on Wed May 17 15:43:41 2006 for The Evolving Tree by  doxygen 1.4.1