[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

vigra/random_forest/rf_region.hxx VIGRA

00001 /************************************************************************/
00002 /*                                                                      */
00003 /*        Copyright 2008-2009 by  Ullrich Koethe and Rahul Nair         */
00004 /*                                                                      */
00005 /*    This file is part of the VIGRA computer vision library.           */
00006 /*    The VIGRA Website is                                              */
00007 /*        http://hci.iwr.uni-heidelberg.de/vigra/                       */
00008 /*    Please direct questions, bug reports, and contributions to        */
00009 /*        ullrich.koethe@iwr.uni-heidelberg.de    or                    */
00010 /*        vigra@informatik.uni-hamburg.de                               */
00011 /*                                                                      */
00012 /*    Permission is hereby granted, free of charge, to any person       */
00013 /*    obtaining a copy of this software and associated documentation    */
00014 /*    files (the "Software"), to deal in the Software without           */
00015 /*    restriction, including without limitation the rights to use,      */
00016 /*    copy, modify, merge, publish, distribute, sublicense, and/or      */
00017 /*    sell copies of the Software, and to permit persons to whom the    */
00018 /*    Software is furnished to do so, subject to the following          */
00019 /*    conditions:                                                       */
00020 /*                                                                      */
00021 /*    The above copyright notice and this permission notice shall be    */
00022 /*    included in all copies or substantial portions of the             */
00023 /*    Software.                                                         */
00024 /*                                                                      */
00025 /*    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND    */
00026 /*    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES   */
00027 /*    OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND          */
00028 /*    NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT       */
00029 /*    HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,      */
00030 /*    WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING      */
00031 /*    FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR     */
00032 /*    OTHER DEALINGS IN THE SOFTWARE.                                   */
00033 /*                                                                      */
00034 /************************************************************************/
00035 #ifndef VIGRA_RANDOM_FOREST_REGION_HXX
00036 #define VIGRA_RANDOM_FOREST_REGION_HXX
00037 #include <algorithm>
00038 #include <map>
00039 #include <numeric>
00040 #include "vigra/mathutil.hxx"
00041 #include "vigra/array_vector.hxx"
00042 #include "vigra/sized_int.hxx"
00043 #include "vigra/matrix.hxx"
00044 #include "vigra/random.hxx"
00045 #include "vigra/functorexpression.hxx"
00046 
00047 
00048 
00049 namespace vigra
00050 {
00051 
00052 
00053 /** Standard Stackentry used to Build a Tree. Contains Information 
00054  * About the current region being split
00055  */
00056 template <class Iter>
00057 class DT_StackEntry
00058 {
00059   public:
00060     typedef Iter IndexIterator;
00061     // tree specific stuff
00062     enum  ParentTag
00063     {
00064         DecisionTreeNoParent = -1
00065     };
00066 
00067     /** Address of left and Right parent in the topology container
00068      */
00069     Int32                                   leftParent;
00070     Int32                                   rightParent;
00071     /** rule associated with current node
00072      */
00073     ArrayVector<std::pair<Int32, double> >  rule;
00074 
00075 
00076     // RegionSpecificStuff
00077     ArrayVector<double>                     classCounts_;
00078     ArrayVector<double>                     weightedClassCounts_;
00079     bool                                    classCountsIsValid;
00080     bool                                    weightedClassCountsIsValid;
00081     IndexIterator                           begin_,  end_;
00082     int                                     size_; 
00083     IndexIterator                           oob_begin_, oob_end_;
00084     int                                     oob_size_;
00085 
00086     Int32 depth()
00087     {
00088         return rule.size();
00089     }
00090 
00091     void setRange(IndexIterator s, IndexIterator e)
00092     {
00093         begin_      = s;
00094         end_        = e;
00095         size_       = e-s;
00096     }
00097     void set_oob_range(IndexIterator s, IndexIterator e)
00098     {
00099         oob_begin_   = s;
00100         oob_end_     = e;
00101         oob_size_       = e-s;
00102     }
00103 
00104     void reset()
00105     {
00106         begin_      = end_      = IndexIterator();
00107         oob_begin_  = oob_end_  = IndexIterator();
00108         size_       = oob_size_ = 0;
00109         leftParent  = DecisionTreeNoParent;
00110         rightParent = DecisionTreeNoParent;
00111         classCountsIsValid = false;
00112     }
00113 
00114     bool  isPure()
00115     {
00116         int num = 0;
00117 
00118         for(int ii = 0; ii < (int)classCounts().size(); ++ii)
00119         {
00120             num += classCounts()[ii] > 0;
00121         }
00122         return num <= 1;
00123     }
00124 
00125     int&  operator[](int i)
00126     {
00127         return *(begin_+i);
00128     }
00129 
00130     IndexIterator & begin()
00131     {
00132         return begin_;
00133     }
00134 
00135     IndexIterator & end()
00136     {
00137         return end_;
00138     }
00139     IndexIterator & oob_begin()
00140     {
00141         return oob_begin_;
00142     }
00143 
00144     IndexIterator & oob_end()
00145     {
00146         return oob_end_;
00147     }
00148     ArrayVector<double> & classCounts()
00149     {
00150         return classCounts_;
00151     }
00152     ArrayVector<double> & weightedClassCounts()
00153     {
00154         return classCounts_;
00155     }
00156     bool  classCountsValid(bool u)
00157     {
00158         classCountsIsValid = u;
00159         return classCountsIsValid;
00160 
00161     }
00162 
00163     void classCounts(ArrayVector<Int32> in);
00164 
00165     DT_StackEntry( IndexIterator i, IndexIterator e,
00166                         int classCount,
00167                         Int32 lp = DecisionTreeNoParent,
00168                         Int32 rp = DecisionTreeNoParent)
00169     :
00170         leftParent(lp),
00171         rightParent(rp),
00172         classCounts_(classCount, 0u),
00173         classCountsIsValid(false),
00174         begin_(i),
00175         end_(e),
00176         size_(e-i)
00177     {}
00178 
00179     
00180     Int32 size()const
00181     {
00182         return size_;
00183     }
00184 
00185 
00186     Int32 oob_size()const
00187     {
00188         return oob_size_;
00189     }
00190 
00191 };
00192 
00193 
00194 }
00195 //namespace vigra
00196 
00197 #endif // VIGRA_RANDOM_FOREST_REGION_HXX

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de)
Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany

html generated using doxygen and Python
vigra 1.8.0 (20 Sep 2011)