casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CEMemModel.h
Go to the documentation of this file.
1 //# CEMemModel.h: this defines CEMemModel
2 //# Copyright (C) 1996,1997,1998,1999,2000
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 addressed 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 //# $Id$
27 
28 #ifndef SYNTHESIS_CEMEMMODEL_H
29 #define SYNTHESIS_CEMEMMODEL_H
30 
31 
32 #include <casa/aips.h>
33 #include <casa/Arrays/Matrix.h>
34 #include <casa/Arrays/Vector.h>
35 #include <casa/Arrays/Array.h>
41 #include <casa/Logging/LogIO.h>
42 
43 
44 namespace casa { //# NAMESPACE CASA - BEGIN
45 
46 // Forward declaration
47 class LatConvEquation;
48 class CEMemProgress;
49 
50 
51 // <summary> Implements the Cornwell & Evans MEM Algorithm on Lattices </summary>
52 
53 // <use visibility=export>
54 
55 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
56 // </reviewed>
57 
58 // <prerequisite>
59 // <li> ResidualEquation/ConvolutionEquation
60 // <li> LinearModel/LinearEquation Paradigm
61 // </prerequisite>
62 //
63 // <etymology>
64 // This class is called CEMemModel because it uses the Cornwell and
65 // Evans MEM algorithm to deconvolve the model.
66 // </etymology>
67 //
68 // <synopsis>
69 // This class is used to perform the Cornwell and Evans MEM Algorithm on an
70 // Array. Only the deconvolved model of the sky are directly stored by this
71 // class. The point spread function (psf) and convolved (dirty) image are
72 // stored in a companion class which is must be derived from
73 // ResidualEquation.
74 //
75 // The deconvolution works like this. The user constructs a CEMemModel by
76 // specifying an initial model of the sky. This can by be
77 // one,two,three... dimensional depending on the dimension of the psf (see
78 // below). The user then constructs a class which implements the forward
79 // equation between the model and the dirty image. Typically this will be
80 // the ConvolutionEquation class, although any class which has a
81 // ResidualEquation interface will work (but perhaps very slowly, as the
82 // ConvolutionEquation class has member functions optimised for CLEAN and MEM)
83 //
84 // The user then calls the solve() function (with the appropriate equation
85 // class as an arguement), and this class will perform the MEM deconvolution.
86 // The various MEM parameters are set (prior to calling solve) using the
87 // functions derived from the Iterate class, in particular
88 // setNumberIterations().
89 //
90 // The solve() function does not return either the deconvolved model or the
91 // residuals. The solved model can be obtained using the getModel() function
92 // (derived from ArrayModel()) and the residual can be obtained using the
93 // residual() member function of the Convolution/Residual Equation Class.
94 //
95 // The size and shape of the model used in this class MUST be the same as
96 // the convolved data (Dirty Image), stored in the companion
97 // ResidualEquation Class. However the model (and convolved data) can have
98 // more dimensions than the psf, as well as a different size (either larger
99 // or smaller). When the dimensionality is different the deconvolution is done
100 // independendtly in each "plane" of the model. (Note this has not
101 // been implemented yet but is relatively simple to do if necessary).
102 //
103 // StokesVectors are not yet implemented.
104 //
105 // A companion class to this one is MaskedCEMemModel. This provides
106 // the same functionality but is used with MaskedArrays which indicate which
107 // regions of the NewtonRaphson (residual) image to apply when forming the
108 // step image (MaskedCEMemModel is not yet implemented).
109 //
110 // </synopsis>
111 //
112 // <example>
113 // <srcblock>
114 // casacore::Matrix<casacore::Float> psf(12,12), dirty(10,10), initialModel(10,10);
115 // ...put appropriate values into psf, dirty, & initialModel....
116 // CEMemModel<casacore::Float> deconvolvedModel(initialModel);
117 // ConvolutionEquation convEqn(psf, dirty);
118 // deconvolvedModel.setSigma(0.001);
119 // deconvolvedModel.setTargetFlux(-2.500);
120 // deconvolvedModel.setNumberIterations(30);
121 // casacore::Bool convWorked = deconvolvedModel.solve(convEqn);
122 // casacore::Array<casacore::Float> finalModel, residuals;
123 // if (convWorked){
124 // finalModel = deconvolvedModel.getModel();
125 // ConvEqn.residual(deconvolvedModel, finalResidual);
126 // }
127 // </srcblock>
128 // </example>
129 //
130 // <motivation>
131 // This class is needed to deconvolve extended images.
132 // In time, the MEM algorithm will be a principle player in the
133 // mosaicing stuff.
134 // </motivation>
135 //
136 // <templating arg=T>
137 // For testing:
138 // <li> casacore::Float: lets try it first
139 // <li> StokesVector: will require lots more work
140 // </templating>
141 //
142 // <todo asof="1998/12/02">
143 // <li> We need to implement soft Masking
144 // </todo>
145 
146 class CEMemModel: public LinearModel< casacore::Lattice<casacore::Float> >
147 {
148 
149  // Any new entropies derived from Entropy must sign the friend list:
150 friend class Entropy;
151 friend class EntropyI;
152 friend class EntropyEmptiness;
153 
154 
155 public:
156 
157  // Construct the CEMemModel object and initialise the model.
158  CEMemModel(Entropy &ent,
160  casacore::uInt nIntegrations = 10,
161  casacore::Float sigma = 0.001,
162  casacore::Float targetFlux = 1.0,
163  casacore::Bool useFluxConstraint = false,
164  casacore::Bool initializeModel = true,
165  casacore::Bool imagePlane = false);
166 
167  // Construct the CEMemModel object, initialise the model and Prior images.
168  CEMemModel(Entropy &ent,
171  casacore::uInt nIntegrations = 10,
172  casacore::Float sigma = 0.001,
173  casacore::Float targetFlux = 1.0,
174  casacore::Bool useFluxConstraint = false,
175  casacore::Bool initializeModel = true,
176  casacore::Bool imagePlane = false);
177 
178  // Construct the CEMemModel object, initialise the model, Prior,
179  // and mask images.
180  CEMemModel(Entropy &ent,
184  casacore::uInt nIntegrations = 10,
185  casacore::Float sigma = 0.001,
186  casacore::Float targetFlux = 1.0,
187  casacore::Bool useFluxConstraint = false,
188  casacore::Bool initializeModel = true,
189  casacore::Bool imagePlane = false);
190 
191 
192  // destructor
193  virtual ~CEMemModel();
194 
195 
196  // solve the convolution equation
197  // returns true if converged
198 
199  // Gives information about the state of the CEMem
200  // (ie, using mask image, using prior image; more work here!)
201  void state();
202 
203 
204  // This needs to be "ResidualEquation", using LatConvEquation as
205  // polymorphism is broken
207 
208  // Set and get various state images and classes
209  // <group>
210  // set or get the Entropy class
211  void setEntropy(Entropy &myEntropy ) {itsEntropy_ptr = &myEntropy;}
212  void getEntropy(Entropy &myEntropy ) {myEntropy = *itsEntropy_ptr;}
213 
214  // set or get the Model image
216  { return (*(itsModel_ptr->clone())); }
218  { itsModel_ptr = model.clone(); }
219 
220  // set or get the Prior image
222  { return (*(itsPrior_ptr->clone())); }
224 
225  // set or get the Mask image
227  { return (*(itsMask_ptr->clone())); }
229 
230  // get the Residual image
232  { return (*(itsResidual_ptr->clone())); }
233 
234  // </group>
235 
236 
237  // set and get alpha and beta
238  // <group>
239  casacore::Float getAlpha() const { return itsAlpha; }
240  casacore::Float getBeta() const { return itsBeta; }
241  void setAlpha(casacore::Float alpha) {itsAlpha = alpha; }
242  void setBeta(casacore::Float beta) {itsBeta = beta; }
243  // </group>
244 
245  // Set various controlling parameters
246  // (The most popular controlling parameters are
247  // set in the constructor)
248  // <group>
251  casacore::Float getQ() {return itsQ; }
252  void setQ(casacore::Float x) { itsQ= x; }
254  void setGain(casacore::Float x) { itsGain = x; }
259  // </group>
260 
261  // The convergence can also be in terms of the maximum residual
262  // (ie, for use in stopping in a major cycle).
263  void setThreshold (const casacore::Float x ) { itsThreshold0 = x; }
264  // Thresh doubles in iter iterations
267 
268  // Set/get the progress display
269  // <group>
270  virtual void setProgress(CEMemProgress& ccp) { itsProgressPtr = &ccp; }
271  virtual CEMemProgress& getProgress() { return *itsProgressPtr; }
272  // </group>
273 
274  // return the number of iterations completed
276 
277  // if this MEMModel is constructed in a MF loop, we may need to
278  // increment the flux by the last iterations flux
281 
282 protected:
283 
284 
285  // Perform One Iteration
286  void oneIteration();
287 
288  // apply mask to a lattice; returns true if mask is available,
289  // false if not
291 
292  // Helper functions that interface with Entropy routines
293  // Access to the entropy should be through this interface; the
294  // points at which the Entropy is mentioned is then limited to
295  // these lines right here, and to the constructors which set the
296  // Entropy. The entropy should not ever change the private
297  //
298  // <group>
300 
302 
304 
306 
308 
310 
312 
313  // </group>
314 
315 
316  // protected generic constrcutor: DON'T USE IT!
317  CEMemModel();
318 
319  // Set entropy pointer to zero: called by Entropy's destructor
321 
322  // initialize itsStep and itsResidual and other stuff
324 
325 
326  // controls how to change Alpha and Beta
327  // <group>
328  void changeAlphaBeta ();
329  // initialize Alpha-Beta (called by changeAlphaBeta)
330  void initializeAlphaBeta();
331  // update Alpha-Beta (called by changeAlphaBeta)
332  void updateAlphaBeta();
333  // </group>
334 
335 
336 
337 
338  // Generic utility functions
339  // <group>
340  // check that a single image is onf plausible shape
342  // check that the lattices and the underlying tile sizes are consistent
344  // check that all is well in Denmark:
345  // ensure all images are the same size,
346  // ensure we have an entropy,
347  // ensure state variables have reasonable values
348  casacore::Bool ok();
349  // </group>
350 
351 
352 
353 
354  // Helper functions for oneIteration:
355  // <group>
356  // calculate size of step
357  void calculateStep();
358 
359  // take one step: clipped addition of
360  // wt1*itsModel + wt2*itsStep
362 
363  // Calculate the flux, itsModMin, and itsModMax
365  // </group>
366 
367  // Determine if the peak residual is less than the getThreshold()
369 
370  // ------------Private Member casacore::Data---------------------
371  // functional form of the entropy
373 
374  // form of the Residual method
376 
377  // Images:
381  // Our OWN internal temp images; delete these upon destruction
384 
385 
386  // Controlling parameters
387  // <group>
395  // tolerance for convergence
397  // N points per beam
399  // gain for adding step image
402  // constrain flux or not?
404  // is this an image plane problem (like Single Dish or Optical?)
408  casacore::Float itsCycleFlux; // flux from previous cycles
409  // </group>
410 
411  // State variables
412  // <group>
417  casacore::Float itsTotalFlux; // itsCycleFlux + itsFlux
419  // sqrt( chi^2/target_chi^2 )
421  // sqrt( chi^2/ Npixels )
423  // numerical value of entropy
425  // Model is constrained to be >= itsNewMin
427  // maximum pixel value in model
429  // minimum pixel value n model
436  // matrix of gradient dot products
439  // </group>
441 
442 
443  // Accesories
444  // <group>
447  // </group>
448 
449  // Enumerate the different Gradient subscript types
451  // Entropy
452  H=0,
453  // Chi_sq
454  C=1,
455  // Flux
456  F=2,
457  // Objective function J
458  J=3
459  };
460 
462 
463 
464 };
465 
466 
467 
468 } //# NAMESPACE CASA - END
469 
470 #endif
471 
casacore::Lattice< casacore::Float > * itsStep_ptr
Our OWN internal temp images; delete these upon destruction.
Definition: CEMemModel.h:382
casacore::Bool itsDoImagePlane
is this an image plane problem (like Single Dish or Optical?)
Definition: CEMemModel.h:405
casacore::Float itsTotalFlux
Definition: CEMemModel.h:417
void setGain(casacore::Float x)
Definition: CEMemModel.h:254
int Int
Definition: aipstype.h:50
void setThreshold(const casacore::Float x)
The convergence can also be in terms of the maximum residual (ie, for use in stopping in a major cycl...
Definition: CEMemModel.h:263
casacore::Float itsGain
gain for adding step image
Definition: CEMemModel.h:400
casacore::Lattice< casacore::Float > * itsModel_ptr
Images:
Definition: CEMemModel.h:378
casacore::Lattice< casacore::Float > * itsPrior_ptr
Definition: CEMemModel.h:379
CEMemModel()
protected generic constrcutor: DON&#39;T USE IT!
casacore::Lattice< casacore::Float > & getPrior() const
set or get the Prior image
Definition: CEMemModel.h:221
casacore::Bool applyMask(casacore::Lattice< casacore::Float > &lat)
apply mask to a lattice; returns true if mask is available, false if not
virtual ~CEMemModel()
destructor
casacore::Float itsDefaultLevel
Definition: CEMemModel.h:393
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
casacore::Float itsThresholdSpeedup
Definition: CEMemModel.h:407
casacore::Float itsAFit
sqrt(chi^2/ Npixels)
Definition: CEMemModel.h:422
ResidualEquation< casacore::Lattice< casacore::Float > > * itsResidualEquation_ptr
form of the Residual method
Definition: CEMemModel.h:375
void updateAlphaBeta()
update Alpha-Beta (called by changeAlphaBeta)
Maximum Emptiness measure used by MEM.
Definition: Entropy.h:220
casacore::Float itsNormGrad
Definition: CEMemModel.h:415
casacore::Bool checkImages(const casacore::Lattice< casacore::Float > *one, const casacore::Lattice< casacore::Float > *other)
check that the lattices and the underlying tile sizes are consistent
casacore::Float getGain()
Definition: CEMemModel.h:253
Class to monitor progress in MEM deconvolution.
Definition: CEMemProgress.h:79
casacore::Float itsRequiredModelMin
Model is constrained to be &gt;= itsNewMin.
Definition: CEMemModel.h:426
void setModel(const casacore::Lattice< casacore::Float > &model)
Set the current model.
Definition: CEMemModel.h:217
virtual CEMemProgress & getProgress()
Definition: CEMemModel.h:271
casacore::Float getCycleFlux()
Definition: CEMemModel.h:280
base class for entropy functions as used by MEM
Definition: Entropy.h:103
casacore::Lattice< casacore::Float > & getResidual() const
get the Residual image
Definition: CEMemModel.h:231
casacore::Float itsMaxNormGrad
Definition: CEMemModel.h:401
Interface class containing functions returning &quot;Domain&quot; type.
Definition: Deconvolver.h:56
casacore::Bool testConvergenceThreshold()
Determine if the peak residual is less than the getThreshold()
void initializeAlphaBeta()
initialize Alpha-Beta (called by changeAlphaBeta)
casacore::Float itsLength
Definition: CEMemModel.h:431
virtual void setProgress(CEMemProgress &ccp)
Set/get the progress display.
Definition: CEMemModel.h:270
ostream-like interface to creating log messages.
Definition: LogIO.h:167
casacore::Int getInitialNumberIterations()
Definition: CEMemModel.h:257
casacore::Float itsSigma
Definition: CEMemModel.h:391
casacore::uInt itsIteration
Definition: CEMemModel.h:434
void setInitialNumberIterations(casacore::Int x)
Definition: CEMemModel.h:258
casacore::Float itsEntropy
numerical value of entropy
Definition: CEMemModel.h:424
void formGDGStep()
Definition: CEMemModel.h:303
casacore::Float itsCycleFlux
Definition: CEMemModel.h:408
void setThresholdSpeedup(const casacore::Float iter)
Thresh doubles in iter iterations.
Definition: CEMemModel.h:265
casacore::Bool initStuff()
initialize itsStep and itsResidual and other stuff
casacore::Float itsModelMin
minimum pixel value n model
Definition: CEMemModel.h:430
virtual casacore::Bool testConvergence()=0
each entropy type can have its distinct convergence criteria
void oneIteration()
Perform One Iteration.
casacore::Float itsThreshold0
Definition: CEMemModel.h:406
virtual Lattice< T > * clone() const =0
Make a copy of the derived object (reference semantics).
void setMaxNormGrad(casacore::Float x)
Definition: CEMemModel.h:256
casacore::Bool testConvergence()
Definition: CEMemModel.h:311
void setEntropy(Entropy &myEntropy)
Set and get various state images and classes.
Definition: CEMemModel.h:211
virtual casacore::Float formEntropy()=0
calculate the entropy for the whole image
casacore::Bool itsUseFluxConstraint
constrain flux or not?
Definition: CEMemModel.h:403
double Double
Definition: aipstype.h:55
casacore::Int numberIterations()
return the number of iterations completed
Definition: CEMemModel.h:275
casacore::Lattice< casacore::Float > * itsMask_ptr
Definition: CEMemModel.h:380
casacore::Float itsTolerance
tolerance for convergence
Definition: CEMemModel.h:396
virtual casacore::Double formGDS()=0
calculate Gradient dot Step
void formEntropy()
Helper functions that interface with Entropy routines Access to the entropy should be through this in...
Definition: CEMemModel.h:299
virtual void entropyType(casacore::String &)=0
report the entropy type for a logging message
casacore::Float itsChisq
Definition: CEMemModel.h:418
casacore::Bool itsInitializeModel
Controlling parameters.
Definition: CEMemModel.h:388
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
casacore::uInt itsFirstIteration
Definition: CEMemModel.h:435
void setCycleFlux(casacore::Float x)
if this MEMModel is constructed in a MF loop, we may need to increment the flux by the last iteration...
Definition: CEMemModel.h:279
casacore::Bool itsDoInit
Definition: CEMemModel.h:390
GradientType
Enumerate the different Gradient subscript types.
Definition: CEMemModel.h:450
void state()
solve the convolution equation returns true if converged
casacore::Float formFlux()
Calculate the flux, itsModMin, and itsModMax.
float Float
Definition: aipstype.h:54
casacore::Float getThreshold()
casacore::Float getBeta() const
Definition: CEMemModel.h:240
virtual void formGDG(casacore::Matrix< double > &)=0
calculate the Gradient dot Gradient matrix
Implements the Cornwell &amp; Evans MEM Algorithm on Lattices.
Definition: CEMemModel.h:146
casacore::Float itsAlpha
State variables.
Definition: CEMemModel.h:413
void setAlpha(casacore::Float alpha)
Definition: CEMemModel.h:241
casacore::Bool checkImage(const casacore::Lattice< casacore::Float > *)
Generic utility functions.
void getEntropy(Entropy &myEntropy)
Definition: CEMemModel.h:212
casacore::LogIO itsLog
Definition: CEMemModel.h:446
casacore::Float itsTargetChisq
Definition: CEMemModel.h:394
void letEntropyDie()
Set entropy pointer to zero: called by Entropy&#39;s destructor.
Definition: CEMemModel.h:320
void setBeta(casacore::Float beta)
Definition: CEMemModel.h:242
casacore::Float itsFit
sqrt(chi^2/target_chi^2)
Definition: CEMemModel.h:420
void changeAlphaBeta()
controls how to change Alpha and Beta
virtual void formGDGStep(casacore::Matrix< double > &)=0
calculate the Gradient dot Gradient matrix, calculate Step
void takeStep(casacore::Float wt1, casacore::Float wt2)
take one step: clipped addition of wt1*itsModel + wt2*itsStep
casacore::Float getMaxNormGrad()
Definition: CEMemModel.h:255
Entropy * itsEntropy_ptr
---------—Private Member casacore::Data------------------— functional form of the entropy ...
Definition: CEMemModel.h:372
casacore::Bool solve(ResidualEquation< casacore::Lattice< casacore::Float > > &eqn)
This needs to be &quot;ResidualEquation&quot;, using LatConvEquation as polymorphism is broken.
casacore::Float itsTargetFlux
Definition: CEMemModel.h:392
casacore::Double itsGradDotStep1
Definition: CEMemModel.h:433
casacore::Float itsCurrentPeakResidual
Definition: CEMemModel.h:438
casacore::Double itsGradDotStep0
Definition: CEMemModel.h:432
casacore::Float getTolerance()
Set various controlling parameters (The most popular controlling parameters are set in the constructo...
Definition: CEMemModel.h:249
casacore::Bool itsChoose
Accesories.
Definition: CEMemModel.h:445
casacore::Float itsQ
N points per beam.
Definition: CEMemModel.h:398
casacore::Matrix< casacore::Double > itsGDG
matrix of gradient dot products
Definition: CEMemModel.h:437
String: the storage and methods of handling collections of characters.
Definition: String.h:223
void setQ(casacore::Float x)
Definition: CEMemModel.h:252
casacore::Float getAlpha() const
set and get alpha and beta
Definition: CEMemModel.h:239
Thermodynamic or Information entropy used by MEM.
Definition: Entropy.h:168
void calculateStep()
Helper functions for oneIteration:
casacore::Lattice< casacore::Float > & getModel() const
set or get the Model image
Definition: CEMemModel.h:215
void setPrior(casacore::Lattice< casacore::Float > &prior)
casacore::uInt itsNumberIterations
Definition: CEMemModel.h:389
void entropyType(casacore::String &str)
Definition: CEMemModel.h:307
virtual casacore::Float relaxMin()=0
are there any constraints on how the Image minimum gets relaxed?
casacore::Bool ok()
check that all is well in Denmark: ensure all images are the same size, ensure we have an entropy...
void setMask(casacore::Lattice< casacore::Float > &mask)
void setTolerance(casacore::Float x)
Definition: CEMemModel.h:250
casacore::Float itsBeta
Definition: CEMemModel.h:414
Objective function J.
Definition: CEMemModel.h:458
CEMemProgress * itsProgressPtr
Definition: CEMemModel.h:461
casacore::Float itsFlux
Definition: CEMemModel.h:416
casacore::Float getQ()
Definition: CEMemModel.h:251
casacore::Lattice< casacore::Float > * itsResidual_ptr
Definition: CEMemModel.h:383
casacore::Lattice< casacore::Float > & getMask() const
set or get the Mask image
Definition: CEMemModel.h:226
casacore::Float itsNumberPixels
Definition: CEMemModel.h:440
casacore::Float itsModelMax
maximum pixel value in model
Definition: CEMemModel.h:428
unsigned int uInt
Definition: aipstype.h:51
Provides a model for use in model fitting applications.