12 #include <sys/times.h>
17 #include <lal/TimeDelay.h>
18 #include <lal/LALInferenceConfig.h>
19 #include <lal/LALStdlib.h>
20 #include <lal/LALInferenceNestedSampler.h>
21 #include <lal/LALInferencePrior.h>
22 #include <lal/LALInferenceLikelihood.h>
23 #include <lal/LALInferenceProposal.h>
24 #include <lal/LALInferenceReadData.h>
25 #include <lal/LALInferenceHDF5.h>
26 #include <lal/LALInferencePriorVolumes.h>
30 #define PROGRAM_NAME "LALInferenceNestedSampler.c"
31 #define CVS_ID_STRING "$Id$"
32 #define CVS_REVISION "$Revision$"
33 #define CVS_SOURCE "$Source$"
34 #define CVS_DATE "$Date$"
35 #define CVS_NAME_STRING "$Name$"
38 #define ACF_TOLERANCE 0.01
41 #define UNUSED __attribute__ ((unused))
51 typedef struct tagNSintegralState
90 s->size =
s->logZarray->length;
116 INT4 N_output_array=0;
125 struct tms tms_buffer;
126 if(times(&tms_buffer))
128 REAL8 execution_time = (
REAL8)tms_buffer.tms_utime / (
REAL8) sysconf (_SC_CLK_TCK);
129 REAL8 *prevtime=NULL;
150 if (access(
filename, F_OK)==-1)
return(0);
169 if( access(
filename, F_OK ) == -1 )
return(1);
186 printf(
"restoring nested sampling integral state\n");
189 fprintf(stderr,
"Unable to read nested sampling state - unable to resume!\n");
195 printf(
"restored %i live points\n",Nlive);
199 printf(
"restoring %i past iterations\n",N_outputarray);
206 double execution_time = 0.0;
214 printf(
"done restoring\n");
229 static void catch_interrupt(UNUSED
int sig, UNUSED siginfo_t *siginfo,UNUSED
void *context);
230 static void catch_interrupt(UNUSED
int sig, UNUSED siginfo_t *siginfo,UNUSED
void *context)
238 static void catch_alarm(UNUSED
int sig, UNUSED siginfo_t *siginfo,UNUSED
void *context);
239 static void catch_alarm(UNUSED
int sig, UNUSED siginfo_t *siginfo,UNUSED
void *context)
255 int checkpoint_time = 3600;
260 checkpoint_time = 3*3600;
266 sa.sa_flags=SA_SIGINFO;
267 sigretcode=sigaction(SIGVTALRM,&sa,NULL);
268 if(sigretcode!=0)
fprintf(stderr,
"WARNING: Cannot establish checkpoint timer!\n");
270 sigretcode=sigaction(SIGUSR2,&sa,NULL);
271 if(sigretcode!=0)
fprintf(stderr,
"WARNING: Cannot establish checkpoint on SIGUSR2.\n");
278 sigretcode=sigaction(SIGINT,&sa,NULL);
279 if(sigretcode!=0)
fprintf(stderr,
"WARNING: Cannot establish checkpoint on SIGINT.\n");
281 sigretcode=sigaction(SIGTERM,&sa,NULL);
282 if(sigretcode!=0)
fprintf(stderr,
"WARNING: Cannot establish checkpoint on SIGTERM.\n");
305 fprintf(stderr,
"Cannot take log of negative number %lf - %lf = %lf !\n",exp(
a),exp(b),exp(
a)-exp(b));
310 return a + log1p(-exp(b-
a));
326 s->oldZarray->data[
j]=
s->logZarray->data[
j];
327 Wtarray[
j]=
s->logwarray->data[
j]+logL+
logsubexp(0,
s->logt2array->data[
j] +
s->logtarray->data[
j])-log(2.0);
328 s->logZarray->data[
j]=
logaddexp(
s->logZarray->data[
j],Wtarray[
j]);
329 if(isfinite(
s->oldZarray->data[
j]) && isfinite(
s->logZarray->data[
j]))
330 s->Harray->data[
j]= exp(Wtarray[
j]-
s->logZarray->data[
j])*logL
331 + exp(
s->oldZarray->data[
j]-
s->logZarray->data[
j])*(
s->Harray->data[
j]+
s->oldZarray->data[
j])-
s->logZarray->data[
j];
332 REAL8 tmp=
s->logtarray->data[
j];
333 s->logtarray->data[
j]=
s->logt2array->data[
j];
334 s->logt2array->data[
j]=tmp;
336 s->logwarray->data[
j]+=
s->logtarray->data[
j];
339 return(
mean(
s->logZarray->data,
s->logZarray->length));
347 char tmpname[1000]=
"";
354 if(first) {
fprintf(
file,
"Adaptive proposal step sizes:\n"); first=0;}
378 if(
s->logZarray==NULL ||
s->Harray==NULL ||
s->oldZarray==NULL ||
s->logwarray==NULL)
379 {
fprintf(stderr,
"Unable to allocate RAM\n"); exit(-1);}
380 for(
UINT4 i=0;
i<Nruns;
i++) {
s->logwarray->data[
i]=logw;
s->logZarray->data[
i]=-INFINITY;
381 s->oldZarray->data[
i]=-INFINITY;
s->Harray->data[
i]=0.0;
s->logtarray->data[
i]=-1.0/Nlive;
382 s->logt2array->data[
i]=-1.0/Nlive;
390 for(
i=0;
i<
N;
i++) sum+=array[
i];
398 while((Nlive--)>1) {
a=gsl_rng_uniform(RNG); t = t>
a ? t :
a;}
413 else {
max=4*maxMCMC; }
416 if(
max>4*maxMCMC)
max=4*maxMCMC;
433 fprintf(stderr,
"Warning: Estimated chain length %i exceeds maximum %i!\n",
max,maxMCMC);
456 for(item=Live[0]->
head;item!=NULL;item=item->
next)
461 {
if(NULL==(*cvm=gsl_matrix_alloc(ND,ND))) {
fprintf(stderr,
"Unable to allocate matrix memory\n"); exit(1);}}
463 if((*cvm)->size1!=(*cvm)->size2 || (*cvm)->size1!=ND)
464 {
fprintf(stderr,
"ERROR: Matrix wrong size. Something has gone wrong in LALInferenceNScalcCVM\n");
469 for(
i=0;
i<(*cvm)->size1;
i++)
for(
j=0;
j<(*cvm)->size2;
j++) gsl_matrix_set(*cvm,
i,
j,0.0);
480 for(item=Live[0]->
head,
j=0;item;item=item->
next){
482 for(
i=0;
i<Nlive;
i++){
506 for(item=Live[0]->
head,
j=0;item;item=item->
next){
515 means[
j] = atan2(
ms[
j],
mc[
j]);
516 means[
j] = means[
j]<0? 2.0*
LAL_PI + means[
j] : means[
j];
526 j_item=k_item=Live[0]->
head;
527 for(
j=0,j_item=Live[0]->
head;j_item;j_item=j_item->
next)
532 for(k_item=Live[0]->
head,
k=0;k_item &&
k<=
j;k_item=k_item->
next)
547 jval = *(
REAL8 *)jptr - means[
j];
552 kval = *(
REAL8 *)kptr - means[
k];
554 gsl_matrix_set(*cvm,
j,
k, gsl_matrix_get(*cvm,
j,
k) + kval*jval);
564 for(
i=0;
i<ND;
i++)
for(
j=0;
j<ND;
j++) gsl_matrix_set(*cvm,
i,
j,gsl_matrix_get(*cvm,
i,
j)/((
REAL8) Nlive));
570 gsl_matrix_set(*cvm,
j,
i,gsl_matrix_get(*cvm,
i,
j));
578 ----------------------------------------------\n\
579 --- Nested Sampling Algorithm Parameters -----\n\
580 ----------------------------------------------\n\
581 --Nlive N Number of live points to use\n\
582 (--Nmcmc M) Over-ride auto chain length determination and use <M> MCMC samples\n\
583 (--maxmcmc M) Use at most M MCMC points when autodetermining the chain (5000)\n\
584 (--Nmcmcinitial M) Use M MCMC points when initially resampling from the prior\n\
585 (otherwise default is to use maxmcmc)\n\
586 (--sloppyratio S) Number of sub-samples of the prior for every sample from the\n\
588 (--Nruns R) Number of parallel samples from logt to use(1)\n\
589 (--tolerance dZ) Tolerance of nested sampling algorithm (0.1)\n\
590 (--randomseed seed) Random seed of sampling distribution\n\
591 (--prior ) Set the prior to use (InspiralNormalised,SkyLoc,malmquist)\n\
592 (default: InspiralNormalised)\n\
593 (--sampleprior N) For Testing: Draw N samples from the prior, will not perform the\n\
594 nested sampling integral\n\
595 (--progress) Output some progress information at each iteration\n\
596 (--verbose) Output more info. N=1: errors, N=2 (default): warnings, N=3: info\n\
597 (--resume) Allow non-condor checkpointing every 4 hours. If given will check \n\
598 or OUTFILE_resume and continue if possible\n\
599 (--checkpoint-exit-code N) Exit with code N when checkpoint is complete.\n\
600 For use with condor's +SuccessCheckpointExitCode option\n\
663 fprintf(stderr,
"Error, must specify number of live points\n");
675 printf(
"set number of MCMC points, over-riding auto-determination!\n");
700 printf(
"set tolerance.\n");
704 tmp=strtod(
ppt->
value,(
char **)NULL);
734 REAL8 *logZarray,*Harray,*logwarray,*logtarray;
736 REAL8 logZ,logZnew,logLmin,logLmax=-INFINITY,logLtmp,logw,
H,logZnoise,dZ=0;
739 REAL8 neginfty=-INFINITY;
741 REAL8 *logLikelihoods=NULL;
744 UINT4 displayprogress=0;
748 int CondorExitCode=0;
770 fprintf(stdout,
"Generating %i samples from the prior\n",samplePrior);
801 fprintf(stderr,
"Must specify --outfile <filename.hdf5>\n");
809 double logvolume=0.0;
827 logw=log(1.0-exp(-1.0/Nlive));
855 printf(
"Output file %s contains complete run, not over-writing\n",
outfile);
875 fprintf(stdout,
"Starting a new run.\n");
878 int sprinklewarning=0;
879 for(
i=0;
i<Nlive;
i++) {
884 runState->
evolve(runState);
886 if(!sprinklewarning &&
j++==100) {
fprintf(stderr,
"Warning: having difficulty sampling prior, check your prior bounds\n"); sprinklewarning=1;}
887 }
while(isnan(logLikelihoods[
i]) || isinf(logLikelihoods[
i]));
892 logZarray=
s->logZarray->data;
893 logtarray=
s->logtarray->data;
894 logwarray=
s->logwarray->data;
895 Harray=
s->Harray->data;
901 logLtmp=logLikelihoods[
i];
902 logLmax=logLtmp>logLmax? logLtmp : logLmax;
903 if(isnan(logLikelihoods[
i]) || isinf(logLikelihoods[
i])) {
904 fprintf(stderr,
"Detected logL[%i]=%lf! Sanity checking...\n",
i,logLikelihoods[
i]);
932 char param_list[FILENAME_MAX+16];
933 snprintf(param_list,
sizeof(param_list),
"%s_params.txt",
outfile);
934 lout=fopen(param_list,
"w");
940 fprintf(stdout,
"Starting nested sampling loop!\n");
950 for(
i=1;
i<Nlive;
i++){
951 if(logLikelihoods[
i]<logLikelihoods[minpos])
954 logLmin=logLikelihoods[minpos];
955 if(samplePrior) logLmin=-INFINITY;
959 H=
mean(Harray,Nruns);
967 while((
j=gsl_rng_uniform_int(runState->
GSLrandom,Nlive))==minpos){};
971 runState->
evolve(runState);
981 logw=
mean(logwarray,Nruns);
983 dZ=
logaddexp(logZ,logLmax-((
double) iter)/((
double)Nlive))-logZ;
985 if(displayprogress)
fprintf(stderr,
"%i: accpt: %1.3f Nmcmc: %i sub_accpt: %1.3f slpy: %2.1f%% H: %3.2lf nats logL:%.3lf ->%.3lf logZ: %.3lf deltalogLmax: %.2lf dZ: %.3lf Zratio: %.3lf \n",\
1011 exit(CondorExitCode);
1015 if(!(iter%(Nlive/10))) {
1037 while(samplePrior?((Nlive+iter)<samplePrior):( iter <= Nlive || dZ>
TOLERANCE));
1040 for(
i=0;
i<Nlive-1;
i++){
1042 logLmin=logLikelihoods[
i];
1043 for(
j=
i+1;
j<Nlive;
j++){
1044 if(logLikelihoods[
j]<logLmin)
1047 logLmin=logLikelihoods[
j];
1053 logLikelihoods[minpos]=logLikelihoods[
i];
1054 logLikelihoods[
i]=logLmin;
1057 for(
i=0;
i<Nlive;
i++){
1063 UINT4 N_output_array=0;
1070 double logB=logZ-logZnoise;
1080 for(
i=0;
i<N_output_array;
i++)
1087 char bayesfile[FILENAME_MAX+10];
1088 sprintf(bayesfile,
"%s_B.txt",
outfile);
1089 fpout=fopen(bayesfile,
"w");
1090 fprintf(fpout,
"%lf %lf %lf %lf\n",logZ-logZnoise,logZ,logZnoise,logLmax);
1104 snprintf(runID,
sizeof(runID),
"%s_%s",
"lalinference_nest",
ppt->
value);
1106 snprintf(runID,
sizeof(runID),
"lalinference_nest");
1125 struct tms tms_buffer;
1126 if(times(&tms_buffer))
1144 for(
i=0;
i<N_output_array;
i++){
1163 char chainfilename[2048]=
"";
1164 char acf_file_name[2048]=
"";
1165 FILE *chainfile=NULL;
1169 REAL8 **data_array=NULL;
1170 REAL8 **acf_array=NULL;
1173 max_iterations/=thinning;
1176 char **param_names=
XLALCalloc(nPar,
sizeof(
char *));
1205 chainfile=fopen(chainfilename,
"w");
1215 acffile=fopen(acf_file_name,
"w");
1229 while(accept==0.0 &&
i<BAILOUT);
1235 for(
i=1;
i<max_iterations;
i++)
1253 for (
i=0;
i<max_iterations;
i++){
1256 this=myCurrentParams.
head;
1259 REAL8 this_mean = gsl_stats_mean(&data_array[
i][0], 1, max_iterations);
1260 for(
j=0;
j<max_iterations;
j++) data_array[
i][
j]-=this_mean;
1266 ACF=(
REAL8) gsl_stats_correlation(&data_array[
i][0], 1, &data_array[
i][lag], 1, max_iterations-lag);
1267 if(isnan(ACF)) ACF=1.;
1268 acf_array[
i][lag]=ACF;
1270 if((ACF<
ACF_TOLERANCE && startflag) || lag==max_iterations/2-1){
1272 ACL*=(
REAL8)thinning;
1285 for(
i=0;
i<max_iterations/2;
i++){
1302 REAL8 oldLogL=-INFINITY;
1303 for(
i=stride,
j=*Ncache;
j<Nnew+*Ncache&&
i<max_iterations;
i+=stride,
j++)
1306 if(newlogL==oldLogL) {
j--;
continue;}
1308 if(!
cache)
fprintf(stderr,
"ERROR!!! Could not resize cache to %i!\n",
j+1);
1321 for (
i=0;
i<max_iterations;
i++){
1331 if(chainfile) fclose(chainfile);
1332 if(acffile) fclose(acffile);
1342 UINT4 outOfBounds=0;
1345 REAL8 logProposalRatio=0.0;
1348 memset(&proposedParams,0,
sizeof(proposedParams));
1350 REAL8 thislogL=-INFINITY;
1357 if (logLmin<thislogL) outOfBounds=0;
1362 REAL8 logPriorNew=runState->
prior(runState, &proposedParams, threadState->
model);
1363 if(isinf(logPriorNew) || isnan(logPriorNew) || log(gsl_rng_uniform(runState->
GSLrandom)) > (logPriorNew-logPriorOld) + logProposalRatio)
1376 if((!outOfBounds) && adaptProp)
1379 if(logLmin<thislogL) threadState->
accepted = accepted;
1380 else threadState->
accepted=accepted=0;
1403 UINT4 N=eigenvectors->size1;
1409 if (proposeIterator == NULL) {
1410 fprintf(stderr,
"Bad proposed params in %s, line %d\n",
1411 __FILE__, __LINE__);
1416 proposeIterator =
params->head;
1417 (*projection)->data[
i]=0.0;
1420 (*projection)->data[
i]+= *((
REAL8 *)proposeIterator->
value) * gsl_matrix_get(eigenvectors,
j,
i);
1423 }
while ((proposeIterator = proposeIterator->
next) != NULL &&
j <
N);
1436 fprintf(stderr,
"Adding cache variables in the sampler\n");
1452 REAL8 logL=-INFINITY;
1468 }
while (logL<=logLmin&&*Ncache>0);
1472 if(*Ncache==0 && logL<=logLmin)
1495 memset(&oldParams,0,
sizeof(oldParams));
1500 REAL8 sloppyfraction=maxsloppyfraction/2.0;
1501 REAL8 minsloppyfraction=0.;
1502 if(Nmcmc==1) maxsloppyfraction=minsloppyfraction=0.0;
1505 UINT4 mcmc_iter=0,Naccepted=0,sub_accepted=0;
1507 UINT4 testnumber=Nmcmc-sloppynumber;
1509 UINT4 subchain_length=(sloppynumber/testnumber) +1;
1514 UINT4 BAILOUT=100*testnumber;
1515 const char *extra_names[]={
"logL",
"optimal_snr",
"matched_filter_snr",
"deltalogL"};
1531 counter+=(1.-sloppyfraction);
1534 if(sub_accepted==0) {
1535 sub_iter+=subchain_length;
1542 sub_iter+=subchain_length;
1544 if(logLnew>logLmin || isinf(logLmin))
1559 sprintf(tmpName,
"deltalogl%s",
data->name);
1573 }
while((mcmc_iter<testnumber||threadState->currentLikelihood<=logLmin||Naccepted==0)&&(mcmc_iter<BAILOUT));
1589 sprintf(tmpName,
"deltalogl%s",
data->name);
1602 if(isfinite(logLmin)){
1603 if((
REAL8)accept_rate>Target) { sloppyfraction+=5.0/(
REAL8)Nmcmc;}
1604 else { sloppyfraction-=5.0/(
REAL8)Nmcmc;}
1605 if(sloppyfraction>maxsloppyfraction) sloppyfraction=maxsloppyfraction;
1606 if(sloppyfraction<minsloppyfraction) sloppyfraction=minsloppyfraction;
1644 fprintf(stderr,
"Unable to allocate memory for %i live points\n",Nlive);
1652 fprintf(stdout,
"Sprinkling %i live points, may take some time\n",Nlive);
1654 for(
i=0;
i<Nlive;
i++)
1665 }
while(isinf(logPrior) || isnan(logPrior));
1680 gsl_matrix *eVectors=NULL;
1681 gsl_vector *eValues =NULL;
1684 gsl_matrix **cvm=NULL;
1702 eVectors=gsl_matrix_alloc(
N,
N);
1710 gsl_matrix *covCopy = gsl_matrix_alloc(
N,
N);
1711 eValues = gsl_vector_alloc(
N);
1712 gsl_eigen_symmv_workspace *ws = gsl_eigen_symmv_alloc(
N);
1714 gsl_matrix_memcpy(covCopy, *cvm);
1716 if ((gsl_status = gsl_eigen_symmv(covCopy, eValues, eVectors, ws)) != GSL_SUCCESS) {
1717 XLALPrintError(
"Error in gsl_eigen_symmv (in %s, line %d): %d: %s\n", __FILE__, __LINE__, gsl_status, gsl_strerror(gsl_status));
1722 eigenValues->
data[
i] = gsl_vector_get(eValues,
i);
1731 gsl_matrix_free(covCopy);
1732 gsl_vector_free(eValues);
1733 gsl_eigen_symmv_free(ws);
struct tagLALH5File LALH5File
struct tagLALH5Dataset LALH5Dataset
LALH5File * LALInferenceH5CreateGroupStructure(LALH5File *h5file, const char *codename, const char *runID)
Create a HDF5 heirarchy in the given LALH5File reference /codename/runID/ Returns a LALH5File pointer...
int LALInferenceCheckNonEmptyFile(char *filename)
Returns 1 if a non-empty file exists, 0 otherwise.
int LALInferencePrintCheckpointFileInfo(char *filename)
Prints the size of the file.
int LALInferenceH5DatasetToVariablesArray(LALH5Dataset *dataset, LALInferenceVariables ***varsArray, UINT4 *N)
int LALInferenceH5VariablesArrayToDataset(LALH5File *h5file, LALInferenceVariables *const *const varsArray, UINT4 N, const char *TableName)
const char LALInferenceHDF5NestedSamplesDatasetName[]
static int WriteNSCheckPointH5(char *filename, LALInferenceRunState *runState, NSintegralState *s)
static int ReadNSCheckPointH5(char *filename, LALInferenceRunState *runState, NSintegralState *s)
static void catch_interrupt(UNUSED int sig, UNUSED siginfo_t *siginfo, UNUSED void *context)
static NSintegralState * initNSintegralState(UINT4 Nruns, UINT4 Nlive)
static int __chainfile_iter
static REAL8 mean(REAL8 *array, int N)
static void catch_alarm(UNUSED int sig, UNUSED siginfo_t *siginfo, UNUSED void *context)
static REAL8 incrementEvidenceSamples(gsl_rng *GSLrandom, UINT4 Nlive, REAL8 logL, NSintegralState *s)
Update the internal state of the integrator after receiving the lowest logL value logL.
static void printAdaptiveJumpSizes(FILE *file, LALInferenceThreadState *threadState)
static UINT4 UpdateNMCMC(LALInferenceRunState *runState)
static double logsubexp(double a, double b)
static int syncLivePointsDifferentialPoints(LALInferenceRunState *state, LALInferenceThreadState *thread)
Sync the live points to the differential evolution buffer.
static int _loadNSintegralStateH5(LALH5File *group, NSintegralState *s)
static volatile sig_atomic_t __ns_saveStateFlag
static void install_resume_handler(int checkpoint_exit)
Install the signal handlers for checkpointing.
static volatile sig_atomic_t __ns_exitFlag
static struct itimerval checkpoint_timer
static REAL8 LALInferenceNSSample_logt(int Nlive, gsl_rng *RNG)
static void LALInferenceNScalcCVM(gsl_matrix **cvm, LALInferenceVariables **Live, UINT4 Nlive)
Calculate covariance matrix from a collection of live points.
static void SetupEigenProposals(LALInferenceRunState *runState)
static int _saveNSintegralStateH5(LALH5File *group, NSintegralState *s)
Utility functions for the resume functionality.
static int CheckOutputFileContents(char *filename)
double LALInferenceMassDistancePriorVolume(LALInferenceRunState *state)
REAL8Vector * XLALH5FileReadREAL8Vector(LALH5File *file, const char *name)
int XLALH5FileWriteREAL8Vector(LALH5File *file, const char *name, REAL8Vector *vector)
void XLALH5FileClose(LALH5File UNUSED *file)
void XLALH5DatasetFree(LALH5Dataset UNUSED *dset)
LALH5File * XLALH5GroupOpen(LALH5File UNUSED *file, const char UNUSED *name)
int XLALH5FileQueryScalarAttributeValue(void UNUSED *value, LALH5File UNUSED *file, const char UNUSED *key)
int XLALH5FileAddScalarAttribute(LALH5File UNUSED *file, const char UNUSED *key, const void UNUSED *value, LALTYPECODE UNUSED dtype)
LALH5File * XLALH5FileOpen(const char UNUSED *path, const char UNUSED *mode)
int XLALH5FileAddStringAttribute(LALH5File UNUSED *file, const char UNUSED *key, const char UNUSED *value)
LALH5Dataset * XLALH5DatasetRead(LALH5File UNUSED *file, const char UNUSED *name)
REAL8 LALInferenceAngularDistance(REAL8 a1, REAL8 a2)
Calculate shortest angular distance between a1 and a2 (modulo 2PI)
void LALInferencePrintSample(FILE *fp, LALInferenceVariables *sample)
Output the sample to file *fp, in ASCII format.
int LALInferenceFprintParameterHeaders(FILE *out, LALInferenceVariables *params)
Print the parameter names to a file as a tab-separated ASCII line.
void LALInferenceAddVariable(LALInferenceVariables *vars, const char *name, const void *value, LALInferenceVariableType type, LALInferenceParamVaryType vary)
Add a variable named name to vars with initial value referenced by value.
REAL8 LALInferenceGetREAL8Variable(LALInferenceVariables *vars, const char *name)
void LALInferenceRemoveVariable(LALInferenceVariables *vars, const char *name)
Remove name from vars Frees the memory for the name structure and its contents.
void LALInferenceCopyVariables(LALInferenceVariables *origin, LALInferenceVariables *target)
Deep copy the variables from one to another LALInferenceVariables structure.
INT4 LALInferenceGetINT4Variable(LALInferenceVariables *vars, const char *name)
int LALInferencePrintProposalStatsHeader(FILE *fp, LALInferenceProposalCycle *cycle)
Output proposal statistics header to file *fp.
void LALInferencePrintProposalStats(FILE *fp, LALInferenceProposalCycle *cycle)
Output proposal statistics to file *fp.
void LALInferenceClearVariables(LALInferenceVariables *vars)
Delete the variables in this structure.
void LALInferenceSortVariablesByName(LALInferenceVariables *vars)
Sorts the variable structure by name.
ProcessParamsTable * LALInferenceGetProcParamVal(ProcessParamsTable *procparams, const char *name)
Returns the element of the process params table with "name".
void * LALInferenceGetVariable(const LALInferenceVariables *vars, const char *name)
Return a pointer to the memory the variable vars is stored in specified by name User must cast this p...
INT4 LALInferenceSanityCheck(LALInferenceRunState *state)
Sanity check the structures in the given state.
INT4(* LALInferenceEvolveOneStepFunction)(struct tagLALInferenceRunState *runState)
Perform one step of an algorithm, replaces runState ->currentParams.
void LALInferenceLogSampleToArray(LALInferenceVariables *algorithmParams, LALInferenceVariables *vars)
Append the sample to an array which can be later processed by the user.
int LALInferenceCheckVariable(LALInferenceVariables *vars, const char *name)
Checks for name being present in vars returns 1(==true) or 0.
char * LALInferencePrintCommandLine(ProcessParamsTable *procparams)
Output the command line based on the ProcessParamsTable procparams.
void LALInferenceSetVariable(LALInferenceVariables *vars, const char *name, const void *value)
Set a variable named name in vars with a value.
@ LALINFERENCE_PARAM_OUTPUT
A parameter that never changes, functions should respect this.
@ LALINFERENCE_PARAM_FIXED
A parameter that is cyclic, such as an angle between 0 and 2pi.
@ LALINFERENCE_PARAM_CIRCULAR
A parameter that simply has a maximum and a minimum.
@ LALINFERENCE_PARAM_LINEAR
@ LALINFERENCE_REAL8Vector_t
@ LALINFERENCE_void_ptr_t
@ LALINFERENCE_gslMatrix_t
REAL8 LALInferenceNullLogLikelihood(LALInferenceIFOData *data)
Identical to LALInferenceFreqDomainNullLogLikelihood, but returns the likelihood of a null template.
void LALInferenceNestedSamplingAlgorithm(LALInferenceRunState *runState)
NestedSamplingAlgorithm implements the nested sampling algorithm, see e.g.
LALInferenceVariables * LALInferenceComputeAutoCorrelation(LALInferenceRunState *runState, UINT4 max_iterations, LALInferenceEvolveOneStepFunction evolve)
Compute the autocorrelation length from the sampler at the current global iteration.
INT4 LALInferenceNestedSamplingOneStep(LALInferenceRunState *runState)
A single iteration of the NS algorithm.
void LALInferenceSetupLivePointsArray(LALInferenceRunState *runState)
Setup the live points by calling runState->initVariables on each of them if it is specified.
INT4 LALInferenceNestedSamplingSloppySample(LALInferenceRunState *runState)
Sample the limited prior distribution using the MCMC method as usual, but run a sub-chain of x iterat...
INT4 LALInferenceNestedSamplingCachedSampler(LALInferenceRunState *runState)
void LALInferenceNestedSamplingAlgorithmInit(LALInferenceRunState *runState)
Initialise the nested sampling algorithm by reading from the commandLine and setting up algorithmPara...
UINT4 LALInferenceMCMCSamplePriorNTimes(LALInferenceRunState *runState, UINT4 N)
Sample the prior N times, returns number of acceptances.
void LALInferenceProjectSampleOntoEigenvectors(LALInferenceVariables *params, gsl_matrix *eigenvectors, REAL8Vector **projection)
Project the sample in params onto the eigenvectors given in eigenvectors.
UINT4 LALInferenceMCMCSamplePrior(LALInferenceRunState *runState)
Perform one MCMC iteration on runState->currentParams.
void LALInferenceDrawFromPrior(LALInferenceVariables *output, LALInferenceVariables *priorArgs, gsl_rng *rdm)
Draw variables from the prior ranges.
void LALInferenceUpdateAdaptiveJumps(LALInferenceThreadState *thread, REAL8 targetAcceptance)
Update the adaptive proposal.
void LALInferenceTrackProposalAcceptance(LALInferenceThreadState *thread)
Update proposal statistics if tracking.
void LALInferenceSetupClusteredKDEProposalFromDEBuffer(LALInferenceThreadState *thread)
Setup a clustered-KDE proposal from the differential evolution buffer.
void LALInferenceZeroProposalStats(LALInferenceProposalCycle *cycle)
REAL8 LALInferenceCyclicProposal(LALInferenceThreadState *thread, LALInferenceVariables *currentParams, LALInferenceVariables *proposedParams)
Proposes a jump from the next proposal in the proposal cycle.
LALInferenceVariables * LALInferencePrintInjectionSample(LALInferenceRunState *runState)
Function to output a sample with logL values etc for the injection, if one is made.
void * XLALCalloc(size_t m, size_t n)
void * XLALMalloc(size_t n)
void * XLALRealloc(void *p, size_t n)
REAL8Vector * XLALCreateREAL8Vector(UINT4 length)
#define XLAL_ERROR_VOID(...)
const char * XLALErrorString(int errnum)
#define XLAL_TRY(statement, errnum)
int XLALPrintError(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
int int XLALPrintWarning(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
int XLALPrintProgressBar(double)
#define XLAL_IS_REAL8_FAIL_NAN(val)
static double logaddexp(double x, double y)
Structure to contain IFO data.
REAL8 * ifo_loglikelihoods
Network SNR at params
Structure containing inference run state This includes pointers to the function types required to run...
ProcessParamsTable * commandLine
LALInferenceVariables * proposalArgs
The data from the interferometers.
LALInferenceVariables * algorithmParams
Any special arguments for the prior function.
struct tagLALInferenceIFOData * data
Log sample, i.e.
LALInferenceVariables * priorArgs
Common arguments needed by proposals, to be copied to thread->cycle.
LALInferenceThreadState * threads
LALInferenceAlgorithm algorithm
A function that returns a new set of variables for the model.
LALInferenceEvolveOneStepFunction evolve
The algorithm function.
LALInferencePriorFunction prior
The algorithm's single iteration function.
LALInferenceLogFunction logsample
The likelihood function.
LALInferenceVariables ** livePoints
Parameters which control the running of the algorithm.
LALInferenceLikelihoodFunction likelihood
MultiNest prior for the parameters.
Structure containing chain-specific variables.
LALInferenceVariables * currentParams
Prior boundaries, etc.
LALInferenceModel * model
Cycle of proposals to call.
INT4 accepted
This should be removed, can be given as an algorithmParams entry.
size_t differentialPointsLength
Array of points for differential evolution.
LALInferenceProposalFunction proposal
Step counter for this thread.
LALInferenceProposalCycle * cycle
The proposal cycle.
LALInferenceVariables * proposalArgs
size_t differentialPointsSkip
Size of the differentialPoints memory block (must be >= length of differential points).
LALInferenceVariables ** differentialPoints
Parameters proposed.
The LALInferenceVariableItem list node structure This should only be accessed using the accessor func...
LALInferenceVariableType type
struct tagVariableItem * next
LALInferenceParamVaryType vary
The LALInferenceVariables structure to contain a set of parameters Implemented as a linked list of LA...
LALInferenceVariableItem * head
structure holding internal state of the NS integrator
CHAR value[LIGOMETA_VALUE_MAX]