Issue
I need a function like Matlab's trimmean() in Java, and I do not want to reinvent the wheel.
Anybody is aware of a ready implementation for that? (Yes, I know I can make it in no time but I wouldn't waste time on it if someone already contributed it to the community.)
I Googled for some alternatives but I only found partial and placeholder implementations (like this or this).
Any suggestion is more than appreciated, the best would be a Maven dependency I can go play with.
Thanks in advance!
Solution
Just for the archives, I found an acceptable solution with Colt:
public static void trimmean(final double[] arr, final int percent) {
if ( percent < 0 || 100 < percent ) {
throw new IllegalArgumentException("Unexpected value: " + percent);
}
if ( 0 == arr.length ) {
return Double.NaN;
}
final int n = arr.length;
final int k = Math.round(n * ( percent / 100.0 ) / 2.0); // Check overflow
final DoubleArrayList list = new DoubleArrayList( arr );
list.sort();
return Descriptive.winsorizedMean( list, Descriptive.mean( list ), k, k );
}
Answered By - rlegendi
Answer Checked By - Pedro (JavaFixing Volunteer)