quickselectFSw_demo

quickselectFSw_demo illustrates the functioning of quickselectFSw

Syntax

  • kD =quickselectFSw_demo(D,W)example
  • kD =quickselectFSw_demo(D,W,p)example
  • [kD , kW ]=quickselectFSw_demo(___)example
  • [kD , kW , kstar]=quickselectFSw_demo(___)example
  • [kD , kW , kstar, varargout]=quickselectFSw_demo(___)example

Description

example

kD =quickselectFSw_demo(D, W) quickselectFSw without optional parameter p gives the weighted median.

example

kD =quickselectFSw_demo(D, W, p)

example

[kD , kW ] =quickselectFSw_demo(___) quickselectFSw when the weights are all equal.

example

[kD , kW , kstar] =quickselectFSw_demo(___)

example

[kD , kW , kstar, varargout] =quickselectFSw_demo(___)

Examples

expand all

  • quickselectFSw without optional parameter p gives the weighted median.
  • The median is 3, but the weighted one is 4, corresponding to the weight 0.3.

    A = [1 2 3 4 5];
    W = [0.15 0.1 0.2 0.3 0.25];
    i=randperm(5);
    A=A(i); W=W(i);
    [kD, kW , kstar] = quickselectFSw_demo(A,W);
    Click here for the graphical output of this example (link to Ro.S.A. website).

  • A=[1 2 3 4 5];
    W=[0.15 0.1 0.2 0.3 0.25];
    i=randperm(5);
    A=A(i); W=W(i);
    perc = 25;
    p    = perc/100;
    [kD, kW , kstar] = quickselectFSw_demo(A,W,p);

  • quickselectFSw when the weights are all equal.
  • The weighted order statistic may logically reduce to the simple order statistic, but pay attention to the different wy to treat even and odd arrays.

    n=10;
    D=randperm(n);
    W=ones(1,n)./n;
    p=0.2;
    kDw = quickselectFSw_demo(D,W,p);

    Input Arguments

    expand all

    D — Input data. Vector.

    A vector containing a set of $n$ data elements.

    Data Types: double

    W — Weights. Vector.

    The vector contains a set of n positive weights summing to 1. The 1-sum requirement does not imply loss of generality: it is just to avoid extra checks and the normalization step inside the function.

    Data Types: double

    Optional Arguments

    p — 100pth percentile ($0<p<1$). Scalar.

    A number between 0 and 1 indicating the fraction of total weights that should be considered in partitioning the associated input data. Default is p=0.5, leading to the weighted median.

    Example: p,0.2

    Data Types: double

    Output Arguments

    expand all

    kD —weighted order statistic in D. Scalar

    Element kstar in vector D ($D(k^{*})$), for which we have $\sum_{i=1}^{k^{*}-1} w_i<=p$ and $\sum_{j=k^{*}+1}^{n} w_j<=1-p$.

    kW —weight associated to kD. Scalar

    Element kstar in vector W. The weight partition around kW is optimal in the sense that the sum of the weights on its left is as close as possible to $p$ and those on its right account for the remaining $1-p$.

    kstar —the index of kD in D and of kW in W. Scalar

    It is the position of the weighted order statistic in the data and weight vectors, that is $D(k^{*})$ and $W(k^{*})$.

    varargout —Ds : Output vector. Array

    At the and of the computation the vector [D(:) , W(:)] is appropriately partitioned around kstar. It is returned ordered in the interval (1:kstar-1,:). Remark: this operation sorts only part of the array, but it can still slow down the algorithm.

    References

    Azzini, I., Perrotta, D. and Torti, F. (2023), A practically efficient fixed-pivot selection algorithm and its extensible MATLAB suite, "arXiv, stat.ME, eprint 2302.05705"

    See Also

    This page has been automatically generated by our routine publishFS