Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALPulsar 7.1.1.1-b246709
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
falsealarm.c
Go to the documentation of this file.
1/*
2* Copyright (C) 2010, 2011, 2014 Evan Goetz
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#include <gsl/gsl_sort.h>
21#include <gsl/gsl_roots.h>
22#include <gsl/gsl_fit.h>
23#include "falsealarm.h"
24#include "statistics.h"
25#include "cdfwchisq.h"
26#include "vectormath.h"
27
28/**
29 * Allocate memory for farStruct
30 * \return Pointer to a farStruct
31 */
33{
34 farStruct *farstruct = NULL;
35 XLAL_CHECK_NULL( ( farstruct = XLALMalloc( sizeof( *farstruct ) ) ) != NULL, XLAL_ENOMEM );
36 farstruct->far = 1.0;
37 farstruct->topRvalues = NULL;
38 return farstruct;
39} // createfarStruct()
40
41
42/**
43 * Destroy an farStruct
44 * \param [in] farstruct Pointer to a farStruct
45 */
46void destroyfarStruct( farStruct *farstruct )
47{
48 if ( farstruct ) {
50 farstruct->topRvalues = NULL;
51 XLALFree( ( farStruct * )farstruct );
52 }
53} // destroyfarStruct()
54
55
56/**
57 * Estimate the FAR of the R statistic from the weights by a number of trials
58 * \param [out] output Pointer to a farStruct
59 * \param [in] template Pointer to a TwoSpectTemplate containing a template
60 * \param [in] trials Number of trials to estimate the FAR
61 * \param [in] thresh Threshold value
62 * \param [in] ffplanenoise Pointer to REAL4VectorAligned containing the expected 2nd FFT background estimates
63 * \param [in] fbinaveratios Pointer to REAL4VectorAligned containing the noise floor variations
64 * \return Status value
65 */
66INT4 estimateFAR( farStruct *output, const TwoSpectTemplate *template, const UINT4 trials, const REAL8 thresh, const REAL4VectorAligned *ffplanenoise, const REAL4VectorAligned *fbinaveratios )
67{
68 XLAL_CHECK( output != NULL && template != NULL && ffplanenoise != NULL && fbinaveratios != NULL, XLAL_EINVAL );
69
70 UINT4 numofweights = 0;
71 for ( UINT4 ii = 0; ii < template->templatedata->length; ii++ ) if ( template->templatedata->data[ii] != 0.0 ) {
72 numofweights++;
73 }
74
75 REAL8 sumofsqweights = 0.0;
76 for ( UINT4 ii = 0; ii < numofweights; ii++ ) {
77 sumofsqweights += ( template->templatedata->data[ii] * template->templatedata->data[ii] );
78 }
79 REAL8 sumofsqweightsinv = 1.0 / sumofsqweights;
80
81 REAL4VectorAligned *Rs = NULL;
82 XLAL_CHECK( ( Rs = XLALCreateREAL4VectorAligned( trials, 32 ) ) != NULL, XLAL_EFUNC );
83
84 gsl_rng *rng = NULL;
85 XLAL_CHECK( ( rng = gsl_rng_alloc( gsl_rng_mt19937 ) ) != NULL, XLAL_EFUNC );
86 //srand(time(NULL));
87 //UINT8 randseed = rand();
88 //gsl_rng_set(rng, randseed);
89 gsl_rng_set( rng, 0 );
90
91 UINT4 numfprbins = ffplanenoise->length;
92
93 for ( UINT4 ii = 0; ii < trials; ii++ ) {
94 //Create noise value and R value
95 REAL8 R = 0.0;
96 for ( UINT4 jj = 0; jj < numofweights; jj++ ) {
97 UINT4 firstfreqbin = template->pixellocations->data[jj] / numfprbins;
98 UINT4 secfreqbin = template->pixellocations->data[jj] - firstfreqbin * numfprbins;
99 REAL8 noise = expRandNum( ffplanenoise->data[secfreqbin] * fbinaveratios->data[firstfreqbin], rng );
101 R += ( noise - ffplanenoise->data[secfreqbin] * fbinaveratios->data[firstfreqbin] ) * template->templatedata->data[jj];
102 }
103 Rs->data[ii] = ( REAL4 )( R * sumofsqweightsinv );
104 } /* for ii < trials */
105 REAL4 mean = calcMean( Rs );
106 REAL4 sigma = 0.0;
107 XLAL_CHECK( calcStddev( &sigma, Rs ) == XLAL_SUCCESS, XLAL_EFUNC );
108
109 //Do an insertion sort. At best this is O(thresh*trials), at worst this is O(thresh*trials*trials).
110 if ( output->topRvalues == NULL ) {
111 XLAL_CHECK( ( output->topRvalues = XLALCreateREAL4VectorAligned( ( INT4 )round( thresh * trials ) + 1, 32 ) ) != NULL, XLAL_EFUNC );
112 }
113 XLAL_CHECK( gsl_sort_float_largest( ( float * )output->topRvalues->data, output->topRvalues->length, ( float * )Rs->data, 1, Rs->length ) == 0, XLAL_EFUNC );
114
115 output->far = output->topRvalues->data[output->topRvalues->length - 1];
116 output->distMean = mean;
117 output->distSigma = sigma;
118
119 //Destroy
121 gsl_rng_free( rng );
122
123 return XLAL_SUCCESS;
124
125} /* estimateFAR() */
126
127
128/**
129 * Numerically solve for the FAR of the R statistic from the weights using the Davies algorithm and a root finding algorithm
130 * \param [out] output Pointer to a farStruct
131 * \param [in] template Pointer to a TwoSpectTemplate containing a template
132 * \param [in] thresh Threshold value
133 * \param [in] ffplanenoise Pointer to REAL4VectorAligned containing the expected 2nd FFT background estimates
134 * \param [in] fbinaveratios Pointer to REAL4VectorAligned containing the noise floor variations
135 * \param [in] inputParams Pointer to UserInput_t
136 * \param [in] rng Pointer to gsl_rng
137 * \param [in] method Integer value of 0 (Brent's method) or 1 (Newton's method)
138 * \return Status value
139 */
140INT4 numericFAR( farStruct *output, const TwoSpectTemplate *template, const REAL8 thresh, const REAL4VectorAligned *ffplanenoise, const REAL4VectorAligned *fbinaveratios, const UserInput_t *inputParams, const gsl_rng *rng, const INT4 method )
141{
142
143 XLAL_CHECK( output != NULL && template != NULL && ffplanenoise != NULL && fbinaveratios != NULL && inputParams != NULL && rng != NULL, XLAL_EINVAL );
144
145 INT4 ii;
146 INT4 errcode = 0;
147
148 //Set up solver: method 0 is Brent's method, method 1 is Newton's method
149 const gsl_root_fsolver_type *T1 = gsl_root_fsolver_brent;
150 gsl_root_fsolver *s1 = NULL;
151 XLAL_CHECK( ( s1 = gsl_root_fsolver_alloc( T1 ) ) != NULL, XLAL_EFUNC );
152 gsl_function F;
153 const gsl_root_fdfsolver_type *T0 = gsl_root_fdfsolver_newton;
154 gsl_root_fdfsolver *s0 = NULL;
155 XLAL_CHECK( ( s0 = gsl_root_fdfsolver_alloc( T0 ) ) != NULL, XLAL_EFUNC );
156 gsl_function_fdf FDF;
157
158
159 //Include the various parameters in the struct required by GSL
160 struct gsl_probR_pars params = {template, ffplanenoise, fbinaveratios, thresh, inputParams, rng, errcode};
161
162 //Assign GSL function the necessary parts
163 if ( method != 0 ) {
164 F.function = &gsl_probR;
165 F.params = &params;
166 } else {
167 FDF.f = &gsl_probR;
168 FDF.df = &gsl_dprobRdR;
169 FDF.fdf = &gsl_probRandDprobRdR;
170 FDF.params = &params;
171 }
172
173 //Start off with an initial guess and set the solver at the beginning
174 REAL8 Rlow = 0.0, Rhigh = 10000.0, root = 400.0;
175 if ( method != 0 ) {
176 XLAL_CHECK( gsl_root_fsolver_set( s1, &F, Rlow, Rhigh ) == GSL_SUCCESS, XLAL_EFUNC );
177 } else {
178 XLAL_CHECK( gsl_root_fdfsolver_set( s0, &FDF, root ) == GSL_SUCCESS, XLAL_EFUNC );
179 }
180
181 //And now find the root
182 ii = 0;
183 INT4 max_iter = 100, jj = 0, max_retries = 10;
184 INT4 status = GSL_CONTINUE;
185 REAL8 prevroot = 0.0;
186 while ( status == GSL_CONTINUE && ii < max_iter ) {
187
188 ii++;
189
190 if ( method != 0 ) {
191 status = gsl_root_fsolver_iterate( s1 );
192 XLAL_CHECK( status == GSL_CONTINUE || status == GSL_SUCCESS, XLAL_EFUNC, "gsl_root_fsolver_iterate() failed with code %d\n", status );
193 if ( ii > 0 ) {
194 prevroot = root;
195 }
196 root = gsl_root_fsolver_root( s1 );
197 Rlow = gsl_root_fsolver_x_lower( s1 );
198 Rhigh = gsl_root_fsolver_x_upper( s1 );
199 status = gsl_root_test_interval( Rlow, Rhigh, 0.0, 0.001 );
200 XLAL_CHECK( status == GSL_CONTINUE || status == GSL_SUCCESS, XLAL_EFUNC, "gsl_root_test_interval() failed with code %d\n", status );
201 } else {
202 status = gsl_root_fdfsolver_iterate( s0 );
203 XLAL_CHECK( status == GSL_CONTINUE || status == GSL_SUCCESS, XLAL_EFUNC, "gsl_root_fdfsolver_iterate() failed with code %d\n", status );
204 prevroot = root;
205 root = gsl_root_fdfsolver_root( s0 );
206 status = gsl_root_test_delta( prevroot, root, 0.0, 0.001 );
207 XLAL_CHECK( status == GSL_CONTINUE || status == GSL_SUCCESS, XLAL_EFUNC, "gsl_root_test_delta() failed with code %d\n", status );
208
209 //If there is an issue that the root is negative, try a new initial guess
210 if ( root < 0.0 && jj < max_retries ) {
211 ii = 0;
212 jj++;
213 status = GSL_CONTINUE;
214 XLAL_CHECK( gsl_root_fdfsolver_set( s0, &FDF, gsl_rng_uniform_pos( rng )*Rhigh ) == GSL_SUCCESS, XLAL_EFUNC );
215 } else if ( root < 0.0 && jj == max_retries ) {
216 status = GSL_FAILURE;
217 } //Up to here
218 }
219 } /* while status==GSL_CONTINUE && ii < max_iter */
220
221 //Failure modes
222 if ( method != 0 ) {
223 XLAL_CHECK( status == GSL_SUCCESS, XLAL_FAILURE, "Root finding iteration (%d/%d) failed with failure code %d. Previous root = %f, current root = %f\n", ii, max_iter, status, prevroot, root );
224 XLAL_CHECK( ii < max_iter, XLAL_EMAXITER, "Root finding iteration (%d/%d) failed with failure code %d. Previous root = %f, current root = %f\n", ii, max_iter, status, prevroot, root );
225 XLAL_CHECK( root != 0.0, XLAL_ERANGE, "Root finding iteration (%d/%d) converged to 0.0\n", ii, max_iter );
226 } else {
227 XLAL_CHECK( status == GSL_SUCCESS, XLAL_FAILURE, "Root finding iteration (%d/%d) failed with failure code %d. Previous root = %f, current root = %f\n", ii, max_iter, status, prevroot, root );
228 XLAL_CHECK( ii < max_iter, XLAL_EMAXITER, "Root finding iteration (%d/%d) failed with failure code %d. Previous root = %f, current root = %f\n", ii, max_iter, status, prevroot, root );
229 XLAL_CHECK( root > 0.0, XLAL_ERANGE, "Threshold value found (%f) is less than 0.0\n", root );
230 }
231
232 output->far = root;
233 output->distMean = 0.0;
234 output->distSigma = 0.0; //Fake the value of sigma
235 output->farerrcode = errcode;
236
237 //Cleanup
238 gsl_root_fsolver_free( s1 );
239 gsl_root_fdfsolver_free( s0 );
240
241 return XLAL_SUCCESS;
242
243} /* numericFAR() */
244
245
246/**
247 * For the root finding, calculating the false alarm probability of R. This method takes the average of 3 values of close by R values for stability
248 * \param [in] R R value of interest
249 * \param [in] param A gsl_probR_pars struct
250 * \return Difference between the false alarm probability and the log10 threshold value
251 */
252REAL8 gsl_probR( const REAL8 R, void *param )
253{
254
255 struct gsl_probR_pars *pars = ( struct gsl_probR_pars * )param;
256
257 REAL8 dR = 0.005;
258 REAL8 R1 = ( 1.0 + dR ) * R;
259 REAL8 R2 = ( 1.0 - dR ) * R;
260 INT4 errcode1 = 0, errcode2 = 0, errcode3 = 0;
261
262 REAL8 prob = ( probR( pars->template, pars->ffplanenoise, pars->fbinaveratios, R, pars->inputParams, pars->rng, &errcode1 ) + probR( pars->template, pars->ffplanenoise, pars->fbinaveratios, R1, pars->inputParams, pars->rng, &errcode2 ) + probR( pars->template, pars->ffplanenoise, pars->fbinaveratios, R2, pars->inputParams, pars->rng, &errcode3 ) ) / 3.0;
263
264 if ( errcode1 != 0 ) {
265 pars->errcode = errcode1;
266 } else if ( errcode2 != 0 ) {
267 pars->errcode = errcode2;
268 } else if ( errcode3 != 0 ) {
269 pars->errcode = errcode3;
270 }
271
272 REAL8 returnval = prob - log10( pars->threshold );
273
274 return returnval;
275
276} /* gsl_probR() */
277
278
279/**
280 * Determine the slope of the inverse cumulative distribution function
281 * \param [in] R R value of interest
282 * \param [in] param A gsl_probR_pars struct
283 * \return The slope of the inverse distribution function
284 */
285REAL8 gsl_dprobRdR( const REAL8 R, void *param )
286{
287
288 struct gsl_probR_pars *pars = ( struct gsl_probR_pars * )param;
289
290 REAL8 dR = 0.005;
291
292 INT4 errcode1 = 0, errcode2 = 0;
293
294 //Explicit computation of slope
295 REAL8 R1 = ( 1.0 + dR ) * R;
296 REAL8 R2 = ( 1.0 - dR ) * R;
297 REAL8 prob1 = gsl_probR( R1, pars );
298 REAL8 prob2 = gsl_probR( R2, pars );
299 while ( fabs( prob1 - prob2 ) < 100.0 * LAL_REAL8_EPS ) {
300 dR *= 2.0;
301 R1 = ( 1.0 + dR ) * R;
302 R2 = ( 1.0 - dR ) * R;
303 prob1 = gsl_probR( R1, pars );
304 prob2 = gsl_probR( R2, pars );
305 }
306 REAL8 diffR = R1 - R2;
307 REAL8 slope = ( prob1 - prob2 ) / diffR;
308
309 if ( errcode1 != 0 ) {
310 pars->errcode = errcode1;
311 } else if ( errcode2 != 0 ) {
312 pars->errcode = errcode2;
313 }
314
315 return slope;
316
317} /* gsl_dprobRdR() */
318
319
320/**
321 * Determine the difference between the probability and log10 of the threshold as well as the slope of the inverse cumulative distribution function
322 * \param [in] R R value of interest
323 * \param [in] param A gsl_probR_pars struct
324 * \param [out] probabilityR The difference between the threshold and the probability of the R value in question
325 * \param [out] dprobRdR The slope of the inverse cumulative distribution function
326 */
327void gsl_probRandDprobRdR( const REAL8 R, void *param, REAL8 *probabilityR, REAL8 *dprobRdR )
328{
329
330 struct gsl_probR_pars *pars = ( struct gsl_probR_pars * )param;
331
332 *probabilityR = gsl_probR( R, pars );
333
334 *dprobRdR = gsl_dprobRdR( R, pars );
335
336} /* gsl_probRandDprobRdR() */
337
338
339/**
340 * Analytically calculate the probability of a true signal using the Davies' method
341 * \param [in] template Pointer to a TwoSpectTemplate with a template
342 * \param [in] ffplanenoise Pointer to a REAL4VectorAligned with an estimate of the background of 2nd FFT powers
343 * \param [in] fbinaveratios Pointer to a REAL4VectorAligned of frequency bin average ratios
344 * \param [in] R The value of R for a given template
345 * \param [in] params Pointer to UserInput_t
346 * \param [in] rng Pointer to gsl_rng
347 * \param [out] errcode Pointer to the error code value from the Davies algorithm
348 * \return log10 false alarm probability value
349 */
350REAL8 probR( const TwoSpectTemplate *template, const REAL4VectorAligned *ffplanenoise, const REAL4VectorAligned *fbinaveratios, const REAL8 R, const UserInput_t *params, const gsl_rng *rng, INT4 *errcode )
351{
352
353 XLAL_CHECK_REAL8( template != NULL && ffplanenoise != NULL && fbinaveratios != NULL && params != NULL && rng != NULL && errcode != NULL, XLAL_EINVAL );
354
355 REAL8 prob = 0.0;
356 REAL8 sumwsq = 0.0;
357 INT4 numweights = 0;
358 for ( UINT4 ii = 0; ii < template->templatedata->length; ii++ ) {
359 if ( template->templatedata->data[ii] != 0.0 ) {
360 numweights++;
361 sumwsq += template->templatedata->data[ii] * template->templatedata->data[ii];
362 } else {
363 break;
364 }
365 }
366
367 UINT4 numfprbins = ffplanenoise->length;
368
369 alignedREAL8Vector *newweights = NULL;
370 INT4Vector *sorting = NULL;
371 XLAL_CHECK_REAL8( ( newweights = createAlignedREAL8Vector( numweights, 32 ) ) != NULL, XLAL_EFUNC );
372 XLAL_CHECK_REAL8( ( sorting = XLALCreateINT4Vector( numweights ) ) != NULL, XLAL_EFUNC );
373
374 REAL8 Rpr = R;
375 for ( UINT4 ii = 0; ii < newweights->length; ii++ ) {
376 UINT4 firstfreqbin = template->pixellocations->data[ii] / numfprbins;
377 UINT4 secfreqbin = template->pixellocations->data[ii] - firstfreqbin * numfprbins;
378 newweights->data[ii] = 0.5 * template->templatedata->data[ii] * ffplanenoise->data[secfreqbin] * fbinaveratios->data[firstfreqbin] / sumwsq;
379 Rpr += template->templatedata->data[ii] * ffplanenoise->data[secfreqbin] * fbinaveratios->data[firstfreqbin] / sumwsq;
380 sorting->data[ii] = ii; //This is for the fact that a few steps later (before using Davies' algorithm, we sort the weights)
381 }
382
383 qfvars vars;
384 vars.weights = newweights;
385 vars.sorting = sorting;
386 vars.dofs = NULL;
387 vars.noncentrality = NULL;
388 vars.arrayNotSorted = 0; //Set because we do the sorting outside of Davies' algorithm with qsort
389 vars.lim = 50000000;
390 vars.c = Rpr;
391 vars.vectorMath = params->vectorMath;
392 REAL8 sigma = 0.0;
393 REAL8 accuracy = 1.0e-11; //(1e-5) old value
394
395 //sort the weights here so we don't have to do it later (qsort)
396 sort_double_ascend( ( REAL8Vector * )newweights );
397
398 //cdfwchisq(algorithm variables, sigma, accuracy, error code)
399 prob = 1.0 - cdfwchisq_twospect( &vars, sigma, accuracy, errcode );
400
401 //Large R values can cause a problem when computing the probability. We run out of accuracy quickly even using double precision
402 //Potential fix: compute log10(prob) for smaller values of R, for when slope is linear between log10 probabilities
403 //Use slope to extend the computation and then compute the exponential of the found log10 probability.
404 REAL8 logprobest = 0.0;
405 INT4 estimatedTheProb = 0;
406 if ( prob <= 1.0e-8 || *errcode != 0 ) {
407 estimatedTheProb = 1;
408
409 INT4 errcode1 = 0;
410 REAL8 probslope = 0.0, tempprob, c1;
411 REAL8 lowerend = 0.0;
412 REAL8 upperend = Rpr;
413 REAL8Vector *probvals = NULL, *cvals = NULL;
414 XLAL_CHECK_REAL8( ( probvals = XLALCreateREAL8Vector( 20 ) ) != NULL, XLAL_EFUNC );
415 XLAL_CHECK_REAL8( ( cvals = XLALCreateREAL8Vector( 20 ) ) != NULL, XLAL_EFUNC );
416
417 for ( UINT4 ii = 0; ii < probvals->length; ii++ ) {
418 c1 = gsl_rng_uniform_pos( rng ) * ( upperend - lowerend ) + lowerend;
419 vars.c = c1;
420 tempprob = 1.0 - cdfwchisq_twospect( &vars, sigma, accuracy, &errcode1 );
421 while ( tempprob <= 1.0e-8 || tempprob >= 1.0e-6 ) {
422 if ( tempprob <= 1.0e-8 ) {
423 upperend = c1;
424 } else if ( tempprob >= 1.0e-6 ) {
425 lowerend = c1;
426 }
427 c1 = gsl_rng_uniform_pos( rng ) * ( upperend - lowerend ) + lowerend;
428 vars.c = c1;
429 tempprob = 1.0 - cdfwchisq_twospect( &vars, sigma, accuracy, &errcode1 );
430
431 INT4 tries = 1;
432 while ( tries < 10 && errcode1 != 0 ) {
433 tries++;
434 c1 = gsl_rng_uniform_pos( rng ) * ( upperend - lowerend ) + lowerend;
435 vars.c = c1;
436 tempprob = 1.0 - cdfwchisq_twospect( &vars, sigma, accuracy, &errcode1 );
437 }
438 if ( tries >= 10 && errcode1 != 0 ) {
439 fprintf( stderr, "%s: cdfwchisq_twospect() failed with code %d after making %d tries.\n", __func__, errcode1, tries );
441 }
442
443 }
444 XLAL_CHECK_REAL8( errcode1 == 0, XLAL_EFUNC, "cdfwchisq_twospect() failed with code %d\n", errcode1 );
445 probvals->data[ii] = log10( tempprob );
446 cvals->data[ii] = c1;
447 }
448
449 REAL8 yintercept, cov00, cov01, cov11, sumsq;
450 XLAL_CHECK_REAL8( gsl_fit_linear( cvals->data, 1, probvals->data, 1, cvals->length, &yintercept, &probslope, &cov00, &cov01, &cov11, &sumsq ) == GSL_SUCCESS, XLAL_EFUNC );
451 logprobest = probslope * Rpr + yintercept;
452 XLAL_CHECK_REAL8( logprobest <= -0.5, XLAL_ERANGE, "Failure calculating accurate interpolated value\n" );
453
454 XLALDestroyREAL8Vector( probvals );
455 XLALDestroyREAL8Vector( cvals );
456
457 *errcode = errcode1;
458
459 }
460
461 //If errcode is still != 0, better fail
462 XLAL_CHECK_REAL8( *errcode == 0, XLAL_EFUNC, "cdfwchisq_twospect() failed at the end with code %d\n", *errcode );
463
464 //Cleanup
465 destroyAlignedREAL8Vector( newweights );
466 XLALDestroyINT4Vector( sorting );
467
468 if ( estimatedTheProb == 1 ) {
469 return logprobest;
470 } else {
471 return log10( prob );
472 }
473
474} /* probR() */
#define __func__
log an I/O error, i.e.
const double c1
#define fprintf
REAL8 expRandNum(const REAL8 mu, const gsl_rng *ptrToGenerator)
Create a exponentially distributed noise value.
void sort_double_ascend(REAL8Vector *vector)
Sort a REAL8Vector in ascending order, modifying the input vector.
INT4 calcStddev(REAL4 *sigma, const REAL4VectorAligned *vector)
Compute the standard deviation of a REAL4VectorAligned.
REAL4 calcMean(const REAL4VectorAligned *vector)
Compute the mean value of a REAL4VectorAligned, computed via recursion like in GSL.
REAL8 cdfwchisq_twospect(qfvars *vars, REAL8 sigma, REAL8 acc, INT4 *ifault)
Definition: cdfwchisq.c:917
farStruct * createfarStruct(void)
Allocate memory for farStruct.
Definition: falsealarm.c:32
void gsl_probRandDprobRdR(const REAL8 R, void *param, REAL8 *probabilityR, REAL8 *dprobRdR)
Determine the difference between the probability and log10 of the threshold as well as the slope of t...
Definition: falsealarm.c:327
REAL8 gsl_dprobRdR(const REAL8 R, void *param)
Determine the slope of the inverse cumulative distribution function.
Definition: falsealarm.c:285
INT4 estimateFAR(farStruct *output, const TwoSpectTemplate *template, const UINT4 trials, const REAL8 thresh, const REAL4VectorAligned *ffplanenoise, const REAL4VectorAligned *fbinaveratios)
Estimate the FAR of the R statistic from the weights by a number of trials.
Definition: falsealarm.c:66
REAL8 gsl_probR(const REAL8 R, void *param)
For the root finding, calculating the false alarm probability of R.
Definition: falsealarm.c:252
REAL8 probR(const TwoSpectTemplate *template, const REAL4VectorAligned *ffplanenoise, const REAL4VectorAligned *fbinaveratios, const REAL8 R, const UserInput_t *params, const gsl_rng *rng, INT4 *errcode)
Analytically calculate the probability of a true signal using the Davies' method.
Definition: falsealarm.c:350
INT4 numericFAR(farStruct *output, const TwoSpectTemplate *template, const REAL8 thresh, const REAL4VectorAligned *ffplanenoise, const REAL4VectorAligned *fbinaveratios, const UserInput_t *inputParams, const gsl_rng *rng, const INT4 method)
Numerically solve for the FAR of the R statistic from the weights using the Davies algorithm and a ro...
Definition: falsealarm.c:140
void destroyfarStruct(farStruct *farstruct)
Destroy an farStruct.
Definition: falsealarm.c:46
#define LAL_REAL8_EPS
double REAL8
uint32_t UINT4
int32_t INT4
float REAL4
void * XLALMalloc(size_t n)
void XLALFree(void *p)
INT4Vector * XLALCreateINT4Vector(UINT4 length)
void XLALDestroyINT4Vector(INT4Vector *vector)
REAL8Vector * XLALCreateREAL8Vector(UINT4 length)
void XLALDestroyREAL8Vector(REAL8Vector *vector)
void XLALDestroyREAL4VectorAligned(REAL4VectorAligned *in)
REAL4VectorAligned * XLALCreateREAL4VectorAligned(const UINT4 length, const UINT4 align)
#define XLAL_ERROR_REAL8(...)
#define xlalErrno
#define XLAL_CHECK(assertion,...)
#define XLAL_CHECK_REAL8(assertion,...)
#define XLAL_CHECK_NULL(assertion,...)
XLAL_ENOMEM
XLAL_SUCCESS
XLAL_ERANGE
XLAL_EFUNC
XLAL_EMAXITER
XLAL_EINVAL
XLAL_FAILURE
int T0
INT4 * data
REAL8 * data
REAL4VectorAligned * topRvalues
const REAL4VectorAligned * fbinaveratios
Definition: falsealarm.h:28
const UserInput_t * inputParams
Definition: falsealarm.h:30
const REAL4 threshold
Definition: falsealarm.h:29
const REAL4VectorAligned * ffplanenoise
Definition: falsealarm.h:27
const gsl_rng * rng
Definition: falsealarm.h:31
const TwoSpectTemplate * template
Definition: falsealarm.h:26
INT4Vector * dofs
Definition: cdfwchisq.h:39
INT4Vector * sorting
Definition: cdfwchisq.h:40
REAL8Vector * noncentrality
Definition: cdfwchisq.h:42
INT4 arrayNotSorted
Definition: cdfwchisq.h:36
INT4 lim
Definition: cdfwchisq.h:35
REAL8 c
Definition: cdfwchisq.h:31
INT4 vectorMath
Definition: cdfwchisq.h:38
alignedREAL8Vector * weights
Definition: cdfwchisq.h:41
void destroyAlignedREAL8Vector(alignedREAL8Vector *vector)
Definition: vectormath.c:67
alignedREAL8Vector * createAlignedREAL8Vector(UINT4 length, const size_t align)
Definition: vectormath.c:55