Octave Commands Cheat Sheet



Some octave commands commonly used in Machine Learning: link. Some commands only appear in the context menu. Among these are: various options for working with the browser ( see 5.1 ); the special grid marker commands for directing Auto-Warp ( see “Syncing Longer Pieces” ); detailed options for zoom-adaptive and fixed grid line width ( see 6.9 ); copying and pasting for Operator’s envelopes.

At its core, this article is about a simple cheat sheet for basicoperations on numeric matrices, which can be very useful if you workingand experimenting with some of the most popular languages that are usedfor scientific computing, statistics, and data analysis.

Sections

  • Introduction
  • MATLAB/Octave
  • Cheat sheet

Introduction

Matrices (or multidimensional arrays) are not only presenting thefundamental elements of many algebraic equations that are used in manypopular fields, such as pattern classification, machine learning, datamining, and math and engineering in general. But in context ofscientific computing, they also come in very handy for managing andstoring data in an more organized tabular form.
Such multidimensional data structures are also very powerfulperformance-wise thanks to the concept of automatic vectorization:instead of the individual and sequential processing of operations onscalars in loop-structures, the whole computation can be parallelized inorder to make optimal use of modern computer architectures.

Language overview

Before we jump to the actual cheat sheet, I wanted togive you at least a brief overview of the different languages that weare dealing with.

All four languages, MATLAB/Octave, Python, R, and Julia are dynamicallytyped, have a command line interface for the interpreter, and come withgreat number of additional and useful libraries to support scientificand technical computing. Conveniently, these languages also offer greatsolutions for easy plotting and visualizations.

Combined with interactive notebook interfaces or dynamic reportgeneration engines(MuPAD for MATLAB,IPython Notebook for Python,knitr for R, andIJulia for Julia based onIPython Notebook) data analysis and documentation has never been easier.

MATLAB (stands for MATrixLABoratory) is the name of an application and language that wasdeveloped byMathWorks back in

  1. One of its strengths is the variety of different and highlyoptimized “toolboxes” (including very powerful functions for image andother signal processing task), which makes suitable for tacklingbasically every possible science and engineering task.
    Like the other languages, which will be covered in this article, it hascross-platform support and is using dynamic types, which allows for aconvenient interface, but can also be quite “memory hungry” forcomputations on large data sets.

Even today, MATLAB is probably (still) the most popular language fornumeric computation used for engineering tasks in academia as well as inindustry.

GNU Octave

It is also worth mentioning that MATLAB is the only language in thischeat sheet which is not free and open-sourced. But since it is soimmensely popular, I want to mention it nonetheless. And as analternative there is also the free GNU Octavere-implementation that follows thesame syntactic rules so that the code is compatible to MATLAB (exceptfor very specialized libraries).

Commands

This imageis a freely usable media under public domain and represents the firsteigenfunction of the L-shaped membrane, resembling (but not identicalto) MATLAB’s logo trademarked by MathWorks Inc.

Initially, the NumPy project started out underthe name “Numeric” in 1995 (renamed to NumPy in 2006) as a Pythonlibrary for numeric computations based on multi-dimensional datastructures, such as arrays and matrices. Since it makes use ofpre-compiled C code for operations on its “ndarray” objects, it isconsiderably faster than using equivalent approaches in (C)Python.

Python NumPy is my personal favorite since I am a big fan of the Pythonprogramming language. Although similar tools exist for other languages,I found myself to be most productive doing my research and data analysesin IPython notebooks.
It allows me to easily combine Python code (sometimes optimized bycompiling it via the Cython C-Extension or thejust-in-time (JIT) Numba compiler if speed isa concern) with different libraries from the Scipystack includingmatplotlib for inline data visualization (youcan find some of my example benchmarks in this GitHubrepository).

The R programming language was developed in1993 and is a modern GNU implementation of an older statisticalprogramming language called S, which wasdeveloped in the Bell Laboratories in 1976.Since its release, it has a fast-growing user base and is particularlypopular among statisticians.

