- 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
    00127 class grid_fnc: public fnc {
    00128 protected:
    00129         rectangular_support sup;
    00130         vec values;
    00131 public:
    00133         void set_support ( rectangular_support &sup0 ) {
    00134                 sup = sup0;
    00135                 values = zeros ( sup.points() );
    00136         }
    00138         void set_values ( double ( *evalptr ) ( const vec& ) );
    00139
    00141         double nearest_val ( const vec &val ) {
    00142                 return values ( sup.linear_index ( sup.nearest_point ( val ) ) );
    00143         }
    00144
    00145         vec eval ( const vec &val ) {
    00146                 return vec_1 ( nearest_val ( val ) );
    00147         }
    00148 };
    00149 UIREGISTER ( grid_fnc );
    00150
    00154 class egrid: public epdf {
    00155 protected:
    00156         rectangular_support sup;
    00157         vec values;
    00158 public:
    00160         double evallog ( const vec &val ) {
    00161                 return log ( values ( sup.linear_index ( sup.nearest_point ( val ) ) ) );
    00162         }
    00163
    00164 };
    00165 }
    00166 #endif //DISCR_H