apache commons Math是一组偏向科学计算为主的函数,主要是针对线性代数,数学分析,概率和统计等方面。

我虽然是数学专业毕业,当年也是抱着《数学分析》啃,但是好久不用,这些概念都开始生疏,写一点例子,仅作参考。

 packagetest.ffm83.commons.math;

 importorg.apache.commons.math3.linear.Array2DRowRealMatrix; 

 import org.apache.commons.math3.linear.LUDecomposition; 

 importorg.apache.commons.math3.linear.RealMatrix; 

 importorg.apache.commons.math3.stat.descriptive.moment.GeometricMean; 

 importorg.apache.commons.math3.stat.descriptive.moment.Kurtosis; 

 importorg.apache.commons.math3.stat.descriptive.moment.Mean; 

 importorg.apache.commons.math3.stat.descriptive.moment.Skewness; 

 importorg.apache.commons.math3.stat.descriptive.moment.StandardDeviation; 

 importorg.apache.commons.math3.stat.descriptive.moment.Variance; 

 import org.apache.commons.math3.stat.descriptive.rank.Max; 

 importorg.apache.commons.math3.stat.descriptive.rank.Min; 

 importorg.apache.commons.math3.stat.descriptive.rank.Percentile; 

 importorg.apache.commons.math3.stat.descriptive.summary.Product; 

 importorg.apache.commons.math3.stat.descriptive.summary.Sum; 

 importorg.apache.commons.math3.stat.descriptive.summary.SumOfSquares;

 /**

  * 简单使用commons Math方法

  * @author 范芳铭

  */

 public class MathUsage {

      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 percentile = newPercentile(); // 百分位数 

         GeometricMean geoMean = newGeometricMean(); // 几何平均数,n个正数的连乘积的n次算术根叫做这n个数的几何平均数 

         Skewness skewness = new Skewness(); //Skewness(); 

         Kurtosis kurtosis = new Kurtosis(); //Kurtosis,峰度 

         SumOfSquares sumOfSquares = newSumOfSquares(); // 平方和 

         StandardDeviation StandardDeviation =new StandardDeviation();//标准差 

         System.out.println("80 percentilevalue: " 

                 + percentile.evaluate(values,80.0)); 

         System.out.println("geometricmean: " + 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)); 

        System.out.println("-------------------------------------"); 

         // Create a real matrix with two rowsand three columns 

         double[][] matrixData = { {1d,2d,3d},{2d,5d,3d}}; 

         RealMatrix m = newArray2DRowRealMatrix(matrixData); 

         System.out.println(m); 

         // One more with three rows, twocolumns 

         double[][] matrixData2 = { {1d,2d},{2d,5d}, {1d, 7d}}; 

         RealMatrix n = newArray2DRowRealMatrix(matrixData2);         

         // Note: The constructor copies  the input double[][] array.          

         // Now multiply m by n 

         RealMatrix p = m.multiply(n); 

        System.out.println("p:"+p); 

        System.out.println(p.getRowDimension());    // 2 

        System.out.println(p.getColumnDimension()); // 2          

         // Invert p, using LUdecomposition 

         RealMatrix pInverse = newLUDecomposition(p).getSolver().getInverse(); 

         System.out.println(pInverse); 

     } 

 }

 运行结果如下:

 min: 0.27333

 max: 1.33

 mean: 0.46269083333333333

 product: 2.3429343978460972E-5

 sum: 5.552289999999999

 variance: 0.08757300031742428

 80 percentile value: 0.5674000000000001

 geometric mean: 0.4112886050879374

 skewness: 2.670095445623868

 kurtosis: 7.718241303328169

 sumOfSquares: 3.5322966905000004

 StandardDeviation: 0.2959273564870681

 -------------------------------------

 Array2DRowRealMatrix{{1.0,2.0,3.0},{2.0,5.0,3.0}}

 p:Array2DRowRealMatrix{{8.0,33.0},{15.0,50.0}}

 2

 2

 Array2DRowRealMatrix{{-0.5263157895,0.3473684211},{0.1578947368,-0.0842105263}}

