- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

# discrete.h

Go to the documentation of this file.

    00001
    00013 #ifndef DISCR_H
    00014 #define DISCR_H
    00015
    00016
    00017 #include "../shared_ptr.h"
    00018 #include "../base/bdmbase.h"
    00019 #include "../math/chmat.h"
    00020
    00021 namespace bdm {
    00022
    00026 class rectangular_support: public root {
    00027 protected:
    00029         Array<vec> ranges;
    00031         ivec gridsizes;
    00033         int dim;
    00035         int Npoints;
    00037         vec actvec;
    00039         vec actvec_ind;
    00041         vec steps;
    00042 public:
    00044         rectangular_support() : dim ( 0 ), Npoints ( 0 ) {
    00045         }
    00046
    00048         void set_parameters ( const Array<vec> &ranges0, const ivec &gridsize0 );
    00049
    00051         void initialize();
    00052
    00054         vec get_vec ( const ivec &inds );
    00055
    00057         long linear_index ( const ivec inds );
    00058
    00060         const vec& first_vec();
    00061
    00063         const vec& next_vec();
    00064
    00066         ivec nearest_point ( const vec &val );
    00067
    00069         int points() const {
    00070                 return Npoints;
    00071         }
    00072
    00075         const vec& _steps() const {
    00076                 return steps;
    00077         }
    00078
    00079         void from_setting ( const Setting &set );
    00080 };
    00081 UIREGISTER ( rectangular_support );
    00082
    00084 class discrete_support: public root {
    00085 protected:
    00087         Array<vec> Spoints;
    00089         int idx;
    00090 public:
    00092         discrete_support() : Spoints ( 0 ), idx ( 0 ) {}
    00094         int points() const {
    00095                 return Spoints.length();
    00096         }
    00098         const vec& first_vec() {
    00099                 bdm_assert_debug ( Spoints.length() > 0, "Empty support" );
    00100                 idx = 0;
    00101                 return Spoints ( idx );
    00102         }
    00104         const vec& next_vec() {
    00105                 bdm_assert_debug ( Spoints.length() > idx - 1, "Out of support points" );
    00106                 return Spoints ( ++idx );
    00107         }
    00108
    00118         void from_setting ( const Setting &set );
    00119
    00121         Array<vec> & _Spoints() {
    00122                 return Spoints;
    00123         }
    00124 };
    00125 UIREGISTER ( discrete_support );
    00126
    00128 class grid_fnc: public fnc {
    00129 protected:
    00131         rectangular_support sup;
    00133         vec values;
    00134 public:
    00136         void set_support ( rectangular_support &sup0 ) {
    00137                 sup = sup0;
    00138                 values = zeros ( sup.points() );
    00139         }
    00141         void set_values ( double ( *evalptr ) ( const vec& ) );
    00142
    00144         double nearest_val ( const vec &val ) {
    00145                 return values ( sup.linear_index ( sup.nearest_point ( val ) ) );
    00146         }
    00147
    00148         vec eval ( const vec &val ) {
    00149                 return vec_1 ( nearest_val ( val ) );
    00150         }
    00151 };
    00152 UIREGISTER ( grid_fnc );
    00153
    00157 class egrid: public epdf {
    00158 protected:
    00160         rectangular_support sup;
    00162         vec values;
    00163 public:
    00165         double evallog ( const vec &val ) {
    00166                 return log ( values ( sup.linear_index ( sup.nearest_point ( val ) ) ) );
    00167         }
    00168
    00169 };
    00170 }
    00171 #endif //DISCR_H