- 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 #include "../shared_ptr.h"
    00017 #include "../base/bdmbase.h"
    00018 #include "../math/chmat.h"
    00019
    00020 namespace bdm {
    00021
    00022 // Abstract support - pokus, jen diskretni.. takze jmeno discrete support je lepci:)
    00023 // ale jediny, co by umel, je first_vec a next_vec, hmm:(
    00024 // class support : public root {
    00025
    00029 class rectangular_support: public root {
    00030 private:
    00032         void initialize();
    00033 protected:
    00035         Array<vec> ranges;
    00037         ivec gridsizes;
    00039         int dim;
    00041         int Npoints;
    00043         vec actvec;
    00045         vec actvec_ind;
    00047         vec steps;
    00048 public:
    00050         rectangular_support() : dim ( 0 ), Npoints ( 0 ) {
    00051         }
    00052
    00054         void set_parameters ( const Array<vec> &ranges0, const ivec &gridsize0 );
    00055
    00057         vec get_vec ( const ivec &inds );
    00058
    00060         long linear_index ( const ivec inds );
    00061
    00063         const vec& first_vec();
    00064
    00066         const vec& next_vec();
    00067
    00069         ivec nearest_point ( const vec &val );
    00070
    00072         int points() const {
    00073                 return Npoints;
    00074         }
    00075
    00078         const vec& _steps() const {
    00079                 return steps;
    00080         }
    00081
    00082         void from_setting ( const Setting &set );
    00083 };
    00084 UIREGISTER ( rectangular_support );
    00085
    00087 class discrete_support: public root {
    00088 protected:
    00090         Array<vec> Spoints;
    00092         int idx;
    00093 public:
    00095         discrete_support() : Spoints ( 0 ), idx ( 0 ) {}
    00097         int points() const {
    00098                 return Spoints.length();
    00099         }
    00101         const vec& first_vec() {
    00102                 bdm_assert_debug ( Spoints.length() > 0, "Empty support" );
    00103                 idx = 0;
    00104                 return Spoints ( idx );
    00105         }
    00107         const vec& next_vec() {
    00108                 bdm_assert_debug ( Spoints.length() > idx - 1, "Out of support points" );
    00109                 return Spoints ( ++idx );
    00110         }
    00111
    00121         void from_setting ( const Setting &set );
    00122
    00124         Array<vec> & _Spoints() {
    00125                 return Spoints;
    00126         }
    00127 };
    00128 UIREGISTER ( discrete_support );
    00129
    00130 class grid_fnc: public fnc {
    00131 protected:
    00132         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:
    00159         rectangular_support sup;
    00160         vec values;
    00161 public:
    00163         double evallog ( const vec &val ) {
    00164                 return log ( values ( sup.linear_index ( sup.nearest_point ( val ) ) ) );
    00165         }
    00166
    00167 };
    00168 }
    00169 #endif //DISCR_H