Apache Commons Math is a set of functions biased toward scientific calculation, mainly for linear algebra, mathematical analysis, probability and statistics.
Although I graduated from mathematics, I was also holding the "mathematical analysis" gnawing, but for a long time, these concepts are beginning unfamiliar, write a little example, only for reference.
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;
/**
* Simple use of the Commons math method
* @author Fan Fangming
*/
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 (); Arithmetic average
Product Product = new product ();//Product
Sum sum = new sum ();
Variance Variance = new Variance ();//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 (); Percentile number of percentiles
Geometricmean Geomean = Newgeometricmean (); Geometric averages, n-times arithmetic roots of a continuous product of n positive numbers are called the geometric averages of the n numbers.
skewness skewness = new skewness (); Skewness ();
Kurtosis Kurtosis = new Kurtosis (); Kurtosis, peak degree
Sumofsquares sumofsquares = Newsumofsquares (); Sum of squares
Standarddeviation standarddeviation =new standarddeviation ();//Standard deviation
System.out.println ("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 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);
}
}
The results of the operation are as follows:
min:0.27333
max:1.33
mean:0.46269083333333333
Product:2.3429343978460972e-5
sum:5.552289999999999
variance:0.08757300031742428
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}}
Introduction and use of Apache Commons math