Commit 08845948 authored by Marcella Wijngaarden's avatar Marcella Wijngaarden
Browse files

Cleanup unused code in BayesCBC + headers + inj option

parent b7c87abc
This diff is collapsed.
......@@ -50,7 +50,6 @@ struct bayesCBC
int debug; // if > 0, prints debug statements in BayesCBCs
int verbose; // set by --verbose flag
// Maybe want to move this here too?
struct Net *net;
double **D;
double ***global;
......@@ -116,13 +115,8 @@ void initialize_net(struct Net *net, double Tobs, double ttrig, int Ndet, char *
void burnin_bayescbc(int N, double Tobs, double ttrig, double **D, double **SN, gsl_rng *r, char *xml_file_path, int start_at_injection, struct bayesCBC *rundata);
void set_bayescbc_priors(struct Net *net, struct bayesCBC *rundata);
void CBC_initialize(struct Net *net, int *mxc, FILE *chainS, double **paramx, double **skyx, double **pallx, int *who, double *heat, double ***history, double ***global, RealVector *freq, double **D, double **SN, int N, double Tobs, double ttrig, gsl_rng *r, char *xml_file_path, int start_at_injection, struct bayesCBC *rundata);
void MCMC_all(struct Net *net, int *mxc, int M, FILE *chain, double **paramx, int *who, double *heat, double ***history, double ***global, RealVector *freq, double **D, double **SN, int N, double Tobs, double ttrig, gsl_rng *r, int istart, struct bayesCBC *rundata);
void BayesCBC_MCMC(int M, int N, double Tobs, double ttrig, gsl_rng *r, int istart, struct bayesCBC *rundata, int ic, double *amphase);
void MCMC_all_wrapper(int M, int N, double Tobs, double ttrig, gsl_rng *r, int istart, struct bayesCBC *rundata);
void cbcGeoTemplate(struct bayesCBC *rundata, int ic, int N, double **template);
void projectCBCWaveform(double *AmpPhase, int N, int NI, double fmin, double Tobs, double *extParams, double **response, double *dtimes, double *Fplus, double *Fcross);
void print_projected_cbc_waveform(double **SN, double Tobs, double ttrig, double **projected, double **data, int N, int iter, struct bayesCBC *rundata);
......
......@@ -773,6 +773,7 @@ void dshifts(struct Net *net, double *sky, double *params, int NX, struct bayesC
{
ecc = 2.0*sky[3]/(1.0+sky[3]*sky[3]);
ComputeDetFant(net, sky[2], sky[0], sky[1], &Fplus[id], &Fcross[id], net->labels[id], rundata->gmst);
F[id] = sqrt(Fplus[id]*Fplus[id]+ecc*ecc*Fcross[id]*Fcross[id]);
lambda[id] = atan2(ecc*Fcross[id],Fplus[id]);
if(lambda[id] < 0.0) lambda[id] += TPI;
......@@ -964,6 +965,105 @@ void skylikesetup(struct Net *net, double **data, double **wave, double *D, dou
}
void FisherEvec(double **fish, double *ej, double **ev, int d)
{
int i, j, ec, sc;
double x, maxc;
// printf("Evec\n");
/*
printf("\n");
for (i = 0 ; i < d ; i++)
{
for (j = 0 ; j < d ; j++)
{
printf("%e ", fish[i][j]);
}
printf("\n");
} */
ec = 0;
for (i = 0 ; i < d ; i++) if(fabs(fish[i][i]) < 1.0e-16) ec = 1;
if(ec == 0)
{
gsl_matrix *m = gsl_matrix_alloc (d, d);
for (i = 0 ; i < d ; i++)
{
for (j = 0 ; j < d ; j++)
{
gsl_matrix_set(m, i, j, fish[i][j]);
}
}
gsl_vector *eval = gsl_vector_alloc (d);
gsl_matrix *evec = gsl_matrix_alloc (d, d);
gsl_eigen_symmv_workspace * w =
gsl_eigen_symmv_alloc (d);
ec = gsl_eigen_symmv (m, eval, evec, w);
gsl_eigen_symmv_free (w);
sc = gsl_eigen_symmv_sort (eval, evec, GSL_EIGEN_SORT_ABS_ASC);
for (i = 0; i < d; i++)
{
ej[i] = gsl_vector_get (eval, i);
//printf("eigenvalue = %g\n", ej[i]);
for (j = 0 ; j < d ; j++)
{
ev[i][j] = gsl_matrix_get(evec, j, i);
//printf("%f ", ev[i][j]);
}
//printf("\n");
}
for (i = 0; i < d; i++)
{
// make sure no eigenvalue is too small
if(ej[i] < 10.0) ej[i] = 10.0;
// turn into 1-sigma jump amplitudes
ej[i] = 1.0/sqrt(ej[i]);
//printf("jump %d = %g\n", i, ej[i]);
}
gsl_matrix_free (m);
gsl_vector_free (eval);
gsl_matrix_free (evec);
}
else
{
for (i = 0; i < d; i++)
{
ej[i] = 10000.0;
for (j = 0 ; j < d ; j++)
{
ev[i][j] = 0.0;
if(i==j) ev[i][j] = 1.0;
}
}
}
return;
}
void fisherskysetup(struct Net *net, double **wave, double **HH, double Tobs, int n)
{
double f;
......@@ -997,6 +1097,26 @@ void fisherskysetup(struct Net *net, double **wave, double **HH, double Tobs, in
}
void fisher_skyproposal(gsl_rng * r, double **skyvecs, double *skyevals, double *jump, struct bayesCBC *rundata)
{
int i, j, k;
int a;
double scale, x;
int NS = rundata->NS;
// pick eigenvector to jump along
a = (int)(gsl_rng_uniform(r)*(double)(NS));
// set size of jump
scale = gsl_ran_gaussian(r,1.0)*skyevals[a];
//decompose eigenjumps into parameter directions
for (j=0; j<NS; j++) jump[j] = scale*skyvecs[a][j];
}
// finds the extrinsic parameters at the new sky location that preserve the waveforms
void skymap(struct Net *net, double *paramsx, double *paramsy, int ifo1, int ifo2, int iref, double gmst)
{
......@@ -1350,6 +1470,7 @@ double log_likelihood_full(struct Net *net, double **D, double *params, RealVect
}
// Projection expects epsilon (temporarily convert)
sky[3] = 2*ciota/(1+ciota*ciota);
// Compute template with current parameters
......@@ -1369,6 +1490,7 @@ double log_likelihood_full(struct Net *net, double **D, double *params, RealVect
rundata->detLogL[id] = logLdet;
}
// Set sky back to inclination instead of epsilon
sky[3] = ciota;
free_double_matrix(twave,net->Nifo);
......@@ -1410,7 +1532,6 @@ void ComputeDetFant(struct Net *net, double psi, double alpha, double sindelta,
{
int i, j;
REAL4 response[3][3];
double Fplus_temp, Fcross_temp;
for(i=0; i<3; i++)
{
......@@ -1418,9 +1539,6 @@ void ComputeDetFant(struct Net *net, double psi, double alpha, double sindelta,
}
XLALComputeDetAMResponse(Fplus, Fcross, (const REAL4(*)[3])response, alpha, asin(sindelta), psi, gmst);
// printf("0 - ComputeDetFant Fplus %f Fcross %f\n", Fplus, Fcross);
// F_ant(psi, alpha, sindelta, &Fplus_temp, &Fcross_temp, net->labels[id], gmst);
// printf("1 - ComputeDetFant Fplus %f Fcross %f\n", Fplus_temp, Fcross_temp);
}
......
......@@ -96,7 +96,6 @@ double DL_fit(double z);
double z_DL(double DL);
void pairs(struct Net *net);
void F_ant(double psi, double alpha, double sindelta, double *Fplus, double *Fcross, int id, double gmst);
void pbt_shift(double *corr, double *corrf, double *data1, double *data2, double *Sn, int imin, int imax, int N);
double fourier_nwip_cbc(double *a, double *b, double *Sn, int imin, int imax, int N);
......@@ -133,13 +132,6 @@ double skydensity_all(double *paramsx, double *paramsy, int ifo1, int ifo2, int
void skymap_all(double *paramsx, double *paramsy, int ifo1, int ifo2, int NX, double gmst);
double det(double *A, int N);
void Times(double alpha, double sindelta, double *dtimes, double gmst);
void F_LHO(double psi, double alpha, double sindelta, double *Fplus, double *Fcross, double gmst);
void F_LLO(double psi, double alpha, double sindelta, double *Fplus, double *Fcross, double gmst);
void F_VIRGO(double psi, double alpha, double sindelta, double *Fplus, double *Fcross, double gmst);
void skystart(struct Net *net, double *params, double *sky, double *pall, double *SNRsq, RealVector *freq, double **D, double **SN, int N, double Tobs, gsl_rng * r, struct bayesCBC *rundata);
void uvwz(double *u, double *v, double *w, double *z, double *params);
void exsolve(double *phiy, double *psiy, double *Ay, double *ey, double uy, double vy, double wy, double zy);
......@@ -174,14 +166,10 @@ double globe(double ***global, double *max, double *min, double Tobs, double *pa
void CBC_start(struct Net *net, int *mxc, FILE *chainI, double **paramx, double **skyx, double **pallx, double *heat, double ***history, double ***global, RealVector *freq, double **D, double **SN, int N, double Tobs, gsl_rng *r, struct bayesCBC *rundata);
void CBC_update(struct Net *net, int *mxc, FILE *chainI, FILE *chainE, double **paramx, double **skyx, double **pallx, int *who, double *heat, double ***history, double ***global, RealVector *freq, double **D, double **SN, int N, double Tobs, gsl_rng *r, struct bayesCBC *rundata);
void MCMC_intrinsic(struct Net *net, int lmax, int *mxc, int M, FILE *chain, double **paramx, double **skyx, double **pallx, int *who, double *heat, double ***history, double ***global, RealVector *freq, double **D, double **SN, int N, double Tobs, gsl_rng *r, struct bayesCBC *rundata);
void updatei(int k, struct Net *net, int lmax, double *logLx, double **paramx, double **paramy, double *min, double *max, double *Fscale, int *who, double *heat, double ***history, double ***global, RealVector *freq, double **D, double **SN, double **ejump, double ***evec, int N, double Tobs, int **cv, int **av, gsl_rng *r, struct bayesCBC *rundata);
void update(int k, struct Net *net, double *logLx, double *logPx, double **rhox, double **paramx, double **paramy, double *min, double *max, int *who, double *heat, double ***history, double ***global, RealVector *freq, double **D, double **SN, double **ejump, double ***evec, int N, double Tobs, int **cv, int **av, gsl_rng *r, int *evolveparams, struct bayesCBC *rundata);
void update_chain(int k, struct Net *net, double *logLx, double *rhox, double *paramx, double *paramy, double *min, double *max, double heat, double **history, double ***global, RealVector *freq, double **D, double **SN, double *ejump, double **evec, int N, double Tobs, int *cv, int *av, gsl_rng *r, int *evolveparams, struct bayesCBC *rundata);
void LambdaTsEta2Lambdas(double lambdaT, double dLambdaT, double eta, double *lambda1, double *lambda2);
......
......@@ -1249,7 +1249,6 @@ void print_help_message(void)
fprintf(stdout," --noPSDfit keep PSD parameters fixed\n");
fprintf(stdout," --bayesLine use BayesLine for PSD model\n");
fprintf(stdout," --stochastic use stochastic background model\n");
fprintf(stdout," --bayesCBC use BayesCBC to model inspiral\n");
fprintf(stdout," --bayesCBC-tidal specify BayesCBC waveform used: NRTidal_V or NoNRT_V (default)) (\n");
fprintf(stdout," --bayesCBC-skip-ext skip BayesCBC extrinsic burnin (\n");
fprintf(stdout,"\n");
......
......@@ -973,6 +973,11 @@ void print_cbc_run_stats(FILE *fptr, struct Data *data, struct bayesCBC *bayescb
else fprintf(fptr, "CBC only");
fprintf(fptr, "\n");
fprintf(fptr, " start at injection params ");
if(bayescbc->injectionStartFlag == 1) fprintf(fptr,"ENABLED");
else fprintf(fptr, "DISABLED");
fprintf(fptr, "\n");
fprintf(fptr, " evolve extrinsic/sky in burnin ");
if(bayescbc->intrinsic_only == 0 && data->skyFixFlag == 0) fprintf(fptr,"ENABLED");
else fprintf(fptr, "DISABLED");
......
......@@ -925,6 +925,7 @@ double EvaluateExtrinsicSearchLogLikelihood(struct Network *projection, double *
double logL = 0.0;
double dt=0,dphi=0,dA=1;
double **h, **d, **r, **t, **c;
double *dtimes;
if(extrinsic_checkrange(params)) return -1.0e60;
......@@ -951,7 +952,10 @@ double EvaluateExtrinsicSearchLogLikelihood(struct Network *projection, double *
//compute instrument response from cbc waveform at geocenter with extrinsic params
if(data->cbcFlag)
{
projectCBCWaveform(amphase, N, NI, fmin, data->Tobs, params, c, projection->dtimes, projection->Fplus, projection->Fcross);
dtimes = double_vector(NI);
for(ifo=0; ifo<NI; ifo++) dtimes[ifo] = -1*projection->dtimes[ifo];
projectCBCWaveform(amphase, N, NI, fmin, data->Tobs, params, c, dtimes, projection->Fplus, projection->Fcross);
free_double_vector(dtimes);
}
//Form up residual
......@@ -998,7 +1002,11 @@ double EvaluateExtrinsicSearchLogLikelihood(struct Network *projection, double *
// compute instrument response from cbc waveform at geocenter with extrinsic params
if(data->cbcFlag)
{
projectCBCWaveform(amphase, N, NI, fmin, data->Tobs, params, c, projection->dtimes, projection->Fplus, projection->Fcross);
dtimes = double_vector(NI);
for(ifo=0; ifo<NI; ifo++) dtimes[ifo] = -1*projection->dtimes[ifo];
projectCBCWaveform(amphase, N, NI, fmin, data->Tobs, params, c, dtimes, projection->Fplus, projection->Fcross);
free_double_vector(dtimes);
}
//Form up residual
......
......@@ -1256,7 +1256,11 @@ void RJMCMC(struct Data *data, struct Model **model, struct BayesLineParams ***b
fprintf(stdout, " Start #1 intrinsic burnin \n");
bayescbc->chainS = fopen("chains/cbc_searchchain.dat","w");
bayescbc->gmst = XLALGreenwichMeanSiderealTime(&data->epoch);
burnin_bayescbc(data->N, data->Tobs, data->trigtime, bayescbc->D, bayescbc->SN, chain->seed, filename, 0, bayescbc);
burnin_bayescbc(
data->N, data->Tobs, data->trigtime, bayescbc->D, bayescbc->SN,
chain->seed, LALInferenceGetProcParamVal(data->commandLine,"--inj")->value,
bayescbc->injectionStartFlag, bayescbc
);
// Quick search to find initial signal extrinisc parameters
......@@ -1268,6 +1272,7 @@ void RJMCMC(struct Data *data, struct Model **model, struct BayesLineParams ***b
extrinsic_burnin_cbc(bayescbc, data, model, chain);
}
fclose(bayescbc->chainS);
// Pass updated cbc parameters to model
for(ic=0; ic<chain->NC; ic++)
{
......@@ -1276,7 +1281,7 @@ void RJMCMC(struct Data *data, struct Model **model, struct BayesLineParams ***b
model[chain->index[ic]]->cbcParams[i] = bayescbc->pallx[chain->index[ic]][i];
}
if (bayescbc->intrinsic_only == 0)
if ((bayescbc->intrinsic_only == 0 && data->skyFixFlag == 0)||bayescbc->injectionStartFlag==1)
{
// Pass extrinsic parameters from BW model to BayesCBC
for(i = bayescbc->NX; i < bayescbc->NP; i++)
......@@ -2657,7 +2662,7 @@ void EvolveBayesCBCParameters(struct Data *data, struct Model **model, struct ba
free_double_vector(dtimes);
// Save 200 waveforms temporarily for checking residuals + template
//if (ic==0 && bayescbc->debug == 1 && chain->mc%(chain->count/200)==0) print_projected_cbc_waveform(bayescbc->SN, data->Tobs, data->trigtime, model_x->cbctemplate, bayescbc->D, N, bayescbc->mxc[0], bayescbc);
if (ic==0 && bayescbc->debug == 1 && chain->mc<=200) print_projected_cbc_waveform(bayescbc->SN, data->Tobs, data->trigtime, model_x->cbctemplate, bayescbc->D, N, bayescbc->mxc[0], bayescbc);
// Recompute likelihoods of current chain
model_x->logLnorm = 0.0;
......
......@@ -1182,10 +1182,21 @@ void initialize_bayescbc(struct bayesCBC *bayescbc, struct Data *data, struct Ch
// bayescbc->ladder = 1.05; // temperature ladder
}
// Reference frequency
if(LALInferenceGetProcParamVal(data->commandLine, "--inj-fref"))
{
bayescbc->fref =atof(LALInferenceGetProcParamVal(data->commandLine, "--inj-fref")->value);
}
else bayescbc->fref = 100.0;
// Start from injection parameters instead of global inits
if(LALInferenceGetProcParamVal(data->commandLine, "--cbc-start-inj")) bayescbc->injectionStartFlag = 1;
else bayescbc->injectionStartFlag = 0;
// Handle injection settings (TODO!)
if(LALInferenceGetProcParamVal(data->commandLine, "--inj"))
{
bayescbc->injectionStartFlag = 1;
sprintf(command, LALInferenceGetProcParamVal(data->commandLine,"--inj")->value);
// If injecting tidal parameters, read values from command line and setup version + sampler type
......
#define _fref 100.0 // reference freqency for PhenomD waveform
#define _DLmax 1.0e10 // Maximum distance in pc
#define _DLmin 1.0e6 // Minimum distance in pc
#define _chi1min -1.0 // Min/max for chi1 and chi2
#define _chi1max 1.0
#define _chi2min -1.0
#define _chi2max 1.0
#define _lambda1min 0.0 // Min/max for lambda1 and lambda2
#define _lambda1max 1000.0 // Only used if NRTidal_value != NoNRT_V and
#define _lambda2min 0.0 // lambda_type_value = lambda
#define _lambda2max 1000.0
#define _lambdaTmin 0.0 // Min/max for lambdaT and dlambdaT
#define _lambdaTmax 1000.0 // Only used if NRTidal_value != NoNRT_V and
#define _dlambdaTmin -0.1 // lambda_type_value = lambdaTilde
#define _dlambdaTmax 0.1
// Mc = Mt * eta^3/5. For eta=1/4 Mc = 0.43527528 Mt. No limit on how small Mc can be if we allow arbitrary q's
// Using q = 10 as the maximum mass ratio we have eta_min = 0.082644628 and Mc = 0.22404 Mt
#define _mcmax 174.0 // maximum chirp mass in Msun. Mc is at most 0.435 times Mt
#define _mcmin 0.23 // minimum chirp mass in Msun
#define _mtmax 400.0 // maximum total mass in Msun (should be not more than 2.3 times mcmax)
#define _mtmin 1.0 // minimum total mass in Msun
// Initial parameter values, the initial values should be in the prior range (there is no check implemented for this yet)
// If fix_initial_params is true, the initial intrinsic signal search is skipped and
// these values are used to start the full MCMC with (for all chains).
#define fix_initial_params false // set to true to start MCMC from fixed initial params (skipping initial search for signal)
#define search_t0 true
#define init_Mc 23.461761368 // DF chirp mass in solar mass units
#define init_q 1.5 // Mass ratio m1/m2 (! currently in BayesCBC it expects q>1.)
#define init_chi1 0.0 // Spin 1 (spin1z)
#define init_chi2 0.0021086903 // Spin 2 (spin2z)
#define init_phi0 0.0 // Phi0 geocenter GW phase (so actually 2x phi0 orbital)
#define init_tpeak 0.0 // Peak time geocenter
#define init_distance 300.0e6 // Distance in pc
#define _init_tidal1 600.0 // Value for lamda1 if lambda_type_value = lambda, lamdaT if lambda_type_value = lambdaTilde
#define _init_tidal2 0.0 // Value for lamda2 if lambda_type_value = lambda, dlamdaT if lambda_type_value = lambdaTilde
#define longitude 2.3521039
#define latitude -0.53280266
#define polarization 0.83545494
#define inclination 0.28047446
// XML Injection from BayesWave settings
#define start_at_xml_injection false // If fix_initial_params, fix inital parameters at values from XML injection file
#define xml_injection_path "../BBH_injections_1214683196_300Mpc.xml"
// If use_injection_data, use data paths set below. This expects the injection
// files + PSDs given by BayesWave.
#define use_injection_data false
#define H1_data "../injected_colored_waveform_H1.dat"
#define L1_data "../injected_colored_waveform_L1.dat"
#define H1_PSD "../H1_fairdraw_psd.dat"
#define L1_PSD "../L1_fairdraw_psd.dat"
#define _intrinsic_only false
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment