question: protected double [ ] makeDistribution ( Instances neighbours , double [ ] distances ) throws Exception { double total = 0 , weight ; double [ ] distribution = new double [ m_NumClasses ] ; if ( m_ClassType == Attribute . NOMINAL ) { for ( int i = 0 ; i < m_NumClasses ; i ++ ) { distribution [ i ] = 1.0 / Math . max ( 1 , m_Train . numInstances ( ) ) ; } total = ( double ) m_NumClasses / Math . max ( 1 , m_Train . numInstances ( ) ) ; } for ( int i = 0 ; i < neighbours . numInstances ( ) ; i ++ ) { Instance current = neighbours . instance ( i ) ; distances [ i ] = distances [ i ] * distances [ i ] ; distances [ i ] = Math . sqrt ( distances [ i ] / m_NumAttributesUsed ) ; switch ( m_DistanceWeighting ) { case WEIGHT_INVERSE : weight = 1.0 / ( distances [ i ] + 0.001 ) ; break ; case WEIGHT_SIMILARITY : weight = 1.0 - distances [ i ] ; break ; default : weight = 1.0 ; break ; } weight *= current . weight ( ) ; try { switch ( m_ClassType ) { case Attribute . NOMINAL : distribution [ ( int ) current . classValue ( ) ] += weight ; break ; case Attribute . NUMERIC : distribution [ 0 ] += current . classValue ( ) * weight ; break ; } } catch ( Exception ex ) { throw new Error ( "Data has no class attribute!" ) ; } total += weight ; } if ( total > 0 ) { Utils . normalize ( distribution , total ) ; } return distribution ; }
target:  Turn the list of nearest neighbors into a probability distribution.