Normalizes a given value of a numeric attribute.

@param x 		the value to be normalized
@param i 		the attribute's index
@return		the normalized value
480730
protected double norm(double x, int i) {
    if (Double.isNaN(m_Ranges[i][R_MIN]) || (m_Ranges[i][R_MAX] == m_Ranges[i][R_MIN]))
      return 0;
    else
      return (x - m_Ranges[i][R_MIN]) / (m_Ranges[i][R_WIDTH]);
  }
273738
private void normalize(DoubleVector v) {
        double magnitude = 0;
        for (int i = 0; i < v.length(); ++i)
            magnitude += Math.pow(v.get(i), 2);
        if (magnitude == 0)
            return;

        magnitude = Math.sqrt(magnitude);
        for (int i = 0; i < v.length(); ++i)
            v.set(i, v.get(i)/magnitude);
    }
258933
public static String getLastMentionedX(List<Timex3> linearDates, int i, String x, Language language) {
		NormalizationManager nm = NormalizationManager.getInstance(language, true);
		
		// Timex for which to get the last mentioned x (i.e., Timex i)
		Timex3 t_i = linearDates.get(i);
		
		String xValue = "";
		int j = i - 1;
		while (j >= 0) {
			Timex3 timex = linearDates.get(j);
			// check that the two timexes to compare do not have the same offset:
				if (!(t_i.getBegin() == timex.getBegin())) {
				
					String value = timex.getTimexValue();
					if (!(value.contains("funcDate"))){
						if (x.equals("century")) {
							if (value.matches("^[0-9][0-9].*")) {
								xValue = value.substring(0,2);
								break;
							}
							else if (value.matches("^BC[0-9][0-9].*")){
								xValue = value.substring(0,4);
								break;
							}
							else {
								j--;
							}
						}
						else if (x.equals("decade")) {
							if (value.matches("^[0-9][0-9][0-9].*")) {
								xValue = value.substring(0,3);
								break;
							}
							else if (value.matches("^BC[0-9][0-9][0-9].*")){
								xValue = value.substring(0,5);
								break;
							}
							else {
								j--;
							}
						}
						else if (x.equals("year")) {
							if (value.matches("^[0-9][0-9][0-9][0-9].*")) {
								xValue = value.substring(0,4);
								break;
							}
							else if (value.matches("^BC[0-9][0-9][0-9][0-9].*")){
								xValue = value.substring(0,6);
								break;
							}
							else {
								j--;
							}
						}
						else if (x.equals("dateYear")) {
							if (value.matches("^[0-9][0-9][0-9][0-9].*")) {
								xValue = value;
								break;
							}
							else if (value.matches("^BC[0-9][0-9][0-9][0-9].*")){
								xValue = value;
								break;
							}
							else {
								j--;
							}
						}
						else if (x.equals("month")) {
							if (value.matches("^[0-9][0-9][0-9][0-9]-[0-9][0-9].*")) {
								xValue = value.substring(0,7);
								break;
							}
							else if (value.matches("^BC[0-9][0-9][0-9][0-9]-[0-9][0-9].*")){
								xValue = value.substring(0,9);
								break;
							}
							else {
								j--;
							}
						}
						else if (x.equals("month-with-details")) {
							if (value.matches("^[0-9][0-9][0-9][0-9]-[0-9][0-9].*")) {
								xValue = value;
								break;
							}
//							else if (value.matches("^BC[0-9][0-9][0-9][0-9]-[0-9][0-9].*")) {
//								xValue = value;
//								break;
//							}
							else {
								j--;
							}
						}
						else if (x.equals("day")) {
							if (value.matches("^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9].*")) {
								xValue = value.substring(0,10);
								break;
							}
//							else if (value.matches("^BC[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9].*")) {
//								xValue = value.substring(0,12);
//								break;
//							}
							else {
								j--;
							}
						}
						else if (x.equals("week")) {
							if (value.matches("^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9].*")) {
								for (MatchResult r : Toolbox.findMatches(Pattern.compile("^(([0-9][0-9][0-9][0-9])-[0-9][0-9]-[0-9][0-9]).*"), value)) {
									xValue = r.group(2)+"-W"+DateCalculator.getWeekOfDate(r.group(1));
									break;
								}
								break;
							}
							else if (value.matches("^[0-9][0-9][0-9][0-9]-W[0-9][0-9].*")) {
								for (MatchResult r : Toolbox.findMatches(Pattern.compile("^([0-9][0-9][0-9][0-9]-W[0-9][0-9]).*"), value)) {
									xValue = r.group(1);
									break;
								}
								break;
							}
							// TODO check what to do for BC times
							else {
								j--;
							}
						}
						else if (x.equals("quarter")) {
							if (value.matches("^[0-9][0-9][0-9][0-9]-[0-9][0-9].*")) {
								String month   = value.substring(5,7);
								String quarter = nm.getFromNormMonthInQuarter(month);
								if(quarter == null) {
									quarter = "1";
								}	
								xValue = value.substring(0,4)+"-Q"+quarter;
								break;
							}
							else if (value.matches("^[0-9][0-9][0-9][0-9]-Q[1234].*")) {
								xValue = value.substring(0,7);
								break;
							}
							// TODO check what to do for BC times
							else {
								j--;
							}
						}
						else if (x.equals("dateQuarter")) {
							if (value.matches("^[0-9][0-9][0-9][0-9]-Q[1234].*")) {
								xValue = value.substring(0,7);
								break;
							}
							// TODO check what to do for BC times
							else {
								j--;
							}
						}
						else if (x.equals("season")) {
							if (value.matches("^[0-9][0-9][0-9][0-9]-[0-9][0-9].*")) {
								String month   = value.substring(5,7);
								String season = nm.getFromNormMonthInSeason(month);
								xValue = value.substring(0,4)+"-"+season;
								break;
							}
//							else if (value.matches("^BC[0-9][0-9][0-9][0-9]-[0-9][0-9].*")) {
//								String month   = value.substring(7,9);
//								String season = nm.getFromNormMonthInSeason(month);
//								xValue = value.substring(0,6)+"-"+season;
//								break;
//							}
							else if (value.matches("^[0-9][0-9][0-9][0-9]-(SP|SU|FA|WI).*")) {
								xValue = value.substring(0,7);
								break;
							}
//							else if (value.matches("^BC[0-9][0-9][0-9][0-9]-(SP|SU|FA|WI).*")) {
//								xValue = value.substring(0,9);
//								break;
//							}
							else {
								j--;
							}
						}	
					} else {
						j--;
					}
				} else {
					j--;
				}
		}
		return xValue;
	}
