Does anyone know of any peakfitting libraries for Java?
I want to give it an array of data, and it tell me the position of the peak.
eg for this data:
x, y
-5, 0.875333026
-4, 0.885868909
-3, 0.895851362
-2, 0.903971085
-1, 0.908274124
0, 0.907117054
1, 0.901894046
2, 0.894918547
3, 0.887651936
4, 0.880114302
5, 0.872150014
it will say that the peak is at (about) -0.75
I'll probably just want to fit a gaussian, or maybe a split gaussian...
.
I've tagged it as curve-fitting, not peak-fitting or peak-finding as I don't have enough reputation to make new tags...
edit: I would prefer Apache (or compatible) licensed code...
Do you want to determine the position of peak by least-squares fitting?
I think the most popular method for this is Levenberg–Marquardt algorithm.
I don't know any Java libraries, but I'd search for terms like: nonlinear curve fitting, nonlinear least-squares, Levenberg–Marquardt or just Marquardt method. You may also consider coding it yourself. If you have a library for matrix manipulations it is like 20-30 lines of code (see Numerical Recipes).
Finally, there is my program for peak detection and peak fitting (peak means bell-shaped curve), on GPL. It includes a library (libfityk) and SWIG-based bindings to this library for Python and Lua. Someone reported generating also Java bindings and using libfityk from Java. But honestly, it may be an overkill for your needs.
Not sure if you've found an answer to this yet, but you can certainly make use of Apache Commons Math http://commons.apache.org/math/index.html It has a couple of curvefitting methods as well as an implementation of the Levenberg-Marquardt library.
Related
I have 3 points [x0 y0], [x1 y1], [x2 y2] with strict conditional x0<x1<x2, y0<y1<y2. All this points lay on some exponentional functions y=ae^(bx)+c. I need to find a,b,c... It's not possible to solve system of 3 equations precisely, therefore I need to approximate it. Is there some math library in java that will help me solve this problem? I find something similar on mathcad
https://help.ptc.com/mathcad/en/index.html#page/PTC_Mathcad_Help/exponential_regression.html but not find in java.
Other way - how to solve system of 3 equations and 3 values approximately.
ae^(bx_0)+c=y_0
ae^(bx_1)+c=y_1
ae^(bx_2)+c=y_2
You have to solve a system of non-linear equations, for which only an approximate solution is possible but can be done using the Newton Raphson's Multivariate method.
The algorithm is, quite frankly, a notational pain but you can go through it here -
http://fourier.eng.hmc.edu/e176/lectures/NM/node21.html.
What is happening essentially is you have a function whose derivative lead you to an 'equilibrium' from an initial random point (which you guess as a possible root)
If you are not willing to write the code yourself this repo can give you a starter of sorts - https://github.com/prasser/newtonraphson.
But AFAIK, no ready library exists for this purpose. You can use Wolfram's Mathematica or MATLAB/OCTAVE for ready libraries though.
That said, here are a few other (more complicated) things you can look into
https://en.wikipedia.org/wiki/Levenberg%E2%80%93Marquardt_algorithm
https://www1.fpl.fs.fed.us/optimization.html
http://icl.cs.utk.edu/f2j/
http://optalgtoolkit.sourceforge.net/
http://scribblethink.org/Computer/Javanumeric/index.html
https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.fmin_l_bfgs_b.html
Hope this helps!
In mathcad there are two functions: cfft and icfft.
I need the same in my java code. It should work for 1d and 2d arrays.
Anyone know any java libraries for it? I tried to use Appache Common Math FastFourierTransformer class, but the length of the data set to be a power of 2.
Check whether JTransforms suits your needs. It is quite known, very fast implementation.
I am trying to convert a Excel Solver solution to a java app
The excel solver is
Solver Parameters:
Set Objective: D24 to Max
By Changing Variable Cells: C4:C23
Subject to the Constraints:
C24 = B24
L24 <= N24
L25 >= N25
(non-negative)
GRG Nonlinear
I have been goggling for sometime and cannot find a java library to achieve this. Any ideas?
I have tried choco-solver http://www.emn.fr/z-info/choco-solver/
Solver solver = new Solver("my first problem");
// 2. Create variables through the variable factory
IntVar x = VariableFactory.bounded("X", 0, 5, solver);
IntVar y = VariableFactory.bounded("Y", 0, 5, solver);
// 3. Create and post constraints by using constraint factories
solver.post(IntConstraintFactory.arithm(x, "+", y, "<", 5));
// 4. Define the search strategy
solver.set(IntStrategyFactory.inputOrder_InDomainMin(new IntVar[]{x,y} ));
// 5. Launch the resolution process
if (solver.findSolution()) {
do {
prettyOut();
}
while (solver.nextSolution());
}
I am finding it difficult to relate this to the Excel solver functions, my math is not great
There is a Simplexsolver implementation in Apache Commons Math, but I can't say anything on performance or possible problem size. Finding non-propertery solutions for optimization problems, can be tricky because it is very difficult to efficently optimize large problem sizes and it is an ongoing field of research with only a hand full of good commerical/research solutions.
If you want to keep excelfiles as input you need to parse the data and convert it. For reading Excel files you can use Apache POI.
If you are looking for an API to read and write to microsoft documents, take a look at Apache POI:
http://poi.apache.org/
http://viralpatel.net/blogs/java-read-write-excel-file-apache-poi/
I'm looking for a Java library to solve this problem:
We know X is sparse(most of it's entries are zero), so X can be recovered by solving this:
variable X;
minimize(norm(X,1)+norm(A*X - Y,2));
It's a MATLAB code, matrix A and vector Y are known and I want the best X.
I saw JOptimizer, but I couldn't use it. (Doesn't have good documentation or examples).
What you need is a reasonably good LP Solver.
Possible Java LP Solver Options
Apache Commons (Math) Simplex Solver.
See this blog post.
If you have access to CPLEX (not-free), its Java API would work great.
Also, you can look into SuanShu, a Java numerical and statistical library
lpSolve has a Java wrapper which can do the job.
Finally, JOptimizer is indeed a good option. Not sure if you looked at this example.
Hope at least one of those help.
As far as I can tell, you're trying to solve a binary integer program for feasibility
Ax = b, x in {0,1}.
I'm not completely sure, but it seems that you might be interested in the optimization problem
min 1'*x
s.t. Ax = b, x in {0,1}
where 1 is a vector of 1's of the same dimension as x.
The feasibility problem may be in practice much easier than the optimization problem - it all depends on a particular A and b.
If you can get a license of either CPLEX or Gurobi (if you're an academic), these are excellent integer programming solvers with good Java API's. If you don't have access to these, lpsolve may be a good option.
As far as I can tell, JOptimizer will not solve your problem since your variables are integers (although I have never used JOptimizer).
To solve convex optimization problems in java you can use the following library https://github.com/erikerlandson/gibbous
For implementation specific reasons, I have to use Java 1.2. I am trying to parse a String object with only numbers (I replace variables beforehand to abstract that step) and operators (PEDMAS). I have found a lot of libraries that do this well, but unfortunately nothing that is compatible with Java 1.2 (Even with fiddling, all of them are dependent on things like generics). Obviously I'm capable of making this myself, but I would certainly prefer to not remake the wheel. Are there any libraries that I just haven't found yet that could do this for me? Thanks.
(Requirements: Binary operators and parentheses)
EDIT: As requested, some examples of input and output:
"(10 / 5) + 4.5 - (8)" would give you -1.5
"(1/3) * 4" would give you 1.3333333...
"5^3 + 4 * 2" would give you 133
"-10 + 5" would give you -5
Hopefully that makes sense.
You can write your own recursive descent parser. This Java implementation uses StreamTokenizer, available since 1.0, but you'll have to substitute int constants for the enum tokens and ignore tokenIs(Symbol.WORD) for function identifiers.