24#include <lal/LALInferencePrior.h>
25#include <lal/LALInference.h>
26#include <lal/XLALError.h>
57 printf(
"Test results: %i failure(s).\n", failureCount);
86 TEST_FAIL(
"Null reference check failed.");
88 strcpy(massRatioName,
"foo");
91 TEST_FAIL(
"Invalid mass ratio name specified but appropriate error not generated.");
93 strcpy(massRatioName,
"q");
103 TEST_FAIL(
"Unphysical masses given but appropriate error not generated.");
117 TEST_FAIL(
"Null reference check failed.");
135 TEST_FAIL(
"Psi in [0,2pi] but phi0 has changed!");
145 TEST_FAIL(
"Psi outside [0,2pi] but phi0 not rotated by 2pi!");
153 TEST_FAIL(
"Psi outside [0,2pi] but phi0 not rotated by 2pi!");
163 TEST_FAIL(
"Psi on boundary of [0,2pi] but phi0 has changed!");
171 TEST_FAIL(
"Psi on boundary of [0,2pi] but phi0 has changed!");
205 TEST_FAIL(
"Null reference check failed.");
210 a_delta = a_max - a_min;
213 b_delta = b_max - b_min;
220 a = a_min + (a_max - a_min) / 2;
221 b = b_min + (b_max - b_min) / 2;
228 TEST_FAIL(
"Values within bounds should remain unchanged.");
243 TEST_FAIL(
"Circular boundary values should remain equal modulo their period.");
258 TEST_FAIL(
"Linear boundary values should remain unchanged.");
262 a = a_min - a_delta / 3;
267 a = a_max + a_delta / 3;
273 TEST_FAIL(
"Circular values outside range should be correctly modded into range.");
277 b = b_min - 10 * b_delta / 3;
282 b = b_max + 7 * b_delta / 5;
288 TEST_FAIL(
"Linear values outside range should be correctly reflected into range.");
301 gsl_rng *rng = gsl_rng_alloc(gsl_rng_default);
316 TEST_FAIL(
"Null reference check failed.");
319 const char *varyName=NULL;
323 for (
i = 0;
i < 2;
i++)
333 varyName =
"circular";
336 sprintf(caseTag,
"[%s] ", varyName);
358 TEST_FAIL(
"%sGaussian variable with zero standard deviation did not match the mean; X = %f, mu = %f.", caseTag, gaussian,
mu);
383 REAL8 correlated = 0;
386 gsl_matrix *covariance = gsl_matrix_calloc(3, 3);
391 gsl_matrix_set(covariance, 0, 0, -1);
394 TEST_FAIL(
"%sNon-positive-definite covariance matrix was not rejected.", caseTag);
398 covariance = gsl_matrix_calloc(3, 3);
399 gsl_matrix_set(covariance, 0, 0, 1);
402 TEST_FAIL(
"%sCould not add semi-positive-definite covariance matrix.", caseTag);
406 covariance = gsl_matrix_calloc(3, 3);
407 gsl_matrix_set(covariance, 0, 0, 2);
408 gsl_matrix_set(covariance, 0, 1, 1);
409 gsl_matrix_set(covariance, 0, 2, 0);
410 gsl_matrix_set(covariance, 1, 0, 1);
411 gsl_matrix_set(covariance, 1, 1, 5);
412 gsl_matrix_set(covariance, 1, 2, 1);
413 gsl_matrix_set(covariance, 2, 0, 0);
414 gsl_matrix_set(covariance, 2, 1, 1);
415 gsl_matrix_set(covariance, 2, 2, 1);
418 TEST_FAIL(
"%sCould not add correlated prior.", caseTag);
421 TEST_FAIL(
"%sCould not generate correlated variable from positive-definite matrix; XLAL error: %s.", caseTag,
XLALErrorString(errnum));
462 TEST_FAIL(
"Null reference check failed.");
479 min = 1.0;
max = 100.0;
481 min = log(min);
max = log(
max);
483 min = 1.0;
max = 20.5;
485 min = log(min);
max = log(
max);
487 min = 1.0;
max = 30.0;
502 min = 0.01;
max = 0.25;
506 gsl_rng *rng = gsl_rng_alloc(gsl_rng_default);
517 else if (isinf(result))
519 TEST_FAIL(
"Parameter configuration within specified min/max bounds for each parameter gave zero prior.");
524 value =
max + (
max - min) / 2;
531 else if (isfinite(result))
533 TEST_FAIL(
"Distance %f is outside [%f,%f] but prior is non-zero.", value, min,
max);
545 REAL8 Mc = pow(
m1 *
m2, 3.0 / 5.0) / pow(
m1 +
m2, 1.0 / 5.0);
547 REAL8 logMc = log(Mc);
554 else if (isfinite(result))
556 TEST_FAIL(
"Mass ratio %f and chirp mass %f define masses outside bounds [%f,%f], but prior is non-zero.",
eta, Mc, min,
max);
596 if(
eta>0.0 && eta<=0.25 && iota>=0.0 && iota<=LAL_PI && phi>=0.0 && phi<=
LAL_TWOPI
597 && ra>=0.0 && ra<=LAL_TWOPI && dec>=-
LAL_PI_2 && dec<=LAL_PI_2 && psi>=0.0 && psi<=
LAL_PI)
600 logdensity = -HUGE_VAL;
623 if ((A>0.0) & (
Omega>0))
626 logdensity = -HUGE_VAL;
int LALInferenceInspiralPriorTest(void)
REAL8 BasicUniformLALPrior(LALInferenceRunState *runState, LALInferenceVariables *params)
int LALInferenceRotateInitialPhaseTest(void)
int LALInferenceCyclicReflectiveBoundTest(void)
int computePriorMassNormTest(void)
REAL8 ASinOmegaTPrior(LALInferenceRunState *runState, LALInferenceVariables *params)
int LALInferenceDrawFromPriorTest(void)
LALInferenceVariables variables
int compareFloats(REAL8 x, REAL8 y, REAL8 epsilon)
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.
void LALInferenceRemoveVariable(LALInferenceVariables *vars, const char *name)
Remove name from vars Frees the memory for the name structure and its contents.
LALInferenceParamVaryType
An enumerated type for denoting the topology of a parameter.
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...
LALInferenceThreadState * LALInferenceInitThread(LALInferenceThreadState *thread)
Structure to contain data-related Reduced Order Quadrature quantities.
LALInferenceVariableType
An enumerated type for denoting the type of a variable.
void LALInferenceSetVariable(LALInferenceVariables *vars, const char *name, const void *value)
Set a variable named name in vars with a value.
@ LALINFERENCE_PARAM_CIRCULAR
A parameter that simply has a maximum and a minimum.
@ LALINFERENCE_PARAM_LINEAR
void LALInferenceRemoveCorrelatedPrior(LALInferenceVariables *priorArgs)
Remove the correlation coefficient matrix and index for a parameter from the priorArgs list.
void LALInferenceAddGaussianPrior(LALInferenceVariables *priorArgs, const char *name, REAL8 *mu, REAL8 *sigma, LALInferenceVariableType type)
Function to add the mu and sigma values for the Gaussian prior onto the priorArgs.
REAL8 LALInferenceComputePriorMassNorm(const double MMin, const double MMax, const double MTotMax, const double McMin, const double McMax, const double massRatioMin, const double massRatioMax, const char *massRatioName)
Computes the numerical normalization of the mass prior applying all cuts in the mass plane implied b...
REAL8 LALInferenceInspiralPrior(LALInferenceRunState *runState, LALInferenceVariables *params, LALInferenceModel *model)
Return the logarithmic prior density of the variables specified, for the non-spinning/spinning inspir...
void LALInferenceAddMinMaxPrior(LALInferenceVariables *priorArgs, const char *name, REAL8 *min, REAL8 *max, LALInferenceVariableType type)
Function to add the minimum and maximum values for the uniform prior onto the priorArgs.
void LALInferenceRemoveMinMaxPrior(LALInferenceVariables *priorArgs, const char *name)
Function to remove the minimum and maximum values for the uniform prior onto the priorArgs.
void LALInferenceRemoveGaussianPrior(LALInferenceVariables *priorArgs, const char *name)
Function to remove the mu and sigma values for the Gaussian prior onto the priorArgs.
void LALInferenceCyclicReflectiveBound(LALInferenceVariables *parameter, LALInferenceVariables *priorArgs)
Apply cyclic and reflective boundaries to parameter to bring it back within the allowed prior ranges ...
void LALInferenceRotateInitialPhase(LALInferenceVariables *parameter)
Rotate initial phase if polarisation angle is cyclic around ranges.
void LALInferenceDrawFromPrior(LALInferenceVariables *output, LALInferenceVariables *priorArgs, gsl_rng *rdm)
Draw variables from the prior ranges.
void LALInferenceGetMinMaxPrior(LALInferenceVariables *priorArgs, const char *name, REAL8 *min, REAL8 *max)
Get the minimum and maximum values of the uniform prior from the priorArgs list, given a name.
void LALInferenceAddCorrelatedPrior(LALInferenceVariables *priorArgs, const char *name, gsl_matrix **cor, REAL8 *mu, REAL8 *sigma, UINT4 *idx)
Function to add a correlation matrix and parameter index for a prior defined as part of a multivariat...
void * XLALCalloc(size_t m, size_t n)
const char * XLALErrorString(int errnum)
#define XLAL_TRY(statement, errnum)
#define XLAL_IS_REAL8_FAIL_NAN(val)
def Omega(v, m1, m2, S1, S2, Ln)
Preccesion frequency spins Eqs.
Structure containing inference run state This includes pointers to the function types required to run...
LALInferenceVariables * priorArgs
Common arguments needed by proposals, to be copied to thread->cycle.
LALInferenceThreadState * threads
Structure containing chain-specific variables.
LALInferenceModel * model
Cycle of proposals to call.
The LALInferenceVariables structure to contain a set of parameters Implemented as a linked list of LA...