637792
def _transform_i(self, x, i):
        """"""
        x = self._shift_or_mirror_into_invertible_i(x, i)
        lb = self._lb[self._index(i)]
        ub = self._ub[self._index(i)]
        al = self._al[self._index(i)]
        au = self._au[self._index(i)]
        if x < lb + al:
            return lb + (x - (lb - al))**2 / 4 / al
        elif x < ub - au:
            return x
        elif x < ub + 3 * au:
            return ub - (x - (ub + au))**2 / 4 / au
        else:
            assert False  # shift removes this case
            return ub + au - (x - (ub + au))
1274312
protected String convertToHex(int i) {

        String hexString = Integer.toHexString(i);
        while (hexString.length() < 2) {
            hexString = "0" + hexString;
        }
        return hexString;
    }
478954
public static int parseInt(String s, int i) {
		if (s == null) {
			return i;
		}
		try {
			return Integer.parseInt(s.trim());
		} catch (NumberFormatException e) {
			return i;
		}
	}
500504
public static double normInf(double[] x) {
        int n = x.length;

        double f = Math.abs(x[0]);
        for (int i = 1; i < n; i++) {
            f = Math.max(f, Math.abs(x[i]));
        }

        return f;
    }
1337663
public static String padTo(final int i, final int pad) {
        String n = Integer.toString(i);
        return padTo(n, pad);
    }
