apache-commons-math

How to perform Integer Linear Programming in Apache Commons Math

狂风中的少年 提交于 2020-01-17 08:16:12
问题 The org.apache.commons.math3.optim.linear package in Apache Commons Math Library allows Linear Optimization but the returned values are double. Is there any way to perform Integer Linear Programming using this library? I tried googling but there seems to be no mention of ILP anywhere. Alternatively, is there any other Java library that can do ILP? please not that I need to run this on android so SCPSolver, GLPK, Or-tools. etc. are not possible. Thanks in advance. 回答1: As this question and

Newton-Raphson method using the Math.Commons library

我们两清 提交于 2019-12-24 11:35:30
问题 I made a test program to try the NewtonRaphsonSolver class through the Apache Commons Math library. Newton's method is used to find roots for a given function. The test program that I wrote references the cos(x) function (I have a more difficult function to analyze and am looking at the cos(x) function first). The code for the test program is import org.apache.commons.math3.analysis.differentiation.DerivativeStructure; import org.apache.commons.math3.analysis.differentiation

How to multiply a RealVector by a RealMatrix?

余生颓废 提交于 2019-12-22 17:42:18
问题 How can I multiply a given RealVector by a RealMatrix ? I can't find any "multiply" method on both classes, only preMultiply but it seems not work: // point to translate final RealVector p = MatrixUtils.createRealVector(new double[] { 3, 4, 5, 1 }); // translation matrix (6, 7, 8) final RealMatrix m = MatrixUtils.createRealMatrix(new double[][] { {1, 0, 0, 6}, {0, 1, 0, 7}, {0, 0, 1, 8}, {0, 0, 0, 1} }); // p2 = m x p final RealVector p2 = m.preMultiply(p); // prints {3; 4; 5; 87} // expected

How to multiply a RealVector by a RealMatrix?

本秂侑毒 提交于 2019-12-22 17:42:18
问题 How can I multiply a given RealVector by a RealMatrix ? I can't find any "multiply" method on both classes, only preMultiply but it seems not work: // point to translate final RealVector p = MatrixUtils.createRealVector(new double[] { 3, 4, 5, 1 }); // translation matrix (6, 7, 8) final RealMatrix m = MatrixUtils.createRealMatrix(new double[][] { {1, 0, 0, 6}, {0, 1, 0, 7}, {0, 0, 1, 8}, {0, 0, 0, 1} }); // p2 = m x p final RealVector p2 = m.preMultiply(p); // prints {3; 4; 5; 87} // expected

Interpolate function using Apache Commons Math

人走茶凉 提交于 2019-12-21 19:41:20
问题 I'm trying to implement some Interpolation functions to plot some values where the X value = Date.seconds and the Y value = double. I'v been researching using the Apache Commons Math lib to achieve this and I've found a method I think I might be able to use here The method I'm trying to understand: public double linearInterp(double[] x, double[] y, double xi) { // return linear interpolation of (x,y) on xi LinearInterpolator li = new LinearInterpolator(); PolynomialSplineFunction psf = li

Is there an equivalent function for anova.lm() in Java?

China☆狼群 提交于 2019-12-18 09:15:08
问题 I am comparing two linear models in R with Anova, and I would like to do the same thing in Java. To simplify it, I took the example code from https://stats.stackexchange.com/questions/48854/why-am-i-getting-different-intercept-values-in-r-and-java-for-simple-linear-regr and modified it a bit below. The models are test_trait ~ geno_A + geno_B and test_trait ~ geno_A + geno_B + geno_A:geno_B . The coefficients of the models implemented in R and Java are the same. In R I use anova(fit, fit2)

Why does tail probability in apache math drop to zero after 1E-16?

不打扰是莪最后的温柔 提交于 2019-12-12 03:48:28
问题 Apache Math 3.4 (and 3.3), java 1.8.0_25 import org.apache.commons.math3.distribution.ChiSquaredDistribution; ChiSquaredDistribution chisq = new ChiSquaredDistribution(23) System.out.println(1.0 - chisq.cumulativeProbability(130) // 1.1102230246251565E-16 System.out.println(1.0 - chisq.cumulativeProbability(131) // 0.0 Why does Apache Math return 0.0 in the second call? Some stat libraries (Excel, but not R) do return values that are much smaller than 1E-16 for the tail probabilities.

Install commons math library for java in Ubuntu

∥☆過路亽.° 提交于 2019-12-10 21:02:31
问题 So I've been looking for a while, and found that I need to import the org.apache.commons.math3.util.ArithmeticUtils library in a Java program I'm writing. Now this is my first Java program, and I can't figure out how to use the library. Am I missing something here? Do I need to attach an option when I'm using the command? javac MyProgramNameGoesHere.java -something(?) Or is there some special place where I need to install the the library package to? Edit:: I am also doing this with gEdit and

How to compute integration of a function in apache commons math3 library?

ε祈祈猫儿з 提交于 2019-12-07 09:01:45
问题 I am trying to integrate a very simple function. integral(x.dx). Instead of getting an answer of 1, I am getting an answer as 0, or 0.5 when I include limits from 0 to 1. Is there something I misunderstand about the implementation of the integration in apache commons library? import org.apache.commons.math3.analysis.integration.*; import org.apache.commons.math3.analysis.polynomials.*; public static void main(String args[]) { SimpsonIntegrator simpson = new SimpsonIntegrator();

Standard deviation with Apache Commons Math

一曲冷凌霜 提交于 2019-12-07 03:52:25
问题 I am computing the SD of a vector using Apache Commons Math. The problem: I get different values than by hand DescriptiveStatistics stats = new DescriptiveStatistics(); stats.addValue(value1); ... stats.addValue(value8); stats.getStandardDeviation(); E.g., take the values [1699.0, 1819.0, 1699.0, 1719.0, 1689.0, 1709.0, 1819.0, 1689.0]. SD should be 52.067 but Commons Math = 55.662. What am I doing wrong? 回答1: The Apache StandardDeviation class can be used for computing both values: "Standard