00001
00002
00003
00004 #ifndef FITYK__NMFIT__H__
00005 #define FITYK__NMFIT__H__
00006
00007 #include <vector>
00008 #include "common.h"
00009 #include "fit.h"
00010
00011
00012 struct Vertex
00013 {
00014 std::vector<realt> a;
00015 bool computed;
00016 realt wssr;
00017
00018 Vertex() : a(0), computed(false), wssr(0.) {}
00019 Vertex(int n) : a(n), computed(false), wssr(0.) {}
00020 Vertex(std::vector<realt>& a_) : a(a_), computed(false), wssr(0.) {}
00021 };
00022
00023
00024 class NMfit : public Fit
00025 {
00026 public:
00027 NMfit(Ftk* F);
00028 ~NMfit();
00029 virtual void init();
00030 void autoiter();
00031 private:
00032 int iteration;
00033 std::vector<Vertex> vertices;
00034 std::vector<Vertex>::iterator best, s_worst , worst;
00035 std::vector<realt> coord_sum;
00036 realt volume_factor;
00037
00038 void find_best_worst();
00039 void change_simplex();
00040 realt try_new_worst(realt f);
00041 void compute_coord_sum();
00042 bool termination_criteria(int iter, realt convergence);
00043 void compute_v(Vertex& v);
00044 };
00045
00046 #endif
00047