xboa
Public Member Functions | Public Attributes | Private Member Functions | List of all members
VoronoiWeighting Class Reference

VoronoiWeighting class enables the user to set statistical weights of Hits in a Bunch based on how close they are to neighbouring Hits. More...

Inherits object.

Public Member Functions

def __init__
 Initialise the VoronoiWeighting. More...
 
def apply_weights
 Apply a weighting $w_i$ to each Hit in bunch corresponding to
$ w_i = c_i f(x_i) $
where $c_i$ is the content of each Voronoi tile and $f(x_i)$ is the value of a multivariate gaussian evaluated at $x_i$. More...
 
def get_pdf
 Calculate a multivariate gaussian at point. More...
 
def plot_two_d_projection
 Plot a 2D projection of the voronoi cells. More...
 

Public Attributes

 dim
 
 voronoi_bound
 
 weight_variables
 
 weight_ellipse_inv
 
 weight_ellipse_det
 
 weight_mean
 
 weight_list
 
 tesselation
 
 tile_content_list
 
 real_points
 

Private Member Functions

def _get_fill_colors
 Get fill colors for plot_two_d_projection. More...
 
def _get_cm_matrix
 
def _tile_content
 Calculate the tile for the index at point_index. More...
 

Detailed Description

VoronoiWeighting class enables the user to set statistical weights of Hits in a Bunch based on how close they are to neighbouring Hits.

The basic principle is that if a Hit is in a sparsely populated region of phase space, but the desired probability distribution would have the Hit in a more densely populated region, we can apply a greater statistical weight to that Hit (i.e. we "count" the Hit more than once in e.g. moment calculations etc).

In order to calculate how sparsely populated a particular region is, xboa uses a "Voronoi" tesselation. xboa determines the nearest Hits surrounding a given Hit, draws lines to those neighbours and then bisects the lines. This generates a closed region around the Hit that is closer to that Hit than any other.

xboa calculates the "content" i.e. area/volume/hypervolume of the Voronoi tile for each Hit. Hits which sit in a tile with a larger content are assumed to be in a more sparsely populated region of phase space, while those that sit in a region with a smaller content are assumed to be in a less sparsely populated region of phase space.

xboa assigns weights to each Hit according to a multivariate gaussian. In order to prevent Hits on the edge of the distribution from acquiring a disproportionate weighting, it is possible to define a bound around the distribution. Hits outside the bound are disregarded. A few points are defined on the bound, which prevent large Voronoi cells from being generated.

Definition at line 70 of file _voronoi_weighting.py.

Constructor & Destructor Documentation

def __init__ (   self,
  weight_variables,
  weight_ellipse,
  weight_mean = None,
  voronoi_bound = None 
)

Initialise the VoronoiWeighting.

  • weight_variables: list of string variable names for call to Bunch.get_hit_variable(...). Should have a length corresponding to the VoronoiWeighting dimension.
  • weight_ellipse: numpy.array corresponding to the covariance matrix of the desired multivariate gaussian. Should have numpy.shape like (dimension, dimension) where dimension is the dimension of the VoronoiWeighting.
  • weight_mean: numpy.array corresponding to the mean of the desired multivariate gaussian. If set to None, defaults to array of 0s. Should have numpy.shape like (dimension) where dimension is the dimension of the VoronoiWeighting.
  • voronoi_bound: BoundingEllipse, corresponding to the maximum bound at which Hits are accepted in the VoronoiWeighting. Hits outside this bound will have weight set to 0. The ellipse bounding_points are used as an external boundary to prevent Voronoi tesselations from getting a big tile content (i.e. area/volume/hypervolume).

Requires numpy and scipy to be installed.

Returns a VoronoiWeighting object.

Definition at line 97 of file _voronoi_weighting.py.

Member Function Documentation

def apply_weights (   self,
  bunch,
  global_cut 
)

