Octave Tutorial Machine Learning WS 12/13 Umer Khan Information Systems and Machine Learning Lab (ISMLL) University of Hildesheim, Germany

Similar documents
Some elements for Matlab programming

Getting Started with MATLAB

Teaching Manual Math 2131

matlab_intro.html Page 1 of 5 Date: Tuesday, September 6, 2005

MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix.

MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP)

Lecturer: Keyvan Dehmamy

Introduction to. The Help System. Variable and Memory Management. Matrices Generation. Interactive Calculations. Vectors and Matrices

An Introduction to MATLAB II

! The MATLAB language

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

Introduction to Matlab. High-Level Computer Vision Summer Semester 2015

Introduction to MATLAB

Matlab Lecture 1 - Introduction to MATLAB. Five Parts of Matlab. Entering Matrices (2) - Method 1:Direct entry. Entering Matrices (1) - Magic Square

MATLAB Introductory Course Computer Exercise Session

MATLAB: Quick Start Econ 837

Desktop Command window

MATLAB and Numerical Analysis

CS129: Introduction to Matlab (Code)

Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

AMATH 352: MATLAB Tutorial written by Peter Blossey Department of Applied Mathematics University of Washington Seattle, WA

A Quick Tutorial on MATLAB. Zeeshan Ali

Outline. User-based knn Algorithm Basics of Matlab Control Structures Scripts and Functions Help

Introduction to MATLAB

Image Processing CS 6640 : An Introduction to MATLAB Basics Bo Wang and Avantika Vardhan

How to learn MATLAB? Some predefined variables

Introduction to Matlab. Summer School CEA-EDF-INRIA 2011 of Numerical Analysis

ELEN E3084: Signals and Systems Lab Lab II: Introduction to Matlab (Part II) and Elementary Signals

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB

Appendix A. Introduction to MATLAB. A.1 What Is MATLAB?

Laboratory 1 Octave Tutorial

Introduction to MATLAB

Lab of COMP 406. MATLAB: Quick Start. Lab tutor : Gene Yu Zhao Mailbox: or Lab 1: 11th Sep, 2013

MATLAB: The Basics. Dmitry Adamskiy 9 November 2011

A Guide to Using Some Basic MATLAB Functions

CS 2750 Machine Learning. Matlab Tutorial

What is MATLAB? What is MATLAB? Programming Environment MATLAB PROGRAMMING. Stands for MATrix LABoratory. A programming environment

Introduction to MATLAB LAB 1

EE 301 Signals & Systems I MATLAB Tutorial with Questions

A QUICK INTRODUCTION TO MATLAB

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB

Math 375 Natalia Vladimirova (many ideas, examples, and excersises are borrowed from Profs. Monika Nitsche, Richard Allen, and Stephen Lau)

Objectives. 1 Running, and Interface Layout. 2 Toolboxes, Documentation and Tutorials. 3 Basic Calculations. PS 12a Laboratory 1 Spring 2014

Chapter 1 Introduction to MATLAB

A QUICK INTRODUCTION TO MATLAB. Intro to matlab getting started

Getting started with MATLAB

Experiment 1: Introduction to MATLAB I. Introduction. 1.1 Objectives and Expectations: 1.2 What is MATLAB?

Getting started with MATLAB

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

Introduction to MATLAB

MATLAB Tutorial EE351M DSP. Created: Thursday Jan 25, 2007 Rayyan Jaber. Modified by: Kitaek Bae. Outline

Matlab Tutorial and Exercises for COMP61021

Introduction to MATLAB. Computational Probability and Statistics CIS 2033 Section 003

Programming in Mathematics. Mili I. Shah

A Quick Introduction to MATLAB/Octave. Kenny Marino, Nupur Chatterji

Lecture 2: Variables, Vectors and Matrices in MATLAB

Matlab Tutorial for COMP24111 (includes exercise 1)

Introduction to Matlab. By: Dr. Maher O. EL-Ghossain

Introduction to GNU-Octave

MATLAB Basics EE107: COMMUNICATION SYSTEMS HUSSAIN ELKOTBY

CSE/NEUBEH 528 Homework 0: Introduction to Matlab

MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

BSM510 Numerical Analysis

Starting Matlab. MATLAB Laboratory 09/09/10 Lecture. Command Window. Drives/Directories. Go to.

2.0 MATLAB Fundamentals

Introduction to MATLAB

FF505 Computational Science. Miscellanea. Marco Chiarandini

AN INTRODUCTION TO MATLAB

STAT/MATH 395 A - PROBABILITY II UW Winter Quarter Matlab Tutorial

