Commit bca6dd57 by Laurent Belcour

Updating the L2 and L_inf norm computation.

`Fixed the infinte loop in the rational_fitter quadprog`
parent 4d98e371
 ... ... @@ -5,53 +5,35 @@ //! \brief L2 norm to data. double function::L2_distance(const data* d) const { double l2 = 0.0; int nb_points = d->size(); for(int i=0; iget(i); vec y1(d->dimY()); for(int j=0; jdimY(); ++j) y1 = x[d->dimX() + j]; // Evaluate data vec y2 = this->value(x); double dist = norm(y1-y2); l2 += dist*dist; } double factor = 1.0/(double)nb_points; vec _min = d->min(); vec _max = d->max(); for(int i=0; idimX(); ++i) { factor *= _max[i]-_min[i]; } return sqrt(l2)*factor; double l2_dist = 0.0; for(int i=0; isize(); ++i) { vec dat = d->get(i); vec y(d->dimY()); for(int j=0; jdimY(); ++j) y[j] = dat[d->dimX()+j]; //linf_dist = std::max(linf_dist, std::abs(norm(y-rj->value(dat)))); l2_dist += std::pow(norm(y-value(dat)), 2); } l2_dist = std::sqrt(l2_dist / d->size()); return l2_dist; } //! \brief Linf norm to data. double function::Linf_distance(const data* d) const { double linf = 0.0; int nb_points = d->size(); for(int i=0; iget(i); vec y1(d->dimY()); for(int j=0; jdimY(); ++j) y1 = x[d->dimX() + j]; // Evaluate data vec y2 = this->value(x); double dist = norm(y1-y2); linf = std::max(dist, linf); } return linf; double linf_dist = 0.0; for(int i=0; isize(); ++i) { vec dat = d->get(i); vec y(d->dimY()); for(int j=0; jdimY(); ++j) y[j] = dat[d->dimX()+j]; linf_dist = std::max(linf_dist, std::abs(norm(y-value(dat)))); } return linf_dist; }
 ... ... @@ -9,7 +9,7 @@ #include #include #define RELATIVE_ERROR //#define RELATIVE_ERROR void vertical_segment::load(const std::string& filename) { ... ...
 ... ... @@ -3,7 +3,7 @@ TEMPLATE = subdirs SUBDIRS = \ # rational_fitter_cgal \ rational_fitter_quadprog \ # rational_fitter_parallel \ rational_fitter_parallel \ # rational_fitter_quadproge \ rational_fitter_eigen \ rational_fitter_leastsquare \ ... ...
 ... ... @@ -270,6 +270,7 @@ bool rational_fitter_parallel::fit_data(const vertical_segment* d, int np, int n rj->update(P, Q); linf_dist = 0.0; l2_dist = 0.0; for(int i=0; isize(); ++i) { vec dat = d->get(i); ... ...
 ... ... @@ -79,9 +79,15 @@ bool rational_fitter_quadprog::fit_data(const data* dat, function* fit, const ar return true ; } std::cout << "<> fit using np = " << temp_np << " & nq = " << temp_nq << " failed\r" ; std::cout.flush() ; if(temp_np == _max_np && temp_nq == _max_nq) { return false; } if(temp_np < _max_np) { ++temp_np ; ... ...
 ... ... @@ -163,10 +163,12 @@ int main(int argc, char** argv) file.close(); //*/ #endif return 0; } else { std::cout << "<> unable to fit the data" << std::endl ; return 1; } } ... ...
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment