protected double calcDistTSAndPattern ( double [ ] ts , double [ ] pValue ) { double INF = 10000000000000000000f ; double bestDist = INF ; int patternLen = pValue . length ; int lastStartP = ts . length - pValue . length + 1 ; if ( lastStartP < 1 ) return bestDist ; Random rand = new Random ( ) ; int startP = rand . nextInt ( ( lastStartP - 1 - 0 ) + 1 ) ; double [ ] slidingWindow = new double [ patternLen ] ; System . arraycopy ( ts , startP , slidingWindow , 0 , patternLen ) ; bestDist = eculideanDistNorm ( pValue , slidingWindow ) ; for ( int i = 0 ; i < lastStartP ; i ++ ) { System . arraycopy ( ts , i , slidingWindow , 0 , patternLen ) ; double tempDist = eculideanDistNormEAbandon ( pValue , slidingWindow , bestDist ) ; if ( tempDist < bestDist ) { bestDist = tempDist ; } } return bestDist ; }
Calculating the distance between time series and pattern .