LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Member Functions | Private Member Functions | Private Attributes | List of all members
lsst::meas::algorithms::shapelet::Legendre2D Class Reference

#include <Legendre2D.h>

Inheritance diagram for lsst::meas::algorithms::shapelet::Legendre2D:
lsst::meas::algorithms::shapelet::Function2D

Public Member Functions

 Legendre2D ()
 
 Legendre2D (double xMin, double xMax, double yMin, double yMax)
 
 Legendre2D (const Bounds &b)
 
 Legendre2D (const Legendre2D &rhs)
 
 Legendre2D (const Bounds &b, const DMatrix &a)
 
 Legendre2D (int xo, int yo, const Bounds &b)
 
 Legendre2D (std::istream &fin)
 
virtual ~Legendre2D ()
 
virtual void write (std::ostream &fout) const
 
virtual std::auto_ptr< Function2DdFdX () const
 
virtual std::auto_ptr< Function2DdFdY () const
 
virtual std::auto_ptr< Function2Dcopy () const
 
virtual void addLinear (double a, double b, double c)
 
virtual void linearPreTransform (double a, double b, double c, double d, double e, double f)
 
virtual void operator+= (const Function2D &rhs)
 
double getXMin () const
 
double getXMax () const
 
double getYMin () const
 
double getYMax () const
 
const BoundsgetBounds () const
 
virtual void setFunction (int xorder, int yorder, const DVector &fvect)
 
- Public Member Functions inherited from lsst::meas::algorithms::shapelet::Function2D
 Function2D ()
 
 Function2D (int xo, int yo)
 
 Function2D (int xo, int yo, const DMatrix &c)
 
 Function2D (const Function2D &rhs)
 
virtual ~Function2D ()
 
virtual std::auto_ptr< Function2Dconj () const
 
virtual void operator*= (double scale)
 
virtual double operator() (double x, double y) const
 
double operator() (const Position &p) const
 
virtual void setTo (double value)
 
bool isNonZero () const
 
int getXOrder () const
 
int getYOrder () const
 
const DMatrixgetCoeffs () const
 
virtual void simpleFit (int order, const std::vector< Position > &pos, const std::vector< double > &v, const std::vector< bool > &shouldUse, const std::vector< double > *sigList=0, double *chisqOut=0, int *dofOut=0, DMatrix *cov=0)
 
virtual void outlierFit (int order, double nsig, const std::vector< Position > &pos, const std::vector< double > &v, std::vector< bool > *shouldUse, const std::vector< double > *sigList=0, double *chisqout=0, int *dofout=0, DMatrix *cov=0)
 
virtual void orderFit (int maxOrder, double equivProb, const std::vector< Position > &pos, const std::vector< double > &v, const std::vector< bool > &shouldUse, const std::vector< double > *sigList=0, double *chisqout=0, int *dofout=0, DMatrix *cov=0)
 
virtual void linearTransform (double a, double b, double c, const Function2D &f, const Function2D &g)
 
virtual void linearTransform (double a, double b, const Function2D &f)
 

Private Member Functions

DVector definePXY (int order, double xy, double min, double max) const
 
virtual DVector definePX (int order, double x) const
 
virtual DVector definePY (int order, double y) const
 

Private Attributes

Bounds _bounds
 

Additional Inherited Members

- Static Public Member Functions inherited from lsst::meas::algorithms::shapelet::Function2D
static std::auto_ptr< Function2Dread (std::istream &fin)
 
- Protected Attributes inherited from lsst::meas::algorithms::shapelet::Function2D
int _xOrder
 
int _yOrder
 
std::auto_ptr< DMatrix_coeffs
 

Detailed Description

Definition at line 12 of file Legendre2D.h.

Constructor & Destructor Documentation

lsst::meas::algorithms::shapelet::Legendre2D::Legendre2D ( )
inline

Definition at line 17 of file Legendre2D.h.

17 {}
lsst::meas::algorithms::shapelet::Legendre2D::Legendre2D ( double  xMin,
double  xMax,
double  yMin,
double  yMax 
)
inline

Definition at line 19 of file Legendre2D.h.

lsst::meas::algorithms::shapelet::Legendre2D::Legendre2D ( const Bounds b)
inline

Definition at line 22 of file Legendre2D.h.

lsst::meas::algorithms::shapelet::Legendre2D::Legendre2D ( const Legendre2D rhs)
inline

Definition at line 24 of file Legendre2D.h.

lsst::meas::algorithms::shapelet::Legendre2D::Legendre2D ( const Bounds b,
const DMatrix a 
)
inline

