当前位置:主页   - 电脑 - 程序设计 - JAVA
Jakarta-Common-Math使用笔记
来源:网络   作者:   更新时间:2012-06-08
收藏此页】    【字号    】    【打印】    【关闭

  apache的math组件,尽管不常用,我今天也整理出来。

  下载地址: http://commons.apache.org/math/

  示例代码:

package demo;
  
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 TestMathUserage ...{
  
  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 };
    /**//*
     * System.out.println( "min: " + StatUtils.min( values ) );
     * System.out.println( "max: " + StatUtils.max( values ) );
     * System.out.println( "mean: " + StatUtils.mean( values ) ); // Returns
     * the arithmetic mean of the entries in the input array, or Double.NaN
     * if the array is empty System.out.println( "product: " +
     * StatUtils.product( values ) ); //Returns the product of the entries
     * in the input array, or Double.NaN if the array is empty.
     * System.out.println( "sum: " + StatUtils.sum( values ) ); //Returns
     * the sum of the values in the input array, or Double.NaN if the array
     * is empty. System.out.println( "variance: " + StatUtils.variance(
     * values ) ); // Returns the variance of the entries in the input
     * array, or Double.NaN if the array is empty.
     */
  
    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 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));
  }
}

其它资源
来源声明

版权与免责声明
1、本站所发布的文章仅供技术交流参考,本站不主张将其做为决策的依据,浏览者可自愿选择采信与否,本站不对因采信这些信息所产生的任何问题负责。
2、本站部分文章来源于网络,其版权为原权利人所有。由于来源之故,有的文章未能获得作者姓名,署“未知”或“佚名”。对于这些文章,有知悉作者姓名的请告知本站,以便及时署名。如果作者要求删除,我们将予以删除。除此之外本站不再承担其它责任。
3、本站部分文章来源于本站原创,本站拥有所有权利。
4、如对本站发布的信息有异议,请联系我们,经本站确认后,将在三个工作日内做出修改或删除处理。
请参阅权责声明