APACHE common中的統計學工具

來源:互聯網
上載者:User

package com.njs.math;

import org.apache.commons.math.stat.descriptive.moment.GeometricMean;
import org.apache.commons.math.stat.descriptive.moment.Kurtosis;
import org.apache.commons.math.stat.descriptive.moment.Mean;
import org.apache.commons.math.stat.descriptive.moment.Skewness;
import org.apache.commons.math.stat.descriptive.moment.StandardDeviation;
import org.apache.commons.math.stat.descriptive.moment.Variance;
import org.apache.commons.math.stat.descriptive.rank.Max;
import org.apache.commons.math.stat.descriptive.rank.Min;
import org.apache.commons.math.stat.descriptive.rank.Percentile;
import org.apache.commons.math.stat.descriptive.summary.Product;
import org.apache.commons.math.stat.descriptive.summary.Sum;
import org.apache.commons.math.stat.descriptive.summary.SumOfSquares;

public class MathDemo {

/**
* @param args
*/
public static void main(String[] args) {
double[] values = new double[] { 0.33, 1.33, 0.27333, 0.3, 0.501,
0.444, 0.44, 0.34496, 0.33, 0.3, 0.292, 0.667 };
Min min = new Min();// 最小
Max max = new Max();// 最大
Mean mean = new Mean(); // 算術平均值
Product product = new Product();// 所有數相乘
Sum sum = new Sum();// 算術和
Variance variance = new Variance();// 方差
System.out.println("min: " + min.evaluate(values));
System.out.println("max: " + max.evaluate(values));
System.out.println("mean: " + mean.evaluate(values));
System.out.println("product: " + product.evaluate(values));
System.out.println("sum: " + sum.evaluate(values));
System.out.println("variance: " + variance.evaluate(values));

/**
* percentile(array,p)演算法一般是:將數組array從小到大排序,計算(n-1)*p的整數部分為i,小數部分為j,其中n為數組大小,則percentile的值是:(1-j)*array第i+1個數+j*array第i+2個數。
* 例如:{1,3,4,5,6,7,8,9,19,29,39,49,59,69,79,80}計算30%的分位元:
* (16-1)*30%=4.5, i= 4, j =0.5
* percentile(a,30%)=(1-0.5)*6+0.5*7=6.5
* */
Percentile percentile = new Percentile(); // 百分位元
GeometricMean geoMean = new GeometricMean(); // 幾何平均數,n個正數的連乘積的n次算術根叫做這n個數的幾何平均數
Skewness skewness = new Skewness(); // Skewness 偏度;
Kurtosis kurtosis = new Kurtosis(); // Kurtosis 峰度
SumOfSquares sumOfSquares = new SumOfSquares(); // 平方和
StandardDeviation StandardDeviation = new StandardDeviation();// 標準方差
System.out.println("80 percentile value: " + percentile.evaluate(values, 80.0));
System.out.println("geometric mean: " + geoMean.evaluate(values));
System.out.println("skewness: " + skewness.evaluate(values));
System.out.println("kurtosis: " + kurtosis.evaluate(values));
System.out.println("sumOfSquares: " + sumOfSquares.evaluate(values));
System.out.println("StandardDeviation: " + StandardDeviation.evaluate(values));

}

}

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.