Definition at line 27 of file Legendre2D.h.

27  :
28  Function2D(a.TMV_colsize()-1,a.TMV_rowsize()-1,a), _bounds(b) {}
afw::table::Key< double > b
lsst::meas::algorithms::shapelet::Legendre2D::Legendre2D ( int  xo,
int  yo,
const Bounds b 
)
inline

Definition at line 30 of file Legendre2D.h.

lsst::meas::algorithms::shapelet::Legendre2D::Legendre2D ( std::istream &  fin)

Definition at line 68 of file Legendre2D.cc.

68  : Function2D()
69  {
70  // Order of parameters is same as for Polynomial2D. Difference
71  // is that instead of x,x^2,x^3,etc., we use P1(x),P2(x),P3(x),etc.
72  fin >> _xOrder >> _yOrder >> _bounds;
73  if (!fin) throw std::runtime_error("reading order, bounds");
74  _coeffs.reset(new DMatrix(_xOrder+1,_yOrder+1));
75  _coeffs->setZero();
76  int maxOrder = std::max(_xOrder,_yOrder);
77  for(int m=0; m<=maxOrder; ++m) {
78  for(int i=std::min(m,_xOrder); m-i<=std::min(m,_yOrder); --i) {
79  fin >> (*_coeffs)(i,m-i);
80  }
81  }
82  if (!fin) throw std::runtime_error("reading (legendre) function");
83  }
tuple m
Definition: lsstimport.py:48
virtual lsst::meas::algorithms::shapelet::Legendre2D::~Legendre2D ( )
inlinevirtual

Definition at line 35 of file Legendre2D.h.

35 {}

Member Function Documentation

void lsst::meas::algorithms::shapelet::Legendre2D::addLinear ( double  a,
double  b,
double  c 
)
virtual

Implements lsst::meas::algorithms::shapelet::Function2D.

Definition at line 107 of file Legendre2D.cc.

108  {
109  double xAve = (getXMin() + getXMax())/2.;
110  double yAve = (getYMin() + getYMax())/2.;
111  double xRange = getXMax() - getXMin();
112  double yRange = getYMax() - getYMin();
113 
114  (*_coeffs)(0,0) += a + b*xAve + c*yAve;
115  (*_coeffs)(1,0) += b*xRange/2.;
116  (*_coeffs)(0,1) += c*yRange/2.;
117  }
afw::table::Key< double > b
virtual std::auto_ptr<Function2D> lsst::meas::algorithms::shapelet::Legendre2D::copy ( ) const
inlinevirtual

Implements lsst::meas::algorithms::shapelet::Function2D.

Definition at line 43 of file Legendre2D.h.

44  { return std::auto_ptr<Function2D>(new Legendre2D(*this)); }
DVector lsst::meas::algorithms::shapelet::Legendre2D::definePX ( int  order,
double  x 
) const
privatevirtual

Implements lsst::meas::algorithms::shapelet::Function2D.

Definition at line 238 of file Legendre2D.cc.

239  {
240  if (x < getXMin() || x > getXMax()) {
241  dbg<<"Error: x = "<<x<<
242  ", min,max = "<<getXMin()<<','<<getXMax()<<std::endl;
243  throw RangeException(Position(x,getYMin()),_bounds);
244  }
245  return definePXY(order,x,getXMin(),getXMax());
246  }
double x
DVector definePXY(int order, double xy, double min, double max) const
Definition: Legendre2D.cc:227
#define dbg
Definition: dbg.h:69
DVector lsst::meas::algorithms::shapelet::Legendre2D::definePXY ( int  order,
double  xy,
double  min,
double  max 
) const
private

Definition at line 227 of file Legendre2D.cc.

229  {
230  DVector temp(order+1);
231  double xyNew = (2.*xy-min-max)/(max-min);
232  temp[0] = 1.; if(order>0) temp[1] = xyNew;
233  for(int i=2;i<=order;++i)
234  temp[i] = ((2.*i-1.)*xyNew*temp[i-1] - (i-1.)*temp[i-2])/i;
235  return temp;
236  }
DVector lsst::meas::algorithms::shapelet::Legendre2D::definePY ( int  order,
double  y 
) const
privatevirtual

Implements lsst::meas::algorithms::shapelet::Function2D.

Definition at line 248 of file Legendre2D.cc.

