3 #ifndef __s2_ftrans_hpp
4 #define __s2_ftrans_hpp
11 #include <least_squares_2d.hpp>
13 #include <mth/least_squares_2d.hpp>
18 typedef double arg_type;
33 virtual arg_type
calc(arg_type x)
const = 0;
40 virtual arg_type
calc(arg_type x)
const;
45 void ftrans(std::vector<arg_type> &func, arg_type &xmn, arg_type &xmx)
47 #define FTRANS_REAL_EPS 1.e-6
52 arg_type zmn = trans(xmn);
53 arg_type zmx = trans(xmx);
55 printf(
"INFO: ftrans: new arg limits %lg->%lg\n", zmn, zmx);
57 std::vector<arg_type> args(func.size());
58 arg_type dx = (xmx-xmn) / (func.size()-1.);
62 for(
int i=0; i<func.size(); ++i) {
63 args[i] = trans(x_cur);
65 printf(
"INFO: ftrans: arg[%ld] = %lg -> %lg\n", i, x_cur, args[i]);
69 printf(
"INFO: ftrans: func recalculated...\n");
71 std::vector<arg_type> func_new;
75 FILE* f = fopen(
"ftrans_res1_f.dat",
"w");
76 for(
int i=0; i<func.size(); ++i)
77 fprintf(f,
"%g\t%g\n", args[i], func[i]);
81 std::size_t i_max = func.size()-1;
84 arg_type dz = (zmx-zmn) / (func.size()-1.);
87 for(
int i=1; i<func.size(); ++i) {
88 if (fabs(dz) > fabs(args[i]-args[i-1]))
89 dz = args[i]-args[i-1];
91 i_max = int(fabs((zmx-zmn)/dz));
94 printf(
"INFO: ftrans: dz=%lg...\n", dz);
95 arg_type z_cur = zmn+dz;
98 func_new.push_back(func[0]);
100 for(std::size_t i=1; i<i_max; ++i) {
105 for(; j<func.size()-1; ++j) {
107 if (fabs(args[j]-z_cur) < FTRANS_REAL_EPS) { bingo =
true;
break; }
108 if (args[j]>z_cur && args[j+1]<z_cur)
break;
109 if (args[j]<z_cur && args[j+1]>z_cur)
break;
111 if (j == func.size()-1) {
112 printf(
"ERROR: arg=%lg was not found...\n", z_cur);
118 printf(
"INFO: ftrans: arg=%lg limits found, j0=%zu...\n", z_cur, j);
121 func_new.push_back(func[j]);
129 unsigned int p_num = 3;
130 std::vector<double> xp(p_num);
131 std::vector<double> yp(p_num);
133 if ((j+p_num-1) >= func.size())
134 j = func.size()-p_num;
136 for (std::size_t i=0; i<p_num; ++i) {
140 printf(
"INFO: ftrans: arg=%lg func[%zu] = %lg\n", z_cur, j, yp[i]);
144 unsigned int deg = p_num-1;
149 printf(
"ERROR: ftrans: arg=%lg : failed to form poly...", z_cur);
153 func_new.push_back(res);
156 printf(
"INFO: ftrans: arg=%lg process complete... val=%lg\n", z_cur, res);
164 func_new.push_back(func[func.size()-1]);
166 printf(
"INFO: ftrans: new func formed...\n");
172 for(std::size_t i=0; i<func_new.size(); ++i) {
174 func.push_back(func_new[func_new.size()-i-1]);
176 func.push_back(func_new[i]);
178 printf(
"INFO: ftrans: new func [%zu] = %lg\n", i, func[i]);
192 printf(
"INFO: ftrans: complete...\n");
193 #undef FTRANS_REAL_EPS
bool getPoly(const vector< double > &x, const vector< double > &y, const vector< double > &w, PolyCoeffs &cfs)
Definition: s2_ftrans.hpp:21
virtual arg_type calc(arg_type x) const =0
arg_type operator()(arg_type x)
Definition: s2_ftrans.hpp:28
Definition: s2_ftrans.hpp:37
std::vector< PolyCoeff > PolyCoeffs
Definition: least_squares_2d.hpp:25
double calcPoly(const PolyCoeffs &coeffs, double x)
virtual arg_type calc(arg_type x) const