Package gmisclib :: Module weighted_percentile
[frames] | no frames]

Module weighted_percentile

source code

This computes order statistics on data with weights.

Functions
[ float, ... ]
wp(data, wt, percentiles)
Compute weighted percentiles.
source code
float
wtd_median(data, wt)
The weighted median is the point where half the weight is above and half the weight is below.
source code
numpy.ndarray
wtd_median_across(list_of_vectors, wt)
Takes a weighted component-by-component median of a sequence of vectors.
source code
 
test_wp() source code
 
test_median() source code
 
test() source code
Variables
  __package__ = 'gmisclib'

Imports: numpy


Function Details

wp(data, wt, percentiles)

source code 

Compute weighted percentiles. If the weights are equal, this is the same as normal percentiles. Elements of the data and wt arrays correspond to each other and must have equal length (unless wt is None).

Parameters:
  • data (A numpy.ndarray array or a list of numbers.) - The data.
  • wt (None or a numpy.ndarray array or a list of numbers. All the weights must be non-negative and the sum must be greater than zero.) - How important is a given piece of data.
  • percentiles (a list of numbers between 0 and 1.) - what percentiles to use. (Not really percentiles, as the range is 0-1 rather than 0-100.)
Returns: [ float, ... ]
the weighted percentiles of the data.

wtd_median(data, wt)

source code 

The weighted median is the point where half the weight is above and half the weight is below. If the weights are equal, this is the same as the median. Elements of the data and wt arrays correspond to each other and must have equal length (unless wt is None).

Parameters:
  • data (A numpy.ndarray array or a list of numbers.) - The data.
  • wt (None or a numpy.ndarray array or a list of numbers. All the weights must be non-negative and the sum must be greater than zero.) - How important is a given piece of data.
Returns: float
the weighted median of the data.

wtd_median_across(list_of_vectors, wt)

source code 

Takes a weighted component-by-component median of a sequence of vectors.

Parameters:
  • list_of_vectors (any sequence of lists or numpy.ndarray. All the inside lists must be of the same length.) - the data to be combined
  • wt (a vector of weights (one weight for each input vector) or None.) - sequence of numbers or None
Returns: numpy.ndarray
the median vector.