Java Array Normalize normalize(double[] probDist)

Here you can find the source of normalize(double[] probDist)

Description

normalize

License

Open Source License

Declaration

public static double[] normalize(double[] probDist) 

Method Source Code

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

import java.util.ArrayList;

import java.util.List;

public class Main {
    public static double[] normalize(double[] probDist) {
        int len = probDist.length;
        double total = 0.0;
        for (double d : probDist) {
            total = total + d;//from  w  ww .  j  a va  2s  . c o m
        }

        double[] normalized = new double[len];
        if (total != 0) {
            for (int i = 0; i < len; i++) {
                normalized[i] = probDist[i] / total;
            }
        }

        return normalized;
    }

    public static List<Double> normalize(List<Double> values) {
        double[] valuesAsArray = new double[values.size()];
        for (int i = 0; i < valuesAsArray.length; i++) {
            valuesAsArray[i] = values.get(i);
        }
        double[] normalized = normalize(valuesAsArray);
        List<Double> results = new ArrayList<Double>();
        for (int i = 0; i < normalized.length; i++) {
            results.add(normalized[i]);
        }
        return results;
    }
}

Related

  1. normalize(double[] doubles, double sum)
  2. normalize(double[] in)
  3. normalize(double[] in)
  4. normalize(double[] point, double[] uni, double[] unideltas)
  5. normalize(double[] points)
  6. normalize(double[] state)
  7. normalize(double[] v)
  8. normalize(double[] v)
  9. normalize(double[] vals)