Misc Classes

The following are classes and functions of which the details is not essential to use sbp-env.

Data structure

class sbp_env.utils.common.Tree(dimension)[source]

A tree representation that stores nodes and edges.

Parameters

dimension (int) – A positive integer that represents \(d\), the dimensionality of the C-space.

add_edge(child, parent)[source]

Add a new edge to this tree

Parameters
  • child (Node) – The child node of the edge

  • parent (Node) – The parent node of the edge

Return type

None

add_vertex(v, pos)[source]

Add a new vertex to this tree

Parameters
  • v (Node) – Node to be added

  • pos (ndarray) – The configuration \(q\) that corresponds to the node v

Return type

None

get_nearest(x)[source]

Get the closest node

Parameters

x (ndarray) – Position

Return type

Node

Returns

the closest node

nearby(x, n)[source]

Find n many nearby nodes that are closest to a given position

Parameters
  • x (ndarray) – Position

  • n (int) – Max number of results

Return type

List[Node]

class sbp_env.utils.common.Node(pos)[source]

Represents a node inside a tree.

Variables
  • pos (numpy.ndarray) – position, a.k.a., the configuration \(q \in C\) that this node represents

  • cost (float) – a positive float that represents the cost of this node

  • parent (Node) – parent node

  • children (a list of Node) – children nodes

  • is_start (bool) – a flag to indicate this is the start node

  • is_goal (bool) – a flag to indicate this is the goal node

Parameters

pos (ndarray) – configuration of this node

class sbp_env.utils.common.PlanningOptions(planner_data_pack, sampler_data_pack, skip_optimality, showSampledPoint, scaling, goalBias, max_number_nodes, radius, ignore_step_size, always_refresh, rrdt_proposal_distribution, start_pt, goal_pt, epsilon=None, goal_radius=None, as_radian=False, simplify_solution=True, no_display=False, first_solution=False, output_dir=None, save_output=None, rover_arm_robot_lengths=None, sampler=None, planner=None, engine=None)[source]

Former: MagicDict

Parameters
  • planner_data_pack (PlannerDataPack) –

  • sampler_data_pack (SamplerDataPack) –

  • skip_optimality (bool) –

  • showSampledPoint (bool) –

  • scaling (float) –

  • goalBias (float) –

  • max_number_nodes (int) –

  • radius (float) –

  • ignore_step_size (bool) –

  • always_refresh (bool) –

  • rrdt_proposal_distribution (str) –

  • start_pt (str) –

  • goal_pt (str) –

  • epsilon (float) –

  • goal_radius (float) –

  • as_radian (bool) –

  • simplify_solution (bool) –

  • no_display (bool) –

  • first_solution (bool) –

  • output_dir (str) –

  • save_output (str) –

  • rover_arm_robot_lengths (str) –

  • sampler (Sampler) –

  • planner (Planner) –

  • engine (Engine) –

Randomness

The following are the random methods supported in sbp-env.

sbp_env.randomness.SUPPORTED_RANDOM_METHODS = ('pseudo_random', 'sobol_sequence', 'saltelli', 'latin_hypercube', 'finite_differences', 'fast')

Supported methods to draw random numbers in samplers. Supported random methods are as follows:

  • pseudo_random from numpy

    Pseudo Random

  • sobol_sequence from SALib

    Sobol sequence

  • saltelli from SALib

    Saltelli’s extension of Sobol sequence

  • latin_hypercube from SALib

    Latin hypercube

  • finite_differences from SALib

    Finite differences

  • fast from SALib

    Fourier Amplitude Sensitivity Test (FAST)

Drawing random samplings

The sbp_env.randomness.RandomnessManager: is used by most samplers to draw random numbers.

class sbp_env.randomness.RandomnessManager(num_dim, bucket_size=10000)[source]

A random number manager that draw a buckets of random numbers at a number and redraw when the bucket is exhausted.

Parameters
  • num_dim (int) – the number of dimension

  • bucket_size (int) –

get_random(random_method)[source]

Get one sample of random number \(r\) where \(0 \le r \le 1\)

Parameters

random_method – The kind of random number method to use, must be one of the choice in SUPPORTED_RANDOM_METHODS

redraw(random_method)[source]

Redraw the random number with the given method

Parameters

random_method (str) – the random method to use

Drawing normally distributed samplings

The sbp_env.randomness.NormalRandomnessManager: is used by sbp_env.planners.rrdtPlanner.RRdTSampler to draw from a von Mises distribution.

class sbp_env.randomness.NormalRandomnessManager[source]

Randomness Manager that draw a bucket of normally distributed random numbers and refill the bucket on-demand when it is exhausted.

draw_half_normal(start_at, scale=1)[source]

Draw from a half normal distribution

Parameters
  • start_at (ndarray) – the origin

  • scale (float, optional) – the scale of the half normal

    Default: 1

