Loading [MathJax]/extensions/TeX/AMSsymbols.js
LAL 7.7.0.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
RngMedBias.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2007 Badri Krishnan, Jolien Creighton
3*
4* This program is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License as published by
6* the Free Software Foundation; either version 2 of the License, or
7* (at your option) any later version.
8*
9* This program is distributed in the hope that it will be useful,
10* but WITHOUT ANY WARRANTY; without even the implied warranty of
11* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12* GNU General Public License for more details.
13*
14* You should have received a copy of the GNU General Public License
15* along with with program; see the file COPYING. If not, write to the
16* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17* MA 02110-1301 USA
18*/
19
20/*-----------------------------------------------------------------------
21 *
22 * File Name: RngMedBias.c
23 *
24 * Authors: Krishnan, B. Itoh, Y.
25 *
26 *
27 * History: Created by Sintes May 21, 2003
28 * Modified...
29 *
30 *-----------------------------------------------------------------------
31 */
32
33#include <lal/RngMedBias.h>
34
35/*
36 * The functions that make up the guts of this module
37 */
38
39/**
40 * Function for finding bias in median for exponential distribution
41 * to be used with any code which uses the running median to estimate PSD.
42 *
43 * For the exponential distribution with unit mean and variance, the value of the
44 * median is \f$\log(2.0)\f$ in the limit of infinite sample size. Thus, if we are
45 * using the running median to estimate the PSD, there is a correction factor
46 * of \f$\log(2.0)\f$. However, for finite sample sizes (i.e. for finite block size
47 * values), there is a bias in the estimator of the median and the correction
48 * factor is different. This program returns the correct normalization factor
49 * for block sizes from 1 to 1000. For larger values it returns \f$\log(2.0)\f$ and
50 * returns and error for smaller values.
51 *
52 */
55{
56 REAL8 biasFactor = 0.;
57
58 /* check block size is positive */
59 XLAL_CHECK_REAL8 ( blkSize > 0, XLAL_EINVAL, "Invalid blkSize = %d, must be >0", blkSize );
60
61 /*
62 * compute sum_{i = 1}^{2 ceil(blkSize/2) - 1} (-1^(i+1))/i
63 *
64 * the sum always has an odd number of terms. the first (i = 1) term is
65 * removed from the loop and added to the final result separately. for
66 * the sake of numerical accuracy, because of the alternating signs the
67 * remaining (even count of) terms are computed in pairs and each pair
68 * added to the sum as a single value. also for the sake of numerical
69 * accuracy, the pairs are computed and added to the total in reverse
70 * order, from smallest (largest i) to largest (smallest i).
71 */
72
73 if ( blkSize & 1 )
74 blkSize += 1;
75 for ( blkSize -= 2; blkSize > 0; blkSize -= 2 )
76 biasFactor -= 1. / (blkSize * (REAL8) (blkSize + 1));
77
78 return 1. + biasFactor;
79
80} // XLALRngMedBias()
81
82/**
83 * \deprecated use XLALRngMedBias() instead.
84 * Just a wrapper for XLALRngMedBias()
85 */
86void
88 REAL8 *biasFactor,
89 INT4 blkSize
90 )
91{
93
94 // check input consistency
95 if ( biasFactor == NULL )
96 ABORT ( status, RNGMEDBIASH_ENULL, RNGMEDBIASH_MSGENULL);
97
98 REAL8 temp = XLALRngMedBias ( blkSize );
99 if ( xlalErrno != 0 )
100 ABORT ( status, RNGMEDBIASH_EVAL, RNGMEDBIASH_MSGEVAL );
101
102 (*biasFactor) = temp;
103
104 /* normal exit */
105 RETURN (status);
106
107} /* LALRngMedBias() */
#define ABORT(statusptr, code, mesg)
#define INITSTATUS(statusptr)
#define RETURN(statusptr)
double REAL8
Double precision real floating-point number (8 bytes).
int32_t INT4
Four-byte signed integer.
#define RNGMEDBIASH_EVAL
Invalid value.
Definition: RngMedBias.h:66
void LALRngMedBias(LALStatus *status, REAL8 *biasFactor, INT4 blkSize)
Definition: RngMedBias.c:87
#define RNGMEDBIASH_ENULL
Null pointer.
Definition: RngMedBias.h:65
REAL8 XLALRngMedBias(INT4 blkSize)
Function for finding bias in median for exponential distribution to be used with any code which uses ...
Definition: RngMedBias.c:54
#define xlalErrno
Modifiable lvalue containing the XLAL error number.
Definition: XLALError.h:571
#define XLAL_CHECK_REAL8(assertion,...)
Macro to test an assertion and invoke a failure if it is not true in a function that returns a REAL8.
Definition: XLALError.h:870
@ XLAL_EINVAL
Invalid argument.
Definition: XLALError.h:409
LAL status structure, see The LALStatus structure for more details.
Definition: LALDatatypes.h:947