Jakarta-Common-Math使用笔记
来源:互联网 发布:网站seo竞争分析工具 编辑:程序博客网 时间:2024/05/20 11:31
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));
}
}
几个主要功能类:
A.RandomData类:
package demo;
import org.apache.commons.math.random.RandomData;
import org.apache.commons.math.random.RandomDataImpl;
public class MathDemo ...{
public static void main(String[] args) ...{
RandomData randomData = new RandomDataImpl();
for (int i = 0; i < 10; i++) ...{
long value = randomData.nextLong(1, 100);
System.out.println(value);
}
System.out.println("===============");
for (int i = 0; i < 10; i++) ...{
randomData = new RandomDataImpl();
long value = randomData.nextLong(1, 100);
System.out.println(value);
}
}
}
B.RealMatrix类,求解方程
2x + 3y - 2z = 1
-x + 7y + 6x = -2
4x - 3y - 5z = 1
package demo;
import java.io.IOException;
import org.apache.commons.math.linear.RealMatrix;
import org.apache.commons.math.linear.RealMatrixImpl;
public class MathDemo ...{
public static void main(String[] args) throws IOException ...{
double[][] coefficientsData = ...{...{2, 3, -2}, ...{-1, 7, 6}, ...{4, -3, -5}};
RealMatrix coefficients = new RealMatrixImpl(coefficientsData);
double[] constants = ...{1, -2, 1};
double[] solution = coefficients.solve(constants);
System.out.println(solution[0]);
System.out.println(solution[1]);
System.out.println(solution[2]);
}
}
- Jakarta-Common-Math使用笔记
- Jakarta-Common-Math使用笔记
- Jakarta-Common-BeanUtils使用笔记- - -
- Jakarta-Common-BeanUtils使用笔记
- Jakarta-Common-BeanUtils使用笔记
- Jakarta-Common-BeanUtils使用笔记
- Jakarta-Common-BeanUtils使用笔记
- Jakarta-Common-BetWixt使用笔记
- Jakarta-Common-Chain使用笔记
- Jakarta-Common-CLI使用笔记
- Jakarta-Common-Configuration使用笔记
- Jakarta-Common-Codec使用笔记
- Jakarta-Common-JXPath使用笔记
- Jakarta-Common-IO使用笔记
- Jakarta-Common-Digester使用笔记
- Jakarta-Common-FileUpload使用笔记
- Jakarta-Common-BeanUtils使用笔记
- Jakarta-Common-BeanUtils使用笔记
- 总结下排序算法——MoreWindows白话经典算法之七大排序总结篇
- FLEX学习-4 登录界面
- 遍历聚合对象中的元素——迭代器模式(五)
- 这是我的第一个博文!
- 黑马程序员——TreeSet集合添加元素的原理
- Jakarta-Common-Math使用笔记
- 遍历聚合对象中的元素——迭代器模式(六)
- 广东省电子商务认证有限公司-笔试、面试总结
- WebSockets的9大杀手级功能
- SQLServer函数 left()、charindex()、stuff()的使用
- 黑马程序员——事件处理机制
- 黑马程序员 接口 总结
- 工厂三兄弟之抽象工厂模式(一)
- 黑马程序员——一个面对对象的小实例