draw_normal(origin, use_vonmises=True, kappa=1, sigma=0.7853981633974483)[source]

Draw from the normal distribution

Parameters
  • origin (ndarray) – the origin (mean) for the random number, which will be used to shift the number that this function returns

  • use_vonmises (bool, optional) – use vom-Mises distribution

    Default: True

  • kappa (float, optional) – the \(\kappa\) value

    Default: 1

  • sigma (float, optional) – the \(\sigma\) value

    Default: 0.7853981633974483

Return type

ndarray

redraw_half_normal(start_at, scale)[source]

Re-draw from a half normal distribution

Parameters
  • start_at (ndarray) – the origin

  • scale (float) – the scale of the half normal

redraw_normal(kappa, sigma, use_vonmises=True)[source]

Redraw the bucket of normally distributed random numbers

Parameters
  • kappa

    the kappa \(\kappa\) parameter to be used to draw from a von Mises distribution

    \[x \sim f_\text{VonMises}( x | \mu, \kappa) \]

  • sigma

    the sigma \(\sigma\) parameter to be used to draw from a normal distribution

    \[x \sim \mathcal{N}( x | \mu, \sigma^2) \]

  • use_vonmises (optional) – (Default value = True)

    Default: True

Planners and Samplers Registry

The following function is used to register a new custom planner.

sbp_env.utils.planner_registry.register_planner(planner_id, planner_class, sampler_id, visualise_pygame_paint_init=None, visualise_pygame_paint=None, visualise_pygame_paint_terminate=None, visualise_klampt_paint_init=None, visualise_klampt_paint=None, visualise_klampt_paint_terminate=None)[source]

Register a planner to make it available for planning.

Parameters
  • planner_id (str) – the unique planner id for this registering planner

  • planner_class (Type[Planner]) – the planner class

  • sampler_id (str) – sampler id to construct

  • visualise_pygame_paint_init (Optional[Callable], optional) – the paint function for pygame, during initialisation

    Default: None

  • visualise_pygame_paint (Optional[Callable], optional) – the paint function for pygame

    Default: None

  • visualise_pygame_paint_terminate (Optional[Callable], optional) – the paint function for pygame, when terminating

    Default: None

  • visualise_klampt_paint_init (Optional[Callable], optional) – the paint function for klampt, during initialisation

    Default: None

  • visualise_klampt_paint (Optional[Callable], optional) – the paint function for klampt

    Default: None

  • visualise_klampt_paint_terminate (Optional[Callable], optional) – the paint function for klampt, when terminating

    Default: None

Return type

None

The following function is used to register a new custom sampler.

sbp_env.utils.planner_registry.register_sampler(sampler_id, sampler_class, visualise_pygame_paint_init=None, visualise_pygame_paint=None, visualise_pygame_paint_terminate=None, visualise_klampt_paint_init=None, visualise_klampt_paint=None, visualise_klampt_paint_terminate=None)[source]

Register a sampler to make it available for planning.

Parameters
  • sampler_id (str) – the unique id for this sampler

  • sampler_class (Type[Sampler]) – the class to construct this sampler

  • visualise_pygame_paint_init (Optional[Callable], optional) – the paint function for pygame, during initialisation

    Default: None

  • visualise_pygame_paint (Optional[Callable], optional) – the paint function for pygame

    Default: None

  • visualise_pygame_paint_terminate (Optional[Callable], optional) – the paint function for pygame, when terminating

    Default: None

  • visualise_klampt_paint_init (Optional[Callable], optional) – the paint function for klampt, during initialisation

    Default: None

  • visualise_klampt_paint (Optional[Callable], optional) – the paint function for klampt

    Default: None

  • visualise_klampt_paint_terminate (Optional[Callable], optional) – the paint function for klampt, when terminating

    Default: None

Return type

None

Registry data structure

class sbp_env.utils.planner_registry.PlannerDataPack(name, visualise_pygame_paint_init, visualise_pygame_paint, visualise_pygame_paint_terminate, visualise_klampt_paint_init, visualise_klampt_paint, visualise_klampt_paint_terminate, planner_class, sampler_id)[source]

Data pack to stores planner class and the sampler with sample_id to use

Parameters
name: str

an unique id to identify this data-pack

planner_class: Type[Planner]

the class to construct the planner

sampler_id: str

the sampler id to associate to this planner

class sbp_env.utils.planner_registry.SamplerDataPack(name, visualise_pygame_paint_init, visualise_pygame_paint, visualise_pygame_paint_terminate, visualise_klampt_paint_init, visualise_klampt_paint, visualise_klampt_paint_terminate, sampler_class)[source]

Data pack to store sampler class

Parameters
name: str

an unique id to identify this data-pack

sampler_class: Type[Sampler]

the class to construct the sampler