GNU Octave
gnu.org
gnu.org
Matlab usage is on a dramatic downswing from my vantage point in quantitative fiance. I don't really know anyone under 40 who uses it anymore as one of their main tools.
And I've never once seen anyone use octave as a substitute, I'm guessing this is mostly due to money for licenses not really being an issue.
Nowadays, the only tools I see people using are R, python(pandas, numpy) and very occasionally Julia.
Where does this leave Octave? What's Octaves niche?
Or put another way, why learn Octave/Matlab when there are other languages out there that provide similar capabilities and that are much more popular?
So I guess for newcomers and for quick prototyping (just 10s or 100s lines of code), octave is nicer.
Say, you have some numbers for a matrix and a vector in files and want to read them in and multiple the vector by the matrix.
In octave you are done in 3 lines of code in 30 seconds.
In python, you first figure which modules to import, the difference between python arrays and numpy arrays, and god forbid you happen to find the numpy matrix type instead of numpy array type. After 5 minutes you think you're all set to calculate the M * v, but then your vector happens to be a line vector and not a column vector and you need to learn the difference. Also it's nicer to write M * v than np.dot(M,v).
Most of the features of python that I presented as cons are actually pros when the codebase is more than 1000 lines and needs structure and safety.
Octave:
m = [0 1 0; 0 0 1; 1 0 0]
v = [2 3 1]'
m\v
ans =
1
2
3
Python: import numpy as np
m = np.array([[0,1,0],[0,0,1],[1,0,0]])
v = np.transpose(np.array([2,3,1]))
# wtf? oh, I guess then
v = np.transpose(np.array([[2,3,1]]))
np.linalg.solve(m,v)
array([[ 1.],
[ 2.],
[ 3.]])
If you just want to play around, Python has more clutter and gotchas.Of course, when you start to write real software, then the tools that Python provides for organizing your code start to weight more and the clumsiness of np.linalg.solve(m,v) over m\v starts to weight less.
But I can see how a 50-line testing script in Octave organically grows to a 2000-line application, and then it's already a lot of work to rewrite in Python.
Edit: a reply below makes a good point simplifying the Python code a little bit.
>>> import numpy as np
>>> m = np.array([[0,1,0],[0,0,1],[1,0,0]])
>>> v = np.array([2,3,1])
>>> np.linalg.solve(m,v)
array([ 1., 2., 3.])
No need to transpose, as numpy handles row and column vectors identically. Using the above variables `m` and `v`: >>> v @ m # treated as row vector
array([1, 2, 3])
>>> m @ v # treated as column vector
array([3, 1, 2])
Where `@`, for those who don't know, is the matrix multiplication operator (`np.dot`) introduced in recent versions of python 3.Exactly.
Python 3.5 was the first version of python3 to implement the PEP: https://docs.python.org/3.5/whatsnew/3.5.html
If I am reading the release notes correctly, Python 3.5.0 was released last year (2015-09-13): https://www.python.org/downloads/release/python-350/
It's fair to say that this is a relatively new development.
I mean in the context as @sampo described it above ...
In the Stanford/Coursera machine learning class, Andrew Ng said that his teaching experience is that students pick up octave/matlab quicker and the course can cover more actual machine learning, compared to python where more time is spent learning the language.
Then "which version of Python, and how is that different..." etc.
is there something wrong with numpys convenience method for transpose but not matlabs postfix unary convenience operator?
Also you too made the same mistake: np.array([2,3,1]).T doesn't do anything, you need np.array([[2,3,1]]).T
[1] https://docs.scipy.org/doc/numpy/reference/generated/numpy.t...
When someone googles Matlab/Octave there won't be the same mixture of contexts as there is for Python. With Python there's "2 or 3?" before even starting. Than Cython or Jython or PyPy? That's nothing against Python except that in one particular time limited context, the questions are a distraction {without even considering the complaints of students when the choice of Python implementation is contrary to their opinion}.
m = matrix([[0, 1, 0],
[0, 0, 1],
[1, 0, 0]])
v = vector([2, 3, 1])
m \ v
(1, 2, 3)and then
sol = m \ v
m * sol
(2, 3, 1) m = matrix( c(0,0,1,1,0,0,0,1,0), nrow=3 )
v = c(2,3,1)
solve(m,v)
[1] 1 2 3
Julia: for this code snippet the syntax is identical to Matlab: m = [0 1 0; 0 0 1; 1 0 0]
v = [2 3 1]'
m\v
3×1 Array{Float64,2}:
1.0
2.0
3.0I've done both his Coursera class and another ML class that used Python. I started the one class with zero Matlab/Octave experience, and the other with some Python but no real Numpy experience.
Getting comfortable with Octave for doing basic vector/matrix operations took very little time, and within an hour I was able to just focus on learning the math. By contrast, I've been using Numpy on-and-off for a year now, and I still feel wedded to the reference manual.
Keeping track of all the @$@#% types is definitely a chore. There may be technical advantages to doing things that way, but that doesn't make it any more learner-friendly. Nor does the Python community's habit of not bothering to specify types in the documentation help things in that department.
I can see the benefit that tooling provides, but from a getting-started standpoint, reducing the complexity makes you significantly more productive. You can concentrate on learning the concepts and not the language nuances.
For someone who already knows and works with numpy or r, Octave might not be necessary. Then again, it's not like its particularly hard to pick up Octave and be able to work with it.
Julia wasn't around, or it was very early, when he designed the Machine Learning course or was teaching Stanford students, and he's moved on since then. I wonder if he would likely choose Julia now.
I like R, but understand that %*% for matrix multiplication, solve() instead of \, and the relatively cumbersome syntax for defining matrices indicate that it not designed primarily for users to interact with matrices at a lower, mechanical level. The xapply() functions can also be more confusing than picturing how you iterate through loops. Python too can be verbose for doing the simple/toy problems that are helpful when learning.
Julia however comes with the easy Matlab/Octave syntax for handling matrices. But then there is a lot of of syntactic sugar too after you get past the early stages. Even things like the built-in support for intermixing Greek letters were surprisingly helpful.
I think the advantage of Matlab is the toolboxes in engineering contexts, but that Julia has a similar learning curve for beginners working with matrices. Perhaps the Matlab IDE is an advantage, but that doesn't come with Octave, and Jupyter or Atom+Julia are relatively user-friendly.
[1] https://www.edx.org/course/optimization-methods-business-ana...!
Simply not having to worry about how to represent a multidimensional array is a win. This keeps FORTRAN alive.
What is the difference? I was thinking about this just recently (in connection with Python and C). But not clear on the diff (for either language), though I know that internally all arrays have to be represented as 1D sequences of bytes in memory, and the translation betwen 1D and say 2D (for 2D arrays) is done by adding and multiplying indices, offsets, etc. Is there any more to it than that? Interested to know.
Allocating an array of arrays can require a lot of allocations, as does copying such an array. This gets expensive if you have some language where arrays are first-class result types. You can't just do one allocate, then copy the entire array.
The C idiom "a[i][j]" has become pervasive, replacing actual multidimensional array subscripts such as "a[i,j]" (Pascal, Modula) or "a(i,j)" (Octave, MATLAB and FORTRAN). Amusingly, you can't overload "operator[]" in C++ with more than one argument. It's a syntax problem. The comma operator (the "evaluate but ignore first operand, return second operand" operator) has higher precedence inside "a[]" than inside "a()". This is a legacy from C's use of the comma operator inside macros.
This seems to be a special case of teaching a course where the students come from diverse backgrounds, having learned different programming languages or none at all. And in any course that involves some computer based activities, it's always good to avoid the situation where fussing with the tools overshadows the content that's being taught.
In this case, a language whose notation mimics the notation being used to describe the math on the chalkboard, is certainly handy. And I appreciate that he's offering a way to do the work without requiring a commercial or platform-specific tool.
I'm not sure it means that Octave is nicer in general, but I can certainly see the appeal if it's well integrated into a well designed course.
But MATLAB not perfect, it has spiky bits and traps for newbies. (And the feature that '' == matrix multiply != the multiplication you almost always want is one of those traps). Also students will* write complicated (perhaps overcomplicated) programs that expose MATLAB's limits.
So what about other languages designed for numerics? Would R be a better choice (I haven't used it). Or maybe a new language should be invented. After all Matlab might be easier overall, but it still has plenty of stupid spiky stuff. And I would count your multiplication example as one of the (milder) stupidities.
Personally I'm more used to other languages and would also tend to python, however I must admit Matlab/Octave is a pretty good way to develop matrix heavy stuff thanks to an extremely good REPL/debugger. That being said, Octave feels pretty slow for loops (lack of a proper jit), so I wouldn't know if I'd really use Octave over Matlab if it were not for licensing issues either. Then again I can rent a lot of cloud time for a Matlab license...
You are under 30. ;-)
I guess it was crippleware...
https://books.google.com/books?id=_i8EAAAAMBAJ&pg=PA38&lpg=P...
http://www.ce.berkeley.edu/~sanjay/e7/syl.pdf
Then if you take an upper div class like EE120, Linear Systems, the homework sets will be in Matlab. We used it again in EE192, Mechatronics. Non engineering students (CS students) will have to pick it up immediately. I'd have preferred using Octave on my laptop rather than Matlab which was installed on Windows machines.
Matlab is definitely used for non-CS engineering.
But maybe since it's an oct-file (or I imagine a mex-file in MATLAB), it's baked into the interpreter and it's a different story.
Perhaps the most time-consuming thing I've found is that, to get NumPy/SciPy to work for some scenarios, you can spend your time tinkering around with a bunch of different parameters whereas the same functions work directly out-of-the-box on MATLAB. Rarely have I found the opposite to be the case, and I know this is the reason a few researchers I work with still don't use Python for their internal work.
Perhaps I can cook up a few examples from my projects, just to make a fair comparison.
Python + numpy + matplotlib + jupyter notebooks are superior to Matlab, IMO. And I used to be really into Matlab.
I was going to ask for a little more information about this, but a quick google search led me to plenty.
This is eye opening. Thank you!
I'm a scientist working at a private company that makes measurement equipment, and I use Python for practically everything now: Modeling, data analysis, and even talking to hardware. Our engineers have been kind enough to provide Python friendly interfaces to our hardware, so I can write things like test scripts that are used in product development and sometimes in manufacturing. I write similar scripts when I'm prototyping hardware myself.
I write some stand-alone Python programs, when it becomes convenient to provide a GUI (via Tkinter). I also use Jupyter quite a lot for data analysis and exploratory work. Often, I use a stand-alone Python program to generate data, and a Jupyter notebook (with inline Matplotlib graphs) to analyze it.
At another level of abstraction, I now use Jupyter as my lab notebook. Just last week, I completed a fairly extensive study that included development of a prototype, automated testing, and data analysis. When I was satisfied with my results, rather than writing a separate report, I simply added explanatory text to the Jupyter notebook, with some cell phone pictures for documentation. And then I scheduled a meeting to present my results. My presentation was a slideshow that was served up from the same Jupyter notebook using the nbconvert utility.
Even though my work will never be revealed to the public, I have embraced the idea that "real science is open and reproducible," and am pushing towards an ideal state where a single file folder contains everything needed to reproduce my work, including hardware design, source code, experimental data, and so forth. I'm also learning to use git, so that this stuff can all be revision controlled.
If someone asks me for help getting started with Python, I suggest that they should get Anaconda, or an alternative that I prefer called WinPython.
The old timers would just hand you a copy of Numerical Recipes and wish you good luck. ;-)
If you're more like me on using numerical methods, then I'd recommend first going through the math (I can be more specific, depending on what kind of work you'd like to do/are interested in) using Julia/MATLAB/Octave and then jump into NumPy stuff.
In my experience, I've found that using NumPy/SciPy numerical libraries effectively requires some knowledge of the underlying numerical algorithms since the default arguments sometimes require tweaking.
Now if you already know how to code in python and know how to use jupyter, you're ready to learn about neural networks. This book[3] did a really good job in explaining the subject.
And, this is what jupyter notebook can do[4].
[0] - https://www.continuum.io/downloads
[1] - http://jupyter.readthedocs.io/en/latest/install.html
[2] - https://www.codecademy.com/learn/python
[3] - https://www.amazon.com/Make-Your-Own-Neural-Network-ebook/dp...
[4] - https://try.jupyter.org/
I also do some modeling for integer programming.
Matlab's out-of-the-box IDE is good and makes debugging/profiling dead simple, the toolboxes cover a huge range of problem domains, and the language itself is easy to learn. But I've moved away from it due to the cost, licensing, closed source, etc.
I use Python. I have an interest in Julia, but the language stability and ecosystem just aren't there yet.
What I will say is that I really enjoy using Octave, just because with a certain fairly narrow domain it's quick, powerful and there's no messing around with dependencies to get going. It's very immediate, which is exactly what I want from a calculator.
I'm a Materials engineer never used Matlab. For numerical stuff I have personally used C/C++ especially GSL library but I rarely do this type of work any more. There is quite a lot of legacy stuff written in Fortan mostly heat transfer and fluid dynamics related. I try to avoid touching it. Commercial Packages like ANSYS get used a lot.
I have seen python a little bit in last couple of years but not for numerical stuff more for interfacing with other libraries like OpenCV.
Bear in mind that you'd have to rewrite both Matlab and GNU Octave if you need to run your simulations on a super computer.
I remember back when I was a first year I was waist-deep in some Matlab when one of the guys at our high-performance computing center jested that if I wrote a for-loop I may just as well run around the building for each iteration and do the calculation with pen and paper. (context: members of the same computer club)
[1] http://octave.sourceforge.net/mpi/ [2] http://octave.sourceforge.net/parallel/
For me, personally, I use Octave at home when prototyping algorithms because I'm cheap and haven't paid the ~$1k for a Matlab license.
In my experience for real-time implementation, neither Matlab nor Python are considered efficient enough, even after using something like the Matlab compiler or Python's psyco or equivalent. Again, in my experience, C is by far the most popular choice.
With regard to learning Octave and/or Matlab, I'd say people learn it because of inertia and that they're well-tuned for numerical analyses. I say this even though Python's my favorite general-purpose language. I still prefer Matlab/Octave over it for crunching data because, to me, they seem better designed for that purpose.
FWIW, you can get a home copy of MATLAB for $149: https://www.mathworks.com/products/matlab-home/
> In my experience for real-time implementation, neither Matlab nor Python are considered efficient enough, even after using something like the Matlab compiler or Python's psyco or equivalent. Again, in my experience, C is by far the most popular choice.
MATLAB Compiler won't make code any faster - it's still just running MATLAB engine underneath the hood. MATLAB Coder converts to C code optimized for real-time systems
Whoa, thanks for that link. IIRC quite awhile ago there was a student edition that wasn't really suitable for anything other than toy problems because there was a limitation in the size of matrices. This looks to be the real deal though!
> MATLAB Compiler won't make code any faster - it's still just running MATLAB engine underneath the hood. MATLAB Coder converts to C code optimized for real-time systems
My mistake: the particular toolboxes often fuse together in my head. Not such a big deal at work where we've got access to so many of them. It'd definitely be a pain if I didn't. My point still stands, though, that I haven't seen anyone on any of the projects I've worked on using MATLAB code that's been automatically converted to C. Or, at the very least, it's not part of any documented process that I've seen.
More limited in the programming sense but easier to do something punctual (and easier to install than the Python tools)
What Matlab brings to the table is a customer-centric focus... meaning an awareness that the customer probably has something to do this week besides screwing around with open source scientific computing packages and their inevitable dozens of scattered dependencies.
As for Octave, it's useful for absolute zero-budget applications at the very low end of the market, and for mass deployment of multiple instances at the high end, but it doesn't have much of a role in the middle. The "home use" licenses introduced by Matlab recently really dropped a bomb on Octave. You can get a ridiculous amount of nifty stuff for less than $500.
Like I mean what the hell does that leave for "personal use"?
Technically the intent was for self-directed personal education. But the real reason is to encourage people to learn Matlab, and not Numpy or R or something else, and to discourage people from messing around with Octave. It's a classic move for a company that's getting worried about their market share.
Given that most of the value of Matlab over Octave lies in its toolboxes -- which are now $45 each -- this strategy seems sound. A few packages still aren't available, such as the toolbox that does HDL code generation, but those aren't available in the FOSS world either.
In university (engineering school) they taught us MATLAB in the two required introductory programming classes. In grad school I took an advanced numerical methods class where the prof was actually cool enough to let us use whatever language we wanted. I took the opportunity to learn python/numpy.
Thanks for working on Octave. I wish people would put money into it rather than (in the case of my university) paying enough for Matlab to fund one or two full-time staff who could do development and support of free stuff with Octave and other things like R. Multiply that by N universities in just in this country...
I don't expect any other JIT backend (libgccjit could be another possibility) would require any less knowledge of compilers and language design. Does Graal have some magic for us? Can it give us a JIT compiler even if most of us are not compiler writers or language designers?
Forget “this language is fast”, “this language has the libraries I need”, and “this language has the tool support I need”. The Truffle framework for implementing managed languages in Java gives you native performance, multi-language integration with all other Truffle languages, and tool support - all of that by just implementing an abstract syntax tree (AST) interpreter in Java.
Truffle applies AST specialization during interpretation, which enables partial evaluation to create highly optimized native code without the need to write a compiler specifically for a language. The Java VM contributes high-performance garbage collection, threads, and parallelism support.
So you won't need the know-how to write a compiler, but instead write an interpreter optimized for execution with Graal.
There is also an actual Octave kernel for Jupyter, similar to the Julia one: https://github.com/Calysto/octave_kernel
> There is no chin under Richard Stallman' beard. There's only another beard. Recursively.
octave:8> fact
Richard Stallman don't cut his hair because there are no GNU/Scissors
meh, let's try again... octave:9> fact
Richard Stallman doesn't read web pages. They write to him.
snerk. Okay, one more... octave:10> fact
"RMS" stands for "RMS Makes Software"
THIS IS GOLD, JERRY, GOLDI saw the version bump on info-gnu the other day; I haven't updated yet (I'm kind of in the middle of a project using Octave) but once that's done I can't wait to try it out.
Glad to see Octave development is ongoing. It'll be fun to check out 4.2.0 and see what it has to offer.
I have since drifted away towards python, and lately Go, but MATLAB/Octave always has a directness that I think few languages since have managed to achieve, and I realize now that it helped lure me out of web-lab, into into coding and bioinformatics-land.
Its been a while since I've worked with Octave toolboxes but it would be great if they were on par with Matlab.
Performance is less of an issue with prototyping than production systems and Matlab has a path to get to compiled C/C++ (Java and perhaps other?) Is there Octave support for generating reasonably performant C++ or Java?
And wait an eternity for anything 3D to render. I usually use Octave for prototyping, and while it is reasonably fast doing calculations once you learn to vectorize computations, plotting moderately large amounts of data can easily block the entire program.
Link: https://www.gnu.org/software/octave/doc/interpreter/Contribu...
The only advantage Python have that I can see are: a) it has better support for non-maths functions - good luck doing OpenGL in native Matlab (although it does easily interface with C++ and Java), and b) it is free; Matlab costs a lot, although they did actually release an affordable 'personal' edition.
Octave is basically a Matlab clone. It's slower, has a less polished GUI (plotting is especially buggy) and is less comprehensive.
Ok and Python doesn't have numpy/plotting literally built-in but if you start with Miniconda or so you get one package which has it all.
https://www.gnu.org/software/octave/doc/v4.0.1/Famous-Matric...
it is not so easy to find whether a numpy equivalent exists, and in which module. Usually the first page of google results is not very helpful.