I'm trying to sort a set of data so that it looks like a histogram of a probability distribution function (I'm assuming normally distributed for the moment).
I have a list of entries:
private static final class SortableDatasetEntry{
Number value;
Comparable key;
public SortableDatasetEntry(Number value, Comparable key){
this.value = value;
this.key = key;
}
}
An example:
I have the items : {1,2,3,4,5,6,7,8,9}
EDIT:
The sorted list I would like: {1,3,5,7,9,8,6,4,2} (or something similar) The numbers will not always be so neat (i.e. simply sorting by odd/even wont work either). I have a partial solution that involves sorting by regular order (lowest to highest) then copying that list to another by inserting into the middle each time, thus the last item inserted (into the middle) is the largest. I'd still like to find a method of doing this with a comparator.
This is quite tricky because its not being sorted by the absolute value of value but by the distance from the Mean(value) within the set, and then somehow moved so those values closest to mean are centered. I know that the compareTo function must be "reversible" (I forget the correct term).
Bonus points: How do I determine the correct distribution for the data (i.e. if it isn't normal, as assumed).
First calculate the mean and store it in a variable called say mean. Next, when you insert the entries into your SortableDatasetEntry, use value - mean as the actual value for each entry rather than value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With