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. IO复用三种方式

    简介 IO复用技术,简单来说就是同时监听多个描述符.在没有用到IO复用以前,只能是一个线程或一个 线程去监听,服务端同时有多个连接的时候,需要创建多个线程或者进程.而且,并不是所有的连 接是一直在传输 ...

  2. 用CSS3实现瀑布流布局

    以前使用瀑布流都要用js,现在有了css3,可以轻松实现了. 掌握点: 1.column-count 把div中的文本分为多少列 2.column-width 规定列宽 3.column-gap 规定 ...

  3. css引入方式

    1.<style>          body{}    </style> 2.写在一个单独的文件里面保存即新建一个文件:xx.css; 注明该文件的位置<link re ...

  4. Linux最常用命令的小总结

    目录及文件的基本操作: cd  .. 切换到当前目录的上一级目录 cd 切换工作目录至当前用户的家目录 cd - 返回到上一个打开的目录(像遥控器上的切换键,切换到上一个播放的电视频道) ll -h ...

  5. 调试一个socket通信bug的心理过程和反思

    背景交代.最近在玩lua的服务端编码, 有项目A,B,AB都是同一个模子的.我手上有A的winsocket客户端和服务端的代码,B项目早期的一份linux下的lua client.服务端.客户端都是L ...

  6. noi 1.5 45:金币

    描述 国王将金币作为工资,发放给忠诚的骑士.第一天,骑士收到一枚金币:之后两天(第二天和第三天)里,每天收到两枚金币:之后三天(第四.五.六天)里,每天收到三枚金币:之后四天(第七.八.九.十天)里, ...

  7. 关于baseflight cleanflight naze32不能解锁的办法

    需要修改源代码,重新编译.. mcfg.mincheck = 1150; mcfg.maxcheck = 1850; 当然,这是笨方法.还有个办法设置解锁检查的最大最小油门 在控制台,也就是 CLI那 ...

  8. Windows Phone 五、配置存储

    基本存储形式 本地设置:ApplicationData.Current.LocalSettings 漫游设置:ApplicationData.Current.RoamingSettings 支持的数据 ...

  9. SWFUpload

    引用:http://www.cnblogs.com/2050/archive/2012/08/29/2662932.html SWFUpload是一个flash和js相结合而成的文件上传插件,其功能非 ...

  10. webservice通信调用天气预报接口实例

    转载:http://www.cnblogs.com/warrior4236/p/5668449.html 一:环境搭建 1:新建一个java project工程weatherInf 2:引入相应的ja ...