public Double earlyAbandonedDistance ( double [ ] series1 , double [ ] series2 , double cutoff ) throws Exception { if ( series1 . length == series2 . length ) { double cutOff2 = cutoff ; if ( Double . MAX_VALUE != cutoff ) { cutOff2 = cutoff * cutoff ; } Double res = 0D ; for ( int i = 0 ; i < series1 . length ; i ++ ) { res = res + distance2 ( series1 [ i ] , series2 [ i ] ) ; if ( res > cutOff2 ) { return Double . NaN ; } } return Math . sqrt ( res ) ; } else { throw new Exception ( "Exception in Euclidean distance: array lengths are not equal" ) ; } }
Implements Euclidean distance with early abandoning .