R was also the first language which kindled my fascination forstatistics and computing. I have used it quite extensively a couple ofyears ago before I discovered Python as my new favorite language fordata analysis.
Although R has great in-built functions for performing all sortsstatistics, as well as a plethora of freely available librariesdeveloped by the large R community, I often hear people complainingabout its rather unintuitive syntax.

With its first release in 2012, Julia is by farthe youngest of the programming languages mentioned in this article. aWhile Julia can also be used as an interpreted language with dynamictypes from the command line, it aims for high-performance in scientificcomputing that is superior to the other dynamic programming languagesfor technical computing thanks to its LLVM-based just-in-time (JIT)compiler.

Personally, I haven’t used Julia that extensively, yet, but there aresome exciting benchmarks that look very promising:

C compiled by gcc 4.8.1, taking best timing from all optimization levels(-O0 through -O3). C, Fortran and Julia use OpenBLAS v0.2.8. The Pythonimplementations of rand_mat_stat and rand_mat_mul use NumPy (v1.6.1)functions; the rest are pure Python implementations.

Bezanson, J., Karpinski, S., Shah, V.B. and Edelman, A. (2012), “Julia:A fast dynamic language for technical computing”.
(Source: http://julialang.org/benchmarks/, with permission from thecopyright holder)

Alternative data structures: NumPy matrices vs. NumPy arrays

Python’s NumPy library also has a dedicated “matrix” type with a syntaxthat is a little bit closer to the MATLAB matrix: For example, the“ * ” operator would perform a matrix-matrix multiplication of NumPymatrices - same operator performs element-wise multiplication on NumPyarrays.

Vice versa, the “.dot()” method is used for element-wisemultiplication of NumPy matrices, wheras the equivalent operation wouldfor NumPy arrays would be achieved via the “ * “-operator.

Most people recommend the usage of the NumPy array type over NumPymatrices, since arrays are what most of the NumPy functions return.

Octave commands cheat sheet

Octave Statistics Tips


Refer to the Octave on-line help for a full description of an Octave command. For example, to find out more about boxplots type:


Octave Commands Cheat Sheet

help boxplot


Reading A Dataset

Browse to C:optoctaveengr390ASCII. You should see several folders. Each folder corresponds to a chapter in the book. Folder CH01 contains all of the datasets from chapter 1. In the CH01 folder you will see datasets for both the examples and the exercises. The example dataset file names start with “exp” while the exercise dataset file names start with “ex”.


Exercise 1.11 contains a single set of test scores. To read the scores into an array use:


scores = readdataset('ch01/ex01-11.txt');


Exercise 1.66 contains five sets of data, use the following command to read in all five data sets (into array variables d1 through d5):


Octave

[d1 d2 d3 d4 d5] = readdataset('ch01/ex01-66');

Octave Commands Cheat Sheet Free


Basic Statistical Commands

n = length(x); % number of observations in dataset

y =sort(x); % sort the observations

sum(x > 100 & x <= 150) % display the number of observations between 100 and 150

m = mean(x); % sample mean

med = median(x); % sample median

s = std(x); % sample standard deviation

v = var(x); % sample variance

x25 = prctile(x, 25); % 25th percentile (Octave definition)

x25 = quantile(x, 0.25); % 25th percentile (text definition)

xtr10 = trimmean(x, 10); % 10% trimmed mean


Pdf

Statistical Plots

hist(x) % 10 bins equally spaced between min and max

Octave Commands Cheat Sheet Download

hist(x, 500:1000:5500) % bins centered at 500, 1500, 2500, …, 5500

hist(x, 500:1000:5500, 1) % relative freq. histogram (bar heights sum to 1)

histpdf(x) % histogram normalized for unit area

boxplot(x, 0, 'xo', 0) % boxplot with outliers (similar to the boxplots in the text)

Octave Commands Cheat Sheet Printable


Octave Commands Cheat Sheet Pdf