Fork me on GitHub

pyhrf.jde.samplerbase module

exception pyhrf.jde.samplerbase.DuplicateVariableException(vName, v)

Bases: exceptions.Exception

class pyhrf.jde.samplerbase.GSDefaultCallbackHandler

Bases: pyhrf.xmlio.Initable

Class handling default action after Gibbs Sampling step (nothing). Should be inherited to define more specialized actions (such as plotting and reporting).

callback(it, vars, samplerEngine)

Execute action to be made after each Gibbs Sampling step (here : nothing). Should be overriden to define more specialized actions. @param it: the number of iterations elapsed in the current sampling process. @param samplerEngine: the parent gibbs sampler object @param vars: variables envolved in the sampling process (list of C{GibbsSamplerVariable} whose index is defined in L{samplerEngine})

class pyhrf.jde.samplerbase.GSPrintCallbackHandler(pace)

Bases: pyhrf.jde.samplerbase.GSDefaultCallbackHandler

Class defining behaviour after each Gibbs Sampling step : printing reports to stdout.

callback(it, variables, samplerEngine)

Execute action to be made after each Gibbs Sampling step (here : nothing). Should be overriden to define more specialized actions. @param it: the number of iterations elapsed in the current sampling process. @param samplerEngine: the parent gibbs sampler object @param vars: variables envolved in the sampling process (list of C{GibbsSamplerVariable} whose index is defined in L{samplerEngine})

class pyhrf.jde.samplerbase.GibbsSampler(variables, nbIt, smplHistoryPace=-1, obsHistoryPace=-1, nbSweeps=None, callbackObj=None, randomSeed=None, globalObsHistoryPace=-1, check_ftval=None, output_fit=False)

Generic class of a Gibbs sampler with gathers common operations for any gibbs sampling: variable initialisation, observables updates (posterior mean), outputs …

computeFit()
finalizeSampling()
getFitAxes()
getGlobalOutputs()
getOutputs()
getShortProfile()
getTinyProfile()
get_variable(label)
initGlobalObservables()
iterate_sampling()
linkToData(dataInput)
regVarsInPipeline()
runSampling(atomData=None)

Launch a complete sampling process by calling the function L{GibbsSamplerVariable.sampleNext()} of each variable. Call the callback function after each iteration. Measure time elapsed and store it in L{tSamplinOnly} and L{analysis_duration}

saveGlobalObservables(it)
set_nb_iterations(n)
stop_criterion(it)
updateGlobalObservables()
class pyhrf.jde.samplerbase.GibbsSamplerVariable(name, valIni=None, trueVal=None, sampleFlag=1, useTrueValue=False, axes_names=None, axes_domains=None, value_label='value')
checkAndSetInitValue(variables)
check_final_value()
chooseSampleNext(flag)
cleanObservables()
finalizeSampling()
getMean()

Wip … Compute mean over MCMC iterations within the window defined by itStart, itEnd and pace. By default itStart is set to ‘nbSweeps’ and itEnd to the last iteration.

getMeanHistory()
getOutputs()
get_accuracy(abs_error, rel_error, fv, tv, atol, rtol)

Return the accuray of the estimate fv, compared to the true value tv

Output:
axes_names (list of str), accuracy (numpy array of booleans)
get_final_summary()
get_final_value()
get_string_value(v)
get_summary()
get_true_value()
get_variable(label)

Return a sibling GibbsSamplerVariable

initObservables()
linkToData()
manageMapping(cuboid)
manageMappingInit(shape, axes_names)
record_trajectories(it)
registerNbIterations(nbIt)
roiMapped()
sampleNextAlt(variables)

Define the behaviour of the variable at each sampling step when its sampling is not activated.

sampleNextInternal(variables)

Define the behaviour of the variable at each sampling step when its sampling is not activated. Must be overriden in child classes.

samplingWarmUp(variables)

Called before the launch of the main sampling loop by the sampler engine. Should be overriden and perform precalculations.

saveCurrentValue(it)
saveObservables(it)
setFinalValue()
setSamplerEngine(sampler)
track_obs_quantity(q, name, axes_names=None, axes_domains=None, history_pace=None)
track_sampled_quantity(q, name, axes_names=None, axes_domains=None, history_pace=None)
updateObsersables()
class pyhrf.jde.samplerbase.Trajectory(variable, axes_names, axes_domains, history_pace, history_start, max_iterations, first_saved_iteration=-1)

Keep track of a numpy array that is modified _inplace_ iteratively

get_last()

Return the last saved element

record(iteration)

Increment the history saving.

to_cuboid()

Pack the current trajectory in a xndarray

exception pyhrf.jde.samplerbase.VariableTypeException(vClass, vName, v)

Bases: exceptions.Exception