public double normalize() {
        double propSum = this.getSum();
        if (propSum == s.zero()) {
            this.fill(s.divide(s.one(), s.fromReal(this.size())));
        } else if (propSum == s.posInf()) {
            int count = count(s.posInf());
            if (count == 0) {
                throw new RuntimeException("Unable to normalize since sum is infinite but contains no infinities: " + this.toString());
            }
            double constant = s.divide(s.one(), s.fromReal(count));
            for (int d=0; d<this.size(); d++) {
                if (this.getValue(d) == s.posInf()) {
                    this.setValue(d, constant);
                } else {
                    this.setValue(d, s.zero());
                }
            }
        } else {
            this.divide(propSum);
            assert !this.containsNaN();
        }
        return propSum;
    }
public double normalize ( ) { double propSum = this . getSum ( ) ; if ( propSum == s . zero ( ) ) { this . fill ( s . divide ( s . one ( ) , s . fromReal ( this . size ( ) ) ) ) ; } else if ( propSum == s . posInf ( ) ) { int count = count ( s . posInf ( ) ) ; if ( count == 0 ) { throw new RuntimeException ( "Unable to normalize since sum is infinite but contains no infinities: " + this . toString ( ) ) ; } double constant = s . divide ( s . one ( ) , s . fromReal ( count ) ) ; for ( int d = 0 ; d < this . size ( ) ; d ++ ) { if ( this . getValue ( d ) == s . posInf ( ) ) { this . setValue ( d , constant ) ; } else { this . setValue ( d , s . zero ( ) ) ; } } } else { this . divide ( propSum ) ; assert ! this . containsNaN ( ) ; } return propSum ; }
Normalizes the values so that they sum to 1