27#include <lal/LALConstants.h>
29#include <gsl/gsl_sf_log.h>
51 return log1p(
x ) -
x;
67int compar(
void *
p,
const void *
a,
const void *b )
71 int ascend = *(
int * )
p;
113 return exp1( -0.5 * sum1 );
131 sum1 += 2 * (
x *
x /
y + ( log1p( -
x ) +
x ) );
135 return exp1( -0.5 * sum1 );
149 rb = 2.0 * vars->
wnmax;
151 rb = 2.0 * vars->
wnmin;
154 u =
u2 / ( 1.0 +
u2 * rb );
159 u =
u2 / ( 1.0 +
u2 * rb );
164 u = 0.5 * ( u1 +
u2 );
165 if (
errbound( vars,
u / ( 1.0 +
u * rb ), &xconst ) > accx ) {
189 rb = 2.0 * vars->
wnmax;
191 rb = 2.0 * vars->
wnmin;
194 u =
u2 / ( 1.0 +
u2 * rb );
199 u =
u2 / ( 1.0 +
u2 * rb );
204 u = 0.5 * ( u1 +
u2 );
224 REAL8 sum1, sum2, prod1, prod2, prod3,
x,
y, err1, err2;
235 sum2 = ( vars->
sigsq + tausq ) *
u *
u;
244 prod3 += vars->
dofs->
data[ii] * gsl_sf_log_1plusx(
x );
247 prod1 += vars->
dofs->
data[ii] * gsl_sf_log_1plusx(
x );
291 REAL8 sum2, prod1, prod2, prod3,
x,
y, err1, err2;
300 sum2 = ( vars->
sigsq + tausq ) *
u *
u;
307 prod2 += 2 *
log(
x );
308 prod3 += 2 * log1p(
x );
311 prod1 += 2 * log1p(
x );
353 REAL8 divis[] = {2.0, 1.4, 1.2, 1.1};
374 for (
UINT4 ii = 0; ii < 4; ii++ ) {
389 REAL8 divis[] = {2.0, 1.4, 1.2, 1.1};
408 for (
UINT4 ii = 0; ii < 4; ii++ ) {
424 REAL8 inpi,
u, sum1, sum2, sum3,
x,
y, z;
428 for (
INT4 ii = nterm; ii >= 0; ii-- ) {
429 u = ( ii + 0.5 ) * interv;
430 sum1 = -2.0 *
u * vars->
c;
432 sum3 = -0.5 * vars->
sigsq *
u *
u;
437 sum3 -= 0.25 * vars->
dofs->
data[jj] * gsl_sf_log_1plusx(
y );
445 x = inpi *
exp1( sum3 ) /
u;
447 x *= ( 1.0 -
exp1( -0.5 * tausq *
u *
u ) );
449 sum1 = sin( 0.5 * sum1 ) *
x;
460 REAL8 inpi,
u, sum1, sum2, sum3,
x, z;
463 REAL8 neg2timesc = -2.0 * vars->
c, neghalftimessigsq = -0.5 * vars->
sigsq, neghalftimestausq = -0.5 * tausq;
465 for (
INT4 ii = nterm; ii >= 0; ii-- ) {
466 u = ( ii + 0.5 ) * interv;
467 sum1 = neg2timesc *
u;
469 sum3 = neghalftimessigsq *
u *
u;
471 REAL8 twotimesu = 2.0 *
u;
474 sum3 -= 0.5 * log1p( (
x *
x ) );
480 x = inpi *
exp1( sum3 ) /
u;
482 x *= ( 1.0 -
exp1( neghalftimestausq *
u *
u ) );
484 sum1 = sin( 0.5 * sum1 ) *
x;
495 for (
INT4 ii = nterm; ii >= 0; ii-- ) {
496 REAL8 u = ( ii + 0.5 ) * interv;
498 REAL8 exptermarguementsum = 0.0, logofproductterm = 0.0, sinetermargumentsum = 0.0, sumofabssinesumargs = 0.0;
508 REAL8 firstterm =
exp1( -2.0 * (
u *
u ) * exptermarguementsum - 0.5 * (
u *
u ) * vars->
sigsq );
509 REAL8 secondterm =
exp1( logofproductterm );
510 REAL8 thirdterm = sin( sinetermargumentsum -
u * vars->
c );
511 REAL8 together = firstterm * secondterm * thirdterm / (
LAL_PI * ( ii + 0.5 ) );
512 REAL8 together2 = firstterm * secondterm * ( sumofabssinesumargs + fabs(
u * vars->
c ) ) / (
LAL_PI * ( ii + 0.5 ) );
514 together *= ( 1.0 -
exp1( -0.5 * tausq *
u *
u ) );
515 together2 *= ( 1.0 -
exp1( -0.5 * tausq *
u *
u ) );
527 for (
INT4 ii = nterm; ii >= 0; ii-- ) {
528 REAL8 u = ( ii + 0.5 ) * interv;
529 REAL8 oneoverPiTimesiiPlusHalf = 1.0 / (
LAL_PI * ( ii + 0.5 ) );
531 REAL8 exptermarguementsum = 0.0, logofproductterm = 0.0, sinetermargumentsum = 0.0, sumofabssinesumargs = 0.0;
535 REAL8 atanTwoUtimesWeight = atan( twoUtimesWeight );
537 logofproductterm += -0.5 * log1p( twoUtimesWeight * twoUtimesWeight );
538 sinetermargumentsum += atanTwoUtimesWeight;
539 sumofabssinesumargs += fabs( atanTwoUtimesWeight );
541 REAL8 firstterm =
exp1( -2.0 * (
u *
u ) * exptermarguementsum );
542 REAL8 secondterm =
exp1( logofproductterm );
543 REAL8 thirdterm = sin( sinetermargumentsum -
u * vars->
c );
544 REAL8 together = firstterm * secondterm * thirdterm * oneoverPiTimesiiPlusHalf;
545 REAL8 together2 = firstterm * secondterm * ( sumofabssinesumargs + fabs(
u * vars->
c ) ) * oneoverPiTimesiiPlusHalf;
547 REAL8 scalingfactor = ( 1.0 -
exp1( -0.5 * tausq *
u *
u ) );
548 together *= scalingfactor;
549 together2 *= scalingfactor;
561 alignedREAL8Vector *uVector = NULL, *twoUvector = NULL, *oneoverPiTimesiiPlusHalfVector = NULL, *uVectorTimesThreshold = NULL, *scaledweightvector = NULL, *scaledweightvectorsq = NULL;
569 for (
INT4 ii = nterm; ii >= 0; ii-- ) {
579 for (
INT4 ii = nterm; ii >= 0; ii-- ) {
583 REAL8 logofproductterm = 0.0, sinetermargumentsum = 0.0, sumofabssinesumargs = 0.0;
584 for (
UINT4 jj = 0; jj < scaledweightvector->length; jj++ ) {
585 REAL8 atanTwoUtimesWeight = atan( scaledweightvector->data[jj] );
587 logofproductterm += log1p( scaledweightvectorsq->data[jj] );
588 sinetermargumentsum += atanTwoUtimesWeight;
589 sumofabssinesumargs += fabs( atanTwoUtimesWeight );
591 logofproductterm *= -0.5;
592 REAL8 secondterm =
exp1( logofproductterm );
593 REAL8 thirdterm = sin( sinetermargumentsum - uVectorTimesThreshold->data[ii] );
594 REAL8 together = secondterm * thirdterm * oneoverPiTimesiiPlusHalfVector->data[ii];
595 REAL8 together2 = secondterm * ( sumofabssinesumargs + fabs( uVectorTimesThreshold->data[ii] ) ) * oneoverPiTimesiiPlusHalfVector->data[ii];
597 REAL8 scalingfactor = ( 1.0 -
exp1( -0.5 * tausq * uVector->
data[ii] * uVector->
data[ii] ) );
598 together *= scalingfactor;
599 together2 *= scalingfactor;
623 REAL8 axl, axl1, axl2, sxl, sum1, lj;
658 sum1 = ( axl - axl1 ) / lj;
659 for (
INT4 jj = ii - 1; jj >= 0; jj-- ) {
663 if ( sum1 > 100.0 ) {
667 return exp2( 0.25 * sum1 ) *
LAL_1_PI / ( axl * axl );
673 if ( sum1 > 100.0 ) {
677 return exp2( 0.25 * sum1 ) *
LAL_1_PI / ( axl * axl );
685 REAL8 axl, axl1, axl2, sxl, sum1, lj;
711 sum1 = ( axl - axl1 ) / lj;
712 for (
INT4 jj = ii - 1; jj >= 0; jj-- ) {
716 if ( sum1 > 100.0 ) {
720 return exp2( 0.25 * sum1 ) *
LAL_1_PI / ( axl * axl );
726 if ( sum1 > 100.0 ) {
730 return exp2( 0.25 * sum1 ) *
LAL_1_PI / ( axl * axl );
755 REAL8 acc1, almx, xlim, xnt, xntm;
756 REAL8 utx, tausq, wnstd, intv, intv1,
x, up, un, d1, d2;
758 INT4 rats[] = {1, 2, 4, 8};
771 vars->
sigsq = sigma * sigma;
793 if ( wnstd == 0.0 ) {
794 if ( vars->
c > 0.0 ) {
802 if ( vars->
wnmin == 0.0 && vars->
wnmax == 0.0 && sigma == 0.0 ) {
807 wnstd = sqrt( wnstd );
822 findu( vars, &utx, 0.5 * acc1 );
825 if ( vars->
c != 0.0 && almx > 0.07 * wnstd ) {
826 tausq = 0.25 * acc1 /
coeff( vars, vars->
c );
829 }
else if (
truncation( vars, utx, tausq ) < 0.2 * acc1 ) {
830 vars->
sigsq += tausq;
831 findu( vars, &utx, 0.25 * acc1 );
838 d1 =
cutoff( vars, acc1, &up ) - vars->
c;
843 d2 = vars->
c -
cutoff( vars, acc1, &un );
858 xntm = 3.0 / sqrt( acc1 );
860 if ( xnt > xntm * 1.5 ) {
866 ntm = (
INT4 )round( xntm );
869 if (
x <= fabs( vars->
c ) ) {
876 tausq = ( 1.0 / 3.0 ) * acc1 / ( 1.1 * ( coeffvalminusx + coeffvalplusx ) );
880 acc1 = ( 2.0 / 3.0 ) * acc1;
886 vars->
sigsq += tausq;
889 findu( vars, &utx, 0.25 * acc1 );
900 nt = (
INT4 )round( xnt );
908 for (
UINT4 ii = 0; ii < 4; ii++ ) {
909 if ( rats[ii] *
x == rats[ii] * up ) {
921 REAL8 acc1, almx, xlim, xnt, xntm;
922 REAL8 utx, tausq, wnstd, intv, intv1,
x, up, un, d1, d2;
924 INT4 rats[] = {1, 2, 4, 8};
937 vars->
sigsq = sigma * sigma;
957 if ( wnstd == 0.0 ) {
958 if ( vars->
c > 0.0 ) {
967 if ( vars->
wnmin == 0.0 && vars->
wnmax == 0.0 ) {
973 wnstd = sqrt( wnstd );
991 if ( vars->
c != 0.0 && almx > 0.07 * wnstd ) {
996 vars->
sigsq += tausq;
1026 xntm = 3.0 / sqrt( acc1 );
1028 if ( xnt > xntm * 1.5 ) {
1030 if ( xntm > xlim ) {
1034 ntm = (
INT4 )round( xntm );
1037 if (
x <= fabs( vars->
c ) ) {
1043 tausq = acc1 / ( 1.1 * ( coeffvalminusx + coeffvalplusx ) * 3.0 );
1047 acc1 = ( 2.0 / 3.0 ) * acc1;
1053 vars->
sigsq += tausq;
1070 nt = (
INT4 )round( xnt );
1077 for (
UINT4 ii = 0; ii < 4; ii++ ) {
1078 if ( rats[ii] *
x == rats[ii] * up ) {
#define __func__
log an I/O error, i.e.
REAL8 truncation(qfvars *vars, REAL8 u, REAL8 tausq)
void integrate_twospect2(qfvars *vars, INT4 nterm, REAL8 interv, REAL8 tausq, INT4 mainx)
void findu_twospect(qfvars *vars, REAL8 *utx, REAL8 accx)
REAL8 coeff(qfvars *vars, REAL8 x)
REAL8 cutoff(qfvars *vars, REAL8 accx, REAL8 *upn)
void integrate_twospect(qfvars *vars, INT4 nterm, REAL8 interv, REAL8 tausq, INT4 mainx)
REAL8 cdfwchisq(qfvars *vars, REAL8 sigma, REAL8 acc, INT4 *ifault)
REAL8 twospect_log_1plusx_mx(REAL8 x)
REAL8 twospect_log_1plusx(REAL8 x)
void findu(qfvars *vars, REAL8 *utx, REAL8 accx)
REAL8 cutoff_twospect(qfvars *vars, REAL8 accx, REAL8 *upn)
REAL8 truncation_twospect(qfvars *vars, REAL8 u, REAL8 tausq)
INT4 fast_integrate_twospect2(qfvars *vars, INT4 nterm, REAL8 interv, REAL8 tausq, INT4 mainx)
REAL8 cdfwchisq_twospect(qfvars *vars, REAL8 sigma, REAL8 acc, INT4 *ifault)
void integrate_eg(qfvars *vars, INT4 nterm, REAL8 interv, REAL8 tausq, INT4 mainx)
REAL8 coeff_twospect(qfvars *vars, REAL8 x)
int compar(void *p, const void *a, const void *b)
REAL8 errbound_twospect(qfvars *vars, REAL8 u, REAL8 *cx)
void integrate(qfvars *vars, INT4 nterm, REAL8 interv, REAL8 tausq, INT4 mainx)
REAL8 errbound(qfvars *vars, REAL8 u, REAL8 *cx)
int XLALHeapIndex(INT4 *indx, void *base, UINT4 nobj, UINT4 size, void *params, int(*compar)(void *, const void *, const void *))
#define XLAL_CHECK(assertion,...)
#define XLAL_CHECK_VOID(assertion,...)
#define XLAL_CHECK_REAL8(assertion,...)
p
RUN ANALYSIS SCRIPT ###.
REAL8Vector * noncentrality
alignedREAL8Vector * weights
INT4 VectorShiftREAL8(alignedREAL8Vector *output, alignedREAL8Vector *input, REAL8 shift, INT4 vectorMath)
void destroyAlignedREAL8Vector(alignedREAL8Vector *vector)
INT4 VectorInvertREAL8(alignedREAL8Vector *output, alignedREAL8Vector *input, INT4 vectorMath)
INT4 VectorScaleREAL8(alignedREAL8Vector *output, alignedREAL8Vector *input, REAL8 scale, INT4 vectorMath)
alignedREAL8Vector * createAlignedREAL8Vector(UINT4 length, const size_t align)
INT4 VectorMultiplyREAL8(alignedREAL8Vector *output, alignedREAL8Vector *input1, alignedREAL8Vector *input2, INT4 vectorMath)