Apply a weighting $w_i$ to each Hit in bunch corresponding to
$ w_i = c_i f(x_i) $
where $c_i$ is the content of each Voronoi tile and $f(x_i)$ is the value of a multivariate gaussian evaluated at $x_i$.

  • bunch: xboa.bunch.Bunch object. Evaluate weights for all Hits in bunch
  • global_cut: if set to True, weighting will be applied to the hit's global_weight. If set to False, weighting will be applied to the hit's local_weight. Returns None (the bunch is weighted "in-place")

Definition at line 141 of file _voronoi_weighting.py.

References VoronoiWeighting._tile_content(), VoronoiWeighting.get_pdf(), VoronoiWeighting.real_points, VoronoiWeighting.tesselation, VoronoiWeighting.tile_content_list, VoronoiWeighting.voronoi_bound, VoronoiWeighting.weight_list, and VoronoiWeighting.weight_variables.

def get_pdf (   self,
  point 
)

Calculate a multivariate gaussian at point.

  • bunch: xboa.bunch.Bunch object. Evaluate weights for all Hits in bunch
  • global_cut: if set to True, weighting will be applied to the hit's global_weight. If set to False, weighting will be applied to the hit's local_weight.

Definition at line 184 of file _voronoi_weighting.py.

References VoronoiWeighting.plot_two_d_projection(), VoronoiWeighting.weight_ellipse_det, and VoronoiWeighting.weight_mean.

Referenced by VoronoiWeighting._get_fill_colors(), and VoronoiWeighting.apply_weights().

def plot_two_d_projection (   self,
  projection_axes,
  fill_option = None,
  lower = None,
  upper = None 
)

Plot a 2D projection of the voronoi cells.

  • projection_axes: list of length two. Determines the projection that will be drawn. Should be a subset of the weight_variables.
  • fill_option: if set to None or 'none', tiles will not be filled. If set to 'weight', 'content', 'pdf', tiles will be filled according to the calculated point weight, calculated tile content or probability density function for that point.
  • lower: integer lower bound for slicing of the tesselation regions. If set to None, defaults to 0.
  • upper: integer upper bound for slicing of the tesselation regions. If set to None, defaults to the end of the tesselation regions list.

Requires ROOT to be installed.

Returns a tuple of (canvas, histogram, point_graph, tile_graph_list) where canvas is the ROOT TCanvas, histogram is the ROOT TH2D that makes the graph axes, point_graph is the graph with the points plotted, tile_graph_list is a list of graphs, one for each tile.

Definition at line 214 of file _voronoi_weighting.py.

References VoronoiWeighting._get_fill_colors(), VoronoiWeighting.real_points, VoronoiWeighting.tesselation, and VoronoiWeighting.weight_variables.

Referenced by VoronoiWeighting.get_pdf().

def _get_fill_colors (   self,
  fill_option,
  lower,
  upper 
)
private
def _get_cm_matrix (   self,
  simplex,
  triangulation,
  dimension 
)
private

Definition at line 292 of file _voronoi_weighting.py.

Referenced by VoronoiWeighting._tile_content().

def _tile_content (   self,
  point_index 
)
private

Calculate the tile for the index at point_index.

Use Cayler-Menger determinant to calculate content of an arbitrary dimensional simplex.

Definition at line 316 of file _voronoi_weighting.py.

References VoronoiWeighting._get_cm_matrix().

Referenced by VoronoiWeighting.apply_weights().

Member Data Documentation

dim

Definition at line 100 of file _voronoi_weighting.py.

voronoi_bound

Definition at line 113 of file _voronoi_weighting.py.

Referenced by VoronoiWeighting.apply_weights().

weight_variables
weight_ellipse_inv

Definition at line 121 of file _voronoi_weighting.py.

weight_ellipse_det

Definition at line 122 of file _voronoi_weighting.py.

Referenced by VoronoiWeighting.get_pdf().

weight_mean

Definition at line 123 of file _voronoi_weighting.py.

Referenced by VoronoiWeighting.get_pdf().

weight_list
tesselation
tile_content_list
real_points

The documentation for this class was generated from the following file: