apache commons math 示例代码
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 示例代码的更多相关文章
- 编写更少量的代码:使用apache commons工具类库
Commons-configuration Commons-FileUpload Commons DbUtils Commons BeanUtils Commons CLI Commo ...
- Apache Commons IO入门教程(转)
Apache Commons IO是Apache基金会创建并维护的Java函数库.它提供了许多类使得开发者的常见任务变得简单,同时减少重复(boiler-plate)代码,这些代码可能遍布于每个独立的 ...
- [转]Apache Commons IO入门教程
Apache Commons IO是Apache基金会创建并维护的Java函数库.它提供了许多类使得开发者的常见任务变得简单,同时减少重复(boiler-plate)代码,这些代码可能遍布于每个独立的 ...
- 【java】org.apache.commons.lang3功能示例
org.apache.commons.lang3功能示例 package com.simple.test; import java.util.Date; import java.util.Iterat ...
- Apache Commons CLI 开发命令行工具示例
概念说明Apache Commons CLI 简介 虽然各种人机交互技术飞速发展,但最传统的命令行模式依然被广泛应用于各个领域:从编译代码到系统管理,命令行因其简洁高效而备受宠爱.各种工具和系统都 提 ...
- 使用 Apache Commons CLI 开发命令行工具示例
Apache Commons CLI 简介 Apache Commons CLI 是 Apache 下面的一个解析命令行输入的工具包,该工具包还提供了自动生成输出帮助文档的功能. Apache Com ...
- 使用 Apache Commons CLI 解析命令行参数示例
很好的输入参数解析方法 ,转载记录下 转载在: https://www.cnblogs.com/onmyway20xx/p/7346709.html Apache Commons CLI 简介 Apa ...
- 上传文件代码报错,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] : ...
- Java Socket长连接示例代码
SocketListenerPusher.java代码如下: import java.io.IOException; import java.net.InetSocketAddress; import ...
随机推荐
- SQL语法整理
SQL是Structured Query Language的缩写,中文全名为结构化查询语言,是一种用于数据存储,查询,更新和管理的关系数据库系统. SQL语法 创建表 create table tab ...
- 青蛙跳100级台阶算法,完整可运行,php版本
/* 算法题目 * 2016年4月11日16:11:08 * 一只青蛙,一次可以跳1步,或者2步,或者3步,现在要跳100级台阶,请问青蛙有多少种上100级台阶的跳法 * 1步的有$n 2步的有$m ...
- JMeter 将上一个请求的结果作为下一个请求的参数——使用正则提取器(转载)
在接口测试和压力测试过程中,经常会将几个流程串联起来才能测试.如:我要进行获取用户信息接口测试,我就要先登录成功后,才能获取用户信息.所以,我就要首先要登录,获得我的登录凭证(tokenId或tick ...
- Secure Digital
https://en.wikipedia.org/wiki/Secure_Digital#Technical_details Secure Digital (SD) is a non-volatile ...
- Symmetric Multiprocessor Organization
COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION
- 源码网站(msdn.itellyou.cn) good
verysource 100万源码http://www.verysource.com/category/delphi-vcl/ MSDN DOWNLOADhttp://msdn.itellyou.cn ...
- NGINX 配置 SSL 双向认证
对于 NGINX 的 HTTPS 配置,通常情况下我们只需要实现服务端认证就行,因为浏览器内置了一些受信任的证书颁发机构(CA),服务器端只需要拿到这些机构颁发的证书并配置好,浏览器会自己校验证书的可 ...
- rbd snap(1)
来自官方文档: 快照介绍 快照是映像在某个特定时间点的一份只读副本. 对当前镜像打过快照以后,Active层仍在当前镜像,快照文件为只读. Note 如果在做快照时映像仍在进行 I/O 操作,快照可能 ...
- awk sed 总结
Awk总结笔记 介绍 90年代 new awk :nawk Linux 的是gawk 我们简化awk 用法 # awk [options ] ‘scripts’ file1 file2 .... # ...
- (转载)spring mvc DispatcherServlet详解之一---处理请求深入解析
要深入理解spring mvc的工作流程,就需要先了解spring mvc的架构: 从上图可以看到 前端控制器DispatcherServlet在其中起着主导作用,理解了DispatcherServl ...