249  {
250  if (y < getYMin() || y > getYMax()) {
251  dbg<<"Error: y = "<<y<<
252  ", min,max = "<<getYMin()<<','<<getYMax()<<std::endl;
253  throw RangeException(Position(getXMin(),y),_bounds);
254  }
255  return definePXY(order,y,getYMin(),getYMax());
256  }
int y
DVector definePXY(int order, double xy, double min, double max) const
Definition: Legendre2D.cc:227
#define dbg
Definition: dbg.h:69
std::auto_ptr< Function2D > lsst::meas::algorithms::shapelet::Legendre2D::dFdX ( ) const
virtual

Implements lsst::meas::algorithms::shapelet::Function2D.

Definition at line 149 of file Legendre2D.cc.

150  {
151  if (_xOrder == 0) {
152  return std::auto_ptr<Function2D >(new Constant2D());
153  }
154  if (_xOrder == 1 && _yOrder == 0) {
155  return std::auto_ptr<Function2D >(
156  new Constant2D((*_coeffs)(1,0)*2./(getXMax()-getXMin())));
157  }
158 
159  int newXOrder = _xOrder-1;
160  int newYOrder = _xOrder > _yOrder ? _yOrder : _yOrder-1;
161 
162  std::auto_ptr<Legendre2D > temp(
163  new Legendre2D(newXOrder,newYOrder,_bounds));
164  // initialized to 0's
165 
166  int maxOrder = std::max(_xOrder,_yOrder);
167  for(int i=_xOrder;i>=1;--i) {
168  for(int j=std::min(maxOrder-i,_yOrder);j>=0;--j) {
169  if (i%2 == 0) {
170  for(int k=0;k<=i/2-1;++k)
171  (*temp->_coeffs)(2*k+1,j) += (4.*k+3.)*(*_coeffs)(i,j);
172  } else {
173  for(int k=0;k<=(i-1)/2;++k)
174  (*temp->_coeffs)(2*k,j) += (4.*k+1.)*(*_coeffs)(i,j);
175  }
176  }
177  }
178  maxOrder = std::max(newXOrder,newYOrder);
179  for(int i=newXOrder;i>=0;--i) {
180  for(int j=std::min(maxOrder-i,newYOrder);j>=0;--j) {
181  (*temp->_coeffs)(i,j) *= 2./(getXMax()-getXMin());
182  }
183  }
184  return std::auto_ptr<Function2D >(temp);
185  }
std::auto_ptr< Function2D > lsst::meas::algorithms::shapelet::Legendre2D::dFdY ( ) const
virtual

Implements lsst::meas::algorithms::shapelet::Function2D.

Definition at line 189 of file Legendre2D.cc.

190  {
191  if (_yOrder == 0) {
192  return std::auto_ptr<Function2D >(new Constant2D());
193  }
194  if (_yOrder == 1 && _xOrder == 0) {
195  return std::auto_ptr<Function2D >(new Constant2D(
196  (*_coeffs)(0,1)*2./(getYMax()-getYMin())));
197  }
198 
199  int newXOrder = _yOrder > _xOrder ? _xOrder : _xOrder-1;
200  int newYOrder = _yOrder-1;
201 
202  std::auto_ptr<Legendre2D > temp(
203  new Legendre2D(newXOrder,newYOrder,_bounds));
204  // initialized to 0's
205 
206  int maxOrder = std::max(_xOrder,_yOrder);
207  for(int j=_yOrder;j>=1;--j) {
208  for(int i=std::min(maxOrder-j,_xOrder);i>=0;--i) {
209  if (j%2 == 0) {
210  for(int k=0;k<=(j-2)/2;++k)
211  (*temp->_coeffs)(i,2*k+1) += (4.*k+3.)*(*_coeffs)(i,j);
212  } else {
213  for(int k=0;k<=(j-1)/2;++k)
214  (*temp->_coeffs)(i,2*k) += (4.*k+1.)*(*_coeffs)(i,j);
215  }
216  }
217  }
218  maxOrder = std::max(newXOrder,newYOrder);
219  for(int j=newYOrder;j>=0;--j) {
220  for(int i=std::min(maxOrder-j,newXOrder);i>=0;--i) {
221  (*temp->_coeffs)(i,j) *= 2./(getYMax()-getYMin());
222  }
223  }
224  return std::auto_ptr<Function2D >(temp);
225  }
const Bounds& lsst::meas::algorithms::shapelet::Legendre2D::getBounds ( ) const
inline

Definition at line 61 of file Legendre2D.h.

double lsst::meas::algorithms::shapelet::Legendre2D::getXMax ( ) const
inline

Definition at line 55 of file Legendre2D.h.

