private static DiscordRecord findBestDiscordBruteForce ( double [ ] series , Integer windowSize , VisitRegistry globalRegistry , double nThreshold ) throws Exception { Date start = new Date ( ) ; long distanceCallsCounter = 0 ; double bestSoFarDistance = - 1.0 ; int bestSoFarPosition = - 1 ; VisitRegistry outerRegistry = globalRegistry . clone ( ) ; int outerIdx = - 1 ; while ( - 1 != ( outerIdx = outerRegistry . getNextRandomUnvisitedPosition ( ) ) ) { // outer loop outerRegistry . markVisited ( outerIdx ) ; // imo this is a useless piece // check the global visits registry // if (globalRegistry.isVisited(outerIdx)) { // continue; // } double [ ] candidateSeq = tsProcessor . znorm ( tsProcessor . subseriesByCopy ( series , outerIdx , outerIdx + windowSize ) , nThreshold ) ; double nearestNeighborDistance = Double . MAX_VALUE ; VisitRegistry innerRegistry = new VisitRegistry ( series . length - windowSize ) ; int innerIdx ; while ( - 1 != ( innerIdx = innerRegistry . getNextRandomUnvisitedPosition ( ) ) ) { // inner loop innerRegistry . markVisited ( innerIdx ) ; if ( Math . abs ( outerIdx - innerIdx ) > windowSize ) { // > means they shall not overlap even // over a single point double [ ] currentSubsequence = tsProcessor . znorm ( tsProcessor . subseriesByCopy ( series , innerIdx , innerIdx + windowSize ) , nThreshold ) ; double dist = ed . earlyAbandonedDistance ( candidateSeq , currentSubsequence , nearestNeighborDistance ) ; distanceCallsCounter ++ ; if ( ( ! Double . isNaN ( dist ) ) && dist < nearestNeighborDistance ) { nearestNeighborDistance = dist ; } } } if ( ! ( Double . isInfinite ( nearestNeighborDistance ) ) && nearestNeighborDistance > bestSoFarDistance ) { bestSoFarDistance = nearestNeighborDistance ; bestSoFarPosition = outerIdx ; LOGGER . trace ( "discord updated: pos {}, dist {}" , bestSoFarPosition , bestSoFarDistance ) ; } } Date firstDiscord = new Date ( ) ; LOGGER . debug ( "best discord found at {}, best distance: {}, in {} distance calls: {}" , bestSoFarPosition , bestSoFarDistance , SAXProcessor . timeToString ( start . getTime ( ) , firstDiscord . getTime ( ) ) , distanceCallsCounter ) ; DiscordRecord res = new DiscordRecord ( bestSoFarPosition , bestSoFarDistance ) ; res . setLength ( windowSize ) ; res . setInfo ( "distance calls: " + distanceCallsCounter ) ; return res ; }
Finds the best discord . BRUTE FORCE algorithm .