cbp.builder

cbp.builder.base_builder

class cbp.builder.base_builder.BaseBuilder(dim, policy, rand_seed=1)[source]

Bases: abc.ABC

add_branch(head_node=None, is_constrained=False, prob=None, is_conv=False)[source]
add_constrained_node(probability=None)[source]
add_factor(name_list, is_conv=False)[source]
add_factor_different(name_list, is_conv=False)[source]
add_trivial_node(dim=None)[source]
abstract init_graph()[source]

cbp.builder.hmm_builder

class cbp.builder.hmm_builder.HMMBuilder(length, node_dim, policy, rand_seed=1)[source]

Bases: cbp.builder.base_builder.BaseBuilder

init_graph()[source]
step(time_stamp=None)[source]

hmm go forward a step, time + 1

Parameters

time_stamp (int) – timer for the current add node

cbp.builder.hmm_zero_builder

class cbp.builder.hmm_zero_builder.HMMZeroBuilder(length, d, policy, rand_seed=1)[source]

Bases: cbp.builder.hmm_builder.HMMBuilder

add_constrained_node(probability=None)[source]
add_factor(name_list, is_conv=False)[source]

cbp.builder.hmm_sim_builder

class cbp.builder.hmm_sim_builder.HMMSimBuilder(length, simulator, policy, random_seed=1)[source]

Bases: cbp.builder.hmm_builder.HMMBuilder

add_branch(head_node=None, is_constrained=False, prob=None, is_conv=False)[source]
add_constrained_node(probability=None)[source]
add_factor(name_list, is_conv=False)[source]

add factor to hmm graph

Parameters
  • name_list (list) – connected node

  • is_conv (bool, optional) – is emit or not , defaults to False– transition

Returns

FactorNode

Return type

cbp.FactorNode

example(num_sample)[source]
fix_initpotential(potential=None)[source]

cbp.builder.hmm_simulator

class cbp.builder.hmm_simulator.HMMSimDate(time_step, state_num, obser_num, *args, **kwargs)[source]

Bases: dict

cal_theory(verbose)[source]
property sensor
property traj
class cbp.builder.hmm_simulator.HMMSimulator(time_step, dim_states, dim_observations, random_seed, is_theorem=False)[source]

Bases: object

get_emission_potential()[source]
get_fix_margin(time_step=None)[source]

return observation marginal

Parameters

time_step – if int then return a specific time distribution

otherwise all distributions as matrxi, defaults to None :type time_step: int, optional :return: array for single time_step or a matrix :rtype: ndarray

get_gt_joint()[source]
get_hidden_margin(time_step=None)[source]

return ground truth marginal

Parameters

time_step – if int then return a specific time distribution

otherwise all distributions as matrix, defaults to None :type time_step: int, optional :return: array for single time_step or a matrix :rtype: ndarray

get_init_potential()[source]
get_precious(time_step=None, verbose=False)[source]

return precious marginal

Parameters

time_step – if int then return a specific time distribution

otherwise all distributions as matrix, defaults to None :type time_step: int, optional :param verbose: whether or not ouput difference between simulation and

theorical margin

Returns

array for single time_step or a matrix

Return type

ndarray

get_sensor()[source]
get_traj()[source]
get_transition_potential()[source]
classmethod load(sim_name: str)[source]

load a simulator from pkl file

Parameters

sim_name (str) – name for the simulator

Returns

simulator

Return type

simulator

property name
observe(state)[source]

do a emission sample

Parameters

state (int) – current states

Returns

the observation of cur states

Return type

int

observe_traj(traj)[source]
register_potential(ptype, potential)[source]

register potential for simulation

Parameters
  • ptype (PotentialType) – potential type

  • potential (ndarray) – [description]

reset()[source]
sample(num_sample)[source]
sample_engine(state, dim, potential)[source]

sample according to conditional prob table

Parameters
  • state (int) – cur_state

  • dim (int) – range of next state or observation

  • potential (ndarray) – conditional prob table

Returns

next state or observation

Return type

int

save()[source]
step(state)[source]

do a states transition sample

Parameters

state (int) – current states

Returns

the next states

Return type

int

viz_emission_potential()[source]
viz_gt()[source]
viz_sensor()[source]
viz_trans_potential()[source]
class cbp.builder.hmm_simulator.PotentialType(value)[source]

