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 ...
随机推荐
- javaScript条件控制语句
当某段代码的执行,需要首先满足某些条件时,我们就需要用到条件控制语句.判断条件是否满足,满足条件才去执行某些代码. 如判断数组中值等于条件值时,将这个值从数组中删除 a.switch <scri ...
- DataStructure 排序 源码实现
本篇博客实现了 1.冒泡排序 2.冒泡排序的一种优化(当某次冒泡没有进行交换时,退出循环) 3.选择排序 4.归并排序 5.快速排序. 主要是源码的实现,并将自己在敲的过程中所遇到的一些问题记录下来. ...
- 读取config配置
在搭建自动化测试框架时,经常会使用config.properties文件存储配置,文件内容格式如下: 读取config.properties文件代码如下: public class Putils { ...
- [bzoj2463]谁能赢呢
我们通过观察可以发现,当n为偶数时,一定可以转化为一种先手必胜态,即棋盘可以被骨牌所覆盖, 如果n是奇数,那么去掉一格后一定能被1*2的骨牌覆盖,但是先手从左上角走,就进入了这个S态(必胜态),那么和 ...
- centos7设置网关
1.cd /etc/sysconfig/network-scripts 2.vi 网络文件 3.service network restart
- HTTP缓存&代理
一.与缓存有关的Header 1.Request If-Modified-Since: 缓存文件的最后修改时间 If-None-Match: ...
- RestTemplate配置
什么是RestTemplate? RestTemplate是Spring提供的用于访问Rest服务的客户端,RestTemplate提供了多种便捷访问远程Http服务的方法,能够大大提高客户端的编写效 ...
- C++学习笔记 构造&析构 友元 new&delete
构造&析构函数 构造函数 定义:与类同名,可以有参可以无参,主要功能用于在类的对象创建时定义初始化的状态,无返回值,也不能用void修饰,构造函数不能被直接调用,必须通过new运算符在创建对象 ...
- MQTT——服务器搭建(一)
MQTT介绍 MQTT,是IBM推出的一种针对移动终端设备的基于TCP/IP的发布/预订协议,可以连接大量的远程传感器和控制设备: 轻量级的消息订阅和发布(publish/subscribe)协议 建 ...
- IntelliJ IDEA 12 与 Tomcat7 配置
IDEA 全称 IntelliJ IDEA,是java语言开发的集成环境,IntelliJ在业界被公认为最好的java开发工具之一,尤其在智能代码助手.代码自动提示.重构.J2EE支持.各类版本工具( ...