@ Override public double [ ] getVotesForInstance ( Instance inst ) { double vSTM [ ] ; double vLTM [ ] ; double vCM [ ] ; double v [ ] ; double distancesSTM [ ] ; double distancesLTM [ ] ; int predClassSTM = 0 ; int predClassLTM = 0 ; int predClassCM = 0 ; try { if ( this . stm . numInstances ( ) > 0 ) { distancesSTM = get1ToNDistances ( inst , this . stm ) ; int nnIndicesSTM [ ] = nArgMin ( Math . min ( distancesSTM . length , this . kOption . getValue ( ) ) , distancesSTM ) ; vSTM = getDistanceWeightedVotes ( distancesSTM , nnIndicesSTM , this . stm ) ; predClassSTM = this . getClassFromVotes ( vSTM ) ; distancesLTM = get1ToNDistances ( inst , this . ltm ) ; vCM = getCMVotes ( distancesSTM , this . stm , distancesLTM , this . ltm ) ; predClassCM = this . getClassFromVotes ( vCM ) ; if ( this . ltm . numInstances ( ) >= 0 ) { int nnIndicesLTM [ ] = nArgMin ( Math . min ( distancesLTM . length , this . kOption . getValue ( ) ) , distancesLTM ) ; vLTM = getDistanceWeightedVotes ( distancesLTM , nnIndicesLTM , this . ltm ) ; predClassLTM = this . getClassFromVotes ( vLTM ) ; } else { vLTM = new double [ inst . numClasses ( ) ] ; } int correctSTM = historySum ( this . stmHistory ) ; int correctLTM = historySum ( this . ltmHistory ) ; int correctCM = historySum ( this . cmHistory ) ; if ( correctSTM >= correctLTM && correctSTM >= correctCM ) { v = vSTM ; } else if ( correctLTM > correctSTM && correctLTM >= correctCM ) { v = vLTM ; } else { v = vCM ; } } else { v = new double [ inst . numClasses ( ) ] ; } this . stmHistory . add ( ( predClassSTM == inst . classValue ( ) ) ? 1 : 0 ) ; this . ltmHistory . add ( ( predClassLTM == inst . classValue ( ) ) ? 1 : 0 ) ; this . cmHistory . add ( ( predClassCM == inst . classValue ( ) ) ? 1 : 0 ) ; } catch ( Exception e ) { return new double [ inst . numClasses ( ) ] ; } return v ; }
Predicts the label of a given sample by using the STM LTM and the CM .