Java Distance Calculate distribution(int[] values)

Here you can find the source of distribution(int[] values)

Description

distribution

License

Open Source License

Declaration

public static double[] distribution(int[] values) 

Method Source Code

//package com.java2s;
/*/*from   w  w  w.j  a va  2s.  co m*/
 * ===========================================================
 * GTNA : Graph-Theoretic Network Analyzer
 * ===========================================================
 * 
 * (C) Copyright 2009-2011, by Benjamin Schiller (P2P, TU Darmstadt)
 * and Contributors
 * 
 * Project Info:  http://www.p2p.tu-darmstadt.de/research/gtna/
 * 
 * GTNA is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * GTNA 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 this program. If not, see <http://www.gnu.org/licenses/>.
 * 
 * ---------------------------------------
 * Util.java
 * ---------------------------------------
 * (C) Copyright 2009-2011, by Benjamin Schiller (P2P, TU Darmstadt)
 * and Contributors 
 * 
 * Original Author: Benjamin Schiller;
 * Contributors:    -;
 * 
 * Changes since 2011-05-17
 * ---------------------------------------
 */

public class Main {
    public static double[] distribution(int[] values) {
        return distribution(values, sum(values));
    }

    public static double[] distribution(int[] values, int sum) {
        double[] distribution = new double[values.length];
        for (int i = 0; i < values.length; i++) {
            distribution[i] = (double) values[i] / (double) sum;
        }
        return distribution;
    }

    public static int sum(int[] values) {
        int sum = 0;
        for (int i = 0; i < values.length; i++) {
            sum += values[i];
        }
        return sum;
    }

    public static long sum(long[] values) {
        long sum = 0;
        for (int i = 0; i < values.length; i++) {
            sum += values[i];
        }
        return sum;
    }

    public static double sum(double[] values) {
        double sum = 0;
        for (int i = 0; i < values.length; i++) {
            sum += values[i];
        }
        return sum;
    }
}

Related

  1. distortion(double[] xvalues, double[] yvalues, int[] include)
  2. distpl(double A, double B, double C, double x, double y)
  3. distPointLineSigned(double px, double py, double qx, double qy, double rx, double ry)
  4. distPointLineSquared(double px, double py, double qx, double qy, double rx, double ry)
  5. distPointSegmentSquared(double px, double py, double qx, double qy, double rx, double ry)
  6. distsimFeaturesException()
  7. distSphericalEarth(double lat1, double lon1, double lat2, double lon2)
  8. distSq(double x1, double y1, double x2, double y2)
  9. distSq(double x1, double y1, double z1, double x2, double y2, double z2)