Gitlab will migrate to a new storage backend starting 0300 UTC on 2020-04-04. We do not anticipate a maintenance window for this migration. Performance may be impacted over the weekend. Thanks for your patience.

Commit 968b4191 authored by Ben Farr's avatar Ben Farr

change some mallocs to callocs in KDE proposal construction

Original: 6d0cdc527a102fed43e9b73498392ccf4a8bb847
parent e2206422
......@@ -834,14 +834,19 @@ LALInferenceKmeans *LALInferenceKmeansExtractCluster(LALInferenceKmeans *kmeans,
* Impose boundaries on individual KDEs.
*
* Draw samples from each cluster. If too many samples lie outside of the
* prior, impose a cyclic/reflective bound for the offending parameter(s).
* If boundaries aren't incountered, box in the cluster using the samples
* drawn. This avoids needing to evaluate KDEs that are too far away.
* prior, impose a cyclic/reflective bound for the offending parameter(s) if
* requested. If boundaries aren't incountered, box in the cluster using the
* samples drawn. This avoids needing to evaluate KDEs that are too far away.
* @param[in] kmeans kmeans to cycle through the clusters of.
* @param[in] params Parameters to impose bounds on.
* @param[in] priorArgs Variables containing prior boundaries.
* @param[in] cyclic_reflective Flag to check for cyclic/reflective bounds
*
*/
void LALInferenceKmeansImposeBounds(LALInferenceKmeans *kmeans,
LALInferenceVariables *params,
LALInferenceVariables *priorArgs) {
LALInferenceVariables *priorArgs,
INT4 cyclic_reflective) {
INT4 i, p, dim;
INT4 n_below, n_above;
INT4 ndraws, n_thresh;
......@@ -894,7 +899,7 @@ void LALInferenceKmeansImposeBounds(LALInferenceKmeans *kmeans,
drawn_max = draw;
}
if (n_below > n_thresh) {
if (cyclic_reflective && n_below > n_thresh) {
/* Impose cyclic boundaries on both sides */
if (param->vary == LALINFERENCE_PARAM_CIRCULAR) {
kmeans->KDEs[c]->lower_bound_types[p] = param->vary;
......@@ -907,7 +912,7 @@ void LALInferenceKmeansImposeBounds(LALInferenceKmeans *kmeans,
kmeans->KDEs[c]->lower_bound_types[p] = LALINFERENCE_PARAM_FIXED;
}
if (n_above > n_thresh) {
if (cyclic_reflective && n_above > n_thresh) {
/* Impose cyclic boundaries on both sides */
if (param->vary == LALINFERENCE_PARAM_CIRCULAR) {
kmeans->KDEs[c]->lower_bound_types[p] = param->vary;
......
......@@ -107,7 +107,7 @@ void LALInferenceKmeansConstructMask(LALInferenceKmeans *kmeans, INT4 *mask, INT
LALInferenceKmeans *LALInferenceKmeansExtractCluster(LALInferenceKmeans *kmeans, INT4 cluster_id);
/* Impose boundaries on KDEs. */
void LALInferenceKmeansImposeBounds(LALInferenceKmeans *kmeans, LALInferenceVariables *params, LALInferenceVariables *priorArgs);
void LALInferenceKmeansImposeBounds(LALInferenceKmeans *kmeans, LALInferenceVariables *params, LALInferenceVariables *priorArgs, INT4 cyclic_reflective);
/* Generate a new matrix by masking an existing one. */
gsl_matrix *mask_data(gsl_matrix *data, INT4 *mask);
......
......@@ -3477,7 +3477,7 @@ void LALInferenceSetupClusteredKDEProposalsFromFile(LALInferenceRunState *runSta
ptmcmc = 1;
}
LALInferenceClusteredKDE *kde = XLALMalloc(sizeof(LALInferenceClusteredKDE));
LALInferenceClusteredKDE *kde = XLALCalloc(1, sizeof(LALInferenceClusteredKDE));
weight = weights[i];
if (nBurnins > 0)
......@@ -3488,7 +3488,7 @@ void LALInferenceSetupClusteredKDEProposalsFromFile(LALInferenceRunState *runSta
char *infilename = command->value;
FILE *input = fopen(infilename, "r");
char *propName = XLALMalloc(512*sizeof(char));
char *propName = XLALCalloc(512, sizeof(char));
sprintf(propName, "%s_%s", clusteredKDEProposalName, infilename);
INT4 nInSamps;
......@@ -3505,7 +3505,7 @@ void LALInferenceSetupClusteredKDEProposalsFromFile(LALInferenceRunState *runSta
/* Only cluster parameters that are being sampled */
INT4 nValidCols=0;
INT4 *validCols = XLALMalloc(nCols * sizeof(INT4));
INT4 *validCols = XLALCalloc(nCols, sizeof(INT4));
for (j=0; j<nCols; j++)
validCols[j] = 0;
......@@ -3516,7 +3516,7 @@ void LALInferenceSetupClusteredKDEProposalsFromFile(LALInferenceRunState *runSta
continue;
}
char* internal_param_name = XLALMalloc(512*sizeof(char));
char* internal_param_name = XLALCalloc(512, sizeof(char));
LALInferenceTranslateExternalToInternalParamName(internal_param_name, params[j]);
for (item = runState->currentParams->head; item; item = item->next) {
......@@ -3549,7 +3549,7 @@ void LALInferenceSetupClusteredKDEProposalsFromFile(LALInferenceRunState *runSta
INT4 acl = (INT4)LALInferenceComputeMaxAutoCorrLen(sampleArray, nInSamps, nValidCols);
if (acl < 1) acl = 1;
INT4 downsampled_size = ceil((REAL8)nInSamps/acl);
REAL8 *downsampled_array = (REAL8 *)XLALMalloc(downsampled_size * nValidCols * sizeof(REAL8));
REAL8 *downsampled_array = (REAL8 *)XLALCalloc(downsampled_size * nValidCols, sizeof(REAL8));
printf("Chain %i downsampling to achieve %i samples.\n", chain, downsampled_size);
for (k=0; k < downsampled_size; k++) {
for (j=0; j < nValidCols; j++)
......@@ -3624,7 +3624,7 @@ void LALInferenceInitClusteredKDEProposal(LALInferenceRunState *runState, LALInf
kde->next = NULL;
/* Selectivey impose bounds on KDEs */
LALInferenceKmeansImposeBounds(kde->kmeans, params, runState->priorArgs);
LALInferenceKmeansImposeBounds(kde->kmeans, params, runState->priorArgs, 0);
/* Print out clustered samples, assignments, and PDF values if requested */
if (LALInferenceGetProcParamVal(runState->commandLine,"--cluster-verbose")) {
......@@ -3811,8 +3811,8 @@ void LALInferenceSetupClusteredKDEProposalFromDEBuffer(LALInferenceRunState *run
/* Get points to be clustered from the differential evolution buffer. */
INT4 nPar = LALInferenceGetVariableDimensionNonFixed(runState->currentParams);
REAL8** DEsamples = (REAL8**) XLALMalloc(nPoints * sizeof(REAL8*));
REAL8* temp = (REAL8*) XLALMalloc(nPoints * nPar * sizeof(REAL8));
REAL8** DEsamples = (REAL8**) XLALCalloc(nPoints, sizeof(REAL8*));
REAL8* temp = (REAL8*) XLALCalloc(nPoints * nPar, sizeof(REAL8));
for (i=0; i < nPoints; i++)
DEsamples[i] = temp + (i*nPar);
......@@ -3838,7 +3838,7 @@ void LALInferenceSetupClusteredKDEProposalFromDEBuffer(LALInferenceRunState *run
* @param ntrials Number of tirals at fixed-k to find optimal BIC
*/
void LALInferenceSetupClusteredKDEProposalFromRun(LALInferenceRunState *runState, REAL8 *samples, INT4 size, INT4 ntrials) {
LALInferenceClusteredKDE *proposal = XLALMalloc(sizeof(LALInferenceClusteredKDE));
LALInferenceClusteredKDE *proposal = XLALCalloc(1, sizeof(LALInferenceClusteredKDE));
REAL8 weight=2.;
/* Keep track of clustered parameter names */
......@@ -3944,7 +3944,7 @@ REAL8 LALInferenceStoredClusterKDEProposal(LALInferenceRunState *runState, LALIn
}
/* Draw a sample and fill the proposedParams variable with the parameters described by the KDE */
REAL8 *current = XLALMalloc(kde->dimension * sizeof(REAL8));
REAL8 *current = XLALCalloc(1, kde->dimension * sizeof(REAL8));
REAL8 *proposed = LALInferenceKmeansDraw(kde->kmeans);
INT4 i=0;
......@@ -4005,8 +4005,8 @@ void LALInferenceComputeMaxAutoCorrLenFromDE(LALInferenceRunState *runState, INT
Nskip = *(INT4*) LALInferenceGetVariable(runState->algorithmParams, "Nskip");
/* Prepare 2D array for DE points */
DEarray = (REAL8**) XLALMalloc(nPoints * sizeof(REAL8*));
temp = (REAL8*) XLALMalloc(nPoints * nPar * sizeof(REAL8));
DEarray = (REAL8**) XLALCalloc(nPoints, sizeof(REAL8*));
temp = (REAL8*) XLALCalloc(nPoints * nPar, sizeof(REAL8));
for (i=0; i < nPoints; i++)
DEarray[i] = temp + (i*nPar);
......
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