Changeset 2666 for trunk/src


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

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

Location:
trunk/src
Files:
7 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_ ;
  • trunk/src/STFitter.h

    r1932 r2666  
    3939#include <scimath/Functionals/Function.h>
    4040#include <scimath/Functionals/CompoundFunction.h>
     41#include <scimath/Fitting/GenericL2Fit.h>
     42
    4143
    4244#include "STFitEntry.h"
     45
    4346
    4447namespace asap {
     
    5558  bool setParameters(std::vector<float> params);
    5659  bool setFixedParameters(std::vector<bool> fixed);
     60  void addConstraint(const std::vector<float>& constraint);
    5761
    5862  std::vector<float> getResidual() const;
     
    7680private:
    7781  void clear();
     82  void applyConstraints(casa::GenericL2Fit<casa::Float>& fitter);
    7883  casa::Vector<casa::Float> x_;
    7984  casa::Vector<casa::Float> y_;
     
    8792  casa::Vector<casa::Float> parameters_;
    8893  casa::Vector<casa::Bool> fixedpar_;
     94  std::vector<std::vector<float> > constraints_;
    8995
    9096  casa::Vector<casa::Float> error_;
  • trunk/src/STLineFinder.h

    r2580 r2666  
    4848#include "ScantableWrapper.h"
    4949#include "Scantable.h"
    50 #include "STFitter.h"
    5150
    5251namespace asap {
  • trunk/src/Scantable.cpp

    r2658 r2666  
    7171#include "STPolStokes.h"
    7272#include "STUpgrade.h"
     73#include "STFitter.h"
    7374#include "Scantable.h"
    7475
  • trunk/src/Scantable.h

    r2658 r2666  
    4343#include "STFit.h"
    4444#include "STFitEntry.h"
    45 #include "STFitter.h"
     45//#include "STFitter.h"
    4646#include "STFocus.h"
    4747#include "STFrequencies.h"
     
    5555
    5656namespace asap {
     57
     58class Fitter;
    5759
    5860/**
  • trunk/src/python_Fitter.cpp

    r1391 r2666  
    4949        .def("getparameters", &Fitter::getParameters)
    5050        .def("setparameters", &Fitter::setParameters)
     51        .def("addconstraint", &Fitter::addConstraint)
    5152        .def("getestimate", &Fitter::getEstimate)
    5253        .def("estimate", &Fitter::computeEstimate)
  • trunk/src/python_asap.cpp

    r2658 r2666  
    124124  casa::pyrap::register_convert_casa_valueholder();
    125125  casa::pyrap::register_convert_casa_record();
     126
    126127#endif
    127128}
Note: See TracChangeset for help on using the changeset viewer.