Loading...
Searching...
No Matches
MatrixSolver.h
Go to the documentation of this file.
//# MatrixSolver.h: the base class for solvers of AX=B
//# Copyright (C) 1994,1995,1999
//# Associated Universities, Inc. Washington DC, USA.
//#
//# This library is free software; you can redistribute it and/or modify it
//# under the terms of the GNU Library General Public License as published by
//# the Free Software Foundation; either version 2 of the License, or (at your
//# option) any later version.
//#
//# This library is distributed in the hope that it will be useful, but WITHOUT
//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
//# License for more details.
//#
//# You should have received a copy of the GNU Library General Public License
//# along with this library; if not, write to the Free Software Foundation,
//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
//#
//# Correspondence concerning AIPS++ should be addressed as follows:
//# Internet email: casa-feedback@nrao.edu.
//# Postal address: AIPS++ Project Office
//# National Radio Astronomy Observatory
//# 520 Edgemont Road
//# Charlottesville, VA 22903-2475 USA
#ifndef SCIMATH_MATRIXSOLVER_H
#define SCIMATH_MATRIXSOLVER_H
#include <casacore/casa/aips.h>
#include <casacore/casa/Arrays/Array.h>
#include <casacore/casa/Arrays/ArrayMath.h>
#include <casacore/casa/Arrays/Matrix.h>
#include <casacore/casa/Arrays/Vector.h>
#include <casacore/casa/Logging/LogSink.h>
#include <casacore/casa/Logging/LogMessage.h>
namespace casacore { //# NAMESPACE CASACORE - BEGIN
typedef Float FType; // floating type (Float, Double)
//<summary>
// MatrixSolver.h: the base class for solvers of linear equations AX=B
//</summary>
// <use visibility=local>
// <reviewed reviewer="" date="",tests="" demos="">
// </reviewed>
// <prerequisite>
// <li> Matrix, Vector
// </prerequisite>
//
// <etymology>
// The MatrixSolver class name reflects its use as the base class for solving
// Linear Equations of the form AX=B. This class is purely virtual
// and provides the essential implementation for derived solvers
// classes.
// </etymology>
//
// <synopsis>
// The MatrixSolver class is a purely virtual base class. The programmer needs
// to define the following functions in a class derived from MatrixSolver:
// <ol>
// <li> the derived destructor.
// <li> <src>void setImageAndPsf(const Array<FType> & image, const
// Array<FType> & psf);</src> Set the image and the Point Spread Function
// (beam). Setting this should reset the internal state, e.g.
// CurrentIter()==0.
// <li> <src>Bool solve();</src> Perform solution of AX=B.
// Returns True if algorithm has converged or stop criterium reached.
// </ol>
// </synopsis>
//
// <todo asof="">
// </todo>
class MatrixSolver {
public:
// Default Constructor
MatrixSolver();
// Copy Constructor
MatrixSolver(const MatrixSolver & other);
// Create a MatrixSolver from a matrix A and a Vector B
// <note role=warning> A and B are accessed by reference, so do not
// modify them during the lifetime of the MatrixSolver </note>
MatrixSolver(const Matrix<FType> & A, const Vector<FType> & B);
// Virtual destructor: calls all derived class destructors
virtual ~MatrixSolver();
// Assignment operator: uses reference semantics, i.e., it
// references the internal arrays of other
MatrixSolver & operator=(const MatrixSolver & other);
// Set A matrix and B vector
void setAB(const Matrix<FType> & A, const Vector<FType> & B);
// Set initial value of X
void setX(const Vector<FType> & X);
// Solve for the X vector.
virtual Bool solve();
// Is the current solution good enough?
Bool accurateSolution();
// Return residual vector B-AX
const Vector<FType> & getResidual();
// Return solution vector
const Vector<FType> & getSolution();
// Set the tolerance for solution
void setTolerance(FType tol);
// Return the tolerance for solution
FType Tolerance();
// Set the maximum number of iterations.
void setMaxIters(uInt maxiters);
// Return the maximum number of iterations.
uInt MaxIters();
// Set the gain for solution
void setGain(FType g);
// Return the gain for solution
FType Gain();
// Set status of solution
void setSolved(Bool s);
// Return status of solution
Bool Solved();
// Return norm of solution i.e. ||B-AX||
FType getNorm();
protected:
LogSink logSink_p;
virtual LogSink& logSink() {return logSink_p;}
// the A matrix data member
Matrix<FType> AMatrix;
// the constraint vector data member
Vector<FType> BVector;
// The residual vector data member
Vector<FType> RVector;
// The solution vector data member
Vector<FType> XVector;
// The solution norm i.e. ||B-AX||
FType RNorm;
// The data norm i.e. ||B||
FType BNorm;
private:
// Tolerance for solution i.e. ||B-AX||/||B|| must be less than this
FType SolTolerance;
// Maximum number of iterations
uInt MaxIterations;
// Has a solution been found?
Bool solved;
// Gain
FType gain;
};
inline void MatrixSolver::setTolerance(FType tol)
{SolTolerance=tol;}
inline FType MatrixSolver::Tolerance()
{return SolTolerance;}
inline void MatrixSolver::setMaxIters(uInt maxiters)
{MaxIterations = maxiters;}
inline uInt MatrixSolver::MaxIters()
{return MaxIterations;}
inline void MatrixSolver::setGain(FType g)
{gain=g;}
inline FType MatrixSolver::Gain()
{return gain;}
inline void MatrixSolver::setSolved(Bool s)
{solved=s;}
inline Bool MatrixSolver::Solved()
{return solved;}
inline FType MatrixSolver::getNorm()
{return RNorm;}
} //# NAMESPACE CASACORE - END
#endif
casacore::LogSink
Definition LogSink.h:138
casacore::MatrixSolver::setAB
void setAB(const Matrix< FType > &A, const Vector< FType > &B)
Set A matrix and B vector.
casacore::MatrixSolver::MaxIterations
uInt MaxIterations
Maximum number of iterations.
Definition MatrixSolver.h:175
casacore::MatrixSolver::MatrixSolver
MatrixSolver(const MatrixSolver &other)
Copy Constructor.
casacore::MatrixSolver::MatrixSolver
MatrixSolver()
Default Constructor.
casacore::MatrixSolver::Solved
Bool Solved()
Return status of solution.
Definition MatrixSolver.h:206
casacore::MatrixSolver::XVector
Vector< FType > XVector
The solution vector data member.
Definition MatrixSolver.h:161
casacore::MatrixSolver::getResidual
const Vector< FType > & getResidual()
Return residual vector B-AX.
casacore::MatrixSolver::setGain
void setGain(FType g)
Set the gain for solution.
Definition MatrixSolver.h:197
casacore::MatrixSolver::Gain
FType Gain()
Return the gain for solution.
Definition MatrixSolver.h:200
casacore::MatrixSolver::solve
virtual Bool solve()
Solve for the X vector.
casacore::MatrixSolver::BNorm
FType BNorm
The data norm i.e.
Definition MatrixSolver.h:167
casacore::MatrixSolver::operator=
MatrixSolver & operator=(const MatrixSolver &other)
Assignment operator: uses reference semantics, i.e., it references the internal arrays of other.
casacore::MatrixSolver::RVector
Vector< FType > RVector
The residual vector data member.
Definition MatrixSolver.h:158
casacore::MatrixSolver::setMaxIters
void setMaxIters(uInt maxiters)
Set the maximum number of iterations.
Definition MatrixSolver.h:191
casacore::MatrixSolver::accurateSolution
Bool accurateSolution()
Is the current solution good enough?
casacore::MatrixSolver::MatrixSolver
MatrixSolver(const Matrix< FType > &A, const Vector< FType > &B)
Create a MatrixSolver from a matrix A and a Vector B Warning: A and B are accessed by reference,...
casacore::MatrixSolver::AMatrix
Matrix< FType > AMatrix
the A matrix data member
Definition MatrixSolver.h:152
casacore::MatrixSolver::gain
FType gain
Gain.
Definition MatrixSolver.h:181
casacore::MatrixSolver::Tolerance
FType Tolerance()
Return the tolerance for solution.
Definition MatrixSolver.h:188
casacore::MatrixSolver::setTolerance
void setTolerance(FType tol)
Set the tolerance for solution.
Definition MatrixSolver.h:185
casacore::MatrixSolver::getNorm
FType getNorm()
Return norm of solution i.e.
Definition MatrixSolver.h:209
casacore::MatrixSolver::setSolved
void setSolved(Bool s)
Set status of solution.
Definition MatrixSolver.h:203
casacore::MatrixSolver::SolTolerance
FType SolTolerance
Tolerance for solution i.e.
Definition MatrixSolver.h:172
casacore::MatrixSolver::setX
void setX(const Vector< FType > &X)
Set initial value of X.
casacore::MatrixSolver::RNorm
FType RNorm
The solution norm i.e.
Definition MatrixSolver.h:164
casacore::MatrixSolver::logSink
virtual LogSink & logSink()
Definition MatrixSolver.h:149
casacore::MatrixSolver::~MatrixSolver
virtual ~MatrixSolver()
Virtual destructor: calls all derived class destructors.
casacore::MatrixSolver::getSolution
const Vector< FType > & getSolution()
Return solution vector.
casacore::MatrixSolver::MaxIters
uInt MaxIters()
Return the maximum number of iterations.
Definition MatrixSolver.h:194
casacore::MatrixSolver::logSink_p
LogSink logSink_p
Definition MatrixSolver.h:148
casacore::MatrixSolver::solved
Bool solved
Has a solution been found?
Definition MatrixSolver.h:178
casacore::MatrixSolver::BVector
Vector< FType > BVector
the constraint vector data member
Definition MatrixSolver.h:155
casacore::Matrix
Definition Matrix.h:87
casacore::Vector
Definition Vector.h:82
casacore
this file contains all the compiler specific defines
Definition mainpage.dox:28
casacore::FType
Float FType
Definition MatrixSolver.h:41
casacore::uInt
unsigned int uInt
Definition aipstype.h:49
casacore::Float
float Float
Definition aipstype.h:52
casacore::Bool
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40