IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 367


Ignore:
Timestamp:
Mar 31, 2004, 11:44:17 PM (22 years ago)
Author:
Paul Price
Message:

Edited the matrix, FFT, polynomial and minimization sections.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/pslib/psLibSDRS.tex

    r366 r367  
    1 %%% $Id: psLibSDRS.tex,v 1.27 2004-04-01 09:42:39 eugene Exp $
     1%%% $Id: psLibSDRS.tex,v 1.28 2004-04-01 09:44:17 price Exp $
    22\documentclass[panstarrs]{panstarrs}
    33
     
    14791479\end{verbatim}
    14801480
     1481The following function populates the histogram bins from the specified
     1482array (\code{myArray}), the number of entries less than \code{minVal}
     1483(\code{minNum}), and the number of entries greater than \code{maxVal}
     1484(\code{maxNum}).  It alters and returns the \code{psHistogram}
     1485structure.
     1486
     1487\begin{verbatim}
     1488/** Calculate a histogram \ingroup MathGroup **/
     1489psHistogram *
     1490psGetArrayHistogram(psHistogram *restrict myHist, ///< Histogram data
     1491                    const psFloatArray *restrict myArray ///< Array to analyse
     1492    );
     1493\end{verbatim}
     1494
    14811495%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    14821496
    14831497\subsection{Matrix operations and linear algebra}
    14841498
    1485 We require the ability to perform basic linear algebra on matrices, in
    1486 order to solve equations:
    1487 
    1488 \begin{verbatim}
    1489 /** A matrix */
    1490 typedef struct {
    1491     int xSize, ySize;                   ///< Dimensions in x and y
    1492     float *restrict *restrict value;    ///< Values in matrix
    1493 } psMatrix;
    1494 \end{verbatim}
    1495 
    1496 Constructor and destructor are:
    1497 
    1498 \begin{verbatim}
    1499 /** Constructor */
    1500 psMatrix *
    1501 psMatrixAlloc(int Xdimen,                       ///< x dimension of new matrix
    1502               int Ydimen                        ///< y dimension of new matrix
    1503               );
    1504 \end{verbatim}
    1505 
    1506 \begin{verbatim}
    1507 /** Destructor */
    1508 void
    1509 psMatrixFree(psMatrix *restrict myMatrix        ///< Matrix to destroy
    1510              );
    1511 \end{verbatim}
    1512 
    1513 We require the following basic matrix operations:
     1499In addition to the ability to perform image arithmetic (\S\ref{sec:arithmetic}),
     1500we also require the ability to perform basic linear algebra on matrices, in order
     1501to solve equations.  We use \code{psImage} as a matrix, since it has the correct
     1502form, and we define the following basic matrix operations:
    15141503\begin{itemize}
     1504\item $LU$ Decompose a matrix, and solve for $x$ in $Ax = b$;
    15151505\item Invert a matrix;
    15161506\item Calculate a matrix determinant;
     
    15191509\item Convert a matrix to a vector.
    15201510\end{itemize}
    1521 The corresponding APIs are:
     1511The corresponding APIs follow.
     1512
     1513\begin{verbatim}
     1514/** LU Decomposition of a matrix */
     1515psImage *
     1516psMatrixLUD(psImage *out,               ///< Matrix to return, or NULL
     1517            psImage *myMatrix           ///< Matrix to decompose
     1518            );
     1519
     1520/** LU Solution.  Solves for and returns x in the equation Ax = b */
     1521psVector *
     1522psMatrixLUSolve(psVector *out,          ///< Vector to return, or NULL
     1523                const psImage *luMatrix, ///< LU-decomposed matrix
     1524                const psVector *rhsVector ///< right-hand-side of the equation
     1525                );
     1526\end{verbatim}
     1527
     1528The above functions decompose a matrix, \code{myMatrix}, into its $LU$
     1529representation (\code{psMatrixLUD}, which returns the decomposed
     1530matrix), and uses the decomposed matrix to solve for $x$ in the
     1531equation $Ax = b$.  In this case, the $LU$ decomposed matrix $A$ is
     1532specified as \code{luMatrix}, and $b$ is \code{rhsVector}; the
     1533solution for $x$ is returned.
    15221534
    15231535\begin{verbatim}
     
    15301542\end{verbatim}
    15311543
     1544\code{psMatrixInvert} returns the inverse of the specified matrix
     1545(\code{myMatrix}), along with the \code{determinant}, if non-NULL.
     1546
     1547The matrix determinant may be calculated using
     1548\code{psMatrixDeterminant}, which simply returns the determinant for
     1549the specified matrix, \code{myMatrix}.
     1550
    15321551\begin{verbatim}
    15331552/** Matrix determinant */
     
    15361555                    );
    15371556\end{verbatim}
     1557
     1558Matrix arithmetic is supported through \code{psMatrixOp}.  Note that
     1559\code{psMatrixOp} differs from \code{psBinaryOp} in that
     1560multiplication with \code{psBinaryOp} acts on corresponding elements,
     1561while \code{psMatrixOp} performs classical matrix multiplication
     1562involving row and column operations.  Addition and subtraction by
     1563\code{psMatrixOp} are identical to that for \code{psBinaryOp} (since
     1564that is how matrix addition is defined).  Matrix division is not
     1565defined.
    15381566
    15391567\begin{verbatim}
     
    15471575\end{verbatim}
    15481576
     1577The transpose of an input matrix, \code{myMatrix}, is returned by
     1578\code{psMatrixTranspose}.
     1579
    15491580\begin{verbatim}
    15501581/** Transpose Matrix */
     
    15551586\end{verbatim}
    15561587
     1588Finally, we specify two functions to convert between matrices and
     1589vectors.  This allows the use of vectors in matrix arithmetic, since
     1590a vector can be converted to a matrix, utilised, and the result can
     1591be converted back to a vector if required.
     1592
    15571593\begin{verbatim}
    15581594/** Convert matrix to vector.  Intended for a 1-d matrix. */
     
    15681604\end{verbatim}
    15691605
    1570 Note that \code{psMatrixOp} differs from \code{psBinaryOp} in that
    1571 \code{psBinaryOp} acts on each element independently, while
    1572 \code{psMatrixOp} performs classical matrix arithmetic, involving row
    1573 and column operations.
    15741606
    15751607%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     
    15941626\end{verbatim}
    15951627
    1596 The \code{p_psFFTDetails *details} entry allows us to wrap the
    1597 external library in the event that it carries information around from
    1598 one transform to the next (as is the case for FFTW).  The intent is
    1599 that every function that employs a FFT will act on a \code{psFFT}.  A
    1600 user will create a \code{psFFT} by stuffing it with the real data,
    1601 perform operations in Fourier space using the \code{psFFT}, and then
    1602 extract the output as an image when done.
     1628The \code{*details} entry allows us to wrap the external library in
     1629the event that it carries information around from one transform to the
     1630next (as is the case for FFTW), and hence it is
     1631implementation-dependent.  The intent is that every function that
     1632employs a FFT will act on a \code{psFFT}.  A user will create a
     1633\code{psFFT} by stuffing it with the real data, perform operations in
     1634Fourier space using the \code{psFFT}, and then extract the output as
     1635an image when done.
    16031636
    16041637We specify two constructors --- one for use with images, and the other
     
    16241657\end{verbatim}
    16251658
    1626 The forward and reverse Fourier transforms may be calculated:
     1659The forward and reverse Fourier transforms may be calculated,
     1660returning the altered \code{psFFT}:
    16271661
    16281662\begin{verbatim}
     
    16391673
    16401674The data in Fourier space may be filtered using functions that return
    1641 a multiplicative factor for a given position in Fourier space:
     1675a multiplicative factor for a given position in Fourier space.  These
     1676function return the altered \code{psFFT}.  If the filter function
     1677specified for \code{psFFTFilter()} returns a real value, $r$, then the
     1678corresponding value in the Fourier plane should be multiplied by $r$.
     1679If the real and imaginary filter functions specified for
     1680\code{psFFTFilterComplex()} return the values $r$ and $s$,
     1681respectively, then the corresponding value in the Fourier plane should
     1682be multiplied by the complex number $r + si$.
    16421683
    16431684\begin{verbatim}
     
    16671708\end{verbatim}
    16681709
    1669 The power spectrum is calculated from the Fourier transform:
     1710The power spectrum is calculated from the Fourier transform, returning
     1711an array of floating-point values containing the power spectrum.
    16701712
    16711713\begin{verbatim}
     
    16761718\end{verbatim}
    16771719
    1678 In convolution, two Fourier transforms are multiplied.
     1720In convolution, two Fourier transforms are multiplied, and the resultant
     1721\code{psFFT} is returned.
    16791722
    16801723\begin{verbatim}
     
    16871730
    16881731And finally, the user may extract both the real data and the complex
    1689 Fourier space data (without needing to destroy the \code{psFFT}).
     1732Fourier space data as \code{psImage}s (without needing to destroy the
     1733\code{psFFT}).  For \code{psFFTGetFT}, note that the output image will be of
     1734type \code{complex float}, since it extracts the data in the Fourier plane,
     1735which is complex.
    16901736
    16911737\begin{verbatim}
     
    17831829\end{verbatim}
    17841830
    1785 And the polynomials may be evaluated:
     1831And the polynomials may be evaluated, returning the value of the
     1832polynomial at the specified coordinates:
    17861833
    17871834\begin{verbatim}
     
    17941841\end{verbatim}
    17951842
    1796 \tbd{generate a Gaussian deviate vector}
     1843\tbd{Generate a Gaussian deviate vector}
    17971844
    17981845%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     
    18021849We require a general minimization routine, a routine that will
    18031850specifically minimize $\chi^2$ given a list of data with associated
    1804 errors, and a function that will analytically determine the polynomial
    1805 fit by least-squares.  The APIs are:
     1851errors, and a function that will analytically determine the best
     1852polynomial fit by minimizing $\chi^2$.  The APIs are:
    18061853
    18071854\begin{verbatim}
     
    18121859           );
    18131860\end{verbatim}
     1861
     1862\code{psMinimize} determines and returns the parameters that minimizes
     1863the specified function.  It takes as input a function,
     1864\code{myFunction}, an initial guess for the parameters that minimize
     1865the function, \code{initialGuess}, and an optional mask for the
     1866parameters to minimize, \code{paramMask}.
    18141867
    18151868\begin{verbatim}
     
    18271880\end{verbatim}
    18281881
     1882\code{psMinimizeChi2} fits a model to observations by minimizing
     1883$\chi^2$, returing the best-fit parameters.  The input parameters are
     1884a function that evaluates the model for a specified domain, given the
     1885parameters, \code{evalModel}; a list of observations, (\code{domain},
     1886\code{data}, and \code{errors}); an initial guess at the best-fit
     1887parameters, \code{initialGuess}, and an optional mask specifying which
     1888parameters are to be fit, \code{paramMask}.
     1889
    18291890\begin{verbatim}
    18301891/** Derive a polynomial that goes through the points --- can be done analytically */
     
    18341895    );
    18351896\end{verbatim}
     1897
     1898\code{psGetArrayPolynomial} calculates analytically and returns the
     1899polynomial that best fits the observations.  The input parameters are
     1900a polynomial that specifies the fit order, \code{myPoly}, which will
     1901be altered and returned with the best-fit coefficients; and the
     1902observations, \code{x}, \code{y} and \code{yErr}.
     1903
     1904\TBD{Higher-order (primarily 2D) polynomial fits may also be specified
     1905in the future.}
    18361906
    18371907%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
     
    21402210
    21412211\subsection{Vector and Image Arithmetic}
     2212\label{sec:arithmetic}
    21422213
    21432214We will need to be able to perform various operations on vectors and
Note: See TracChangeset for help on using the changeset viewer.