Bases: str, enum.Enum

Potential Type Enum

EMISSION = 'Emission'
INIT = 'Init'
TRANSITION = 'Transition'
cbp.builder.hmm_simulator.cal_single(traj, col_num, state_num)[source]

cbp.builder.line_builder

class cbp.builder.line_builder.LineBuilder(num_node, d, policy, rand_seed=1)[source]

Bases: cbp.builder.base_builder.BaseBuilder

init_graph()[source]

cbp.builder.migr_simulator

class cbp.builder.migr_simulator.MigrSimulator(time_step, d_col, d_row, random_seed)[source]

Bases: cbp.builder.hmm_simulator.HMMSimulator

compile()[source]

register various potential for simulation

viz_emission_potential()[source]
viz_estm(estimated_marginal)[source]
viz_gt()[source]
viz_sensor()[source]
viz_trans_potential()[source]

cbp.builder.migr_visualizer

class cbp.builder.migr_visualizer.MigrVisualizer(d_row, d_col)[source]

Bases: object

ind2rowcol(index)[source]
migration(data, **kwargs)[source]

draw migration figure, heat map distribution 3 reservered key in kwargs: * fig_name: savefig * xlabel: xlabel * ylabel

Parameters

data – [i,j] record i-th particle position at j timestamp

potential_heatmap(data, **kwargs)[source]

plot potential heatmap and save png. 2 reserved keys:

  • title figure title

  • path figure path prefix

Parameters

data (ndarray) – i-th row represents the potential of d state

visualize_location(xx, yy, xy_size, **kwargs)[source]

plot grid location distribution. Origin point is in DownLeft. 3 reservered key in kwargs: * fig_name: savefig * xlabel: xlabel * ylabel

Parameters
  • xx (ndarray) – scatter plot x

  • yy (ndarray) – scatter plot y

  • xy_size (ndarray) – at position (x,y) the number of particles

visualize_map_bins(bins, **kwargs)[source]

converts the statistics bins data to the map figure. 3 reservered key in kwargs: * fig_name: savefig * xlabel: xlabel * ylabel

Parameters

bins (list or ndarray) – every element represents how many particles in the cell

cbp.builder.potential_utils

cbp.builder.potential_utils.diagonal_potential(d_1: int, d_2: int, rng: numpy.random.mtrand.RandomState) → numpy.ndarray[source]
cbp.builder.potential_utils.diagonal_potential_conv(d_1: int, d_2: int, rng: numpy.random.mtrand.RandomState) → numpy.ndarray[source]
cbp.builder.potential_utils.diagonal_potential_different(d_1: int, d_2: int, rng: numpy.random.mtrand.RandomState) → numpy.ndarray[source]
cbp.builder.potential_utils.identity_potential(d_1: int, d_2: int, rng: numpy.random.mtrand.RandomState) → numpy.ndarray[source]

cbp.builder.star_builder

class cbp.builder.star_builder.StarBuilder(num_node, d, policy, rand_seed)[source]

Bases: cbp.builder.base_builder.BaseBuilder

init_graph()[source]

cbp.builder.tree_builder

class cbp.builder.tree_builder.TreeBuilder(tree_depth, d, policy, rand_seed=1)[source]

Bases: cbp.builder.base_builder.BaseBuilder

init_graph()[source]

cbp.builder.wifi_hmm_builder

class cbp.builder.wifi_hmm_builder.WifiHMMBuilder(length, grid_d, policy, rand_seed=1, num_sensor=16, time_step=60)[source]

Bases: cbp.builder.hmm_sim_builder.HMMSimBuilder

builder with wifi-type simulator. Sparse observation. pass the wifi-simulator to the cbp.builder.HMMSimBuilder

cbp.builder.wifi_simulator

class cbp.builder.wifi_simulator.WifiSimulator(time_step, d_col, d_row, random_seed)[source]

Bases: cbp.builder.migr_simulator.MigrSimulator

simulate ensemble move, sensor is sparse - place sensors in some place - draw various data

compile()[source]

register various potential for simulation

draw_sensor()[source]

draw wifi sensor position in grid

fixed_sensors(space_d=1)[source]
random_sensor(num)[source]
register_hotspot(row, col)[source]
viz_sensor()[source]

draw raw sensor data