Introduction To Matlab for Cognitive Programming

Document Sample
Introduction To Matlab for Cognitive Programming Powered By Docstoc
					  Introduction to Matlab
for Cognitive Programming
            Scott Bolland

 School of Information Technology and
         Electrical Engineering
                   Introduction
   Matlab is a “Matrix Laboratory” software package that
    can be used as an interactive programming environment.
   One of Matlab‟s 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 Matlab‟s 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
             What is a Matrix

   A matrix is defined as being a rectangular
    array of numbers, containing a number of
    rows and columns:
                    Columns


                23 2
                              A 3 Row by 2
    Rows
                              Column Matrix
                4      1.2
                1      87
    Why 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

 Patient 1      72      134      3.2
         2      81      201      3.5
         3      69      156      7.1
         4      82      148      2.8
    Why are Matrices Interesting?
   They Can Represent: Cellular Automata

                                            =0
Pattern =
                                            =1
     Why are Matrices Interesting?
    They Can Represent: A Population for a GA
                  Individuals
 Population =      1     0      1   1   1   1   1
                   0     0      0   1   0   0   1
            1
            0      1     0      1   1   1   1   1
            1
Genome =    1      1     1      1   1   1   1   1
            1
            0      1     1      0   1   1   1   1
            1
            1      0     0      0   0   1   1   1
                   1     1      1   1   1   1   1
                   1     1      1   1   1   1   1
    Why are Matrices Interesting?
   They Can Represent: Weights of a Neural Network
    Single Layer
    Feedforward Network
                                 To Unit

                                 1   0     1   1   1
                                 0   0     0   1   0
                                 1   0     1   1   1
                          From   1   1     1   1   1
                          Unit   1   1     0   1   1
                                 0   0     0   0   1
                                 1   0     0   0   1
                                 1   1     1   1   1
         Benefits of Using Matlab

   Matrices are easily loaded, or generated
>> 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
>>
         Benefits of Using Matlab

   Matrices are easily loaded, or generated
>> 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

>>
         Benefits of Using Matlab

   Matrices are easily transformed
>> 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
>> 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
>> mu = mean(data), sigma = std(data)
m=
  2.0545
s=
  1.0405
>>
            Benefits of Using Matlab
   Matlab provides powerful graphing functions

    >>   [X,Y] = meshgrid(-8:.5:8);
    >>   R = sqrt(X.^2 + Y.^2) + eps;
    >>   Z = sin(R)./R;
    >>   mesh(X,Y,Z,'EdgeColor','black')
    >>
            Benefits of Using Matlab
   Matlab provides powerful graphing functions

    >>   [X,Y] = meshgrid(-8:.5:8);
    >>   R = sqrt(X.^2 + Y.^2) + eps;
    >>   Z = sin(R)./R;
    >>   mesh(X,Y,Z,'EdgeColor','black')
    >>
                Benefits 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 = 2:height)
      lastRow = totalPattern(end,:);
      newRow = [];
      for (y = 1:width)
         newRow(1,y) = getBit(lastRow,y);
      end
      totalPattern = [totalPattern; newRow];
    end

    image(totalPattern*63);
    colormap(gray);
    axis off;
                Benefits 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 = 2:height)
      lastRow = totalPattern(end,:);
      newRow = [];
      for (y = 1:width)
         newRow(1,y) = getBit(lastRow,y);
      end
      totalPattern = [totalPattern; newRow];
    end

    image(totalPattern*63);
    colormap(gray);
    axis off;
            Workshop 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
               Workbook Overview
                  The Matlab Interface
                  How to enter Matrices
Introduction
to Matlab         Matrix Manipulation
                  How to reference elements
                  Graphics Functions
                  Programming with Matlab
                  Implementing Cellular Automata
Implementing      Implementing Genetic Algorithms
Cognitive
Models            Implementing Backpropagation
                  Using the Neural Network Toolbox
    Section 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
    Section 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.
    Section 7: Implementing Simple
           Cellular Automata
   The resulting pattern can be fairly simple:
    Section 7: Implementing Simple
           Cellular Automata
   The resulting pattern can contain
    nested patterns:
    Section 7: Implementing Simple
           Cellular Automata
   The resulting pattern can be completely random
    (non-repeating if you look down a single
    column):
    Section 7: Implementing Simple
           Cellular Automata
   Such patterns are ubiquitous in nature:
     Section 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.
Section 8: Implementing a GA
           Toolbox
      Section 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
    Section 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
    Matlab‟s Neural Network Toolbox
   Tasks explored include:
       Autoencoders: emulating the self-organising nature of
        the primate visual cortex
       Detecting mines using sonar
                 Timetable
 9 – 10:30 Programming
10:30-11:00 Morning Tea
 11:00 Intro to Genetic Algorithms

 11:00-12:30 Programming

12:30-1:30 Lunch
 1:30-3:00 Programming

3:00-3:30 Afternoon Tea
 3:00-5:00 Programming

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:10
posted:10/8/2011
language:English
pages:27