apache commons math 示例代码的更多相关文章

  1. 编写更少量的代码:使用apache commons工具类库

    Commons-configuration   Commons-FileUpload   Commons DbUtils   Commons BeanUtils  Commons CLI  Commo ...

  2. Apache Commons IO入门教程(转)

    Apache Commons IO是Apache基金会创建并维护的Java函数库.它提供了许多类使得开发者的常见任务变得简单,同时减少重复(boiler-plate)代码,这些代码可能遍布于每个独立的 ...

  3. [转]Apache Commons IO入门教程

    Apache Commons IO是Apache基金会创建并维护的Java函数库.它提供了许多类使得开发者的常见任务变得简单,同时减少重复(boiler-plate)代码,这些代码可能遍布于每个独立的 ...

  4. 【java】org.apache.commons.lang3功能示例

    org.apache.commons.lang3功能示例 package com.simple.test; import java.util.Date; import java.util.Iterat ...

  5. Apache Commons CLI 开发命令行工具示例

    概念说明Apache Commons CLI 简介 虽然各种人机交互技术飞速发展,但最传统的命令行模式依然被广泛应用于各个领域:从编译代码到系统管理,命令行因其简洁高效而备受宠爱.各种工具和系统都 提 ...

  6. 使用 Apache Commons CLI 开发命令行工具示例

    Apache Commons CLI 简介 Apache Commons CLI 是 Apache 下面的一个解析命令行输入的工具包,该工具包还提供了自动生成输出帮助文档的功能. Apache Com ...

  7. 使用 Apache Commons CLI 解析命令行参数示例

    很好的输入参数解析方法 ,转载记录下 转载在: https://www.cnblogs.com/onmyway20xx/p/7346709.html Apache Commons CLI 简介 Apa ...

  8. 上传文件代码报错,java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileItemFactory

    2018-09-11 11:11:08.235 ERROR 14352 --- [nio-8080-exec-5] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : ...

  9. Java Socket长连接示例代码

    SocketListenerPusher.java代码如下: import java.io.IOException; import java.net.InetSocketAddress; import ...

随机推荐

  1. 一段神奇的代码(python 2.7)网上抓图小Demo

    二话不说 先上代码: #coding=utf-8 import urllib import re import time global x x = 1 def getHtml(url): page = ...

  2. 高仿中国银行ATM系统

    温馨提示由于代码太多只是上传了ATM客户端部分,管理员和超级管理员还有数据库部分上传了工程包,可以直接点击https://i.cnblogs.com/Files.aspx去里面找.package At ...

  3. 用3D再现2D偶像的可爱,Cygames【偶像大师 灰姑娘女孩】开发示例

          作为万代南梦宫娱乐的偶像养成游戏[偶像大师]的派生作品,是由Mobage创作的[偶像大师 灰姑娘女孩].这个游戏的最新作品,是现在累计下载突破1200万的大作,Android/iOS平台的 ...

  4. Urimoo做试卷

    Urimoo做试卷 题目描述 SBJ最近收到了n张数学卷子,这些卷子的标号为0-n−1,他不想写这些卷子,于是他的好朋友SCX热心地想要帮他撕掉n−1张卷子.SBJ很高兴,但是SCX说,他撕试卷的顺序 ...

  5. FTPClient.listFiles()不能获取文件

    今天使用ftp获取另一台服务器上的文件,发现不管切换到哪个目录,获取什么文件,调用FTPClient.listFiles()方法时返回的始终为空,但是代码又运行正常没有异常抛出. 网上查了下,发现有很 ...

  6. 一个链接引发的血案---------服务器 IO及网络流量暴涨解决历程

    在这里介绍一次因为更改网站地址而引发服务器IO读取速度,网络流入流出速度暴涨10倍的解决经历. 环境:Ubuntu + Nginx + php-cgi + Wordpress 事情是这样的,现在网站使 ...

  7. SELENIUM2 使用JavascriptExecutor在页面Javascipt执行

    目的: 1. 执行一段JS,来改变HTML2. 一些非标准控件无法用selenium2的API时,可以执行JS的办法来取代 主要操作:JavascriptExecutor j = (Javascrip ...

  8. ASP.NET MVC 4 视图页去哪里儿

    这里特别感谢 swagon 提到了Displaymodeprovider,所以才有了本篇博客,也使我对[View的呈现]中寻找视图页的过程有了清晰的认识! 前戏 在MVC中,执行完Action之后,会 ...

  9. Java不同编码方式,中英文字符所占字节数

    测试代码 public class Test { public static void main(String[] args){ String[] charsetNames={ "UTF-8 ...

  10. PHP无限极分类,多种方法|很简单,这里说的很详细,其它地方说的很不好懂

    当你学习php无限极分类的时候,大家都觉得一个字"难"我也觉得很难,所以,现在都还在看,因为工作要用到,所以,就必须得研究研究.   到网上一搜php无限极分类,很多,但好多都是一 ...