Removing Outliers from Multisets

by
Paraskevas V. Lekeas 
National Technical University of Athens
Algorithms and Logic Lab
plekeas@mail.ntua.gr
Dafnis 2 B, 15772, Zografou,
Greece

30 May 2006

Removing Outliers from multisets

The following function is for removing outliers from a multiset. The arguments used are the multiset and the outliers (max or min) to be removed resp.

UnsortedComplement[x_List, y__List] := 
      Replace[x, 
        Dispatch[(# :> Sequence[]) & /@ Union[y]], 
        1]

Example

Here is a multiset of Length 20:

S = {0.1, 0.1, 2, 3, 4, 4, 5, 6, 7, 8, 10, 11, 2, 3, 234, 321, 23, 
        1000, 12, 124}

Length[S]

We want to chop all the Max and Min outliers. We use function UnsortedComplement[x_List,y__List] 2 times, one for Max and one for Min outliers.

S = UnsortedComplement[S, {Max[S]}]

S = UnsortedComplement[S, {Min[S]}]

Here the function deleted 3 outliers.

Length[S]