1329434
public static char cArrayGet(char[] a, int i) {
        try {
            return a[i];
        } catch (Throwable t) {
            return a[DefaultGroovyMethodsSupport.normaliseIndex(i,a.length)];
        }
    }
907949
public static void standardize(double[][] x) {
        int n = x.length;
        int p = x[0].length;

        double[] center = colMeans(x);
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < p; j++) {
                x[i][j] = x[i][j] - center[j];
            }
        }

        double[] scale = new double[p];
        for (int j = 0; j < p; j++) {
            for (int i = 0; i < n; i++) {
                scale[j] += Math.sqr(x[i][j]);
            }
            scale[j] = Math.sqrt(scale[j] / (n-1));

            if (!Math.isZero(scale[j])) {
                for (int i = 0; i < n; i++) {
                    x[i][j] /= scale[j];
                }
            }
        }
    }
283888
public AttributeVector column(int i) {
        if (i < 0 || i >= attributes.length) {
            throw new IllegalArgumentException("Invalid column index: " + i);
        }

        double[] vector = new double[size()];
        for (int j = 0; j < vector.length; j++) {
            vector[j] = data.get(j).x[i];
        }

        return new AttributeVector(attributes[i], vector);
    }
281662
public double interpolate(double... x) {
        if (x.length != this.x[0].length) {
            throw new IllegalArgumentException(String.format("Invalid input vector size: %d, expected: %d", x.length, this.x[0].length));
        }

        double sum = 0.0, sumw = 0.0;
        for (int i = 0; i < this.x.length; i++) {
            double f = rbf.f(Math.distance(x, this.x[i]));
            sumw += w[i] * f;
            sum += f;
        }

        return normalized ? sumw / sum : sumw;
    }
1299222
protected AIntLiteralExp getIntLiteral(long i)
	{
		AIntLiteralExp number = new AIntLiteralExp();
		ILexIntegerToken literal = new LexIntegerToken(i, null);
		number.setValue(literal);
		return number;
	}
662045
public static void normalizeF( DMatrixRMaj A ) {
        double val = normF(A);

        if( val == 0 )
            return;

        int size = A.getNumElements();

        for( int i = 0; i < size; i++) {
            A.div(i , val);
        }
    }
944200
public int get(int i, int j) {
        if (i < 0 || i >= size()) {
            throw new IllegalArgumentException("Invalid index: i = " + i);
        }

        int[] x = get(i).x;
        if (x.length == 0) {
            return 0;
        }
        
        int low = 0;
        int high = x.length - 1;
        int mid = (low + high) / 2;
        
        while (j != x[mid] && low <= high) {
            mid = (low + high) / 2;
            if (j < x[mid]) 
                high = mid - 1;
            else
                low = mid + 1;
        }
        
        if (j == x[mid]) {
            return 1;
        } else {
            return 0;
        }
    }
43660
public static void normalize(double[] a) {
    double total = sum(a);
    if (total == 0.0 || Double.isNaN(total)) {
      throw new RuntimeException("Can't normalize an array with sum 0.0 or NaN: " + Arrays.toString(a));
    }
    multiplyInPlace(a, 1.0/total); // divide each value by total
  }
762812
public boolean set(int i, double x) {
        if (x == 0.0) {
            remove(i);
            return false;
        }
        
        Iterator<Entry> it = array.iterator();
        for (int k = 0; it.hasNext(); k++) {
            Entry e = it.next();
            if (e.i == i) {
                e.x = x;
                return false;
            } else if (e.i > i) {
                array.add(k, new Entry(i, x));
                return true;
            }
        }
        
        array.add(new Entry(i, x));
        return true;
    }