gns.samplers module

gns.samplers.applyBoundaries(livePoint, targetSupport, boundaryList)[source]

Either does nothing, reflects or wraps parameter value at its boundary (give by targetSupport) according to paramGeomList. Assumes that values in paramGeomList are sensible, i.e. if the target support is unbounded, then its value should be ‘nothing’

gns.samplers.applyBoundary(point, lower, upper, differenceCorrection, pointCorrection)[source]

give a point in or outside the domain, in case of point being in the domain it does nothing. When it is outside, it calculates a ‘distance’ from the domain according to differenceCorrection type, and then uses this ‘distance’ to transform the point into the domain by using either reflective or wrapping methods according to the value of pointCorrection. It is recommended that differenceCorrection and pointCorrection take the same values (makes most intuitive sense to me) Examples with domain of -5 to +5: wrapping (differenceCorrection == ‘wrap’ and pointCorrection == ‘wrap’): -7 -> 3 -15 -> 5 (n.b. boundaries are effectively treated as open intervals, so -5 wraps round to 5) -17 -> 3 7 -> -3 15 -> -5 17 -> -3 reflecting (differenceCorrection == ‘reflect’ and pointCorrection == ‘reflect’): -7 -> -3 -15 -> -5 -17 -> 3 7 -> 3 15 -> 5 17 -> -3

gns.samplers.calcInitTrialSig(livePoints)[source]

calculate initial standard deviation based on width of domain defined by max and min parameter values of livepoints in each dimension

gns.samplers.calcTrialLhood(trialPoint, LhoodFunc, targetSupport)[source]

Checks if trialPoint is in support of target function, if it is returns trial Lhood value. If not returns nan as Lhood value

gns.samplers.checkBoundary(trialPoint, targetSupport)[source]

Checks if each dimension of trialPoint is within bounds given by targetSupport. If any dimensions are not, returns false. Otherwise returns true

gns.samplers.getNewLiveBlind(invPriorFunc, LhoodFunc, LhoodStar, nDims)[source]

Blindly picks points isin U[0, 1]^D, converts these to physical values according to physical prior and uses as candidates for new livepoint until L > L* is found LhoodFunc can be Lhood or LLhood func, either works fine

gns.samplers.getNewLiveMH(livePointsPhys, deadIndex, priorFunc, targetSupport, LhoodFunc, LhoodStar, nDims, nonGeomList, boundaryList, circleList, torusList, sphereList, nonGeomLowerLimits, nonGeomUpperLimits, circleLowerLimits, circleUpperLimits, torusLowerLimits, torusUpperLimits, sphereLowerLimits, sphereUpperLimits)[source]

gets new livepoint using variant of MCMC MH algorithm. From current livepoints (not including one to be excluded in current NS iteration), first picks a point at random as starting point. Next the standard deviation of the trial distribution is calculated from the width of the current livepoints (including the one to be excluded) as 0.1 * [max(param_value) - min(param_value)] in each dimension. A trial distribution (CURRENTLY GAUSSIAN) is centred on the selected livepoint with the calculated variance, and the output is used as a trial point. This point is kept with probability prior(trial) / prior(previous) if L_trial > L* and rejected otherwise. Each time a trial point is proposed, nTrials is incremented. If the trial point was accepted nAccept is incremented, if not nReject is. The trial distribution is updated based on nAccept, nReject such that the acceptance rate should be roughyl 50%. Once nTrials nTrials = maxTrials, if nAccept = 0 the whole process is repeated as failure to do so will mean the returned live point is a copy of another point. If not, the new livepoint is returned. One would hope that nAccept is > 1 to ensure that the sampling space is explored uniformly. LhoodFunc can be Lhood or LLhood func, either works fine TODO: find better function of nDims from which maxTrials can be calculated

gns.samplers.modToDomainReflect(point, lower, upper)[source]

following ensures point isin [lower, upper]. This reflects according to (positive) difference between point and nearest bound and returns a ‘distance’ which can actually be used to get the correct value of the point within the domain. It makes most intuitive sense to me to use this when you want to reflect the points in the domain. Operation done to ensure reflecting is different based on whether the difference between the point and the nearest part of the domain is an odd or even (incl. 0) multiple of the boundary.

gns.samplers.modToDomainWrap(point, lower, upper)[source]
gns.samplers.pickTrial(startPoint, trialVar, targetSupport, proposalType)[source]

pick trial point based on proposalType, which currently can be multivariate normal (not truncated) or truncated multivariate normal. When truncated, the truncation in each dimension is the width of the support in that dimension, centred on the startPoint. For the dimensions where the support is unbounded, there is no truncation

gns.samplers.testTrial(trialPoint, startPoint, trialLhood, startLhood, LhoodStar, priorFunc)[source]

Check if trial point has L > L* and accept with probability prior(trial) / prior(previous)

gns.samplers.updateTrialSigma(trialSigma, nAccept, nReject, method='nothing')[source]

update standard deviation as in Sivia 2006, or do nothing. Apparently former ensures that ~50% of the points are accepted, but I’m sceptical. TODO: research new way to update trial sigma which isn’t ridiculous