Here you can find the source of normalizeVectorMaxMin(float[] samples)
Parameter | Description |
---|---|
samples | a parameter |
public static float[] normalizeVectorMaxMin(float[] samples)
//package com.java2s; /*//from w w w. j a va 2s.c o m * Copyright (c) 2008-2013 Maksim Khadkevich and Fondazione Bruno Kessler. * * This file is part of MART. * MART is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2, as published * by the Free Software Foundation. * * MART is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with MART; if not, write to the Free Software Foundation, * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ public class Main { /** * Normalizes vector so that all values are in the range [0, 1] * * @param samples * @return */ public static float[] normalizeVectorMaxMin(float[] samples) { float[] out = new float[samples.length]; float maxValue = findMax(samples); float minValue = findMin(samples); if (maxValue > minValue) { for (int i = 0; i < samples.length; i++) { out[i] = (samples[i] - minValue) / (maxValue - minValue); } } else { for (int i = 0; i < samples.length; i++) { out[i] = 0; } } return out; } /** * Finds maximal element in array * * @param array array * @return Minimum Value */ public static float findMax(float[] array) { float max = Float.MIN_VALUE; for (int i = 0; i < array.length; i++) { if (array[i] > max) { max = array[i]; } } return max; } public static int findMax(int[] array) { int max = Integer.MIN_VALUE; for (int i = 0; i < array.length; i++) { if (array[i] > max) { max = array[i]; } } return max; } /** * Finds minimal element in array * * @param array array * @return Minimum Value */ public static float findMin(float[] array) { float min = Float.MAX_VALUE; for (int i = 0; i < array.length; i++) { if (array[i] < min) { min = array[i]; } } return min; } }