Ignore:
Timestamp:
10/15/12 15:52:38 (12 years ago)
Author:
Malte Marquarding
Message:

Ticket #173: added setting of constraints on the fitter.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/STFitter.cpp

    r2580 r2666  
    8080  y_.resize();
    8181  m_.resize();
     82  constraints_.clear();
    8283}
    8384
     
    294295}
    295296
     297void Fitter::addConstraint(const std::vector<float>& constraint)
     298{
     299  if (funcs_.nelements() == 0)
     300    throw (AipsError("Function not yet set."));
     301  constraints_.push_back(constraint);
     302 
     303}
     304
     305void Fitter::applyConstraints(GenericL2Fit<Float>& fitter)
     306{
     307  std::vector<std::vector<float> >::const_iterator it;
     308  for (it = constraints_.begin(); it != constraints_.end(); ++it) {
     309    Vector<Float> tmp(*it);
     310    fitter.addConstraint(tmp(Slice(0,tmp.nelements()-1)),
     311                         tmp(tmp.nelements()-1));
     312  }
     313}
     314
    296315bool Fitter::setFixedParameters(std::vector<bool> fixed)
    297316{
     
    377396  // Convergence criterium
    378397  fitter.setCriteria(0.001);
     398  applyConstraints(fitter);
    379399
    380400  // Fit
     
    397417  chisquared_ = fitter.getChi2();
    398418
    399 //   residual_.resize();
    400 //   residual_ =  y_;
    401 //   fitter.residual(residual_,x_);
    402419  // use fitter.residual(model=True) to get the model
    403420  thefit_.resize(x_.nelements());
    404421  fitter.residual(thefit_,x_,True);
    405   // residual = data - model
    406422  residual_.resize(x_.nelements());
    407423  residual_ = y_ - thefit_ ;
     
    419435
    420436  fitter.setFunction(func);
    421   //fitter.setMaxIter(50+n*10);
    422   // Convergence criterium
    423   //fitter.setCriteria(0.001);
    424 
    425   // Fit
    426 //   Vector<Float> sigma(x_.nelements());
    427 //   sigma = 1.0;
     437  applyConstraints(fitter);
    428438
    429439  parameters_.resize();
    430 //   parameters_ = fitter.fit(x_, y_, sigma, &m_);
    431440  parameters_ = fitter.fit(x_, y_, &m_);
    432441  std::vector<float> ps;
     
    439448  chisquared_ = fitter.getChi2();
    440449
    441 //   residual_.resize();
    442 //   residual_ =  y_;
    443 //   fitter.residual(residual_,x_);
    444   // use fitter.residual(model=True) to get the model
    445450  thefit_.resize(x_.nelements());
    446451  fitter.residual(thefit_,x_,True);
    447   // residual = data - model
    448452  residual_.resize(x_.nelements());
    449453  residual_ = y_ - thefit_ ;
Note: See TracChangeset for help on using the changeset viewer.