double lsst::meas::algorithms::shapelet::Legendre2D::getXMin ( ) const
inline

Definition at line 53 of file Legendre2D.h.

double lsst::meas::algorithms::shapelet::Legendre2D::getYMax ( ) const
inline

Definition at line 59 of file Legendre2D.h.

double lsst::meas::algorithms::shapelet::Legendre2D::getYMin ( ) const
inline

Definition at line 57 of file Legendre2D.h.

void lsst::meas::algorithms::shapelet::Legendre2D::linearPreTransform ( double  a,
double  b,
double  c,
double  d,
double  e,
double  f 
)
virtual

Implements lsst::meas::algorithms::shapelet::Function2D.

Definition at line 119 of file Legendre2D.cc.

121  {
122  // Not implemented yet.
123  Assert(false);
124  }
#define Assert(x)
Definition: dbg.h:73
void lsst::meas::algorithms::shapelet::Legendre2D::operator+= ( const Function2D rhs)
virtual

Implements lsst::meas::algorithms::shapelet::Function2D.

Definition at line 126 of file Legendre2D.cc.

127  {
128  const Legendre2D* lrhs = dynamic_cast<const Legendre2D*>(&rhs);
129  Assert(lrhs);
130  Assert(getBounds() == lrhs->getBounds());
131  if (_xOrder == lrhs->_xOrder && _yOrder == lrhs->_yOrder) {
132  *_coeffs += *lrhs->_coeffs;
133  } else {
134  int newXOrder = std::max(_xOrder,lrhs->_xOrder);
135  int newYOrder = std::max(_yOrder,lrhs->_yOrder);
136  std::auto_ptr<DMatrix > newc(
137  new DMatrix(newXOrder+1,newYOrder+1));
138  newc->setZero();
139  newc->TMV_subMatrix(0,_xOrder+1,0,_yOrder+1) = *_coeffs;
140  newc->TMV_subMatrix(0,lrhs->_xOrder+1,0,lrhs->_yOrder+1) += *lrhs->_coeffs;
141  _coeffs = newc;
142  _xOrder = newXOrder;
143  _yOrder = newYOrder;
144  }
145  }
#define Assert(x)
Definition: dbg.h:73
void lsst::meas::algorithms::shapelet::Legendre2D::setFunction ( int  xorder,
int  yorder,
const DVector fvect 
)
virtual

Implements lsst::meas::algorithms::shapelet::Function2D.

Definition at line 51 of file Legendre2D.cc.

53  {
54  if (_xOrder != xOrder || _yOrder != yOrder) {
55  _xOrder = xOrder; _yOrder = yOrder;
56  _coeffs.reset(new DMatrix(_xOrder+1,_yOrder+1));
57  _coeffs->setZero();
58  }
59  int k=0;
60  for(int m=0; m <= std::max(_xOrder,_yOrder); ++m) {
61  for(int i=std::min(m,_xOrder);m-i<=std::min(m,_yOrder);--i) {
62  (*_coeffs)(i,m-i) = fVect(k++);
63  }
64  }
65  Assert(k==(int)fVect.size());
66  }
tuple m
Definition: lsstimport.py:48
#define Assert(x)
Definition: dbg.h:73
void lsst::meas::algorithms::shapelet::Legendre2D::write ( std::ostream &  fout) const
virtual

Implements lsst::meas::algorithms::shapelet::Function2D.

Definition at line 85 of file Legendre2D.cc.

86  {
87  int oldprec = fout.precision(6);
88  std::ios::fmtflags oldf =
89  fout.setf(std::ios::scientific,std::ios::floatfield);
90  int maxOrder = std::max(_xOrder,_yOrder);
91  if (maxOrder == 0) {
92  fout << "C " << (*_coeffs)(0,0) << std::endl;
93  } else {
94  fout << "L " << _xOrder << ' ' << _yOrder << ' ' << _bounds << ' ';
95  for(int m=0; m<=maxOrder; ++m) {
96  for(int i=std::min(m,_xOrder);m-i<=std::min(m,_yOrder);--i) {
97  fout << (*_coeffs)(i,m-i) << ' ';
98  }
99  }
100  fout << std::endl;
101  }
102  if (!fout) throw std::runtime_error("writing (legendre) function");
103  fout.precision(oldprec);
104  fout.flags(oldf);
105  }
tuple m
Definition: lsstimport.py:48

Member Data Documentation

Bounds lsst::meas::algorithms::shapelet::Legendre2D::_bounds
private

Definition at line 68 of file Legendre2D.h.


The documentation for this class was generated from the following files: