public void setWeight ( int i , double w ) { if ( i >= size ( ) || i < 0 ) throw new IndexOutOfBoundsException ( "Dataset has only " + size ( ) + " members, can't access index " + i ) ; else if ( Double . isNaN ( w ) || Double . isInfinite ( w ) || w < 0 ) throw new ArithmeticException ( "Invalid weight assignment of " + w ) ; if ( w == 1 && weights == null ) return ; //nothing to do, already handled implicitly if ( weights == null ) //need to init? { weights = new double [ size ( ) ] ; Arrays . fill ( weights , 1.0 ) ; } //make sure we have enouh space if ( weights . length <= i ) weights = Arrays . copyOfRange ( weights , 0 , Math . max ( weights . length * 2 , i + 1 ) ) ; weights [ i ] = w ; }
Sets the weight of a given datapoint within this data set .