Opened 9 years ago

Closed 9 years ago

## #497 closed defect (fixed)

# Center (se.lu.onk.Center) median calculation is flawed and should be replaced

Reported by: | olle | Owned by: | olle |
---|---|---|---|

Priority: | major | Milestone: | ZZ Other tickets |

Component: | se.lu.onk series plug-ins | Keywords: | |

Cc: |

### Description

Center (se.lu.onk.Center) median calculation is flawed and should be replaced. The idea behind the current algorithm is not clear, and it will only give the correct result in very special cases. The algorithm should be replaced by a more general one.

**Note:**See TracTickets for help on using tickets.

(In [2012]) Fixes #497. Refs #79. Class/file

`center/Center.java`

in`se.lu.onk.Center`

updated in median calculation:`median(List<Float> vec)`

is updated by replacing the current algorithm by a call to new private method`float calculatePercentile(List<Float> vec, float fraction)`

, with`fraction`

value set to 0.5.`float calculatePercentile(List<Float> vec, float fraction)`

added. It first sorts the values in ascending order (the original input list is not changed), and then returns a weighted value of the list values of the two index values nearest to the desired percentile. If the percentile corresponds exactly to an integer index, the list value for that index is returned.