Commit c9466026 authored by John Douglas Veitch's avatar John Douglas Veitch 💬
Browse files

Working XML output

Original: 4fb69c2fdfb731f32ee6a75e82b01f1d338270de
parent 65f281c1
......@@ -240,7 +240,7 @@ typedef void (LALInferenceEvolveOneStepFunction) (struct tagLALInferenceRunState
typedef void (LALInferenceAlgorithm) (struct tagLALInferenceRunState *runState);
/** Type declaration for output logging function, can be user-declared */
typedef void (LALInferenceLogOutput) (struct tagLALInferenceRunState *runState, LALInferenceVariables *vars);
typedef void (LALInferenceLogFunction) (struct tagLALInferenceRunState *runState, LALInferenceVariables *vars);
/** Structure containing inference run state
* This includes pointers to the function types required to run
......@@ -255,7 +255,7 @@ tagLALInferenceRunState
LALInferenceLikelihoodFunction *likelihood; /** The likelihood function */
LALInferenceProposalFunction *proposal; /** The proposal function */
LALInferenceTemplateFunction *template; /** The template generation function */
LALInferenceLogOutput *logsample; /** Log sample, i.e. to disk */
LALInferenceLogFunction *logsample; /** Log sample, i.e. to disk */
struct tagLALInferenceIFOData *data; /** The data from the interferometers */
LALInferenceVariables *currentParams, /** The current parameters */
*priorArgs, /** Any special arguments for the prior function */
......
......@@ -12,7 +12,9 @@
#include <lal/LALStdlib.h>
#ifdef HAVE_LIBLALXML
#include <lal/LALInferenceXML.h>
#endif
RCSID("$Id$");
#define PROGRAM_NAME "LALInferenceNestedSampler.c"
......@@ -47,9 +49,18 @@ static REAL8 mean(REAL8 *array,int N){
/** Append the sample to an array which is maintained elsewhere */
void LALInferenceLogSampleToArray(LALInferenceRunState *state, LALInferenceVariables *vars)
{
(void)state;
output_array=realloc(output_array, (N_output_array+1) *sizeof(LALInferenceVariables));
LALInferenceCopyVariables(vars,output_array[N_output_array]);
N_output_array++;
if(!output_array){
XLALPrintError("Unable to allocate array for samples\n");
XLAL_ERROR_VOID( __func__, XLAL_EFAULT );
}
else
{
memset(&(output_array[N_output_array]),0,sizeof(LALInferenceVariables));
LALInferenceCopyVariables(vars,&output_array[N_output_array]);
N_output_array++;
}
return;
}
......@@ -247,7 +258,14 @@ void LALInferenceNestedSamplingAlgorithm(LALInferenceRunState *runState)
LALInferenceVariableItem *param_ptr;
char *outVOTable=NULL;
if ( !LALInferenceCheckVariable(runState->algorithmParams, "logZnoise" ) ){
#ifdef HAVE_LIBLALXML
char *outVOTable=NULL;
runState->logsample=LALInferenceLogSampleToArray;
#else
runState->logsample=NULL;
#endif
if ( !LALInferenceCheckVariable(runState->algorithmParams, "logZnoise" ) ){
if (runState->data->modelDomain == LALINFERENCE_DOMAIN_FREQUENCY )
logZnoise=LALInferenceNullLogLikelihood(runState->data);
......@@ -287,7 +305,7 @@ void LALInferenceNestedSamplingAlgorithm(LALInferenceRunState *runState)
exit(1);
}
char *outfile=ppt->value;
#ifdef HAVE_LIBLALXML
ProcessParamsTable *ppt=LALInferenceGetProcParamVal(runState->commandLine,"--outXML");
if(!ppt){
fprintf(stderr,"Can specify --outXML <filename.dat> for VOTable output\n");
......@@ -295,7 +313,7 @@ void LALInferenceNestedSamplingAlgorithm(LALInferenceRunState *runState)
else{
outVOTable=ppt->value;
}
#endif
fpout=fopen(outfile,"w");
FILE *lout=NULL;
char param_list[FILENAME_MAX];
......@@ -366,7 +384,7 @@ void LALInferenceNestedSamplingAlgorithm(LALInferenceRunState *runState)
for(j=0;j<Nruns;j++) oldZarray[j]=logZarray[j];
/* Write out old sample */
if(runState->logOutput) runState->logOutput(runState,runState->livePoints[minpos]);
if(runState->logsample) runState->logsample(runState,runState->livePoints[minpos]);
LALInferencePrintSample(fpout,runState->livePoints[minpos]);
fprintf(fpout,"%lf\n",logLikelihoods[minpos]);
......@@ -436,7 +454,7 @@ void LALInferenceNestedSamplingAlgorithm(LALInferenceRunState *runState)
logwarray[j]+=LALInferenceNSSample_logt(Nlive,runState->GSLrandom);
logZarray[j]=logadd(logZarray[j],logLikelihoods[i]+logwarray[j]);
}
if(runState->logOutput) runState->logOutput(runState,runState->livePoints[minpos]);
if(runState->logsample) runState->logsample(runState,runState->livePoints[minpos]);
LALInferencePrintSample(fpout,runState->livePoints[i]);
fprintf(fpout,"%lf\n",logLikelihoods[i]);
}
......@@ -448,7 +466,8 @@ void LALInferenceNestedSamplingAlgorithm(LALInferenceRunState *runState)
fpout=fopen(bayesfile,"w");
fprintf(fpout,"%lf %lf %lf %lf\n",logZ-logZnoise,logZ,logZnoise,logLmax);
fclose(fpout);
#ifdef HAVE_LIBLALXML
/* Write out the XML if requested */
if(output_array && outVOTable && N_output_array>0){
xmlNodePtr votable=XLALInferenceVariablesArray2VOTTable(output_array, N_output_array);
......@@ -456,8 +475,11 @@ void LALInferenceNestedSamplingAlgorithm(LALInferenceRunState *runState)
char *xmlString = XLALCreateVOTStringFromTree ( xmlTable );
fprintf(fpout,"%s",xmlString);
fclose(fpout);
free(xmlString);
}
#endif
if(output_array) free(output_array);
}
/* Evolve nested sampling algorithm by one step, i.e.
......
......@@ -44,7 +44,7 @@
/* double logadd(double a,double b); */
/* Append sample to an array maintained elsewhere */
void LALInferenceLogSampleToArray(LALInferenceRunState *state, LALInferenceVariables *vars)
void LALInferenceLogSampleToArray(LALInferenceRunState *state, LALInferenceVariables *vars);
/** NestedSamplingAlgorithm implements the nested sampling algorithm,
see e.g. Sivia "Data Analysis: A Bayesian Tutorial, 2nd edition */
......@@ -113,5 +113,6 @@ XLALMultiStudentDeviates(REAL4Vector *vector,
UINT4 LALInferenceCheckPositiveDefinite(gsl_matrix *matrix, UINT4 dim);
void LALInferenceSetupLivePointsArray(LALInferenceRunState *runState);
#endif
......@@ -363,4 +363,4 @@ VOTABLE_DATATYPE LALInferenceVariableType2VOT(const LALInferenceVariableType lit
}
}
\ 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