public static IntTuple getArgmax ( float [ ] [ ] array , float delta ) { float maxValue = Float . NEGATIVE_INFINITY ; int maxX = - 1 ; int maxY = - 1 ; float numMax = 1 ; for ( int x = 0 ; x < array . length ; x ++ ) { for ( int y = 0 ; y < array [ x ] . length ; y ++ ) { float diff = Primitives . compare ( array [ x ] [ y ] , maxValue , delta ) ; if ( diff == 0 && Prng . nextFloat ( ) < 1.0 / numMax ) { maxValue = array [ x ] [ y ] ; maxX = x ; maxY = y ; numMax ++ ; } else if ( diff > 0 ) { maxValue = array [ x ] [ y ] ; maxX = x ; maxY = y ; numMax = 1 ; } } } return new IntTuple ( maxX , maxY ) ; }
Gets the argmax breaking ties randomly .