Title: Introduction to Matlab for Cognitive Programming
1Introduction to Matlabfor Cognitive Programming
- Scott Bolland
- School of Information Technology and Electrical
Engineering
2Introduction
- Matlab is a Matrix Laboratory software package
that can be used as an interactive programming
environment. - One of Matlabs main strengths lies in its
ability to handle numeric computations involving
matrices and vectors in a succinct and intuitive
manner. - The aim of this Workshop is to provide an
hands-on introduction to Matlabs interface and
programming language - Furthermore, the Workshop also offers the option
to explore implementations of various cognitive
models, from simple cellular automata, to genetic
algorithms and neural networks
3What is a Matrix
- A matrix is defined as being a rectangular array
of numbers, containing a number of rows and
columns
Columns
23 2 4 1.2 1 87
A 3 Row by 2 Column Matrix
Rows
4Why are Matrices Interesting?
- They Can Represent Experiment Data
Scores
21. 1.7 1.6 1.5 NaN 1.9 1.8 1.5 5.1 1.8 1.4 2.2
1.6 1.8
Data
Heart Rate Weight Exercise Hours
72 134 3.2 81 201 3.5 69 156 7.1 82 148 2.8
Patient 1 2 3 4
5Why are Matrices Interesting?
- They Can Represent Cellular Automata
0
Pattern
1
6Why are Matrices Interesting?
- They Can Represent A Population for a GA
Individuals
Population
1 0 1 1 1 0 1 1
0 0 0 1 1 0 1 1
1 0 1 1 0 0 1 1
1 1 1 1 1 0 1 1
1 0 1 1 1 1 1 1
1 0 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 0 1 1 1 0 1 1
Genome
7Why are Matrices Interesting?
- They Can Represent Weights of a Neural Network
Single Layer Feedforward Network
To Unit
From Unit
8Benefits of Using Matlab
- Matrices are easily loaded, or generated
gtgt data load(experiment2.txt) data 2.1
1.7 1.6 1.5 NaN 1.9 1.8 1.5 5.1 1.8 1.4 2.2 gtgt
9Benefits of Using Matlab
- Matrices are easily loaded, or generated
gtgt population round(rand(5,10)) population
0 0 0 0 1 1 0 1
0 1 0 0 1 1 0 1
1 0 1 0 1 1 0 1
1 0 0 1 1 0 0 0
1 0 0 0 1 1 1 0
0 0 0 1 1 0 0 1 1
1 gtgt
10Benefits of Using Matlab
- Matrices are easily transformed
gtgt data load(experiment2.txt) data 2.1
1.7 1.6 1.5 NaN 1.9 1.8 1.5 5.1 1.8 1.4 2.2 gtgt
data data(finite(data)) data 2.1 1.7 1.6 1.5
1.9 1.8 1.5 5.1 1.8 1.4 2.2 gtgt mu mean(data),
sigma std(data) m 2.0545 s
1.0405 gtgt
11Benefits of Using Matlab
- Matlab provides powerful graphing functions
gtgt X,Y meshgrid(-8.58) gtgt R sqrt(X.2
Y.2) eps gtgt Z sin(R)./R gtgt
mesh(X,Y,Z,'EdgeColor','black') gtgt
12Benefits of Using Matlab
- Matlab provides powerful graphing functions
gtgt X,Y meshgrid(-8.58) gtgt R sqrt(X.2
Y.2) eps gtgt Z sin(R)./R gtgt
mesh(X,Y,Z,'EdgeColor','black') gtgt
13Benefits of Using Matlab
- Matlab provides simple, yet powerful programming
language
global keys global values global width keys
0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0
1 1 1 values 0 0 0 0 0 0 0 1 width
21 height 10 startPattern
round(rand(1,width)) totalPattern
startPattern for (x 2height) lastRow
totalPattern(end,) newRow for (y
1width) newRow(1,y) getBit(lastRow,y)
end totalPattern totalPattern newRow end
image(totalPattern63) colormap(gray) axis
off
14Benefits of Using Matlab
- Matlab provides simple, yet powerful programming
language
global keys global values global width keys
0 0 0 0 0 1 0 1 0 0 1 1 1 0 0 1 0 1 1 1 0
1 1 1 values 0 0 0 0 0 0 0 1 width
21 height 10 startPattern
round(rand(1,width)) totalPattern
startPattern for (x 2height) lastRow
totalPattern(end,) newRow for (y
1width) newRow(1,y) getBit(lastRow,y)
end totalPattern totalPattern newRow end
image(totalPattern63) colormap(gray) axis
off
15Workshop Overview
- You will be provided with 2 booklets
- A Matlab Manual
- A Matlab Workbook
- The aim is work at your own pace, reading through
the manual, and to use Matlab to answer the
corresponding questions in the Workbook - Feel free to ask questions at any time
16Workbook Overview
- The Matlab Interface
- How to enter Matrices
- Matrix Manipulation
- How to reference elements
- Graphics Functions
- Programming with Matlab
- Implementing Cellular Automata
- Implementing Genetic Algorithms
- Implementing Backpropagation
- Using the Neural Network Toolbox
Introduction to Matlab
Implementing Cognitive Models
17Section 7 Implementing Simple Cellular Automata
- Cellular Automata are a very simple form of
artificial life - Demonstrates that highly complex behaviour can
emerge from very simple mechanisms - Much of the complexity in nature can be
understood in such terms
18Section 7 Implementing Simple Cellular Automata
- The tutorial focuses on 1d Cellular Automata
Given a initial row of cells, new rows are
generated following a set of defined rules
Rules the rules specify what the colour of a
cell in the new row should be, given the colour
of it and its neighbours in the previous row.
19Section 7 Implementing Simple Cellular Automata
- The resulting pattern can be fairly simple
20Section 7 Implementing Simple Cellular Automata
- The resulting pattern can contain nested patterns
21Section 7 Implementing Simple Cellular Automata
- The resulting pattern can be completely random
(non-repeating if you look down a single column)
22Section 7 Implementing Simple Cellular Automata
- Such patterns are ubiquitous in nature
23Section 8 Implementing a GA Toolbox
- Evolution is, in effect, a method of searching
among an enormous number of possibilities for
solutions. In biology the enormous set of
possibilities is the set of possible genetic
sequences, and the desired solutions are highly
fit organisms organisms well able to survive
and reproduce in their environment. Evolution
can also be seen as a method for designing
innovative solutions to complex problems.
24Section 8 Implementing a GA Toolbox
25Section 8 Implementing a GA Toolbox
- In this section of the Workbook, you will be
implementing a general Genetic Algorithm toolbox - Includes roulette wheel and tournament selection,
mutation and crossover. - Although a simple fitness function is tested,
this can be readily modified to handle more
complex tasks (e.g. evolution of neural networks) - I will be taking a small introductory tutorial on
Genetic Algorithms at 11
26Section 9-10 Neural Networks
- If you have a background in neural networks,
these sections teach you how to implement
backpropagation from scratch, and how to use
Matlabs Neural Network Toolbox - Tasks explored include
- Autoencoders emulating the self-organising
nature of the primate visual cortex - Detecting mines using sonar
27Timetable
- 9 1030 Programming
- 1030-1100 Morning Tea
- 1100 Intro to Genetic Algorithms
- 1100-1230 Programming
- 1230-130 Lunch
- 130-300 Programming
- 300-330 Afternoon Tea
- 300-500 Programming