Commit 44a8e824 authored by Rory Smith's avatar Rory Smith
Browse files

added a warning if bad parameter space region is sampled

Original: 3251d61814247722c93babfce8f60f4f7950347b
parent f42531d6
......@@ -122,3 +122,38 @@ def draw_N_posterior_many(datas, Nlives, Npost, logLcols=None, verbose=False):
for samp in post:
bigpos.append(samp)
return bigpos
def draw_posterior_many_ROQ_runs(datas, Nlives,logLcols=None, verbose=False):
"""Draw samples from the posteriors represented by the
(Nruns, Nsamples, Nparams)-shaped array datas from ROQ runs, each sampled with
the corresponding Nlive number of live points. First rescales evidence in each
mass prior bin then will draw without repetition,
and weight according to the evidence in each input run ala draw_posterior_many"""
# list of log_evidences, log_weights
if logLcols is None:
logLcols = [-1 for d in datas]
log_evs,log_wts=zip(*[compute_weights(data[:,logLcol],Nlive) for data,Nlive,logLcol in zip(datas, Nlives,logLcols)])
if verbose: print 'Computed log_evidences: %s'%(str(log_evs))
log_total_evidence=reduce(logaddexp, log_evs)
log_max_evidence=max(log_evs)
#print 'evidences: %s'%(str(log_evs))
fracs=[exp(log_ev-log_max_evidence) for log_ev in log_evs] #TODO: add logPriorVol from ROQ run
if verbose: print 'Relative weights of input files: %s'%(str(fracs))
Ns=[fracs[i]/len(datas[i]) for i in range(len(fracs))]
Ntot=max(Ns)
fracs=[n/Ntot for n in Ns]
if verbose: print 'Relative weights of input files taking into account their length: %s'%(str(fracs))
bigpos=[]
posts=[draw_posterior(data,logwt) for (data,logwt,logZ) in zip(datas,log_wts,log_evs)]
if verbose: print 'Number of input samples: %s'%(str([len(x) for x in log_wts]))
if verbose: print 'Expected number of samples from each input file %s'%(str([int(f*len(p)) for f,p in zip(fracs,posts)]))
for post,frac in zip(posts,fracs):
for samp in post:
if(uniform()<frac):
bigpos.append(samp)
if verbose: print 'Total number of samples produced: %i'%(len(bigpos))
return bigpos
......@@ -1010,6 +1010,7 @@ static REAL8 LALInferenceFusedFreqDomainLogLikelihood(LALInferenceVariables *cur
// the ROM breaks down for these parameter values so throw a large and negative likelihood to avoid
// strange likelihood values
loglikelihood = -1e15;
fprintf(stdout, "WARNING: sampling a bad region of parameter space; skipping\n");
}
return(loglikelihood); /* The ROQ isn't compatible with the stuff below, so we can just exit here */
......
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