Introduction. Matlab for Psychologists. Overview. Coding v. button clicking. Hello, nice to meet you. Variables

Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial

Introduction to MatLab. Introduction to MatLab K. Craig 1

Why use MATLAB? Mathematcal computations. Used a lot for problem solving. Statistical Analysis (e.g., mean, min) Visualisation (1D-3D)

Introduction to Matlab. By: Hossein Hamooni Fall 2014

CSCI 6906: Fundamentals of Computational Neuroimaging. Thomas P. Trappenberg Dalhousie University

Introudction to Computation and Cognition 2015 Dr. Oren Shriki Shay Ben-Sasson, Ofer Groweiss. MATLAB tutorial

Grace days can not be used for this assignment

UNIVERSITI TEKNIKAL MALAYSIA MELAKA FAKULTI KEJURUTERAAN ELEKTRONIK DAN KEJURUTERAAN KOMPUTER

Matlab Tutorial, CDS

Objectives. 1 Basic Calculations. 2 Matrix Algebra. Physical Sciences 12a Lab 0 Spring 2016

Matlab course at. P. Ciuciu 1,2. 1: CEA/NeuroSpin/LNAO 2: IFR49

Creates a 1 X 1 matrix (scalar) with a value of 1 in the column 1, row 1 position and prints the matrix aaa in the command window.

Introduction to MATLAB. Simon O Keefe Non-Standard Computation Group

Introduction to MATLAB for Engineers, Third Edition

CDA6530: Performance Models of Computers and Networks. Chapter 4: Using Matlab for Performance Analysis and Simulation

Datenanalyse (PHY231) Herbstsemester 2017

A Brief Introduction to MATLAB

Fall 2014 MAT 375 Numerical Methods. Introduction to Programming using MATLAB

Introduction to MATLAB 7 for Engineers

Introduction to MATLAB programming: Fundamentals

MATLAB Premier. Middle East Technical University Department of Mechanical Engineering ME 304 1/50

Fundamentals of MATLAB Usage

Introduction to Matlab

LabVIEW MathScript Quick Reference

Introduction to Matlab

CDA6530: Performance Models of Computers and Networks. Chapter 4: Using Matlab for Performance Analysis and Simulation

QUICK INTRODUCTION TO MATLAB PART I

MATLAB TUTORIAL WORKSHEET

Computational Photonics, Summer Term 2012, Abbe School of Photonics, FSU Jena, Prof. Thomas Pertsch

Introduction to MATLAB Practical 1

Transcription:

Octave Tutorial Machine Learning WS 12/13 Umer Khan Information Systems and Machine Learning Lab (ISMLL) University of Hildesheim, Germany 1

Basic Commands Try Elementary arithmetic operations: 5+6, 3-2, 5*8, 1/2, 2^6 etc Logical Operations: 1==2 % false, 1 ~= 2, 1 && 0 % AND, 1 0 % OR, xor(1,0) To change your octave prompt: PS1( >> ); Octave Variables: >> a=3; >> b = hi ; >> b % print the value of b >> disp(b); % will print hi >> a=pi; >> disp(sprintf( 2 decimals: %0.2f, a)) % 2 decimals: 3.14 Matrices and Vectors >> A = [1 2; 3 4; 5 6] % prints a 3x2 matrix 1 2 3 4 5 6 % ; marks the next row >> v = [1 2 3] % a 1x3 row vector >> v = [1; 2; 3] % a 3x1 column vector >> v = 1:0.1:2 % assigns v a row vector with values starting from 1, incrementing by 0.1 up-till 2 >> v = 1:6 % v = 1 2 3 4 5 6 >> ones(2,3) % generates a 2x3 matrix of 1 >> C = 2*ones(2,3) >> w = zeros(1,3) >> w = rand(1,3) % generates 1x3 matrix of random numbers from uniform distribution between 0 and 1. Use randn to get random numbers from Gaussian distribution. >> w = -6 + sqrt(10)*(randn(1,10000)); >> hist(w) % octave creates a histogram and show in a new window. >> hist (w, 50) % increase the number of bins to 50 >> I = eye (4) % generates a 4x4 identity matrix. >> help % for getting help on any command

