36#include <gsl/gsl_vector.h>
37#include <gsl/gsl_matrix.h>
38#include <gsl/gsl_blas.h>
39#include <gsl/gsl_permutation.h>
40#include <gsl/gsl_linalg.h>
41#include <gsl/gsl_rng.h>
42#include <gsl/gsl_randist.h>
43#include <gsl/gsl_sf_bessel.h>
44#include <gsl/gsl_integration.h>
45#include <gsl/gsl_monte.h>
46#include <gsl/gsl_monte_plain.h>
47#include <gsl/gsl_monte_miser.h>
48#include <gsl/gsl_monte_vegas.h>
50#include <lal/LALGSL.h>
51#include <lal/AVFactories.h>
52#include <lal/LALInitBarycenter.h>
53#include <lal/UserInput.h>
54#include <lal/SFTfileIO.h>
55#include <lal/ExtrapolatePulsarSpins.h>
56#include <lal/NormalizeSFTRngMed.h>
57#include <lal/ComputeFstat.h>
58#include <lal/LALHough.h>
59#include <lal/LogPrintf.h>
60#include <lal/FstatisticTools.h>
61#include <lal/LALPulsarVCSInfo.h>
63#define SQ(x) ((x)*(x))
116 INT4 integrationMethod;
134int main(
int argc,
char *argv[] );
139int XLALsynthesizeSignals( gsl_matrix **A_Mu_i, gsl_matrix **s_mu_i, gsl_matrix **Amp_i, gsl_vector **rho2,
141 gsl_rng *rnd,
UINT4 numDraws );
144int XLALcomputeLogLikelihood( gsl_vector **lnL,
const gsl_matrix *A_Mu_i,
const gsl_matrix *s_mu_i,
const gsl_matrix *x_mu_i );
145int XLALcomputeFstatistic( gsl_vector **Fstat, gsl_matrix **A_Mu_MLE_i,
const gsl_matrix *M_mu_nu,
const gsl_matrix *x_mu_i );
165int main(
int argc,
char *argv[] )
170 CHAR *version_string;
173 gsl_matrix *Amp_i = NULL;
174 gsl_matrix *A_Mu_i = NULL;
175 gsl_matrix *s_mu_i = NULL;
176 gsl_matrix *n_mu_i = NULL;
177 gsl_matrix *x_mu_i = NULL;
178 gsl_matrix *x_Mu_i = NULL;
181 gsl_vector *rho2_i = NULL;
182 gsl_vector *lnL_i = NULL;
183 gsl_vector *Fstat_i = NULL;
184 gsl_vector *Bstat_i = NULL;
185 gsl_vector *Bhat_i = NULL;
192 gsl_set_error_handler_off();
215 if ( ! uvar.SignalOnly ) {
221 XLAL_CHECK_MAIN( ( gslstat = gsl_matrix_memcpy( x_mu_i, n_mu_i ) ) == 0,
XLAL_EFAILED,
"gsl_matrix_memcpy() failed): %s\n", gsl_strerror( gslstat ) );
223 XLAL_CHECK_MAIN( ( gslstat = gsl_matrix_add( x_mu_i, s_mu_i ) ) == 0,
XLAL_EFAILED,
"gsl_matrix_add() failed): %s\n", gsl_strerror( gslstat ) );
232 switch ( uvar.integrationMethod ) {
251 if ( uvar.outputStats ) {
255 XLAL_CHECK_MAIN( ( fpStat = fopen( uvar.outputStats,
"wb" ) ) != NULL,
XLAL_ESYS,
"\nError opening file '%s' for writing..\n\n", uvar.outputStats );
260 fprintf( fpStat,
"%%%% cmdline: %s\n", logstr );
262 fprintf( fpStat,
"%s\n", version_string );
265 fprintf( fpStat,
"%%%% h0Nat cosi psi phi0 n1 n2 n3 n4 rho2 lnL 2F Bstat Bhat\n" );
266 for (
i = 0;
i < Bstat_i->size;
i ++ ) {
267 fprintf( fpStat,
"%10f %10f %10f %10f %10f %10f %10f %10f %12f %12f %12f %12f %12f\n",
268 gsl_matrix_get( Amp_i,
i, 0 ),
269 gsl_matrix_get( Amp_i,
i, 1 ),
270 gsl_matrix_get( Amp_i,
i, 2 ),
271 gsl_matrix_get( Amp_i,
i, 3 ),
273 gsl_matrix_get( n_mu_i,
i, 0 ),
274 gsl_matrix_get( n_mu_i,
i, 1 ),
275 gsl_matrix_get( n_mu_i,
i, 2 ),
276 gsl_matrix_get( n_mu_i,
i, 3 ),
278 gsl_vector_get( rho2_i,
i ),
280 gsl_vector_get( lnL_i,
i ),
281 gsl_vector_get( Fstat_i,
i ),
282 gsl_vector_get( Bstat_i,
i ),
284 gsl_vector_get( Bhat_i,
i )
295 gsl_matrix_free( s_mu_i );
296 gsl_matrix_free( Amp_i );
297 gsl_matrix_free( A_Mu_i );
298 gsl_vector_free( rho2_i );
299 gsl_vector_free( lnL_i );
300 gsl_vector_free( Fstat_i );
301 gsl_matrix_free( x_mu_i );
302 gsl_matrix_free( x_Mu_i );
303 gsl_matrix_free( n_mu_i );
304 gsl_vector_free( Bstat_i );
305 gsl_vector_free( Bhat_i );
307 gsl_rng_free(
GV.
rng );
326 uvar->outputStats = NULL;
332 uvar->numMCpoints = 1e4;
334 uvar->integrationMethod = 0;
356 XLALRegisterUvarMember( integrationMethod,
INT4,
'm', OPTIONAL,
"2D Integration-method: 0=Gauss-Kronod, 1=Monte-Carlo(Vegas)" );
404 if ( ( cfg->
M_mu_nu = gsl_matrix_calloc( 4, 4 ) ) == NULL ) {
408 gsl_matrix_set( cfg->
M_mu_nu, 0, 0, uvar->A );
409 gsl_matrix_set( cfg->
M_mu_nu, 1, 1, uvar->B );
410 gsl_matrix_set( cfg->
M_mu_nu, 0, 1, uvar->C );
411 gsl_matrix_set( cfg->
M_mu_nu, 1, 0, uvar->C );
413 gsl_matrix_set( cfg->
M_mu_nu, 2, 2, uvar->A );
414 gsl_matrix_set( cfg->
M_mu_nu, 3, 3, uvar->B );
415 gsl_matrix_set( cfg->
M_mu_nu, 2, 3, uvar->C );
416 gsl_matrix_set( cfg->
M_mu_nu, 3, 2, uvar->C );
419 gsl_matrix_set( cfg->
M_mu_nu, 0, 3, uvar->E );
420 gsl_matrix_set( cfg->
M_mu_nu, 1, 2, -uvar->E );
421 gsl_matrix_set( cfg->
M_mu_nu, 3, 0, uvar->E );
422 gsl_matrix_set( cfg->
M_mu_nu, 2, 1, -uvar->E );
430 cfg->
rng = gsl_rng_alloc( gsl_rng_default );
449 const gsl_matrix *M_mu_nu,
457 REAL8 h0NatMin, h0NatMax;
471 if ( !M_mu_nu || M_mu_nu->size1 != M_mu_nu->size2 || M_mu_nu->size1 != 4 ) {
475 if ( !( numDraws > 0 ) ) {
479 if ( ( ( *A_Mu_i ) != NULL ) || ( ( *s_mu_i ) != NULL ) || ( ( *Amp_i ) != NULL ) ) {
485 if ( ( ( *A_Mu_i ) = gsl_matrix_calloc( numDraws, 4 ) ) == NULL ) {
489 if ( ( ( *s_mu_i ) = gsl_matrix_calloc( numDraws, 4 ) ) == NULL ) {
493 if ( ( ( *Amp_i ) = gsl_matrix_calloc( numDraws, 4 ) ) == NULL ) {
498 if ( ( ( *rho2_i ) = gsl_vector_calloc( numDraws ) ) == NULL ) {
510 h0NatMin = AmpRange.
h0Nat;
511 h0NatMax = h0NatMin + AmpRange.
h0NatBand;
514 for (
row = 0;
row < numDraws;
row ++ ) {
517 h0 = gsl_ran_flat( rng, h0NatMin, h0NatMax );
518 cosi = gsl_ran_flat( rng, cosiMin, cosiMax );
521 Amp.
psi = gsl_ran_flat( rng, psiMin, psiMax );
522 Amp.
phi0 = gsl_ran_flat( rng, phi0Min, phi0Max );
537 gsl_vector_view A_Mu = gsl_vector_view_array( A_Mu_data, 4 );
538 gsl_vector_view s_mu = gsl_vector_view_array( s_mu_data, 4 );
549 if ( ( gslstat = gsl_blas_dsymv( CblasUpper, 1.0, M_mu_nu, &A_Mu.vector, 0.0, &s_mu.vector ) ) ) {
555 if ( ( gslstat = gsl_blas_ddot( &A_Mu.vector, &s_mu.vector, &res_rho2 ) ) ) {
562 REAL8 rescale_h0 = SNR / sqrt( res_rho2 );
563 Amp.
aPlus *= rescale_h0;
565 res_rho2 =
SQ( SNR );
566 gsl_vector_scale( &A_Mu.vector, rescale_h0 );
567 gsl_vector_scale( &s_mu.vector, rescale_h0 );
570 gsl_vector_set( *rho2_i,
row, res_rho2 );
572 gsl_matrix_set( *Amp_i,
row, 0,
h0 );
573 gsl_matrix_set( *Amp_i,
row, 1,
cosi );
574 gsl_matrix_set( *Amp_i,
row, 2, Amp.
psi );
575 gsl_matrix_set( *Amp_i,
row, 3, Amp.
phi0 );
577 gsl_matrix_set_row( *A_Mu_i,
row, &A_Mu.vector );
578 gsl_matrix_set_row( *s_mu_i,
row, &s_mu.vector );
600 const gsl_matrix *M_mu_nu,
605 gsl_matrix *tmp, *M_chol;
611 if ( !M_mu_nu || M_mu_nu->size1 != M_mu_nu->size2 || M_mu_nu->size1 != 4 ) {
615 if ( !( numDraws > 0 ) ) {
619 if ( ( ( *n_mu_i ) != NULL ) ) {
625 if ( ( ( *n_mu_i ) = gsl_matrix_calloc( numDraws, 4 ) ) == NULL ) {
631 if ( ( M_chol = gsl_matrix_calloc( 4, 4 ) ) == NULL ) {
635 if ( ( tmp = gsl_matrix_calloc( 4, 4 ) ) == NULL ) {
639 if ( ( gslstat = gsl_matrix_memcpy( tmp, M_mu_nu ) ) ) {
643 if ( ( gslstat = gsl_linalg_cholesky_decomp( tmp ) ) ) {
649 for ( col = 0; col <=
row; col ++ ) {
650 gsl_matrix_set( M_chol,
row, col, gsl_matrix_get( tmp,
row, col ) );
654 if ( ( normal = gsl_matrix_calloc( numDraws, 4 ) ) == NULL ) {
659 for (
row = 0;
row < numDraws;
row ++ ) {
660 gsl_matrix_set( normal,
row, 0, gsl_ran_gaussian( rng, 1.0 ) );
661 gsl_matrix_set( normal,
row, 1, gsl_ran_gaussian( rng, 1.0 ) );
662 gsl_matrix_set( normal,
row, 2, gsl_ran_gaussian( rng, 1.0 ) );
663 gsl_matrix_set( normal,
row, 3, gsl_ran_gaussian( rng, 1.0 ) );
669 for (
row = 0;
row < numDraws;
row ++ ) {
670 gsl_vector_const_view normi = gsl_matrix_const_row( normal,
row );
671 gsl_vector_view ni = gsl_matrix_row( *n_mu_i,
row );
677 if ( ( gslstat = gsl_blas_dgemv( CblasNoTrans, 1.0, M_chol, &( normi.vector ), 0.0, &( ni.vector ) ) ) ) {
684 gsl_matrix_free( tmp );
685 gsl_matrix_free( M_chol );
686 gsl_matrix_free( normal );
699 const gsl_matrix *A_Mu_i,
700 const gsl_matrix *s_mu_i,
701 const gsl_matrix *x_mu_i
710 if ( ( *lnL_i ) != NULL ) {
714 if ( !A_Mu_i || !s_mu_i || !x_mu_i ) {
719 numDraws = A_Mu_i->size1;
720 if ( !( numDraws > 0 ) ) {
725 if ( ( A_Mu_i->size1 != numDraws ) || ( A_Mu_i->size2 != 4 ) ) {
729 if ( ( s_mu_i->size1 != numDraws ) || ( s_mu_i->size2 != 4 ) ) {
733 if ( ( x_mu_i->size1 != numDraws ) || ( x_mu_i->size2 != 4 ) ) {
739 if ( ( ( *lnL_i ) = gsl_vector_calloc( numDraws ) ) == NULL ) {
745 if ( ( tmp = gsl_matrix_alloc( numDraws, 4 ) ) == NULL ) {
751 gsl_matrix_memcpy( tmp, s_mu_i );
752 gsl_matrix_scale( tmp, - 0.5 );
753 gsl_matrix_add( tmp, x_mu_i );
757 for (
row = 0;
row < numDraws;
row ++ ) {
758 gsl_vector_const_view A_Mu = gsl_matrix_const_row( A_Mu_i,
row );
759 gsl_vector_const_view d_mu = gsl_matrix_const_row( tmp,
row );
764 if ( ( gslstat = gsl_blas_ddot( &A_Mu.vector, &d_mu.vector, &res_lnL ) ) ) {
769 gsl_vector_set( *lnL_i,
row, res_lnL );
774 gsl_matrix_free( tmp );
786 gsl_matrix **A_Mu_MLE_i,
787 const gsl_matrix *M_mu_nu,
788 const gsl_matrix *x_mu_i
792 gsl_permutation *perm = gsl_permutation_calloc( 4 );
793 gsl_matrix *Mmunu_LU = gsl_matrix_calloc( 4, 4 );
798 if ( !M_mu_nu || !x_mu_i ) {
802 if ( ( ( *Fstat_i ) != NULL ) ) {
807 numDraws = x_mu_i->size1;
808 if ( !( numDraws > 0 ) ) {
813 if ( ( M_mu_nu->size1 != 4 ) || ( M_mu_nu->size2 != 4 ) ) {
817 if ( ( x_mu_i->size1 != numDraws ) || ( x_mu_i->size2 != 4 ) ) {
823 if ( ( ( *Fstat_i ) = gsl_vector_calloc( numDraws ) ) == NULL ) {
827 if ( ( ( *A_Mu_MLE_i ) = gsl_matrix_calloc( numDraws, 4 ) ) == NULL ) {
832 gsl_matrix_memcpy( Mmunu_LU, M_mu_nu );
846 if ( ( gslstat = gsl_linalg_LU_decomp( Mmunu_LU, perm, &sig ) ) ) {
851 for (
row = 0;
row < numDraws;
row ++ ) {
852 gsl_vector_const_view xi = gsl_matrix_const_row( x_mu_i,
row );
853 gsl_vector_view x_Mu = gsl_matrix_row( ( *A_Mu_MLE_i ),
row );
868 if ( ( gslstat = gsl_linalg_LU_solve( Mmunu_LU, perm, &( xi.vector ), &( x_Mu.vector ) ) ) ) {
878 fprintf( stderr,
"A^mu_MLE = " );
880 fprintf( stderr,
"MLE: h0 = %g, cosi = %g, psi = %g, phi0 = %g\n",
h0,
cosi, psi,
phi0 );
890 if ( ( gslstat = gsl_blas_ddot( &( xi.vector ), &( x_Mu.vector ), &x2 ) ) ) {
896 gsl_vector_set( *Fstat_i,
row, x2 );
900 gsl_permutation_free( perm );
901 gsl_matrix_free( Mmunu_LU );
916 const gsl_matrix *M_mu_nu,
917 const gsl_matrix *x_mu_i,
922 gsl_monte_vegas_state *MCS_vegas = gsl_monte_vegas_alloc( 2 );
923 gsl_monte_function F;
929 if ( !M_mu_nu || !x_mu_i || !rng ) {
933 if ( ( ( *Bstat_i ) != NULL ) ) {
938 numDraws = x_mu_i->size1;
939 if ( !( numDraws > 0 ) ) {
944 if ( ( M_mu_nu->size1 != 4 ) || ( M_mu_nu->size2 != 4 ) ) {
948 if ( ( x_mu_i->size1 != numDraws ) || ( x_mu_i->size2 != 4 ) ) {
954 if ( ( ( *Bstat_i ) = gsl_vector_calloc( numDraws ) ) == NULL ) {
961 pars.
A = gsl_matrix_get( M_mu_nu, 0, 0 );
962 pars.
B = gsl_matrix_get( M_mu_nu, 1, 1 );
963 pars.
C = gsl_matrix_get( M_mu_nu, 0, 1 );
964 pars.
E = gsl_matrix_get( M_mu_nu, 0, 3 );
970 for (
row = 0;
row < numDraws;
row ++ ) {
971 gsl_vector_const_view xi = gsl_matrix_const_row( x_mu_i,
row );
973 double AmpLower[2], AmpUpper[2];
975 pars.
x_mu = &( xi.vector );
977 gsl_monte_vegas_init( MCS_vegas );
997 if ( ( gslstat = gsl_monte_vegas_integrate( &F, AmpLower, AmpUpper, 2, numMCpoints, rng, MCS_vegas, &Bb, &abserr ) ) ) {
1001 gsl_vector_set( *Bstat_i,
row, 2.0 *
log( Bb ) );
1005 gsl_monte_vegas_free( MCS_vegas );
1019 const gsl_matrix *M_mu_nu,
1020 const gsl_matrix *x_mu_i
1026 double epsrel = 1
e-2;
1031 gsl_integration_workspace *
w = gsl_integration_workspace_alloc( 1000 );
1034 if ( !M_mu_nu || !x_mu_i ) {
1039 if ( ( ( *Bstat_i ) != NULL ) ) {
1044 numDraws = x_mu_i->size1;
1045 if ( !( numDraws > 0 ) ) {
1050 if ( ( M_mu_nu->size1 != 4 ) || ( M_mu_nu->size2 != 4 ) ) {
1054 if ( ( x_mu_i->size1 != numDraws ) || ( x_mu_i->size2 != 4 ) ) {
1060 if ( ( ( *Bstat_i ) = gsl_vector_calloc( numDraws ) ) == NULL ) {
1066 pars.
A = gsl_matrix_get( M_mu_nu, 0, 0 );
1067 pars.
B = gsl_matrix_get( M_mu_nu, 1, 1 );
1068 pars.
C = gsl_matrix_get( M_mu_nu, 0, 1 );
1069 pars.
E = gsl_matrix_get( M_mu_nu, 0, 3 );
1074 for (
row = 0;
row < numDraws;
row ++ ) {
1075 gsl_vector_const_view xi = gsl_matrix_const_row( x_mu_i,
row );
1077 double CosiLower, CosiUpper;
1079 pars.
x_mu = &( xi.vector );
1095 if ( ( gslstat = gsl_integration_qags( &F, CosiLower, CosiUpper, epsabs, epsrel, 1000,
w, &Bb, &abserr ) ) ) {
1096 LogPrintf(
LOG_CRITICAL,
"%s: row = %d: gsl_integration_qag() failed: res=%f, abserr=%f, intervals=%zu, %s\n",
1097 __func__,
row, Bb, abserr,
w->size, gsl_strerror( gslstat ) );
1101 gsl_vector_set( *Bstat_i,
row, 2.0 *
log( Bb ) );
1105 gsl_integration_workspace_free(
w );
1125 double epsrel = 1
e-3;
1128 double PsiLower, PsiUpper;
1130 static gsl_integration_workspace *
w = NULL;
1133 w = gsl_integration_workspace_alloc( 1000 );
1154 if ( ( gslstat = gsl_integration_qags( &F, PsiLower, PsiUpper, epsabs, epsrel, 1000,
w, &ret, &abserr ) ) ) {
1155 LogPrintf(
LOG_CRITICAL,
"%s: gsl_integration_qag() failed: res=%f, abserr=%f, intervals=%zu, %s\n",
1156 __func__, ret, abserr,
w->size, gsl_strerror( gslstat ) );
1200 double x1, x2, x3, x4;
1201 double al1, al2, al3, al4;
1202 double eta, etaSQ, etaSQp1SQ;
1203 double psi, sin2psi, cos2psi, sin2psiSQ, cos2psiSQ;
1204 double gammaSQ, qSQ, Xi;
1213 x1 = gsl_vector_get(
par->x_mu, 0 );
1214 x2 = gsl_vector_get(
par->x_mu, 1 );
1215 x3 = gsl_vector_get(
par->x_mu, 2 );
1216 x4 = gsl_vector_get(
par->x_mu, 3 );
1220 etaSQp1SQ =
SQ( ( 1.0 + etaSQ ) );
1223 sin2psi = sin( 2.0 * psi );
1224 cos2psi = cos( 2.0 * psi );
1225 sin2psiSQ =
SQ( sin2psi );
1226 cos2psiSQ =
SQ( cos2psi );
1229 al1 = 0.25 * etaSQp1SQ * cos2psiSQ + etaSQ * sin2psiSQ;
1230 al2 = 0.25 * etaSQp1SQ * sin2psiSQ + etaSQ * cos2psiSQ;
1231 al3 = 0.25 *
SQ( ( 1.0 - etaSQ ) ) * sin2psi * cos2psi;
1232 al4 = 0.5 *
eta * ( 1.0 + etaSQ );
1235 gammaSQ = al1 *
par->A + al2 *
par->B + 2.0 * al3 *
par->C + 2.0 * al4 *
par->E;
1238 qSQ = al1 * (
SQ( x1 ) +
SQ( x3 ) ) + al2 * (
SQ( x2 ) +
SQ( x4 ) ) + 2.0 * al3 * ( x1 * x2 + x3 * x4 ) + 2.0 * al4 * ( x1 * x4 - x2 * x3 );
1241 Xi = 0.25 * qSQ / gammaSQ;
1243 integrand = exp( Xi );
1246 printf(
"%f %f %f %f %f\n",
eta, psi, integrand, gammaSQ, Xi );
1260 const gsl_matrix *x_mu_i
1266 if ( !M_mu_nu || !x_mu_i ) {
1270 if ( ( M_mu_nu->size1 != 4 ) || ( M_mu_nu->size2 != 4 ) ) {
1274 size_t numDraws = x_mu_i->size1;
1275 if ( ( x_mu_i->size1 != numDraws ) || ( x_mu_i->size2 != 4 ) ) {
1281 if ( ( Bhat_i = gsl_vector_calloc( numDraws ) ) == NULL ) {
1286 gsl_matrix *Mmunu_LU = gsl_matrix_calloc( 4, 4 );
1287 if ( Mmunu_LU == NULL ) {
1290 gsl_permutation *perm = gsl_permutation_calloc( 4 );
1291 if ( Mmunu_LU == NULL ) {
1295 gsl_matrix_memcpy( Mmunu_LU, M_mu_nu );
1310 if ( ( gslstat = gsl_linalg_LU_decomp( Mmunu_LU, perm, &sig ) ) ) {
1315 gsl_matrix *M_MuNu = gsl_matrix_calloc( 4, 4 );
1316 if ( M_MuNu == NULL ) {
1327 if ( ( gslstat = gsl_linalg_LU_invert( Mmunu_LU, perm, M_MuNu ) ) ) {
1332 gsl_matrix *Ah_Mu_i = gsl_matrix_calloc( 4, numDraws );
1333 if ( Ah_Mu_i == NULL ) {
1341 if ( ( gslstat = gsl_blas_dgemm( CblasNoTrans, CblasTrans, 1.0, M_MuNu, x_mu_i, 0.0, Ah_Mu_i ) ) ) {
1346 for (
UINT4 iTrial = 0; iTrial < numDraws; iTrial ++ ) {
1347 gsl_vector_const_view x_mu = gsl_matrix_const_row( x_mu_i, iTrial );
1348 gsl_vector_const_view A_Mu = gsl_matrix_const_column( Ah_Mu_i, iTrial );
1353 if ( ( gslstat = gsl_blas_ddot( &( x_mu.vector ), &( A_Mu.vector ), &TwoF ) ) ) {
1357 REAL8 Bhat = 0.5 * TwoF;
1365 gsl_vector_set( Bhat_i, iTrial, Bhat );
1370 gsl_permutation_free( perm );
1371 gsl_matrix_free( Mmunu_LU );
1372 gsl_matrix_free( M_MuNu );
1373 gsl_matrix_free( Ah_Mu_i );
1388 if ( !M_mu_nu || !A_Mu_in ) {
1392 if ( ( M_mu_nu->size1 != 4 ) || ( M_mu_nu->size2 != 4 ) ) {
1396 if ( A_Mu_in->size != 4 ) {
1402 REAL8 R_array[4 * 4] = {
1408 gsl_matrix_const_view R_mu_nu_view = gsl_matrix_const_view_array( R_array, 4, 4 );
1409 const gsl_matrix *R_mu_nu = &( R_mu_nu_view.matrix );
1412 REAL8 A1 = gsl_vector_get( A_Mu_in, 1 );
1413 REAL8 A2 = gsl_vector_get( A_Mu_in, 2 );
1414 REAL8 A3 = gsl_vector_get( A_Mu_in, 3 );
1415 REAL8 A4 = gsl_vector_get( A_Mu_in, 4 );
1417 REAL8 A_array[4] = { A1, A2, A3, A4 };
1418 REAL8 AR_array[4] = { A4, -A3, -A2, A1 };
1419 gsl_vector_view A_mu_view = gsl_vector_view_array( A_array, 4 );
1420 gsl_vector_view AR_mu_view = gsl_vector_view_array( AR_array, 4 );
1422 gsl_vector *A_mu = &( A_mu_view.vector );
1423 gsl_vector *AR_mu = &( AR_mu_view.vector );
1429 if ( ( gslstat = gsl_blas_ddot( A_mu, A_mu, &ks ) ) ) {
1433 if ( ( gslstat = gsl_blas_ddot( AR_mu, A_mu, &ka ) ) ) {
1440 REAL8 tmpV_array[4], tmpM_array [ 4 * 4 ];
1441 gsl_vector_view tmpV_view = gsl_vector_view_array( tmpV_array, 4 );
1442 gsl_matrix_view tmpM_view = gsl_matrix_view_array( tmpM_array, 4, 4 );
1443 gsl_vector *tmpV = &( tmpV_view.vector );
1444 gsl_matrix *tmpM = &( tmpM_view.matrix );
1446 REAL8 K_mu_array [4], K_mu_nu_array[4 * 4];
1447 gsl_vector_view K_mu_view = gsl_vector_view_array( K_mu_array, 4 );
1448 gsl_matrix_view K_mu_nu_view = gsl_matrix_view_array( K_mu_nu_array, 4, 4 );
1449 gsl_vector *K_mu = &( K_mu_view.vector );
1450 gsl_matrix *K_mu_nu = &( K_mu_nu_view.matrix );
1453 gsl_vector_memcpy( K_mu, A_mu );
1454 gsl_vector_scale( K_mu, 4.0 * ks );
1456 gsl_vector_memcpy( tmpV, AR_mu );
1457 gsl_vector_scale( tmpV, - 4.0 * ka );
1458 gsl_vector_add( K_mu, tmpV );
1462 gsl_matrix_set_identity( K_mu_nu );
1463 gsl_matrix_scale( K_mu_nu, 4.0 * ks );
1465 gsl_matrix_memcpy( tmpM, R_mu_nu );
1466 gsl_matrix_scale( tmpM, - 4.0 * ka );
1467 gsl_matrix_add( K_mu_nu, tmpM );
1470 gsl_matrix_const_view A_mat = gsl_matrix_const_view_vector( A_mu, 1, 4 );
1471 if ( ( gslstat = gsl_blas_dgemm( CblasTrans, CblasNoTrans, 1.0, &( A_mat.matrix ), &( A_mat.matrix ), 0.0, tmpM ) ) ) {
1474 gsl_matrix_scale( tmpM, 8.0 );
1475 gsl_matrix_add( K_mu_nu, tmpM );
1478 gsl_matrix_const_view AR_mat = gsl_matrix_const_view_vector( AR_mu, 1, 4 );
1479 if ( ( gslstat = gsl_blas_dgemm( CblasTrans, CblasNoTrans, 1.0, &( AR_mat.matrix ), &( AR_mat.matrix ), 0.0, tmpM ) ) ) {
1482 gsl_matrix_scale( tmpM, - 8.0 );
1483 gsl_matrix_add( K_mu_nu, tmpM );
1489 REAL8 a_mu_array [4], a_mu_nu_array[4 * 4];
1490 gsl_vector_view a_mu_view = gsl_vector_view_array( a_mu_array, 4 );
1491 gsl_matrix_view a_mu_nu_view = gsl_matrix_view_array( a_mu_nu_array, 4, 4 );
1492 gsl_vector *a_mu = &( a_mu_view.vector );
1493 gsl_matrix *a_mu_nu = &( a_mu_nu_view.matrix );
1496 gsl_vector_memcpy( a_mu, K_mu );
1497 gsl_vector_scale( a_mu, - 3.0 / ( 4.0 * K ) );
1499 gsl_matrix_memcpy( a_mu_nu, K_mu_nu );
1500 gsl_matrix_scale( a_mu_nu, K );
1502 gsl_matrix_const_view Kmu_mat = gsl_matrix_const_view_vector( K_mu, 1, 4 );
1503 if ( ( gslstat = gsl_blas_dgemm( CblasTrans, CblasNoTrans, 1.0, &( Kmu_mat.matrix ), &( Kmu_mat.matrix ), 0.0, tmpM ) ) ) {
1506 gsl_matrix_sub( a_mu_nu, tmpM );
1508 gsl_matrix_scale( a_mu_nu, -3.0 / ( 4.0 *
SQ( K ) ) );
1511 REAL8 N_array[4 * 4];
1512 gsl_matrix_view N_view = gsl_matrix_view_array( N_array, 4, 4 );
1513 gsl_matrix *N_mu_nu = &( N_view.matrix );
1515 gsl_matrix_memcpy( N_mu_nu, M_mu_nu );
1516 gsl_matrix_sub( N_mu_nu, a_mu_nu );
1519 REAL8 NLU_array[4 * 4];
1520 gsl_matrix_view NLU_view = gsl_matrix_view_array( NLU_array, 4, 4 );
1521 gsl_matrix *NLU_mu_nu = &( NLU_view.matrix );
1523 size_t perm_data[4];
1524 gsl_permutation perm = {4, perm_data };
1527 gsl_matrix_memcpy( NLU_mu_nu, N_mu_nu );
1528 if ( ( gslstat = gsl_linalg_LU_decomp( NLU_mu_nu, &perm, &sig ) ) ) {
1533 detN = gsl_linalg_LU_det( NLU_mu_nu, 1 );
1536 REAL8 deltaB = - 0.5 *
log( detN );
#define __func__
log an I/O error, i.e.
void LALCheckMemoryLeaks(void)
const LALVCSInfoList lalPulsarVCSInfoList
NULL-terminated list of VCS and build information for LALPulsar and its dependencies
ConfigVariables GV
global container for various derived configuration settings
#define XLAL_INIT_DECL(var,...)
char * XLALVCSInfoString(const LALVCSInfoList vcs_list, const int verbose, const char *prefix)
int XLALfprintfGSLvector(FILE *fp, const char *fmt, const gsl_vector *vect) _LAL_GCC_VPRINTF_FORMAT_(2)
void LogPrintf(LogLevel_t, const char *format,...) _LAL_GCC_PRINTF_FORMAT_(2
REAL8 PulsarAmplitudeVect[4]
Struct for 'canonical' coordinates in amplitude-params space A^mu = {A1, A2, A3, A4}.
#define XLAL_ERROR_NULL(...)
#define XLAL_CHECK(assertion,...)
#define XLAL_CHECK_MAIN(assertion,...)
#define XLAL_ERROR_MAIN(...)
p
RUN ANALYSIS SCRIPT ###.
Signal (amplitude) parameter ranges.
REAL8 h0Nat
h0 in natural units ie h0Nat = h0 * sqrt(T/Sn)
REAL8 SNR
if > 0: alternative to h0Nat/h0NatBand: fix optimal signal SNR
REAL8 h0NatBand
draw h0Nat from Band [h0Nat, h0Nat + Band ]
Configuration settings required for and defining a coherent pulsar search.
gsl_rng * rng
gsl random-number generator
AmpParamsRange_t AmpRange
signal amplitude-parameter ranges: lower bounds + bands
gsl_matrix * M_mu_nu
antenna-pattern matrix and normalization
Type containing the JKS 'amplitude parameters' {h0, cosi, phi0, psi}.
REAL8 aCross
Signal amplitude (cross)
REAL8 psi
polarization angle psi
REAL8 aPlus
Signal amplitude (plus)
REAL8 phi0
initial signal-phase (at some reference time)
double cosi
only used for inner 2D Gauss-Kronod gsl-integration: value of cosi at which to integrate over psi
int main(int argc, char *argv[])
MAIN function Generates samples of B-stat and F-stat according to their pdfs for given signal-params.
int XLALcomputeBstatisticMC(gsl_vector **Bstat, const gsl_matrix *M_mu_nu, const gsl_matrix *x_mu_i, gsl_rng *rng, UINT4 numMCpoints)
Compute the B-statistic for given input data, using Monte-Carlo integration for the marginalization o...
double BstatIntegrandInner(double psi, void *p)
log likelihood ratio lnL marginalized over {h0, phi0} (analytical) for given psi and pars->cosi Bstat...
int initUserVars(UserInput_t *uvar)
Register all our "user-variables" that can be specified from cmd-line and/or config-file.
int XLALcomputeFstatistic(gsl_vector **Fstat, gsl_matrix **A_Mu_MLE_i, const gsl_matrix *M_mu_nu, const gsl_matrix *x_mu_i)
Compute F-statistic for given input data.
int XLALcomputeBstatisticGauss(gsl_vector **Bstat, const gsl_matrix *M_mu_nu, const gsl_matrix *x_mu_i)
Compute the B-statistic for given input data, using standard Gauss-Kronod integration (gsl_integratio...
int XLALsynthesizeNoise(gsl_matrix **n_mu_i, const gsl_matrix *M_mu_nu, gsl_rng *rng, UINT4 numDraws)
Generate random-noise draws and combine with (FIXME: single!) signal.
int XLALcomputeLogLikelihood(gsl_vector **lnL, const gsl_matrix *A_Mu_i, const gsl_matrix *s_mu_i, const gsl_matrix *x_mu_i)
Compute log-likelihood function for given input data.
int vrbflg
defined in lal/lib/std/LALError.c
int InitCode(ConfigVariables *cfg, const UserInput_t *uvar)
Initialized Fstat-code: handle user-input and set everything up.
double BstatIntegrandOuter(double cosi, void *p)
log likelihood ratio lnL marginalized over {h0, phi0} (analytical) and integrated over psi in [-pi/4,...
int XLALsynthesizeSignals(gsl_matrix **A_Mu_i, gsl_matrix **s_mu_i, gsl_matrix **Amp_i, gsl_vector **rho2, const gsl_matrix *M_mu_nu, AmpParamsRange_t AmpRange, gsl_rng *rnd, UINT4 numDraws)
Generate random signal draws with uniform priors in given bands [h0, cosi, psi, phi0],...
REAL8 XLALComputeBhatCorrection(const gsl_vector *A_Mu, const gsl_matrix *M_mu_nu)
Compute 'Bstat' approximate correction terms with respect to F, ie deltaB in Bstat = F + deltaB.
double BstatIntegrand(double A[], size_t dim, void *p)
compute log likelihood ratio lnL for given Amp = {h0, cosi, psi, phi0} and M_{mu,nu}.
gsl_vector * XLALcomputeBhatStatistic(const gsl_matrix *M_mu_nu, const gsl_matrix *x_mu_i)
Compute an approximation to the full B-statistic, without using any integrations! Returns Bhat vector...