Fork me on GitHub

pyhrf.sandbox.stats module

class pyhrf.sandbox.stats.GSVariable(name, initialization, do_sampling=True, axes_names=None, axes_domains=None)
check_against_truth(atol, rtol, inaccuracy_handling='print')
check_initialization_arg(ia)
enable_sampling(flag=True)
get_accuracy_against_truth(abs_error, rel_error, fv, tv, atol, rtol)

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

get_custom_init()

Must return a numpy.ndarray. Consider initializing with a good guess so that sampling converges more quickly.

get_estim_value_for_check()
get_random_init()

Must return a random numpy.ndarray that will then be used as init value for sampling. For example, it can be a sample from the prior distribution. This function will also be used to test for the sensitivity to initialization.

get_true_value_for_check()
get_variable(vname)
get_variable_value(vname)

Short-hand to get variable among all those defined in the parent sampler

init_observables()
init_sampling()
reset()
sample()

Draw a sample conditionally to the current Gibbs Sampler state. Must return a numpy.ndarray.

Variables which have been registered in the parent GibbsSampler object can be retrieved via methods self.get_variable(var_name) and self.get_variable_value(var_name)

set_init_value()

Set the initial value of self.current_value, depending on the initialization scenario (random, custom, truth).

set_initialization(init)
set_outputs(outputs, output_type='ndarray')
Parameters:
  • outputs (-) – dictionary to be updated with custom outputs.
  • output_type (-) – ‘ndarray’ or ‘cuboid’

Return: None

set_true_value(true_value)
track_obs_quantity(name, quantity, history_pace=None, axes_names=None, axes_domains=None)
track_sampled_quantity(name, quantity, history_pace=None, axes_names=None, axes_domains=None)
update_observables()

Update quantities after the burnin period

class pyhrf.sandbox.stats.GibbsSampler(sampled_variables, nb_its_max, obs_pace=1, burnin=0.3, sample_hist_pace=-1, obs_hist_pace=-1)
check_against_truth(default_atol=0.1, default_rtol=0.1, var_specific_atol=None, var_specific_rtol=None, inaccuracy_handling='print')
get_outputs(output_type='ndarray')

output_type : ‘ndarray’ or ‘cuboid’

get_variable(vname)
get_variable_value(vname)
iterate_sampling()
reset()
Reset the Gibbs Sampler:
  • remove all previous history of quantities (trajectories)
  • call reset method of all variables
run()
set_initialization(vname, init)
set_true_value(vname, true_value)
set_true_values(true_values)
set_variable(name, var)
set_variables(var_dict)
stop_criterion(iteration)
track_obs_quantity(name, q, history_pace=None, axes_names=None, axes_domains=None)
track_sampled_quantity(name, q, history_pace=None, axes_names=None, axes_domains=None)
class pyhrf.sandbox.stats.Trajectory(variable, history_pace, history_start, max_iterations, init_iteration=None, axes_names=None, axes_domains=None)

Keep track of a numpy array that is modified _inplace_ iteratively TODO: when mature, should be moved to pyhrf.ndarray should replace pyhrf.jde.samplerbase.Trajectory

get_last()

Return the last saved element

to_cuboid()

Pack the current trajectory in a xndarray

update(iteration)

Record the current variable value