00001 /** @file psFunctions.h 00002 * @brief Standard Mathematical Functions. 00003 * @ingroup Stats 00004 * 00005 * This file will hold the prototypes for procedures which allocate, free, 00006 * and evaluate various polynomials. Those polynomial structures are also 00007 * defined here. 00008 * 00009 * @ingroup Stats 00010 * 00011 * @author Someone at IfA 00012 * @author GLG, MHPCC 00013 * 00014 * @version $Revision: 1.44 $ $Name: rel5_0 $ 00015 * @date $Date: 2005/03/31 23:01:46 $ 00016 * 00017 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii 00018 */ 00019 00020 #if !defined(PS_FUNCTIONS_H) 00021 #define PS_FUNCTIONS_H 00022 00023 #include <stdio.h> 00024 #include <stdbool.h> 00025 #include <float.h> 00026 #include <math.h> 00027 00028 #include "psVector.h" 00029 #include "psScalar.h" 00030 00031 /** \addtogroup Stats 00032 * \{ 00033 */ 00034 00035 /** Evaluate a non-normalized Gaussian with the given mean and sigma at the 00036 * given coordianate. 00037 * 00038 * Note that this is not a Gaussian deviate. The evaluated Gaussian is: 00039 * \f[ exp(-\frac{(x-mean)^2}{2\sigma^2}) \f] 00040 * 00041 * @return psF32 value on the gaussian curve given the input parameters 00042 */ 00043 psF32 psGaussian( 00044 psF32 x, ///< Value at which to evaluate 00045 psF32 mean, ///< Mean for the Gaussian 00046 psF32 stddev, ///< Standard deviation for the Gaussian 00047 psBool normal ///< Indicates whether result should be normalized 00048 ); 00049 00050 /** Produce a vector of random numbers from a Gaussian distribution with 00051 * the specified mean and sigma 00052 * 00053 * @return psVector* vector of random numbers 00054 * 00055 */ 00056 psVector* p_psGaussianDev( 00057 psF32 mean, ///< The mean of the Gaussian 00058 psF32 sigma, ///< The sigma of the Gaussian 00059 psS32 Npts ///< The size of the vector 00060 ); 00061 00062 typedef enum { 00063 PS_POLYNOMIAL_ORD, ///< Ordinary Polynomial 00064 PS_POLYNOMIAL_CHEB ///< Chebyshev Polynomial 00065 } psPolynomialType; 00066 00067 /** One-dimensional polynomial */ 00068 typedef struct 00069 { 00070 psPolynomialType type; ///< Polynomial type 00071 psS32 n; ///< Number of terms 00072 psF32 *coeff; ///< Coefficients 00073 psF32 *coeffErr; ///< Error in coefficients 00074 psU8 *mask; ///< Coefficient mask 00075 } 00076 psPolynomial1D; 00077 00078 /** Two-dimensional polynomial */ 00079 typedef struct 00080 { 00081 psPolynomialType type; ///< Polynomial type 00082 psS32 nX; ///< Number of terms in x 00083 psS32 nY; ///< Number of terms in y 00084 psF32 **coeff; ///< Coefficients 00085 psF32 **coeffErr; ///< Error in coefficients 00086 psU8 **mask; ///< Coefficients mask 00087 } 00088 psPolynomial2D; 00089 00090 /** Three-dimensional polynomial */ 00091 typedef struct 00092 { 00093 psPolynomialType type; ///< Polynomial type 00094 psS32 nX; ///< Number of terms in x 00095 psS32 nY; ///< Number of terms in y 00096 psS32 nZ; ///< Number of terms in z 00097 psF32 ***coeff; ///< Coefficients 00098 psF32 ***coeffErr; ///< Error in coefficients 00099 psU8 ***mask; ///< Coefficients mask 00100 } 00101 psPolynomial3D; 00102 00103 /** Four-dimensional polynomial */ 00104 typedef struct 00105 { 00106 psPolynomialType type; ///< Polynomial type 00107 psS32 nW; ///< Number of terms in w 00108 psS32 nX; ///< Number of terms in x 00109 psS32 nY; ///< Number of terms in y 00110 psS32 nZ; ///< Number of terms in z 00111 psF32 ****coeff; ///< Coefficients 00112 psF32 ****coeffErr; ///< Error in coefficients 00113 psU8 ****mask; ///< Coefficients mask 00114 } 00115 psPolynomial4D; 00116 00117 00118 /** Allocates a psPolynomial1D structure with n terms 00119 * 00120 * @return psPolynomial1D* new 1-D polynomial struct 00121 */ 00122 psPolynomial1D* psPolynomial1DAlloc( 00123 psS32 n, ///< Number of terms 00124 psPolynomialType type ///< Polynomial Type 00125 ); 00126 00127 /** Allocates a 2-D polynomial structure 00128 * 00129 * @return psPolynomial2D* new 2-D polynomial struct 00130 */ 00131 psPolynomial2D* psPolynomial2DAlloc( 00132 psS32 nX, ///< Number of terms in x 00133 psS32 nY, ///< Number of terms in y 00134 psPolynomialType type ///< Polynomial Type 00135 ); 00136 00137 /** Allocates a 3-D polynomial structure 00138 * 00139 * @return psPolynomial3D* new 3-D polynomial struct 00140 */ 00141 psPolynomial3D* psPolynomial3DAlloc( 00142 psS32 nX, ///< Number of terms in x 00143 psS32 nY, ///< Number of terms in y 00144 psS32 nZ, ///< Number of terms in z 00145 psPolynomialType type ///< Polynomial Type 00146 ); 00147 00148 /** Allocates a 4-D polynomial structure 00149 * 00150 * @return psPolynomial4D* new 4-D polynomial struct 00151 */ 00152 psPolynomial4D* psPolynomial4DAlloc( 00153 psS32 nW, ///< Number of terms in w 00154 psS32 nX, ///< Number of terms in x 00155 psS32 nY, ///< Number of terms in y 00156 psS32 nZ, ///< Number of terms in z 00157 psPolynomialType type ///< Polynomial Type 00158 ); 00159 00160 /** Evaluates a 1-D polynomial at specific coordinates. 00161 * 00162 * @return psF32 result of polynomial at given location 00163 */ 00164 psF32 psPolynomial1DEval( 00165 const psPolynomial1D* myPoly, ///< Coefficients for the polynomial 00166 psF32 x ///< location at which to evaluate 00167 ); 00168 00169 /** Evaluates a 2-D polynomial at specific coordinates. 00170 * 00171 * @return psF32 result of polynomial at given location 00172 */ 00173 psF32 psPolynomial2DEval( 00174 const psPolynomial2D* myPoly, ///< Coefficients for the polynomial 00175 psF32 x, ///< x location at which to evaluate 00176 psF32 y ///< y location at which to evaluate 00177 ); 00178 00179 /** Evaluates a 3-D polynomial at specific coordinates. 00180 * 00181 * @return psF32 result of polynomial at given location 00182 */ 00183 psF32 psPolynomial3DEval( 00184 const psPolynomial3D* myPoly, ///< Coefficients for the polynomial 00185 psF32 x, ///< x location at which to evaluate 00186 psF32 y, ///< y location at which to evaluate 00187 psF32 z ///< z location at which to evaluate 00188 ); 00189 00190 /** Evaluates a 4-D polynomial at specific coordinates. 00191 * 00192 * @return psF32 result of polynomial at given location 00193 */ 00194 psF32 psPolynomial4DEval( 00195 const psPolynomial4D* myPoly, ///< Coefficients for the polynomial 00196 psF32 w, ///< w location at which to evaluate 00197 psF32 x, ///< x location at which to evaluate 00198 psF32 y, ///< y location at which to evaluate 00199 psF32 z ///< z location at which to evaluate 00200 ); 00201 00202 psVector *psPolynomial1DEvalVector( 00203 const psPolynomial1D *myPoly, ///< Coefficients for the polynomial 00204 const psVector *x ///< x locations at which to evaluate 00205 ); 00206 00207 psVector *psPolynomial2DEvalVector( 00208 const psPolynomial2D *myPoly, ///< Coefficients for the polynomial 00209 const psVector *x, ///< x locations at which to evaluate 00210 const psVector *y ///< y locations at which to evaluate 00211 ); 00212 00213 psVector *psPolynomial3DEvalVector( 00214 const psPolynomial3D *myPoly, ///< Coefficients for the polynomial 00215 const psVector *x, ///< x locations at which to evaluate 00216 const psVector *y, ///< y locations at which to evaluate 00217 const psVector *z ///< z locations at which to evaluate 00218 ); 00219 00220 psVector *psPolynomial4DEvalVector( 00221 const psPolynomial4D *myPoly, ///< Coefficients for the polynomial 00222 const psVector *w, ///< w locations at which to evaluate 00223 const psVector *x, ///< x locations at which to evaluate 00224 const psVector *y, ///< y locations at which to evaluate 00225 const psVector *z ///< z locations at which to evaluate 00226 ); 00227 00228 /*****************************************************************************/ 00229 00230 /* Double-precision polynomials, mainly for use in astrometry */ 00231 00232 /** Double-precision one-dimensional polynomial */ 00233 typedef struct 00234 { 00235 psPolynomialType type; ///< Polynomial type 00236 psS32 n; ///< Number of terms 00237 psF64 *coeff; ///< Coefficients 00238 psF64 *coeffErr; ///< Error in coefficients 00239 psU8 *mask; ///< Coefficient mask 00240 } 00241 psDPolynomial1D; 00242 00243 /** Double-precision two-dimensional polynomial */ 00244 typedef struct 00245 { 00246 psPolynomialType type; ///< Polynomial type 00247 psS32 nX; ///< Number of terms in x 00248 psS32 nY; ///< Number of terms in y 00249 psF64 **coeff; ///< Coefficients 00250 psF64 **coeffErr; ///< Error in coefficients 00251 psU8 **mask; ///< Coefficients mask 00252 } 00253 psDPolynomial2D; 00254 00255 /** Double-precision three-dimensional polynomial */ 00256 typedef struct 00257 { 00258 psPolynomialType type; ///< Polynomial type 00259 psS32 nX; ///< Number of terms in x 00260 psS32 nY; ///< Number of terms in y 00261 psS32 nZ; ///< Number of terms in z 00262 psF64 ***coeff; ///< Coefficients 00263 psF64 ***coeffErr; ///< Error in coefficients 00264 psU8 ***mask; ///< Coefficient mask 00265 } 00266 psDPolynomial3D; 00267 00268 /** Double-precision four-dimensional polynomial */ 00269 typedef struct 00270 { 00271 psPolynomialType type; ///< Polynomial type 00272 psS32 nW; ///< Number of terms in w 00273 psS32 nX; ///< Number of terms in x 00274 psS32 nY; ///< Number of terms in y 00275 psS32 nZ; ///< Number of terms in z 00276 psF64 ****coeff; ///< Coefficients 00277 psF64 ****coeffErr; ///< Error in coefficients 00278 psU8 ****mask; ///< Coefficients mask 00279 } 00280 psDPolynomial4D; 00281 00282 /** Allocates a double-precision 1-D polynomial structure with n terms 00283 * 00284 * @return psPolynomial1D* new double-precision 1-D polynomial struct 00285 */ 00286 psDPolynomial1D* psDPolynomial1DAlloc( 00287 psS32 n, ///< Number of terms 00288 psPolynomialType type ///< Polynomial Type 00289 ); 00290 00291 /** Allocates a double-precision 2-D polynomial structure 00292 * 00293 * @return psPolynomial2D* new double-precision 2-D polynomial struct 00294 */ 00295 psDPolynomial2D* psDPolynomial2DAlloc( 00296 psS32 nX, ///< Number of terms in x 00297 psS32 nY, ///< Number of terms in y 00298 psPolynomialType type ///< Polynomial Type 00299 ); 00300 00301 /** Allocates a double-precision 3-D polynomial structure 00302 * 00303 * @return psPolynomial3D* new double-precision 3-D polynomial struct 00304 */ 00305 psDPolynomial3D* psDPolynomial3DAlloc( 00306 psS32 nX, ///< Number of terms in x 00307 psS32 nY, ///< Number of terms in y 00308 psS32 nZ, ///< Number of terms in z 00309 psPolynomialType type ///< Polynomial Type 00310 ); 00311 00312 /** Allocates a double-precision 4-D polynomial structure 00313 * 00314 * @return psPolynomial4D* new double-precision 4-D polynomial struct 00315 */ 00316 psDPolynomial4D* psDPolynomial4DAlloc( 00317 psS32 nW, ///< Number of terms in w 00318 psS32 nX, ///< Number of terms in x 00319 psS32 nY, ///< Number of terms in y 00320 psS32 nZ, ///< Number of terms in z 00321 psPolynomialType type ///< Polynomial Type 00322 ); 00323 00324 /** Evaluates a double-precision 1-D polynomial at specific coordinates. 00325 * 00326 * @return psF32 result of polynomial at given location 00327 */ 00328 psF64 psDPolynomial1DEval( 00329 const psDPolynomial1D* myPoly, ///< Coefficients for the polynomial 00330 psF64 x ///< Value at which to evaluate 00331 ); 00332 00333 /** Evaluates a double-precision 2-D polynomial at specific coordinates. 00334 * 00335 * @return psF32 result of polynomial at given location 00336 */ 00337 psF64 psDPolynomial2DEval( 00338 const psDPolynomial2D* myPoly, ///< Coefficients for the polynomial 00339 psF64 x, ///< Value x at which to evaluate 00340 psF64 y ///< Value y at which to evaluate 00341 ); 00342 00343 /** Evaluates a double-precision 3-D polynomial at specific coordinates. 00344 * 00345 * @return psF32 result of polynomial at given location 00346 */ 00347 psF64 psDPolynomial3DEval( 00348 const psDPolynomial3D* myPoly, ///< Coefficients for the polynomial 00349 psF64 x, ///< Value x at which to evaluate 00350 psF64 y, ///< Value y at which to evaluate 00351 psF64 z ///< Value z at which to evaluate 00352 ); 00353 00354 /** Evaluates a double-precision 4-D polynomial at specific coordinates. 00355 * 00356 * @return psF32 result of polynomial at given location 00357 */ 00358 psF64 psDPolynomial4DEval( 00359 const psDPolynomial4D* myPoly, ///< Coefficients for the polynomial 00360 psF64 w, ///< Value w at which to evaluate 00361 psF64 x, ///< Value x at which to evaluate 00362 psF64 y, ///< Value y at which to evaluate 00363 psF64 z ///< Value z at which to evaluate 00364 ); 00365 00366 psVector *psDPolynomial1DEvalVector( 00367 const psDPolynomial1D *myPoly, ///< Coefficients for the polynomial 00368 const psVector *x ///< x locations at which to evaluate 00369 ); 00370 00371 psVector *psDPolynomial2DEvalVector( 00372 const psDPolynomial2D *myPoly, ///< Coefficients for the polynomial 00373 const psVector *x, ///< x locations at which to evaluate 00374 const psVector *y ///< y locations at which to evaluate 00375 ); 00376 00377 psVector *psDPolynomial3DEvalVector( 00378 const psDPolynomial3D *myPoly, ///< Coefficients for the polynomial 00379 const psVector *x, ///< x locations at which to evaluate 00380 const psVector *y, ///< y locations at which to evaluate 00381 const psVector *z ///< z locations at which to evaluate 00382 ); 00383 00384 psVector *psDPolynomial4DEvalVector( 00385 const psDPolynomial4D *myPoly, ///< Coefficients for the polynomial 00386 const psVector *w, ///< w locations at which to evaluate 00387 const psVector *x, ///< x locations at which to evaluate 00388 const psVector *y, ///< y locations at which to evaluate 00389 const psVector *z ///< z locations at which to evaluate 00390 ); 00391 00392 00393 00394 typedef struct 00395 { 00396 psS32 n; ///< The number of spline polynomials 00397 psPolynomial1D **spline; ///< An array of n pointers to the spline polynomials 00398 psF32 *p_psDeriv2; ///< For cubic splines, the second derivative at each domain point. Size is n+1. 00399 psF32 *domains; ///< The boundaries between each spline piece. Size is n+1. 00400 psVector *knots; ///< The boundaries between each spline piece. Size is n+1. 00401 } 00402 psSpline1D; 00403 00404 psSpline1D *psSpline1DAlloc(psS32 n, 00405 psS32 order, 00406 psF32 min, 00407 psF32 max); 00408 00409 psSpline1D *psSpline1DAllocGeneric(const psVector *bounds, 00410 psS32 order); 00411 00412 psF32 psSpline1DEval( 00413 const psSpline1D *spline, 00414 psF32 x 00415 ); 00416 00417 psVector *psSpline1DEvalVector( 00418 const psSpline1D *spline, 00419 const psVector *x 00420 ); 00421 00422 psS32 p_psVectorBinDisect(psVector *bins, 00423 psScalar *x); 00424 00425 psScalar *p_psVectorInterpolate(psVector *domain, 00426 psVector *range, 00427 psS32 order, 00428 psScalar *x); 00429 00430 #if 0 00431 psF32 p_psNRSpline1DEval(psSpline1D *spline, 00432 const psVector* x, 00433 const psVector* y, 00434 psF32 X); 00435 #endif 00436 00437 /* \} */// End of MathGroup Functions 00438 00439 #endif 00440
1.3.9.1