Giter Club home page Giter Club logo

Comments (7)

apete avatar apete commented on August 20, 2024

float is used in some parts of ojAlgo, but is not available with the optimisation solvers. And it wont be easy to add. Further I'm not convinced it would be much faster. For larger models you could potentially save a lot of memory and that would improve L1/L2/L3 cache usage.

There may be other things to do. Do you have inequality constraints? Are all problems the same size (same number of variables AND constraints)? Do you use ExpressionsBasedModel?

from ojalgo.

gsaxena888 avatar gsaxena888 commented on August 20, 2024

We do have inequality contraints. (All x >= 0). If it helps, we can even make a reasonable guess on upper bounds for x too. I've been doing some thinking, though, and I suspect that floats would probably achieve somewhere between 50% to 100% improvement, though I understand that it may require a fair bit of dev (or more importantly, testing.)

The problems are not exactly all the same size, but your question gave me a pretty big idea. Although there are ~100 million matrix As to optimize (the equation is the standard least squares of --> min ||Y - A.X||^2, with X >= 0) , all (or maybe say 90%) of the 100 million matrix As could probably be represented by a handful (eg ~40 to ~100) distinct matrixes...(The observation Y would all vary, but at least AtA and, more importantly, its inverse could be cached and so it would not need to recomputed). This idea occurred to me once you mentioned "Are all problems the same size". (Also, the x >= 0 constraint is the same, though the size of x vairies of course from problem to problem.) Thoughts regarding the idea of caching AtA and its inverse? For caching the invese, though, I presume I would need to modify the solver code to "handle caching"? Is there a "recommened" approach that's clean to do this, or does it ultimately require copying the code for that class and performing the needed surgery?

On a different note, I like the "premultiply" options. However, I couldn't figure out how to do a similar "preTranspose" operation. Specifically, after I create A, I wish to do something like "preTranspose" A, but it doensn't seem possible to do so. (matrix "A" is generated through PrimitiveDenseStore.Factory.rows(...) statement.) Is it possible? (One workaround is to premultiply matrix A with the Identity Matrix, and then do the transpose, but that's an necessary multiplication.) Also, on a related note, if I understood the code correctly, the matrixes are stored in column major order, right? So would A.x (where A is a matrix and x is a vector) be slighly less efficient (due to caching) that if matrix A were stored in row major order like say ejml? (I'm just trying to understand at this stage, so no big deal if this question is esoteric.)

Finally, how would Expression Builder improve performance in this case compared to simply using the ConveSolver.Builder(). As near as I can tell, the ExpressionBasedModel will call the ConvexSolver but in my case it seem both simpler and more direct (possibly even faster) to just supply matrix Q and C directly to the convex solver rather than (artificially) introducing an intermediary layer via Expression Builder (which would require some more coding for the translation of matrix A etc into the Expression Builder format.) Thoughts? Thanks in advance, apete.

from ojalgo.

apete avatar apete commented on August 20, 2024

from ojalgo.

apete avatar apete commented on August 20, 2024

To answer your original question...

The requirements to make the ConvexSolver:s optionally work with float rather than double has little to do with the solvers themselves. What's needed is a PhysicalStore.Factory implementation that produces suitable DecompositionStore instances (based on float[]).

That factory would then be used when instantiating the solvers, and in turn when instantiating the various internal matrix decomposers and solvers.

Copy-and-paste and search-and-replace on PrimitiveDenseStore will get you underway.

public final class Primitive32DenseStore extends Primitive32Array implements PhysicalStore<Float>, DecompositionStore<Float> {

The Primitive32Array you need to extend already exists. Then there is a collection of supporting classes like FunctionSet, AggregatorSet and Scalar.Factory. To make everything work you also need to "copy-and-paste and search-and-replace" one method in each of the classes in the org.ojalgo.matrix.store.operation package.

Then I assume there will be cases where one would have to reconsider various interface declarations...

from ojalgo.

gsaxena888 avatar gsaxena888 commented on August 20, 2024

Awesome! Thank you. What about the last 2 remaining questions:

On a different note, I like the "premultiply" options. However, I couldn't figure out how to do a similar "preTranspose" operation. Specifically, after I create A, I wish to do something like "preTranspose" A, but it doensn't seem possible to do so. (matrix "A" is generated through PrimitiveDenseStore.Factory.rows(...) statement.) Is it possible? (One workaround is to premultiply matrix A with the Identity Matrix, and then do the transpose, but that's an necessary multiplication.) Also, on a related note, if I understood the code correctly, the matrixes are stored in column major order, right? So would A.x (where A is a matrix and x is a vector) be slighly less efficient (due to caching) that if matrix A were stored in row major order like say ejml? (I'm just trying to understand at this stage, so no big deal if this question is esoteric.)

from ojalgo.

apete avatar apete commented on August 20, 2024

Not sure I understand the problem. Can't you just call matrix.transpose();

ojAlgo's matrix multiplication implementations do not differentiate between vector och matrix arguments, and they're proven to be quite efficient.

from ojalgo.

apete avatar apete commented on August 20, 2024

As far as I know your questions have been answered.

I have created a project here at GitHub to review matrix element type support: https://github.com/optimatika/ojAlgo/projects/2

from ojalgo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.