casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
VisCalSolver.h
Go to the documentation of this file.
1 //# VisCalSolver.h: Default solver for calibration using visibilities
2 //# Copyright (C) 1996,1997,2000,2001,2002,2003
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be adressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //#
27 
28 #ifndef SYNTHESIS_VISCALSOL_H
29 #define SYNTHESIS_VISCALSOL_H
30 
31 #include <casa/aips.h>
32 #include <casa/BasicSL/Complex.h>
33 #include <casa/BasicSL/Constants.h>
34 #include <casa/Arrays/Array.h>
35 #include <casa/Arrays/Vector.h>
36 #include <casa/Arrays/Matrix.h>
42 
43 namespace casa { //# NAMESPACE CASA - BEGIN
44 
45 // <summary>
46 // VisCalSolver: Default solver for calibration using visibility data
47 // </summary>
48 
49 // <use visibility=export>
50 
51 // <reviewed reviewer="" date="" tests="" demos="">
52 
53 // <prerequisite>
54 // <li> <linkto class="MeasurementComponents">MeasurementComponents</linkto> module
55 // <li> <linkto class="VisEquation">VisEquation</linkto> module
56 // </prerequisite>
57 //
58 // <etymology>
59 // VisCal for visibility calibration (meaning solved from visibilities), Solver for
60 // solving.
61 // </etymology>
62 //
63 // <synopsis>
64 //
65 // VisCalSolver describes an interface for solving for calibration from visibility
66 // data in a VisBuffer. It hosts the communication of visibility data with otherwise
67 // generic solving mechanims. A Levenberg-Marquardt solver is supplied here by
68 // default, but it is intended that this class be the template for interfaces to
69 // third-party solving mechanisms.
70 //
71 // </synopsis>
72 //
73 // <example>
74 // <srcblock>
75 
76 // </srcblock>
77 // </example>
78 //
79 // <motivation>
80 // It is desirable to establish the distinct communicative boundary between generic
81 // solving mechanims and the particulars of visibility data and calibration
82 // component descriptions. This class is intended to serve this purpose, by providing
83 // access to visibility data and calibration in terms of quantities necessary for
84 // least-squares (and other) style solvers.
85 // </motivation>
86 //
87 // <todo asof="97/10/01">
88 // </todo>
89 
90 // **********************************************************
91 // VisCalSolver
92 //
93 
94 class VisCalSolver {
95 public:
96 
97  // Constructor currently generic
98  VisCalSolver();
99 
100  // Destructor
101  ~VisCalSolver();
102 
103  // Do the solve
106 
107 protected:
108 
109  // Access to fundamental external objects:
110  inline VisBuffer& svb() { return *svb_; };
111  inline VisBuffGroupAcc& vbga() { return *vbga_; };
112  inline VisEquation& ve() { return *ve_; };
113  inline SolvableVisCal& svc() { return *svc_; };
114 
115  // Accessors to current svb's (differentiated) Residuals
116  inline casacore::Cube<casacore::Complex>& R() { return R_; };
119 
121 
122  // Access to maxIter_
123  inline casacore::Int& maxIter() { return maxIter_; };
124 
125  // Access to chi2
126  inline casacore::Double& chiSq() { return chiSq_; };
128  inline casacore::Double& lastChiSq() { return lastChiSq_; };
129  inline casacore::Double& dChiSq() { return dChiSq_; };
130  inline casacore::Double& sumWt() { return sumWt_; };
131  inline casacore::Int& nWt() { return nWt_; };
132 
133  // Access to parameters, & grad,hess,dp
134  inline casacore::Int& nTotalPar() { return nTotalPar_; };
135  inline casacore::Int& nCalPar() { return nCalPar_; };
136  inline casacore::Int& nSrcPar() { return nSrcPar_; };
148 
149  inline casacore::Double& lambda() { return lambda_; };
150 
151  // Initialize solving data
152  void initSolve();
153 
154  // Obtain trial residuals w.r.t svc's current pars
155  void residualate();
156  void residualate2();
157 
158  // Differentiate the svb w.r.t svc's pars
159  void differentiate();
160  void differentiate2();
161 
162  // Calculate residuals (incl. diff'd) and chi2
163  void chiSquare();
164  void chiSquare2();
165 
166  // Check for convergence
168 
169  // Internal solving methods
170  void accGradHess();
171  void accGradHess2();
172  void revert();
173  void solveGradHess();
174  void updatePar();
175 
176  // Optimize the step parabolically
177  void optStepSize();
178  void optStepSize2();
179 
180  // Get and print par errors
181  void getErrors();
182 
183  void printPar(const casacore::Int& iter);
184 
185 private:
186 
187  // Diagnostic print level
188  inline casacore::Int& prtlev() { return prtlev_; };
189 
190  // VisBuffer (from outside)
191  VisBuffer* svb_;
193 
194  // VisEquation (from outside)
196 
197  // SVC (from outside)
199 
200  // Total Number of parameters
204 
205  // Residual/Differentiation caches
209 
210  // Derivative wrt Q and U
212 
213  // Maximum number of solve iterations to attempt
215 
216  // Chi2, sum wts
224 
225  // Parameter storage
226  // (these are casacore::Complex to match the VisCal solvePar)
232 
233  // Parameter update
236 
237  // Gradient, Hessian
238  // (these are casacore::Double for precision in accumulation
241 
242  // LM factor
244 
245  // Step optimization toggle
247 
248  // Diagnostic print level
250 
251 };
252 
253 }
254 #endif
casacore::Vector< casacore::Bool > parOK_
Definition: VisCalSolver.h:228
int Int
Definition: aipstype.h:50
casacore::Array< casacore::Complex > & dSrc()
Definition: VisCalSolver.h:120
casacore::Double & dChiSq()
Definition: VisCalSolver.h:129
casacore::Vector< casacore::Complex > dcalpar_
Definition: VisCalSolver.h:235
casacore::Array< casacore::Complex > dR_
Definition: VisCalSolver.h:207
casacore::Int & maxIter()
Access to maxIter_.
Definition: VisCalSolver.h:123
casacore::Cube< casacore::Complex > R_
Residual/Differentiation caches.
Definition: VisCalSolver.h:206
casacore::Cube< casacore::Complex > & R()
Accessors to current svb&#39;s (differentiated) Residuals.
Definition: VisCalSolver.h:116
casacore::Double & lastChiSq()
Definition: VisCalSolver.h:128
casacore::Double & lambda()
Definition: VisCalSolver.h:149
void chiSquare()
Calculate residuals (incl.
casacore::Vector< casacore::Complex > & lastCalPar()
Definition: VisCalSolver.h:146
casacore::Double lastChiSq_
Definition: VisCalSolver.h:219
casacore::Vector< casacore::Complex > lastSrcPar_
Definition: VisCalSolver.h:231
VisEquation & ve()
Definition: VisCalSolver.h:112
casacore::Vector< casacore::Complex > & srcPar()
Definition: VisCalSolver.h:140
casacore::Double chiSq_
Chi2, sum wts.
Definition: VisCalSolver.h:217
casacore::Int prtlev_
Diagnostic print level.
Definition: VisCalSolver.h:249
casacore::Vector< casacore::Complex > & dSrcPar()
Definition: VisCalSolver.h:145
casacore::Vector< casacore::Complex > & dpar()
Definition: VisCalSolver.h:143
casacore::Int nTotalPar_
Total Number of parameters.
Definition: VisCalSolver.h:201
casacore::Double & sumWt()
Definition: VisCalSolver.h:130
casacore::Matrix< casacore::Bool > Rflg_
Definition: VisCalSolver.h:208
VisBuffer & svb()
Access to fundamental external objects:
Definition: VisCalSolver.h:110
VisCalSolver()
Constructor currently generic.
casacore::Double dChiSq_
Definition: VisCalSolver.h:220
casacore::Vector< casacore::Double > hess_
Definition: VisCalSolver.h:240
~VisCalSolver()
Destructor.
casacore::Vector< casacore::DComplex > & grad()
Definition: VisCalSolver.h:141
VisBuffGroupAcc & vbga()
Definition: VisCalSolver.h:111
casacore::Vector< casacore::Complex > & dCalPar()
Definition: VisCalSolver.h:144
casacore::Vector< casacore::Double > chiSqV_
Definition: VisCalSolver.h:218
casacore::Vector< casacore::Bool > & parOK()
Definition: VisCalSolver.h:138
casacore::Bool converged()
Check for convergence.
casacore::Int & nSrcPar()
Definition: VisCalSolver.h:136
casacore::Array< casacore::Complex > & dR()
Definition: VisCalSolver.h:117
void initSolve()
Initialize solving data.
casacore::Int & nWt()
Definition: VisCalSolver.h:131
double Double
Definition: aipstype.h:55
casacore::Bool solve(VisEquation &viseq, SolvableVisCal &svc, VisBuffer &svb)
Do the solve.
casacore::Double & chiSq()
Access to chi2.
Definition: VisCalSolver.h:126
void getErrors()
Get and print par errors.
casacore::Bool optstep_
Step optimization toggle.
Definition: VisCalSolver.h:246
casacore::Vector< casacore::Float > parErr_
Definition: VisCalSolver.h:229
casacore::Double lambda_
LM factor.
Definition: VisCalSolver.h:243
casacore::Vector< casacore::Complex > srcPar_
Definition: VisCalSolver.h:230
casacore::Int & prtlev()
Diagnostic print level.
Definition: VisCalSolver.h:188
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
casacore::Int & nTotalPar()
Access to parameters, &amp; grad,hess,dp.
Definition: VisCalSolver.h:134
casacore::Vector< casacore::Float > & parErr()
Definition: VisCalSolver.h:139
SolvableVisCal & svc()
Definition: VisCalSolver.h:113
casacore::Vector< casacore::DComplex > grad_
Gradient, Hessian (these are casacore::Double for precision in accumulation.
Definition: VisCalSolver.h:239
void differentiate()
Differentiate the svb w.r.t svc&#39;s pars.
A class to group separately averaged VisBuffers.
casacore::Array< casacore::Complex > dSrc_
Derivative wrt Q and U.
Definition: VisCalSolver.h:211
casacore::Vector< casacore::Double > & chiSqV()
Definition: VisCalSolver.h:127
casacore::Int nSrcPar_
Definition: VisCalSolver.h:203
casacore::Int nCalPar_
Definition: VisCalSolver.h:202
VisEquation * ve_
VisEquation (from outside)
Definition: VisCalSolver.h:195
casacore::Int nWt_
Definition: VisCalSolver.h:222
SolvableVisCal * svc_
SVC (from outside)
Definition: VisCalSolver.h:198
VisBuffGroupAcc * vbga_
Definition: VisCalSolver.h:192
casacore::Vector< casacore::Complex > & par()
Definition: VisCalSolver.h:137
casacore::Int maxIter_
Maximum number of solve iterations to attempt.
Definition: VisCalSolver.h:214
casacore::Vector< casacore::Double > & hess()
Definition: VisCalSolver.h:142
casacore::Vector< casacore::Complex > & lastSrcPar()
Definition: VisCalSolver.h:147
casacore::Vector< casacore::Complex > lastCalPar_
Definition: VisCalSolver.h:231
void accGradHess()
Internal solving methods.
void residualate()
Obtain trial residuals w.r.t svc&#39;s current pars.
VisBuffers encapsulate one chunk of visibility data for processing.
Definition: VisBuffer.h:153
casacore::Vector< casacore::Complex > par_
Parameter storage (these are casacore::Complex to match the VisCal solvePar)
Definition: VisCalSolver.h:227
casacore::Int cvrgcount_
Definition: VisCalSolver.h:223
casacore::Matrix< casacore::Bool > & Rflg()
Definition: VisCalSolver.h:118
VisCalSolver: Default solver for calibration using visibility data.
Definition: VisCalSolver.h:94
VisBuffer * svb_
VisBuffer (from outside)
Definition: VisCalSolver.h:188
casacore::Vector< casacore::Complex > dpar_
Parameter update.
Definition: VisCalSolver.h:234
void optStepSize()
Optimize the step parabolically.
casacore::Int & nCalPar()
Definition: VisCalSolver.h:135
casacore::Double sumWt_
Definition: VisCalSolver.h:221
void printPar(const casacore::Int &iter)
casacore::Vector< casacore::Complex > dsrcpar_
Definition: VisCalSolver.h:235