first simple program in julia- a greedy knapsack

A couple realizations:

1.) Having learned R first, I’m continually disappointed when standard arrays don’t implement sorting well.

2.) I wanted to implement this using a queue, but apparently those aren’t standard elements in Julia’s base. And, for some reason, Julia’s package/module interface wasn’t working. Their explanation is cryptic on how to import functions from modules made out of installed packages, and what the relationship is between modules and packages. Maybe that’s because it’s at 2am, but I never had a problem understanding python import, Haskell’s Cabal, or R taskview/package structure at any time of night.

3.) I haven’t bench-marked this against my tail-recursed Haskell implementation that’s “Faster than C"™ but I’ll have to soon. For such a simple algorithm, I have a hard time believing anything can beat tail recursion.

4.) Julia has some serious benefits over python in terms of speed and sparse matrix handling. It’s also nicer to write in Julia than in R. If it achieves parity with statistics and visualization, it’d be hard to go back. Of course, it’s an open question as to whether or not Julia’s going to.

5.) There is already a shapefile library, a k-nearest library, and some other geography-related stuff. Add in a baked-in connection to NLOpt, Gurobi, Cplex, and BLAS and it looks like this environment was custom-made for spatial optimization. It’s nice to see equal focus on optimization and statistics, where R’s optimization libraries are anemic at best and slower than enumeration at worst :)

6.) The community is small, and I see a gap where I can contribute some serious tools. One might be building an interface between it and PySAL. Of course, if Julia’s the faster language, it might be smarter to go the other way around, doing analysis in Julia and piping it back into PySAL. Who knows. With IJulia, it might be better to do it that way. I’ll think on it.

7.) I’m getting better at programming. This took me much less time than the last few times I implemented similar (or more simple algorithms). Maybe I should move to out of kilter implementation as my first-case work…

8.) I might just have become a Julian!

imported from: yetanothergeographer