00001 #ifndef Impala_Core_Feature_RandomTreeTable_h 00002 #define Impala_Core_Feature_RandomTreeTable_h 00003 00004 #include "Core/Column/Types.h" 00005 #include "Core/Vector/Types.h" 00006 #include "Core/Table/TableTem.h" 00007 #include "Core/Feature/FeatureTable.h" 00008 00009 namespace Impala 00010 { 00011 namespace Core 00012 { 00013 namespace Feature 00014 { 00015 00016 // We can store a number of random trees in a RandomTreeTable for disk i/o. 00017 typedef Table::TableTem<Column::ColumnInt32, 00018 Column::ColumnInt32, 00019 Column::ColumnReal64> RandomTreeTable; 00020 00021 const Quid cInvalidCodeWord = 0x8000000000000000LL; 00022 00023 RandomTreeTable* 00024 MakeRandomTreeTable(FeatureTable* ft) 00025 { 00026 RandomTreeTable* rtt = new RandomTreeTable(ft->Size()); 00027 for(int i=0 ; i<ft->Size() ; ++i) 00028 { 00029 Quid q = ft->Get1(i); 00030 const Vector::VectorReal64& v = ft->Get2(i); 00031 double dimension = v[0]; 00032 double treshold = v[1]; 00033 rtt->Add((q == cInvalidCodeWord) ? -1 : q, dimension, treshold); 00034 } 00035 return rtt; 00036 } 00037 00038 FeatureTable* 00039 MakeFeatureTable(RandomTreeTable* rtt) 00040 { 00041 FeatureDefinition fdef("ceci_nest_pas_un_feature_table_its_a_random-forest"); 00042 FeatureTable* ft = new FeatureTable(fdef, rtt->Size(), 2); 00043 for(int i=0 ; i<rtt->Size() ; ++i) 00044 { 00045 int codeword = rtt->Get1(i); 00046 Vector::VectorReal64 v(2); 00047 v[0] = rtt->Get2(i); 00048 v[1] = rtt->Get3(i); 00049 ft->Add((codeword == -1) ? cInvalidCodeWord : codeword, v); 00050 } 00051 return ft; 00052 } 00053 00054 } // namespace Koen 00055 } // namespace Sandbox 00056 } // namespace Impala 00057 00058 #endif