25#include <lal/LALInference.h>
27#include <lal/LALInferencePrior.h>
28#include <lal/LALInferenceProposal.h>
29#include <lal/LALInferenceLikelihood.h>
30#include <lal/LALInferenceReadData.h>
31#include <lal/LALInferenceInit.h>
32#include <lal/LALInferenceCalibrationErrors.h>
57 MPI_Bcast(&randomseed, 1, MPI_INT, 0, MPI_COMM_WORLD);
61 printf(
" initialize(): random seed: %u\n", randomseed);
67 for (
i = 0;
i < mpi_rank;
i++)
68 randomseed = gsl_rng_get(run_state->
GSLrandom);
70 gsl_rng_set(run_state->
GSLrandom, randomseed);
79 REAL8 *sampleArray = NULL;
92 INT4 mpi_rank, walker;
93 MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
98 FILE *input = fopen(infile,
"r");
108 INT4 nvalid_cols=0,
j=0;
111 for (
j = 0;
j < ncols;
j++) {
112 char* internal_pname =
XLALCalloc(512,
sizeof(
char));
118 for (item = current_param->
head; item; item = item->
next) {
121 if (!strcmp(item->
name, internal_pname)) {
122 col_order[
i] = nvalid_cols;
135 if (nvalid_cols != ndim) {
136 fprintf(stderr,
"Inconsistent dimensions for starting state!\n");
137 fprintf(stderr,
"Sampling in %i dimensions, %i read from file!\n",
143 INT4 ch, nsamples = 0;
144 while ( nsamples < mpi_rank*nwalkers_per_thread &&
145 (ch = getc(input)) != EOF) {
150 INT4 nlines = (
INT4) nwalkers_per_thread;
157 for (walker=0; walker<run_state->
nthreads; walker++) {
158 thread = &run_state->
threads[walker];
160 for (
i = 0;
i < ndim;
i++)
161 parameters[
i] = sampleArray[mpi_rank*nwalkers_per_thread*ndim + walker*ndim + col_order[
i]];
179 printf(
"Distributing ensemble according to prior.\n");
184 printf(
"Completed prior sampling.\n");
188 #pragma omp parallel for
189 for (walker = 0; walker < nwalkers_per_thread; walker++)
190 thread = &run_state->
threads[walker];
203 ----------------------------------------------\n\
204 --- General Algorithm Parameters -------------\n\
205 ----------------------------------------------\n\
206 (--nwalkers n) Number of MCMC walkers to sample with (1000).\n\
207 (--nsteps n) Total number of steps for all walkers to make (10000).\n\
208 (--skip n) Number of steps between writing samples to file (100).\n\
209 (--update-interval n) Number of steps between ensemble updates (100).\n\
210 (--randomseed seed) Random seed of sampling distribution (random).\n\
212 ----------------------------------------------\n\
213 --- Output -----------------------------------\n\
214 ----------------------------------------------\n\
215 (--data-dump) Output waveforms to file.\n\
216 (--outfile file) Write output files <file>.<chain_number>\n\
217 (ensemble.output.<random_seed>.<mpi_thread>).\n";
218 INT4 mpi_rank, mpi_size,
i;
222 MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
223 MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
242 INT4 nwalkers = 1000;
243 INT4 nwalkers_per_thread = nwalkers;
247 nwalkers_per_thread = nwalkers / mpi_size;
249 if (nwalkers % mpi_size != 0.0) {
251 nwalkers_per_thread = (
INT4)ceil((
REAL8)nwalkers / (
REAL8)mpi_size);
252 nwalkers = mpi_size * nwalkers_per_thread;
255 printf(
"Rounding up number of walkers to %i to provide \
256 consistent performance across the %i available \
257 MPI threads.\n", nwalkers, mpi_size);
277 INT4 update_interval = 1000;
283 INT4 cyclic_reflective = 0;
285 cyclic_reflective = 1;
339 thread->
id = mpi_rank*nwalkers_per_thread +
i;
349 INT4 update_interval, nprior_steps, nsteps;
358 nprior_steps = 2 * update_interval - 1;
374int main(
int argc,
char *argv[]){
381 MPI_Init(&argc, &argv);
382 MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
385 printf(
" ========== lalinference_kombine ==========\n");
397 if (run_state == NULL) {
399 fprintf(stderr,
"run_state not allocated (%s, line %d).\n",
426 if (run_state == NULL)
436 printf(
" ========== sampling complete ==========\n");
ProcessParamsTable * LALInferenceParseCommandLine(int argc, char *argv[])
void LALInferenceApplyCalibrationErrors(LALInferenceIFOData *IFOdata, ProcessParamsTable *commandLine)
LALInferenceRunState * LALInferenceInitRunState(ProcessParamsTable *command_line)
void LALInferenceInitCBCThreads(LALInferenceRunState *run_state, INT4 nthreads)
void LALInferenceDrawThreads(LALInferenceRunState *run_state)
int main(int argc, char *argv[])
INT4 on_your_marks(LALInferenceRunState *run_state)
INT4 sample_prior(LALInferenceRunState *run_state)
INT4 init_ensemble(LALInferenceRunState *run_state)
INT4 init_mpi_randomstate(LALInferenceRunState *run_state)
void ensemble_sampler(struct tagLALInferenceRunState *run_state)
Ensemble Markov-Chain Monte Carlo sampler written for LALInference.
REAL8 LALInferenceZeroLogLikelihood(LALInferenceVariables *currentParams, LALInferenceIFOData UNUSED *data, LALInferenceModel UNUSED *model)
For testing purposes (for instance sampling the prior), likelihood that returns 0....
void LALInferenceInjectInspiralSignal(LALInferenceIFOData *IFOdata, ProcessParamsTable *commandLine)
void LALInferenceReadAsciiHeader(FILE *input, char params[][VARNAME_MAX], INT4 *nCols)
Read column names from an ASCII file.
INT4 LALInferenceGetVariableDimensionNonFixed(LALInferenceVariables *vars)
Get number of dimensions in vars which are not fixed to a certain value.
INT4 LALInferenceGetINT4Variable(LALInferenceVariables *vars, const char *name)
ProcessParamsTable * LALInferenceGetProcParamVal(ProcessParamsTable *procparams, const char *name)
Returns the element of the process params table with "name".
void LALInferenceAddINT4Variable(LALInferenceVariables *vars, const char *name, INT4 value, LALInferenceParamVaryType vary)
REAL8 * LALInferenceParseDelimitedAscii(FILE *input, INT4 nCols, INT4 *wantedCols, INT4 *nLines)
Utility for readling in delimited ASCII files.
void LALInferenceCopyArrayToVariables(REAL8 *origin, LALInferenceVariables *target)
void LALInferenceTranslateExternalToInternalParamName(char *outName, const char *inName)
Converts between externally used parameter names and those internal.
void LALInferenceSetVariable(LALInferenceVariables *vars, const char *name, const void *value)
Set a variable named name in vars with a value.
int LALInferenceCheckVariableNonFixed(LALInferenceVariables *vars, const char *name)
Checks for name being present in vars and having type LINEAR or CIRCULAR.
@ LALINFERENCE_PARAM_OUTPUT
A parameter that never changes, functions should respect this.
void LALInferenceInitLikelihood(LALInferenceRunState *runState)
Initialisation function which reads runState->commaneLine and sets up the likelihood function accordi...
void LALInferenceInitCBCPrior(LALInferenceRunState *runState)
Initialize the prior based on command line arguments.
LALInferenceVariables * LALInferenceParseProposalArgs(LALInferenceRunState *runState)
Go through all logic for deciding proposals to use.
void * XLALCalloc(size_t m, size_t n)
Structure to contain IFO data.
Structure containing inference run state This includes pointers to the function types required to run...
ProcessParamsTable * commandLine
LALInferenceVariables * algorithmParams
Any special arguments for the prior function.
INT4 nthreads
Array of live points for Nested Sampling.
struct tagLALInferenceIFOData * data
Log sample, i.e.
LALInferenceThreadState * threads
LALInferenceAlgorithm algorithm
A function that returns a new set of variables for the model.
LALInferenceLikelihoodFunction likelihood
MultiNest prior for the parameters.
Structure containing chain-specific variables.
LALInferenceVariables * currentParams
Prior boundaries, etc.
LALInferenceModel * model
Cycle of proposals to call.
LALInferenceVariables * proposalArgs
The LALInferenceVariableItem list node structure This should only be accessed using the accessor func...
struct tagVariableItem * next
The LALInferenceVariables structure to contain a set of parameters Implemented as a linked list of LA...
LALInferenceVariableItem * head
CHAR value[LIGOMETA_VALUE_MAX]