00001
00002
00003
00004 #ifndef FITYK__FUNC__H__
00005 #define FITYK__FUNC__H__
00006
00007 #include <map>
00008 #include <assert.h>
00009
00010 #include "tplate.h"
00011 #include "var.h"
00012
00013 class Settings;
00014 class VariableManager;
00015
00016 class Function : public VariableUser
00017 {
00018 public:
00019
00020 struct Multi
00021 {
00022 int p; int n; realt mult;
00023 Multi(int n_, const Variable::ParMult& pm)
00024 : p(pm.p), n(n_), mult(pm.mult) {}
00025 };
00026
00027 Function(const Settings* settings, const std::string &name,
00028 const Tplate::Ptr tp, const std::vector<std::string> &vars);
00029 virtual ~Function() {}
00030 virtual void init();
00031
00032 static Function* factory(const Settings* settings, const std::string &name,
00033 const Tplate::Ptr tp,
00034 const std::vector<std::string> &vars);
00035
00036 const Tplate::Ptr& tp() const { return tp_; }
00037
00038
00039 int nv() const {return tp_->fargs.empty() ? av_.size() : tp_->fargs.size();}
00040
00041
00042 virtual void calculate_value_in_range(const std::vector<realt> &x,
00043 std::vector<realt> &y,
00044 int first, int last) const = 0;
00045 void calculate_value(const std::vector<realt> &x,
00046 std::vector<realt> &y) const;
00047 realt calculate_value(realt x) const;
00048
00049 virtual void calculate_value_deriv_in_range(const std::vector<realt> &x,
00050 std::vector<realt> &y,
00051 std::vector<realt> &dy_da,
00052 bool in_dx,
00053 int first, int last) const = 0;
00054 void calculate_value_deriv(const std::vector<realt> &x,
00055 std::vector<realt> &y,
00056 std::vector<realt> &dy_da,
00057 bool in_dx=false) const;
00058
00059 void do_precomputations(const std::vector<Variable*> &variables);
00060 virtual void more_precomputations() {}
00061 void erased_parameter(int k);
00062 virtual bool get_nonzero_range(double ,
00063 realt& , realt& ) const { return false; }
00064
00065
00066
00067 virtual bool get_center(realt* a) const;
00068 virtual bool get_height(realt* ) const { return false; }
00069 virtual bool get_fwhm(realt* ) const { return false; }
00070 virtual bool get_area(realt* ) const { return false; }
00071
00072 bool get_iwidth(realt* a) const;
00073
00074
00075 virtual const std::vector<std::string>& get_other_prop_names() const
00076 { static const std::vector<std::string> empty; return empty; }
00077
00078 virtual realt get_other_prop(const std::string&) const { return 0; }
00079
00080 const std::vector<realt>& av() const { return av_; }
00081 std::string get_basic_assignment() const;
00082 std::string get_current_assignment(const std::vector<Variable*> &variables,
00083 const std::vector<realt> ¶meters) const;
00084 virtual std::string get_current_formula(const std::string& x = "x") const;
00085
00086
00087 virtual std::string get_param(int n) const { return tp_->fargs[n]; }
00088
00089 int get_param_nr(const std::string& param) const;
00090 realt get_param_value(const std::string& param) const;
00091
00092 realt numarea(realt x1, realt x2, int nsteps) const;
00093 realt find_x_with_value(realt x1, realt x2, realt val,
00094 int max_iter=1000) const;
00095 realt find_extremum(realt x1, realt x2, int max_iter=1000) const;
00096
00097 virtual std::string get_bytecode() const { return "No bytecode"; }
00098 protected:
00099 const Settings* settings_;
00100 Tplate::Ptr tp_;
00101
00102
00103 std::vector<realt> av_;
00104 std::vector<Multi> multi_;
00105 int center_idx_;
00106
00107 private:
00108 static std::vector<realt> calc_val_xx, calc_val_yy;
00109 };
00110
00111 #endif
00112