Java Array Normalize normalize(double[][] matrix, double lower, double upper)

Here you can find the source of normalize(double[][] matrix, double lower, double upper)

Description

normalize

License

Open Source License

Declaration

public static double[][] normalize(double[][] matrix, double lower, double upper) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.Arrays;

public class Main {
    public static double[][] normalize(double[][] matrix, double lower, double upper) {
        double[][] normalized = new double[matrix.length][];
        for (int row = 0; row < matrix.length; row++) {
            //Feed each row to the overloaded method
            normalized[row] = normalize(matrix[row], lower, upper);
        }//from   ww w.j ava2  s .c o m
        return normalized;
    }

    public static double[] normalize(double[] vector, double lower, double upper) {
        double[] normalized = new double[vector.length];
        double max = Arrays.stream(vector).max().getAsDouble();
        double min = Arrays.stream(vector).min().getAsDouble();

        for (int i = 0; i < normalized.length; i++) {
            normalized[i] = (vector[i] - min) * (upper - lower) / (max - min) + lower;
        }
        return normalized;
    }
}

Related

  1. normalize(double[] w)
  2. normalize(double[] weights)
  3. normalize(double[] weights)
  4. normalize(double[] x)
  5. normalize(double[] xs)
  6. normalize(double[][] result)
  7. normalize(double[][] X)
  8. normalize(final byte[] input, final int bit)
  9. normalize(final double[] a)