将输入数组标准化为-1.0到1.0之间的双精度值。
//package com.nowjava; /**来 自 NowJava.com - 时代Java**/ public class Main { /** * Normalizes the input array to double values between -1.0 and 1.0. * @param input * @return */ public static double[] normalize(short[] input) { double[] normalizedSamples = new double[input.length]; int max = maxValue(input); for (int i = 0; i < input.length; i++) { normalizedSamples[i] = ((double) input[i]) / max; } return normalizedSamples; } /** * Normalizes the input array to double values between -1.0 and 1.0. * @param input * @return */ public static double[] normalize(double[] input) { double[] normalizedSamples = new double[input.length]; double max = maxValue(input);// from N o w J a v a . c o m for (int i = 0; i < input.length; i++) { normalizedSamples[i] = input[i] / max; } return normalizedSamples; } /** * Calculates max absolute value. * @param input * @return */ public static short maxValue(short[] input) { short max = Short.MIN_VALUE; for (int i = 0; i < input.length; i++) { if (Math.abs(input[i]) > max) { max = (short) Math.abs(input[i]); } } return max; } /** * Calculates max absolute value. * @param input * @return */ public static