Moving Data Around >> size (A) % gives you size of a matrix like 3 2 >> b = size (A) % creates a 1x2 matrix with values 3 2 >> size(a, 1) % size of dimension 1 i.e. 3 >> length(a) % returns size of longest dimension. length is usually applied to vectors % Go to desired directory, where your data file is present. >> load [filename] >> who % shows what variables are there in out octave workspace % data filename is also a variable. Just type that variable, to see whole data on octave terminal >> size(filename) % returns the rows x cols of data. >> whos % shows you detail view of variables in workspace >> clear [variable] % will remove the variable from workspace >>v = datafilename(1:10) % saves first 10 elements of datafilename >> save hello.mat v; // saves data in binary format >> load hello.mat >> who % you can see variable v back in your workspace >> save hello.txt v ascii % save as text (ASCII) >> A(3,2) % accessing an index in matrix A, at 3 rd row and 2 nd col. >> A(2, :) % : means every element along that row/column >> A([1 3], :) % get all the elements of A from 1 st and 3 rd row, and every column. >> A(:, 2) = [10; 11; 12] % Assigning every element in 2 nd col of A, to the new values 10, 11 & 12 >> A = [A, [100; 101; 102]] % adds another column vector to A with values.. >> A(:) % put all elements of A into a single column vector. >> C = [A B] % concatenating matrix A and B into C. [A B] is same as [A, B] >> C = [A; B] % putting matrices on top of each other. Try size(c)

Computing on Data >> A=[1 2; 3 4; 5 6] >> B=[11 12; 13 14; 15 16] >> C = [1 1; 2 2] >> V = [1; 2; 3] >> A*C; % Multiply >> A.*B % Element-wise Multiply >> A. ^2 % Element-wise squaring ex. A 2 >> 1./ C % Element-wise reciprocal of C >> log(c) % Element wise logarithm >> exp(c) % base e exponentiation of C >> abs([-1; 2; -3]) % gives the element-wise absolute value >> -V % gives -1*V >> V + ones(length(v),1) % just as V+1 >> A % A transpose >> val = max (A) % gives column-wise max >> [val, ind] = max(a) % gives max value and its index >> V < 3; % returns element-wise comparison truth value >> find(v<3) % returns elements < 3 >> A = magic (3) % try it to find what is interesting?? >> [r,c]=find(a >= 7) % gives index of an element which is >= 7 >> % useful functions sum(a), prod(a), floor(a), ceil(a), rand(3), max(rand(3), rand(3)) >> max(a, [ ], 1) % takes column-wise max and max(a, [ ], 2 ) takes row-wise max : default is col-wise >>max(max(a)) % gives the maximum value in whole matrix >>sum(a,1) % column-wise sum And sum(a,2) gives row-wise sum >> A= magic(9); % then do like A.* eye(9) b= sum(a.* eye(9)) sum(b) >> flipud(eye(9)); % flip up-side down the matrix >> pinv(a) % gives the inverse of matrix try pinv(a) *A

Plotting the Data >> t=[0:0.01:0.98]; >> y1=sin(2*pi*4*t); >>plot(t,y1); >>y2=cos(2*pi*4*t); >>plot(t,y2); >>plot(t,y1); >>hold on; % plotting one function plot over another >>plot(t,y2, r ); >>xlabel( time ); % giving a lable to x-axis >>ylabel( value ); % giving a lable to Y-axis >>legend( sin, cos ); % giving a legend >>title( My Plot ); % giving title of your plot >> print -dpng myplot.png ; % saving the plot as png image file. For other file formats use help >> figure(1); plot(t,y1); % also try figure(2);plot(t,y2); % save two plots in your current dir. >> subplot(1,2,1) % divides a plot into 1x2 grid, and access the first element >> plot(t,y1); >>subplot(1,2,2) % access 2 nd element >> plot(t,y2); >> axis([0.5 1-1 1]) % sets the scale of axis. >> clf; % clears a figure >> A = magic(5); >> imagesc(a); % assigns each element of matrix a color. Also try imagesc(a), colorbar, colormap gray; >>a=1, b=2, c=3 % carries three commands and executes one after another. Comma chaining of commands

Control Statements >> v = zeros(10,1); >> for i=1:10, % a for loop iterating from i=1 to 10 v(i)=2^i; >>indices = 1:10 >> for i= indices. % using predefined indices >> i = 1; >> while i<5, % try this while loop and its output v(i) = 100; i=i+1; >> i=1; >> while true, v(i)= 999; i= i+1; if i == 6, break; >> % also try using if, elseif and else. % use disp( ) function if you want to display some string.

Defining Functions >> addpath( C:/Users/Umer/Desktop ); % adds a search path for Octave to search for function/data files >> % Create Function files with.m extension and execute them. Just follow me on screen. >> X = [1 1; 1 2; 1 3] >> y= [1; 2; 3] >> theta = [0;1]; >> create a costfunctionj.m function file and code as following me on screen. >> J = costfunctionj(x, y, theta);