IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 25, 2004, 5:07:45 PM (22 years ago)
Author:
eugene
Message:

re-organized structures
fixed eqnarrays

File:
1 edited

Legend:

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

    r306 r307  
    3535\section{PanSTARRS Library PSLib}
    3636
    37 \subsection{Data Manipulation}
    38 
    39 \subsubsection{Matrix Operations}
     37\subsection{Math Utilities}
     38
     39\subsection{Sorting}
     40
     41A variety of sorting algorithms exist, with a wide range in speed for
     42different set sizes.  Three of the best sorting algorithms are
     43``heapsort'', ``quicksort'', and ``mergesort'' (see, e.g.,
     44\citealt{knuth}, \citealt{sedgewick}, \citealt{press}).  These three
     45sorting algorithms all run in a time of $O(n \log n)$ in the best
     46case, but have different worse-case run times.  Implementations of all
     47three sorting algorithms are described in references above and in
     48various places online (e.g.,
     49http://www.iti.fh-flensburg.de/lang/algorithmen/sortieren/algoen.htm).
     50The linux \code{qsort} function orignially mades use of the quicksort
     51algorithm, but now uses \tbd{what algorithm?}.  The GSL function
     52\code{gsl_heapsort} uses the heapsort algorithm.  Both of these
     53implemenations require a pointer to the comparison function, which may
     54result in a slower code. 
     55
     56For PSLib, the sorting functions shall be implemented via
     57\code{qsort}.  The function \code{psSort} shall return the sorted
     58result of the input array without over-writing the input array.  The
     59function \code{psSortIndex} shall return an integer index to the
     60sequence of the input array without overwriting the input array.
     61Given the following line of code, \code{out = psSortIndex (NULL,
     62&in);}, the elements of the array \code{out} are in the sequence
     63\code{in.arr[out->arr[0]]} to \code{in.arr[out->arr[in.n - 1]]}.
     64
     65\subsection{Smoothing: Boxcar and Gaussian}
     66\label{smooth}
     67
     68Smoothing may occasionally be perfomed on data.  We present the
     69algorithms for two typical versions: boxcar and Gaussian smoothing.
     70In both smoothing techniques, given a series of data values $f_i$, the
     71smoothed values $g_i$ are determined by calculating a linear
     72combination based on the input data point and its nearest $2N$
     73neighbors in the form:
     74
     75\[ g_i = \sum_{n=-N}^N c_n f_i \]
     76%
     77where the values of $c_n$ determine the filter type.  For boxcar
     78smoothing, the values $c_n$ are constant, and must be equal to $1/(2N
     79+ 1)$ to maintain the zeroth moment of the data (care must be taken at
     80the ends of the data range to reduce the value of $c_n$ as fewer input
     81data points may be used).  For Gaussian smoothing, the crucial
     82parameter is $\sigma$, the standard deviation.  The
     83value of $N$ should be chosen to be large enough, $N = 5\sigma$, and
     84the values of $c_n$ are then just the Gaussian curve:
     85
     86\[ c_n = \frac{e^{\frac{-n^2}{2\sigma^2}}}{\sqrt{2\pi\sigma^2}} \]
     87
     88\subsection{Statistics}
     89
     90The general statistics function \code{psStats} performs a variety of
     91statistical calculations on a collection of floating point numbers.
     92These statistics include both sample values, in which the formal
     93statistic is calculated for the complete sample, and robust values, in
     94which the statistic is estimated on the basis of an assumption of an
     95underlying population.  While more reliable in general, the robust
     96estimators may be somewhat slower than the sample statisic, so their
     97use may vary depending on the context.  In addition, certain
     98sigma-clipped values are defined as an intermediate choice between the
     99sample and robust estimators. 
     100
     101\subsubsection{Sample Statistics}
     102
     103We define the following statistical terms, assuming there is a set of
     104data elements $x_i$.
     105
     106\paragraph{Mean}
     107
     108The mean is defined as: \[ \bar{x} = \frac{1}{N} \sum_{i = 1}^{N} x_i \]
     109
     110\paragraph{Median}
     111
     112The median is defined as the value for which 50\% of the data values
     113are larger and 50\% are smaller.  For a sample, the values are sorted
     114and the median is given by the value of the middle element, if the
     115number of values is odd, and by the average of the two middle values
     116if the number of values is even.  This median should be avoided for
     117samples which are large (e.g., $N > 10000$ elements) as the basic
     118robust median is quicker and more accurate. 
     119
     120\paragraph{Upper and Lower Quartiles}
     121
     122The upper and lower quartiles ($U_{\frac{1}{4}}$ and
     123$L_{\frac{1}{4}}$) are first and last quarter equivalents to the
     124median.  The upper quartile is the value for which 25\% of the data
     125are larger and 75\% are smaller.  The lower quartile is the value for
     126which 75\% of the data are larger and 25\% are smaller.  For a sample,
     127the values are sorted and the quartiles are given by the values of
     128elements $N/4$ and $3N/4$.  For the purpose of a sample upper and
     129lower quartile, it is sufficient to provide the closest integer entry
     130to these values.  The sample quartiles should be avoided for samples
     131which are large (e.g., $N > 10000$ elements) as the robust quartiles
     132are quicker and more accurate.
     133
     134\paragraph{Standard Deviation}
     135
     136The standard deviation of the sample is given by:
     137
     138\[ \sigma = \sqrt{\sum_{i = 1}^N \frac{(x_i - \bar{x})^2}{N - 1}} \]
     139
     140To minimize the numerical rounding error, this should be calculated
     141numerically as:
     142
     143\[ \sigma = \sqrt{\frac{1}{N - 1} [ \sum_{i = 1}^{N} (x_i - \bar{x})^2 - \frac{1}{N} (\sum_{i = 1}^{N} (x_i - \bar{x}))^2 ]} \]
     144
     145\subsubsection{Clipped Statistics}
     146
     147The clipped statistics are used to determine the mean and $\sigma$ of
     148a distribution in the presence of outliers. The clipped statistics are
     149quicker than the complete robust statistical estimators and more
     150reliable than the sample statistics.  The clipped statistics algorithm
     151produces the clipped mean and clipped standard deviation.  The
     152algorithm has 2 parameters: $N$, the number of iterations and $k$, the
     153multiplying factor of $\sigma$ used to exclude outliers.  Typical
     154values for both $N$ and $k$ are 3.  The algorithm is as follows:
     155
     156\begin{enumerate}
     157\item Compute the sample median.
     158\item Compute the sample standard deviation.
     159\item Use the sample median as the first estimator of the mean, $\bar{x}$.
     160\item Use the sample standard deviation as the first estimator of the
     161  true standard deviation, $\sigma$.
     162\item Repeat the following N times:
     163  \begin{enumerate}
     164  \item Exclude all values $x_{i}$ for while $|x_{i} - \bar{x}| > k \sigma$.
     165  \item Compute the mean and standard deviation of the sub-sample.
     166  \item Use the new mean for $\bar{x}$.
     167  \item Use the new standard deviations for $\sigma$.
     168\end{enumerate}
     169\item The last calulcated value of $\bar{x}$ is the clipped mean.
     170\item The last calulcated value of $\sigma$ is the clipped standard deviation.
     171\end{enumerate}
     172
     173\subsubsection{Robust Statistics}
     174
     175The robust version of the statistics provide estimators of basic
     176statistical concepts which are reliable even for data samples with
     177significant contamination.  A typical case is the situation in which
     178the data of interest represent a primary population of interest with a
     179single-valued mean and standard deviation and a secondary population
     180of data with a substantially different distribution.  For example, an
     181image of an uncrowded night-time field may consist of a sparse
     182collection of stars and an overall background level.  The majority of
     183pixels have the background value, with some variance due to noise
     184sources, but many are significantly higher (contributed by stars) or
     185significantly lower (dead pixels).  If we want to measure the mean of
     186the background, a robust mean is necessary as the outliers will
     187strongly bias the sample statistics.
     188
     189The robust statistics are calculated by constructing a histogram of
     190the values and performing the measurements on the histogram.  The
     191choice of a bin size requires some care.  If the data are integer
     192valued, the natural bin size is an integer.  Otherwise, the bin should
     193be a fraction of an estimate of the standard deviation.  Use the
     194sample upper and lower quartiles to determine an estimate of the
     195standard deviation: $\sigma_e = (U_{\frac{1}{4}} - L_{\frac{1}{4}}) /
     1961.34$.  The bin size shall be set at $\sigma_e / 10$.  The remaining
     197steps of the algorithm are as follows:
     198
     199\begin{itemize}
     200\item Construct the histogram with the specified bin size.
     201\item Smooth the histogram by a Gaussian with $\sigma_s = \sigma_e /
     202  4$. 
     203\item Find the bin with the peak value in the range $L_{\frac{1}{4}}$
     204  to $U_{\frac{1}{4}}$; this is the robust mode $\mbox{mode}_r$. 
     205\item Determine $dL = (U_{\frac{1}{4}} - L_{\frac{1}{4}}) / 8$.
     206\item Fit a Gaussian to the bins in the range $\mbox{mode}_r - dL$ to
     207  $\mbox{mode}_r + dL$.
     208\item The resulting fit parameters are the robust mean,
     209$\mbox{mean}_r$ and the robust standard deviation, $\sigma_r$.
     210\end{itemize}
     211
     212To determine the robust median, construct the cumulative histogram
     213from the histogram above. Select the bin which contains the 50th
     214percentile value and its two neighbors.  Fit a quadratic to these
     215three points.  The robust median value is the coordinate of the
     216quadratic which returns the 50\% value.
     217
     218
     219\subsection{Matrix Operations}
    40220
    41221In this section, we define the linear algebra operations performed on
     
    56236\code{gsl_linalg_LU_decomp}.
    57237
    58 \paragraph{LU Decomposition}
     238\subsubsection{LU Decomposition}
    59239\label{LUdecomp}
    60240
     
    91271\[ \alpha_{ij} = \frac{1}{\beta_{jj}} \left( a_{ij} - \sum_{k=1}^{j-1} \alpha_{ik}\beta_{kj} \right) \]
    92272
    93 \paragraph{Calculate a matrix determinant}
     273\subsubsection{Calculate a matrix determinant}
    94274
    95275The determinant $D$ of a matrix $a_{ij}$ is calculated from the
     
    105285shall be used.
    106286
    107 \paragraph{Solving a Linear Equation}
     287\subsubsection{Solving a Linear Equation}
    108288
    109289The LU decomposition of a matrix may be used to solve the
     
    121301\[ x_i = \frac{1}{\beta_{ii}}\left(y_i - \sum_{j=i+1}^N \beta_{ij} y_ij\right) \]
    122302
    123 \paragraph{Invert a matrix}
     303\subsubsection{Invert a matrix}
    124304
    125305Inversion of a matrix using the LU decomposition is performed by
     
    130310operation shall be implemented using the GSL function \code{gsl_linalg_LU_invert}.
    131311
    132 \paragraph{Perform matrix addition, subtraction and multiplication}
     312\subsubsection{Perform matrix addition, subtraction and multiplication}
    133313
    134314Matrix binary arithmetic operations differ from image binary
     
    148328operators: $+, -, \times, /$
    149329
    150 \paragraph{Transpose a matrix}
     330\subsubsection{Transpose a matrix}
    151331
    152332The transpose of a matrix is simply the reorganization of the matrix
     
    159339where $M_{ji}$ is the matrix to be transposed.
    160340
    161 \paragraph{Convert a matrix to a vector}
     341\subsubsection{Convert a matrix to a vector}
    162342\TBD{write me}
     343
     344\subsection{Fitting}
    163345
    164346\subsubsection{General Polynomial Fitting}
     
    255437\end{center}
    256438
    257 \subsection{Sorting}
    258 
    259 A variety of sorting algorithms exist, with a wide range in speed for
    260 different set sizes.  Three of the best sorting algorithms are
    261 ``heapsort'', ``quicksort'', and ``mergesort'' (see, e.g.,
    262 \citealt{knuth}, \citealt{sedgewick}, \citealt{press}).  These three
    263 sorting algorithms all run in a time of $O(n \log n)$ in the best
    264 case, but have different worse-case run times.  Implementations of all
    265 three sorting algorithms are described in references above and in
    266 various places online (e.g.,
    267 http://www.iti.fh-flensburg.de/lang/algorithmen/sortieren/algoen.htm).
    268 The linux \code{qsort} function orignially mades use of the quicksort
    269 algorithm, but now uses \tbd{what algorithm?}.  The GSL function
    270 \code{gsl_heapsort} uses the heapsort algorithm.  Both of these
    271 implemenations require a pointer to the comparison function, which may
    272 result in a slower code. 
    273 
    274 For PSLib, the sorting functions shall be implemented via
    275 \code{qsort}.  The function \code{psSort} shall return the sorted
    276 result of the input array without over-writing the input array.  The
    277 function \code{psSortIndex} shall return an integer index to the
    278 sequence of the input array without overwriting the input array.
    279 Given the following line of code, \code{out = psSortIndex (NULL,
    280 &in);}, the elements of the array \code{out} are in the sequence
    281 \code{in.arr[out->arr[0]]} to \code{in.arr[out->arr[in.n - 1]]}.
    282 
    283 \subsection{Smoothing: Boxcar and Gaussian}
    284 \label{smooth}
    285 
    286 Smoothing may occasionally be perfomed on data.  We present the
    287 algorithms for two typical versions: boxcar and Gaussian smoothing.
    288 In both smoothing techniques, given a series of data values $f_i$, the
    289 smoothed values $g_i$ are determined by calculating a linear
    290 combination based on the input data point and its nearest $2N$
    291 neighbors in the form:
    292 
    293 \[ g_i = \sum_{n=-N}^N c_n f_i \]
    294 %
    295 where the values of $c_n$ determine the filter type.  For boxcar
    296 smoothing, the values $c_n$ are constant, and must be equal to $1/(2N
    297 + 1)$ to maintain the zeroth moment of the data (care must be taken at
    298 the ends of the data range to reduce the value of $c_n$ as fewer input
    299 data points may be used).  For Gaussian smoothing, the crucial
    300 parameter is $\sigma$, the standard deviation.  The
    301 value of $N$ should be chosen to be large enough, $N = 5\sigma$, and
    302 the values of $c_n$ are then just the Gaussian curve:
    303 
    304 \[ c_n = \frac{e^{\frac{-n^2}{2\sigma^2}}}{\sqrt{2\pi\sigma^2}} \]
    305 
    306 \subsection{Statistics}
    307 
    308 The general statistics function \code{psStats} performs a variety of
    309 statistical calculations on a collection of floating point numbers.
    310 These statistics include both sample values, in which the formal
    311 statistic is calculated for the complete sample, and robust values, in
    312 which the statistic is estimated on the basis of an assumption of an
    313 underlying population.  While more reliable in general, the robust
    314 estimators may be somewhat slower than the sample statisic, so their
    315 use may vary depending on the context.  In addition, certain
    316 sigma-clipped values are defined as an intermediate choice between the
    317 sample and robust estimators. 
    318 
    319 \subsubsection{Sample Statistics}
    320 
    321 We define the following statistical terms, assuming there is a set of
    322 data elements $x_i$.
    323 
    324 \paragraph{Mean}
    325 
    326 The mean is defined as: \[ \bar{x} = \frac{1}{N} \sum_{i = 1}^{N} x_i \]
    327 
    328 \paragraph{Median}
    329 
    330 The median is defined as the value for which 50\% of the data values
    331 are larger and 50\% are smaller.  For a sample, the values are sorted
    332 and the median is given by the value of the middle element, if the
    333 number of values is odd, and by the average of the two middle values
    334 if the number of values is even.  This median should be avoided for
    335 samples which are large (e.g., $N > 10000$ elements) as the basic
    336 robust median is quicker and more accurate. 
    337 
    338 \paragraph{Upper and Lower Quartiles}
    339 
    340 The upper and lower quartiles ($U_{\frac{1}{4}}$ and
    341 $L_{\frac{1}{4}}$) are first and last quarter equivalents to the
    342 median.  The upper quartile is the value for which 25\% of the data
    343 are larger and 75\% are smaller.  The lower quartile is the value for
    344 which 75\% of the data are larger and 25\% are smaller.  For a sample,
    345 the values are sorted and the quartiles are given by the values of
    346 elements $N/4$ and $3N/4$.  For the purpose of a sample upper and
    347 lower quartile, it is sufficient to provide the closest integer entry
    348 to these values.  The sample quartiles should be avoided for samples
    349 which are large (e.g., $N > 10000$ elements) as the robust quartiles
    350 are quicker and more accurate.
    351 
    352 \paragraph{Standard Deviation}
    353 
    354 The standard deviation of the sample is given by:
    355 
    356 \[ \sigma = \sqrt{\sum_{i = 1}^N \frac{(x_i - \bar{x})^2}{N - 1}} \]
    357 
    358 To minimize the numerical rounding error, this should be calculated
    359 numerically as:
    360 
    361 \[ \sigma = \sqrt{\frac{1}{N - 1} [ \sum_{i = 1}^{N} (x_i - \bar{x})^2 - \frac{1}{N} (\sum_{i = 1}^{N} (x_i - \bar{x}))^2 ]} \]
    362 
    363 \subsubsection{Clipped Statistics}
    364 
    365 The clipped statistics are used to determine the mean and $\sigma$ of
    366 a distribution in the presence of outliers. The clipped statistics are
    367 quicker than the complete robust statistical estimators and more
    368 reliable than the sample statistics.  The clipped statistics algorithm
    369 produces the clipped mean and clipped standard deviation.  The
    370 algorithm has 2 parameters: $N$, the number of iterations and $k$, the
    371 multiplying factor of $\sigma$ used to exclude outliers.  Typical
    372 values for both $N$ and $k$ are 3.  The algorithm is as follows:
    373 
    374 \begin{enumerate}
    375 \item Compute the sample median.
    376 \item Compute the sample standard deviation.
    377 \item Use the sample median as the first estimator of the mean, $\bar{x}$.
    378 \item Use the sample standard deviation as the first estimator of the
    379   true standard deviation, $\sigma$.
    380 \item Repeat the following N times:
    381   \begin{enumerate}
    382   \item Exclude all values $x_{i}$ for while $|x_{i} - \bar{x}| > k \sigma$.
    383   \item Compute the mean and standard deviation of the sub-sample.
    384   \item Use the new mean for $\bar{x}$.
    385   \item Use the new standard deviations for $\sigma$.
    386 \end{enumerate}
    387 \item The last calulcated value of $\bar{x}$ is the clipped mean.
    388 \item The last calulcated value of $\sigma$ is the clipped standard deviation.
    389 \end{enumerate}
    390 
    391 \subsubsection{Robust Statistics}
    392 
    393 The robust version of the statistics provide estimators of basic
    394 statistical concepts which are reliable even for data samples with
    395 significant contamination.  A typical case is the situation in which
    396 the data of interest represent a primary population of interest with a
    397 single-valued mean and standard deviation and a secondary population
    398 of data with a substantially different distribution.  For example, an
    399 image of an uncrowded night-time field may consist of a sparse
    400 collection of stars and an overall background level.  The majority of
    401 pixels have the background value, with some variance due to noise
    402 sources, but many are significantly higher (contributed by stars) or
    403 significantly lower (dead pixels).  If we want to measure the mean of
    404 the background, a robust mean is necessary as the outliers will
    405 strongly bias the sample statistics.
    406 
    407 The robust statistics are calculated by constructing a histogram of
    408 the values and performing the measurements on the histogram.  The
    409 choice of a bin size requires some care.  If the data are integer
    410 valued, the natural bin size is an integer.  Otherwise, the bin should
    411 be a fraction of an estimate of the standard deviation.  Use the
    412 sample upper and lower quartiles to determine an estimate of the
    413 standard deviation: $\sigma_e = (U_{\frac{1}{4}} - L_{\frac{1}{4}}) /
    414 1.34$.  The bin size shall be set at $\sigma_e / 10$.  The remaining
    415 steps of the algorithm are as follows:
    416 
    417 \begin{itemize}
    418 \item Construct the histogram with the specified bin size.
    419 \item Smooth the histogram by a Gaussian with $\sigma_s = \sigma_e /
    420   4$. 
    421 \item Find the bin with the peak value in the range $L_{\frac{1}{4}}$
    422   to $U_{\frac{1}{4}}$; this is the robust mode $\mbox{mode}_r$. 
    423 \item Determine $dL = (U_{\frac{1}{4}} - L_{\frac{1}{4}}) / 8$.
    424 \item Fit a Gaussian to the bins in the range $\mbox{mode}_r - dL$ to
    425   $\mbox{mode}_r + dL$.
    426 \item The resulting fit parameters are the robust mean,
    427 $\mbox{mean}_r$ and the robust standard deviation, $\sigma_r$.
    428 \end{itemize}
    429 
    430 To determine the robust median, construct the cumulative histogram
    431 from the histogram above. Select the bin which contains the 50th
    432 percentile value and its two neighbors.  Fit a quadratic to these
    433 three points.  The robust median value is the coordinate of the
    434 quadratic which returns the 50\% value.
    435 
    436 
    437 \section{Polynomials}
     439\subsection{Polynomials}
    438440
    439441We will employ Chebyshev polynomials (NR \S 5.8) to approximate functions:
    440442\begin{equation}
    441 f(x) = \Sum_{i=0}^{n} c_i T_i(x)
     443f(x) = \sum_{i=0}^{n} c_i T_i(x)
    442444\end{equation}
    443445These have some desirable features:
     
    450452
    451453The first few Chebyshev polynomials are:
    452 \begin{equation}
    453 T_0(x) = 1
    454 
    455 T_1(x) = x
    456 
    457 T_2(x) = 2x^2 - 1
    458 
    459 T_3(x) = 4x^3 - 3x
    460 
    461 T_4(x) = 8x^4 - 8x^2 + 1
    462 \end{equation}
     454\begin{eqnarray}
     455T_0(x) & = & 1 \\
     456T_1(x) & = & x \\
     457T_2(x) & = & 2x^2 - 1 \\
     458T_3(x) & = & 4x^3 - 3x \\
     459T_4(x) & = & 8x^4 - 8x^2 + 1 \\
     460\end{eqnarray}
    463461Chebyshev polynomials follow the recurrence relation:
    464462\begin{equation}
     
    468466Practically, Chebyshev polynomials should be evaluated using Clenshaw's recurrence
    469467formula (NR \S 5.5):
    470 \begin{equation}
    471 d_j = 2xd_{j+1} - d_{j+2} + c_j
    472 
    473 f(x) = x*d_1 - d_2 + 1/2 c_0
    474 \end{equation}
     468\begin{eqnarray}
     469d_j  & = & 2xd_{j+1} - d_{j+2} + c_j \\
     470f(x) & = & x*d_1 - d_2 + 1/2 c_0 \\
     471\end{eqnarray}
    475472
    476473It shall be the responsibility of the user to convert the domain into the range
    477474$-1 < x < 1$.
    478475
    479 \subsection{Multi-dimensional polynomials}
     476\subsubsection{Multi-dimensional polynomials}
    480477
    481478Multi-dimensional polynomials shall be composed of multiplications of 1D polynomials.
    482479
    483480
     481\subsection{Astronomy Utilities}
     482
     483\section{Modules}
     484
     485\subsection{Image Processing Modules}
     486\subsubsection{debias}
     487\subsubsection{mask}
     488\subsubsection{trim}
     489\subsubsection{flatten}
     490\subsubsection{sky/fringe subtract}
     491\subsubsection{warp}
     492\subsubsection{stack}
     493\subsubsection{difference}
     494\subsubsection{kernel convolution}
     495\subsubsection{special stack}
     496
     497\subsection{Object Detection Modules}
     498\subsubsection{find peaks}
     499\subsubsection{background }
     500\subsubsection{aperture photometry}
     501\subsubsection{get shape}
     502
     503\subsection{Miscellaneous Modules}
     504
     505\section{Analysis Stages}
     506\subsection{Phase 1}
     507\subsection{Phase 2}
     508\subsection{Phase 3}
     509\subsection{Phase 4}
     510\subsection{Cal 1}
     511\subsection{Cal 2}
     512\subsection{Cal 3}
     513\subsection{Astrom Ref}
     514\subsection{Photom Ref}
     515
     516\section{Architectual Components}
     517
    484518\end{document}
Note: See TracChangeset for help on using the changeset viewer.