public static double [ ] [ ] invert ( double [ ] [ ] weights , boolean normalize ) { double [ ] [ ] result = new double [ weights . length ] [ weights [ 0 ] . length ] ; for ( int indexOfWeight = 0 ; indexOfWeight < weights . length ; indexOfWeight ++ ) { if ( normalize ) { double sum = 0 ; for ( int indexOfComponent = 0 ; indexOfComponent < weights [ indexOfWeight ] . length ; indexOfComponent ++ ) { sum = sum + ( 1.0 / weights [ indexOfWeight ] [ indexOfComponent ] ) ; } for ( int indexOfComponent = 0 ; indexOfComponent < weights [ indexOfWeight ] . length ; indexOfComponent ++ ) { result [ indexOfWeight ] [ indexOfComponent ] = ( 1.0 / weights [ indexOfWeight ] [ indexOfComponent ] ) / sum ; } } else { for ( int indexOfComponent = 0 ; indexOfComponent < weights [ indexOfWeight ] . length ; indexOfComponent ++ ) result [ indexOfWeight ] [ indexOfComponent ] = 1.0 / weights [ indexOfWeight ] [ indexOfComponent ] ; } } return result ; }
Calculate the inverse of a set of weight vectors