Switching from / to Octave when working with the Coursera machine learning course can be a bit of a hassle, since some of the Octave syntax is special. Here is my own cheat sheet to remember the most important statements required for the exercises.

## Matrices

1 |
a = [1, 2; 3, 4] |

- , Column separator
- ; Row separator

### Submatrices

1 |
a(rows,cols) |

- indexes start with one
- slices just like in python : a(1,2:3) selects first row, cols 2 and 3

### Adding ONES

1 |
X = [ones(rows(X), 1) X]; |

- rows gets number of rows in X
- ones(rows(X),1) creates a column vector of 1
- […] combines both

### TranspOSE

1 |
a' |

### APPLY Operator ON VECTOR ELEMENTS

Dot operator

1 |
./ |

### do not print result of statement / REDUCE VERBOSE OUTPUT

Append “;” to statement

1 |
a=5; |

### FOR-LOOP

1 2 3 |
for i=1:m ... endfor |

## Functions

1 2 3 |
function r = J(arg) r=<expression> endfunction |

## Neural Networks

### Multiplication of layers

Assume calculation of layer with n nodes to m nodes, then \(\Theta \) will be a matrix with m rows and n colums. And the multiplication will be \(a^{(n+1)}=\Theta*a^{(n)}\). The final value will be \(a^{(n+1)}=sigmoid(\Theta*a^{(n)})\)

### Sigmoid

1 |
g = 1./(1+ e.^-z); |

which means:

\(1/{1+e^{-z}}\) for each of the vector elements.