Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pure Java support for L-BFGS-B ? #811

Open
BerryHoll opened this issue Feb 23, 2025 · 4 comments
Open

Pure Java support for L-BFGS-B ? #811

BerryHoll opened this issue Feb 23, 2025 · 4 comments
Labels

Comments

@BerryHoll
Copy link

Dear Haifeng Li,

thank you for providing this great repository of code! We are working in the Gaia Data Processing and Analyses Consortium (DPAC) of the European Space Agency (ESA) space mission Gaia, reducing data of over a billion sources to catalog our galaxy for all kind of interesting objects (https://www.esa.int/Science_Exploration/Space_Science/Gaia).

Within the part of the consortium we work in, we are only allowed to use pure Java (without extensions like BLAS). In the analyses of astrometric data (one-dimensional time-series of positional measurements) we would like to make use of L-BFGS-B as our go-to method for non-linear fitting with parameter constraints, as it seems the superior method to use in our (non-production) Python code.
So far we have not found a good Java library for this other than yours. However, running the (latest) unit test (smile.math/BGGSTest) we see that only testLBFGS, and testBFGS pass without the need of installing BLAS. Since installing BLAS is not possible in our official run-environment (and over which we have no control), would it be possible to implement the L-BFGS-B functionality in pure Java?
Or else, would you know if it already exists?

Apologies for asking about a functionality that in principle already exists in your code, but which unfortunately we cannot make use of in this context.

Best regards,
Berry Holl on behalf of several of my colleagues working on detecting exoplanets in Gaia data

@kklioss
Copy link
Collaborator

kklioss commented Feb 23, 2025

Hi Berry,

Thanks for reaching out. All BFGS family algorithms (BFGS, L-BFGS, and L-BFGS-B) are implemented in pure Java. You can safely add smile-base.jar into your project for your purpose without any dependencies.

@BerryHoll
Copy link
Author

Dear @kklioss, many thanks for your quick reply!
I added smile-base.jar to my project, then copied the latest BFGSTest.java into my project and run the tests:

  • testBFGS: PASS
  • testLBFGS: PASS
  • testLBFGSB: FAIL
  • testLBFGSB2: FAIL
  • testLBFGSB3: FAIL

where all the LBFGSB* tests fail due to no OpenBLAS being available, see stack trace below.

Did I understand correctly from your reply that I should be able to run/configure the code in a way that will allow me to not have OpenBLAS installed/coupled?
Note that I am running this test from a Mac M1 processor, though the official code will be run on some other architecture.

Full stack trace for testLBFGSB:

java.lang.NoClassDefFoundError: org/bytedeco/openblas/global/openblas
	at smile.math.blas.openblas.OpenBLAS.gemv(OpenBLAS.java:116)
	at smile.math.matrix.Matrix.mv(Matrix.java:1519)
	at smile.math.matrix.IMatrix.tv(IMatrix.java:322)
	at smile.math.BFGS.cauchy(BFGS.java:766)
	at smile.math.BFGS.minimize(BFGS.java:634)
	at gaia.cu4.du437.utils.test.BFGSTest.testLBFGSB(BFGSTest.java:137)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.BlockJUnit4ClassRunner$1.evaluate(BlockJUnit4ClassRunner.java:100)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:103)
	at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:63)
	at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
	at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
	at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:93)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:529)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:756)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:452)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
Caused by: java.lang.ClassNotFoundException: org.bytedeco.openblas.global.openblas
	... 30 more

@kklioss
Copy link
Collaborator

kklioss commented Feb 24, 2025

Sorry, my bad. L-BFGS-B does need to compute matrix inverse on the fly. So, it depends on LAPACK. However, Smile V1 has pure Java implementation on matrix computation including matrix inverse. You will need to create a package that combine V1 Matrix class with V4's BFGS class.

@BerryHoll
Copy link
Author

Thanks @kklioss, I'll have a look, many thanks for your quick feedback!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants