casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ResidualEquation.h
Go to the documentation of this file.
00001 //# ResidualEquation.h: this defines ResidualEquation
00002 //# Copyright (C) 1996,1997,1999,2000
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //#
00027 //#
00028 //# $Id$
00029 
00030 #ifndef SYNTHESIS_RESIDUALEQUATION_H
00031 #define SYNTHESIS_RESIDUALEQUATION_H
00032 
00033 #include <casa/aips.h>
00034 #include <synthesis/MeasurementEquations/LinearModel.h>
00035 
00036 namespace casa { //# NAMESPACE CASA - BEGIN
00037 
00038 template<class Domain> class LinearModel;
00039 
00040 // <summary>Interface class containing functions returning "Domain" type</summary>
00041 
00042 // <use visibility=local>
00043 
00044 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00045 // </reviewed>
00046 
00047 // <prerequisite>
00048 //   This class should be read in conjunction with:
00049 //   <li> <linkto class="LinearModel">LinearModel</linkto>
00050 //   <li> <linkto class="LinearEquation">LinearEquation</linkto>
00051 // </prerequisite>
00052 //
00053 // <etymology>
00054 // ResidualEquation reflects the fact that the residual() function was the
00055 // first, and perhaps most important member of the class.
00056 // </etymology>
00057 //
00058 // <synopsis>
00059 // ResidualEquation is an abstract interface class into the more extensive
00060 // LinearEquation class. It is composed of the subset of functions from
00061 // LinearEquation which return objects of the "Domain", type. These objects
00062 // can be used by the solve() function in the LinearModel to determine a new
00063 // model. The separation of the ResidualEquation functions isolates the
00064 // model, of type "Domain" from knowing what the data "Range", used by the
00065 // LinearEquation class is. 
00066 // </synopsis>
00067 //
00068 // <example>
00069 // Suppose we have a simple class that has a vector model and knows (using
00070 // the solve() function) how to update this vector if it is told the error
00071 // betweeen the measured data and a model of the data produced using the
00072 // current vector. 
00073 // <srcblock> 
00074 // SimpleModel< Vector<Float> > simplemodel;
00075 // </srcblock> 
00076 // 
00077 // Suppose we also have a big complicated equation that does
00078 // the forward modelling from vectors to some arbitrary class;
00079 //
00080 // <srcblock> 
00081 // FancyEquation<Vector<Float>, VisibilitySet> eqn;
00082 // </srcblock> 
00083 //
00084 // Then Simplemodel class does not need to know anything about the
00085 // VisibilitySet class as it knows that the FancyEquation class will have 
00086 // (via inheritence) a ResidualEquation interface which returns vectors,
00087 // so that it can use code like:
00088 // <srcblock> 
00089 // Vector<Float> error;
00090 // if (eqn.residual(*this, error)){ 
00091 //   use the error to determine a new model
00092 // }
00093 // </srcblock> 
00094 // as part of the solve function.
00095 // </example>
00096 //
00097 // <motivation>
00098 // The main reason for the existence of this class is to isolate the type of
00099 // the model ("Domain" type) from knowing what the "Range" of the equation is.
00100 // </motivation>
00101 //
00102 // <templating arg=Domain>
00103 // The template determines the type used to return the results for all the
00104 // functions in this class. So even complicated template arguements should
00105 // be OK.
00106 // </templating>
00107 //
00108 // <thrown>
00109 // This is an interface class and does not contain any implementation (and
00110 // hence does not throw exceptions)
00111 // </thrown>
00112 //
00113 // <todo asof="1996/03/29">
00114 //   <li> decide whether to add a derivative function
00115 //   <li> decide whether functions which return scalars should also be in
00116 //   this class
00117 // </todo>
00118 
00119 template<class Domain> class ResidualEquation
00120 {
00121 public:
00122   // A virtual destructor may be necessary for use in derived classes.
00123   virtual ~ResidualEquation();
00124 
00125   // The canonical member of this class defines a function which 
00126   // gives the residual when the model is propagated through the
00127   // equation and compared with the data. It returns False if the answer
00128   // could not be computed.
00129   virtual Bool residual(Domain & answer,
00130                         const LinearModel<Domain> & model) = 0;
00131 
00132   // Same as above, but also calculates Chi^2 (rms of residual image)
00133   virtual Bool residual(Domain & answer, Float & chisq,
00134                       const LinearModel<Domain> & model) = 0;
00135 
00136   // Same as above, but also calculates Chi^2 (rms of residual image)
00137   // considering a mask image
00138   virtual Bool residual(Domain & answer, Float & chisq,
00139                         Domain & mask,
00140                         const LinearModel<Domain> & model) = 0;
00141 
00142   // A proposal for another member of this class which returns the
00143   // derivative of the equation with respect to the current model.
00144   //   virtual Bool derivative(const LinearModel<Domain> & model, 
00145   //                    Domain & answer) = 0;
00146 
00147 
00148 };
00149 
00150 
00151 } //# NAMESPACE CASA - END
00152 
00153 #ifndef AIPS_NO_TEMPLATE_SRC
00154 #include <synthesis/MeasurementEquations/ResidualEquation.tcc>
00155 #endif //# AIPS_NO_TEMPLATE_SRC
00156 #endif