00001 #include "HTL/T_Uneven_Partition.h"
00002
00003
00004
00005
00006
00007
00008
00009 #define TEMPLATE___
00010 #define CLASS___ T_Uneven_Partition
00011 #define T_Point double
00012
00013
00014 TEMPLATE___
00015 CLASS___::T_Uneven_Partition( HTL_STD::vector<float> &some_points,
00016 End_Point_Convention a_convention )
00017 #ifdef HTL_USE_EXCEPTIONS
00018 throw (HTLExceptions::NotEnoughPoints)
00019 #endif //HTL_USE_EXCEPTIONS
00020 : I_Partition(), end_point_convention_ (a_convention)
00021 {
00022 if (some_points.size() < 2) {
00023 HTL_ERR("Less than two points specified for variable binning");
00024 #ifdef HTL_USE_EXCEPTIONS
00025 throw HTLExceptions::NotEnoughPoints();
00026 #endif //HTL_USE_EXCEPTIONS
00027 }
00028
00029 points_.resize(some_points.size());
00030 for (size_t i=0; i < some_points.size(); i++) {
00031 points_[i] = some_points[i];
00032 }
00033 initializePartition();
00034 }
00035
00036 TEMPLATE___
00037 CLASS___::T_Uneven_Partition( HTL_STD::vector<double> &some_points,
00038 End_Point_Convention a_convention )
00039 #ifdef HTL_USE_EXCEPTIONS
00040 throw (HTLExceptions::NotEnoughPoints)
00041 #endif //HTL_USE_EXCEPTIONS
00042 : I_Partition(), end_point_convention_ (a_convention)
00043 {
00044 if (some_points.size() < 2) {
00045 HTL_ERR("Less than two points specified for variable binning");
00046 #ifdef HTL_USE_EXCEPTIONS
00047 throw HTLExceptions::NotEnoughPoints();
00048 #endif //HTL_USE_EXCEPTIONS
00049 }
00050
00051 points_.resize(some_points.size());
00052 for (size_t i=0; i < some_points.size(); i++) {
00053 points_[i] = some_points[i];
00054 }
00055 initializePartition();
00056 }
00057
00058 TEMPLATE___
00059 void CLASS___:: initializePartition()
00060 {
00061 count_ = points_.size() - 1;
00062 lower_point_ = points_[0];
00063 upper_point_ = points_[ count_ ];
00064 }
00065
00066 TEMPLATE___
00067 CLASS___::T_Uneven_Partition( I_Partition &another )
00068 #ifdef HTL_USE_EXCEPTIONS
00069 throw (HTLExceptions::NotEnoughPoints)
00070 #endif //HTL_USE_EXCEPTIONS
00071 : points_( another.bin_count()+1 )
00072 {
00073 count_ = another.bin_count();
00074 if (count_ > 1) {
00075 lower_point_ = T_Point( another.i_lower_point() );
00076 upper_point_ = T_Point( another.i_upper_point() );
00077 for( Index i=0; i<count_; i++ ) {
00078 points_[i] = T_Point( another.i_lower_point(i) );
00079 }
00080 points_[count_] = upper_point_;
00081 end_point_convention_ = another.end_point_convention();
00082 } else {
00083 HTL_ERR("Less than two points specified for variable binning");
00084 #ifdef HTL_USE_EXCEPTIONS
00085 throw HTLExceptions::NotEnoughPoints();
00086 #endif //HTL_USE_EXCEPTIONS
00087 }
00088 }
00089
00090
00091 TEMPLATE___
00092 void CLASS___::map_index1( T_Point a_point, Index &an_index,
00093 Extra_Index &an_extra_index )
00094 {
00095
00096
00097
00098
00099
00100
00101
00102
00103 if( a_point < lower_point() ) {
00104
00105 an_extra_index = H_UNDERFLOW;
00106 return;
00107
00108 } else if( a_point > upper_point() ) {
00109
00110 an_extra_index = H_OVERFLOW;
00111 return;
00112 }
00113
00114
00115 if (!( a_point >= lower_point() && a_point <= upper_point() )) {
00116 HTL_ERR("a_point >= lower_point() && a_point <= upper_point()");
00117 return;
00118 }
00119
00120
00121
00122
00123
00124
00125 an_index = 0;
00126 while( an_index < bin_count() ) {
00127 if( a_point < upper_point( an_index ) ) break;
00128 an_index ++;
00129 }
00130
00131
00132 if (!( an_index >= 0 && an_index <= count_ )) {
00133 HTL_ERR("( an_index >= 0 && an_index <= count_ )");
00134 return;
00135 }
00136
00137
00138
00139
00140
00141
00142
00143 if( end_point_convention_ == LEFT_OPEN ) {
00144 if( (upper_point() == a_point) ||
00145 (lower_point(an_index) == a_point) )
00146 {
00147
00148
00149
00150
00151 an_index --;
00152 }
00153 }
00154
00155 if( an_index < 0 ) {
00156
00157
00158 an_extra_index = H_UNDERFLOW;
00159 return;
00160
00161 } else if( an_index >= bin_count() ) {
00162
00163
00164
00165 an_extra_index = H_OVERFLOW;
00166 return;
00167 }
00168
00169
00170
00171 an_extra_index = H_IN_RANGE;
00172
00173
00174 if (! (an_index >= 0) && (an_index < count_))
00175 HTL_ERR("(an_index >= 0) && (an_index < count_)");
00176
00177 }
00178
00179
00180
00181
00182
00183
00184 #undef T_Point
00185 #undef CLASS___
00186 #undef TEMPLATE___
00187
00188