danielparthier / BehaviourAnalysis

Behavioural Analysis
GNU General Public License v3.0
1 stars 0 forks source link

Jumps in output need correction #6

Closed danielparthier closed 4 years ago

danielparthier commented 4 years ago

A correction is needed for random jumps of labels. I am currently investigating whether a median filter and then deviation from there could be used or whether an ARIMA modelling could help. Currently, the median filter would work nicely, however, jumps at the beginning will not be corrected if they are closer than the rolling window size. Any suggestions?

danielparthier commented 4 years ago

After checking further the easiest option is probably to detect the jumps by looking into the distance between labels. For example the ears should have a similar distance over time. A loss of a label would shift this. That what we can see in this example: leftear_xVSrightear_x

When looking at the ratio we can use it to identify these anomalies. Ratio

And when normalising we can even apply it without adjusting thresholds. z-score

I will try to do this for all labels which belong to a structure and then interpolate coordinates.

danielparthier commented 4 years ago

It seems to be possible to fit a t-distribution to the differential of all the coordinates. This allows to detect outliers in a robust way and will be updated soon.

fitDT <- function(par, x){
  -sum(dt(x = x-par[2], df = par[1], log = T))
}

nlminb(x = diff(Input), fitDT, start = c(1,0))

The interpolation is now the missing end. I will look for an appropriate interpolation (probably not linear?).

danielparthier commented 4 years ago

The issue was fixed in the last commit. The jumps are detected based on the t-distribution of the coordinate differential and then interpolated by using b-splines.

Without correction: UncorrectedTrack

With correction: CorrectedTrack