Live data from Hacker News

Kotlin and linear programming

tomstechnicalblog.blogspot.com

21–30 of 46 posts

Re: Kotlin and linear programming

#21
post #3
post #2

> “Linear” means continuous No. As in G. Simmons, the two pillars of the field of 'analysis' in math are linearity and continuity. The two are quite different. Linearity usually has to do with numbers and vectors. The numbers are usually in the set R of real numbers or the set C of complex numbers. Commonly the numbers are called scalars. Then, a function f is 'linear' provided for scalars a and b and vectors x and y…

> Maybe what was meant was usually when we mention linear programming we have, say, find x to solve Ax = b, x >= 0 Close. Linear programming is: minimize z = cx subject to Ax = 0. Linear programming can be solved by application of the Simplex method or interior point methods. Integer linear programming constrains x to the integers, and mixed integer linear programming constrains only some of x to the integers. (x is…

No. I'm correct: Not only can we do linear programming with equality constraints Ax = b, for the simplex algorithm that is what we must do. To convert a linear inequality to an equivalent linear equality, we use a non-negative slack or surplus variable. To get an initial feasible solution, we just append one via artificial variables and then use the simplex algorithm to drive the artificial variables to zero and out of the problem. Then all we have are the original variables and the slack and surplus variables. In that case, we know that the problem is feasible, and as the OP mentioned sometimes that is enough. Actually, in principle finding a feasible solution is no easier than finding an optimal solution starting with a feasible solution. That is, feasibility alone is not trivial. The field of constraint programming is basically looking for feasible solutions and, so, is not really much easier in the work to be done or different from optimization.

No. Sure, the objective function z = cx is linear. But far and away, what is just crucial, the real power that makes linear programming work, is the linearity of the matrix A. Then the feasible region is a finite intersection of closed half spaces and is convex with flat sides and extreme points. To find optimal solutions, it is sufficient to look only at the extreme points, and there are only finitely many of those.

We can do a lot of relaxing of the objective function and still do well; relaxing the linearity of the constraints promises to give us much more trouble.

Re: Kotlin and linear programming

#22
post #11
post #5

Not sure why Kotlin would be picking this fight - Python and to some extent R already dominate in data science with a little bit of Scala added in Spark - where does author see an opening for Kotlin? For high performance libraries nobody would pick Python or any JVM-based language either, and that's what most of the wrappers end up calling anyway (C++, CUDA, Fortran, OpenCL).

I use Python for machine learning, but I wish I could use a friendly, modern, statically-typed language like Kotlin, Swift, etc. instead. Dynamically typed languages feel scary beyond around 1000 lines of code.

The downside is that static typing makes your programs much more rigid. Even if you program to interfaces, apply open-closed principle etc. After a while you start fighting the type system.

That's why I like dynamic typing. Coupled with Python's type annotations for hard cases and good documentation, dynamic typing allows you to go further by reducing cognitive load.

Re: Kotlin and linear programming

#23
Just adding that there are tricks that allow adding (apparently) non linear conditions to the problem such as variables that activate or not based on other conditions or even if-then-else statements.

Without these tricks the technique is pretty limited at solving real world problems.

Re: Kotlin and linear programming

#24
post #5

Not sure why Kotlin would be picking this fight - Python and to some extent R already dominate in data science with a little bit of Scala added in Spark - where does author see an opening for Kotlin? For high performance libraries nobody would pick Python or any JVM-based language either, and that's what most of the wrappers end up calling anyway (C++, CUDA, Fortran, OpenCL).

IBM and NVidia do have CUDA JVM support.

There are .NET CUDA implementations as well.

Re: Kotlin and linear programming

#25
post #14
post #11

Earlier quoted context omitted.

I use Python for machine learning, but I wish I could use a friendly, modern, statically-typed language like Kotlin, Swift, etc. instead. Dynamically typed languages feel scary beyond around 1000 lines of code.

Python 3.6's optional types are pretty great. Block out your solution first then start constraining it where you need to.

+1, I recently wrote some data extraction and processing code using pandas and mypy, and it was pretty great. And progress is happening to add types to numpy and pandas themselves.

Re: Kotlin and linear programming

#28
post #24
post #5

Not sure why Kotlin would be picking this fight - Python and to some extent R already dominate in data science with a little bit of Scala added in Spark - where does author see an opening for Kotlin? For high performance libraries nobody would pick Python or any JVM-based language either, and that's what most of the wrappers end up calling anyway (C++, CUDA, Fortran, OpenCL).

IBM and NVidia do have CUDA JVM support. There are .NET CUDA implementations as well.

Cuda4j is only implemented in the ibm jvm and last I saw was slow to add newer cuda versions.

Re: Kotlin and linear programming

#29
post #13
post #4

Adding to my other comment, my biggest dissatisfaction with this article is that all it did was show the quite excessively verbose problem setup, without actually showing an algorithm for integer linear programming. An interesting post would have explained how to implement branch and bound in Kotlin, not how to call somebody else's library. Needless to say, I'm not sold on Kotlin from reading this.

Also, I believe no one is doing linear programming without vectorized operations (SIMD) nowadays. I know JVM optimizes small methods, so maybe their JIT optimizer does that automatically, but I'm not sure that optimizer is better that manually optimized code like in numpy.

We see folks using our linalg library for this and deep learning: http://nd4j.org We maintain our own c++ and cuda stack underneath this as well. It also allow control of these native components from java. We implement everything from our own garbage collector for cpu and gpu to our own cuda kernels.

Re: Kotlin and linear programming

#30
post #5

Not sure why Kotlin would be picking this fight - Python and to some extent R already dominate in data science with a little bit of Scala added in Spark - where does author see an opening for Kotlin? For high performance libraries nobody would pick Python or any JVM-based language either, and that's what most of the wrappers end up calling anyway (C++, CUDA, Fortran, OpenCL).

Python is often a second class citizen in these areas, even if much is made about its widespread support in the data science realm. I don't want to say it's hype is overblown... but a lot of the pain points and cracks in the seams are glossed over. Take spark, for instance. You run into extreme performance issues the second your data has to be serialized to cross the py4j gap. An many essential parts of its API requi…

Scala is a lot simpler than Kotlin once you get into the details - it uses a few simple but very general features rather than a lot of ad-hoc language-level functionality. A lot of the time what looks like some complex construct in Scala is actually two or three separate features combining in a way that makes perfect sense once you look at the pieces, and you can click through to see how the thing is implemented in plain Scala. (Indeed I'd say Kotlin is far more perl-like - its design deliberately emphasises immediate developer convenience at the expense of having a coherent underlying model)
Post reply on HN