CS 175 Project in AI Discussion -- matlab

Slides:



Advertisements
Similar presentations
Introduction to Matlab
Advertisements

1 EMT 101 – Engineering Programming Dr. Farzad Ismail School of Aerospace Engineering Universiti Sains Malaysia Nibong Tebal Pulau Pinang Week 10.
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
MATLAB – What is it? Computing environment / programming language Tool for manipulating matrices Many applications, you just need to get some numbers in.
CS231A Matlab Tutorial Philip Lee Winter Overview  Goals › Introduction to Matlab › Matlab Snippets › Basic image manipulations › Helpful Matlab.
Introduction to Matlab By: Dr. Maher O. EL-Ghossain.
Exam #3 Review: Comprehensive Exam Class 14.2 Palm Matlab Book Ch. 1-5.
Lecture 6 Sept 15, 09 Goals: two-dimensional arrays matrix operations circuit analysis using Matlab image processing – simple examples.
Concatenation MATLAB lets you construct a new vector by concatenating other vectors: – A = [B C D... X Y Z] where the individual items in the brackets.
C ENTER FOR I NTEGRATED R ESEARCH C OMPUTING MATLAB
Dr. Jie Zou PHY Welcome to PHY 3320 Computational Methods in Physics and Engineering.
Matlab intro The Environment
1 MATLAB 基礎. 2 MATLAB  Workspace: environment (address space) where all variables reside  After carrying out a calculation, MATLAB assigns the result.
MATLAB Basics With a brief review of linear algebra by Lanyi Xu modified by D.G.E. Robertson.
Matlab tutorial course Lesson 2: Arrays and data types
MATLAB INTRO CONTROL LAB1  The Environment  The command prompt Getting Help : e.g help sin, lookfor cos Variables Vectors, Matrices, and Linear Algebra.
1 Statistical Computing in MATLAB AMS 597 Ling Leng.
Martin Ellison University of Warwick and CEPR Bank of England, December 2005 Introduction to MATLAB.
Nonparametric Econometrics1 Intro to Matlab for Data Analysis and Statistical Modeling.
Introduction to Matlab 1. Outline: What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators Plotting Flow Control Using of M-File Writing.
Introduction to MATLAB
Introduction to MATLAB. Windows in MATLAB Command Window – where you enter data, run MATLAB code, and display results Command History - displays a log.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
How to Use MATLAB A Brief Introduction. 2 What can MATLAB do? Matrix Operations Symbolic Computations Simulations Programming 2D/3D Visualization.
Matlab Programming, part 1 M-files It is generally more convenient to program in Matlab using m-files, ascii text files containing a set of Matlab commands.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
COMP 116: Introduction to Scientific Programming Lecture 36: Final Review I.
Introduction to MATLAB Session 1 Simopekka Vänskä, THL 2010.
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display.
Introduction to Matlab. What is Matlab? A software environment for interactive numerical computations Examples:  Matrix computations and linear algebra.
Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a.
Introduction to Matlab By E. Noura Semary. Contents MATLAB Environment  Command window, Workspace, Path window, Editor window,and Figure window) Basic.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. Introduction to MATLAB 7 for Engineers William J. Palm.
MATLAB Lecture Two Tuesday 5 July Chapter 3.
Computer Simulation Lab Electrical and Computer Engineering Department SUNY – New Paltz SUNY-New Paltz “Lecture 2”
MATLAB Tutorial EE313 Signals and Systems Created: Thursday Jan 25, 2007 Rayyan Jaber Modified by: Jeff Andrews.
Introduction to Matlab Part II 1Daniel Baur / Introduction to Matlab Part II Daniel Baur / Michael Sokolov ETH Zurich, Institut für Chemie- und Bioingenieurwissenschaften.
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
CSE 455 : Computer Vision MATLAB 101 Getting Started with MATLAB.
Intro to Matlab Rogelio Long September 3, How to access MyDesktop Log in with your utep id and password.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
Intro to Matlab Yipei Wang & Qihui Li {yipeiw,
CS100A, Fall 1998, Lecture 201 CS100A, Fall 1998 Lecture 20, Tuesday Nov 10 More Matlab Concepts: plotting (cont.) 2-D arrays Control structures: while,
Outline What is MATLAB MATLAB desktop Variables, Vectors and Matrices Matrix operations Array operations Built-in functions: Scalar, Vector, Matrix Data.
How to use MATLAB (using M-files) Double click this icon To start Matlab 6.5.
LAB 2 Vectors and Matrices Dr.Abdel Fattah FARES.
Introduction to Matlab. Outline:  What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators.
Matrix Mayhem: Outline
Introduction to MATLAB
Statistical Computing in MATLAB
Scripts & Functions Scripts and functions are contained in .m-files
Introduction to MATLAB
MATLAB DENC 2533 ECADD LAB 9.
Introduction to Matlab
Matlab Workshop 9/22/2018.
StatLab Matlab Workshop
MATLAB How to use (using M-files) Double click this icon
MATH 493 Introduction to MATLAB
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
Matlab tutorial course
MATLAB How to use (using M-files) Double click this icon
Introduction to MATLAB [Vectors and Matrices] Lab 2
MATLAB How to use (using M-files)
Review of Linear Algebra Introduction to Matlab
INTRODUCTION TO MATLAB
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Announcements P3 due today
How to Use MATLAB A Brief Introduction.
Matlab Training Session 2: Matrix Operations and Relational Operators
Presentation transcript:

CS 175 Project in AI Discussion -- matlab Yutian Chen

help help help help Documentation doc help

Useful functions who, whos size, length clear clc sum, max, min

Matrix Allocation Enter an explicit list of elements. Colon operator Generate matrices using built-in functions. linspace, logspace, zeros, ones, eye, rand Tips: Pre-allocation avoids reallocation of matrices

Matrix Indexing end, find exercise: Subscripted Indexing (1-based) A = [11 14 17; ... % use “…” to continue on the next line 12 15 18; ... 13 16 19]; A(2:3,2) Linear Indexing (matrix is store by column) A([3,1,8]) Logical Indexing A(logical([0 0 1 0 1])) end, find exercise: last column of A A(:,end) diagonal of A diag(A) or A(logical(eye(size(A)))) Find all the elements greater than 15 A(A>15)

Matrix Manipulation Transpose A=A' A(:) repmat reshape [] Cat

Matrix Manipulation cont. exercise: A=ones(2,2); B=rand(2); concatenate A and B along the 1st, 2nd, 3rd dimension 1st: [A;B] or cat(1,A,B) 2nd: [A,B] or cat(2,A,B) 3rd: cat(3,A,B) generate [1 1 1 1 1 2 2 2 2 2] [ones(1,5),2*ones(1,5)] or reshape(repmat([1, 2],5,1),1,10) transform A=[1 2; 3 4; 5 6; 7 8] to [1 2 3 4; 5 6 7 8] A = reshape(A',4,2)'

Flow Control if, else, switch for loop while loop continue break for i = [1 3 5 6]; H(i) = 1/i; end while loop continue break

Logical operators Element-wise operator &, |, ~ <, <=, >, >=, ==, ~= A=ones(2,2); B=A; A==B Some functions to reduce the results of matrix comparisons to scalar conditions: isequal, isempty, all, any

Save/Load save load save a.mat save a.mat x y save('a.mat','x','y') load a.mat load a.mat x load('a.mat','x')

Vectorization For simplicity and speed Vector dot product A=[1 2 3 4 5]; B=[5 4 3 2 1]; p = 0; for i=1:5 p=p+A(i)*B(i); end Or p = A*B'; p = sum(A.*B);

Vectorization cont. Matrix multiplication A=ones(5); B=eye(5); p = zeros(size(A,1),size(B,2)); for i=1:size(p,1) for j=1:size(p,2) for k=1:size(p,2) p=p+A(i,k)*B(k,j); end Or p = A*B Compare the multiplication of two 100x100 matrix to see the difference

Vectorization cont. Exercise A is a row vector, C=A(1)*A(2)+A(2)*A(3)+...+A(N- 1)*A(N); C = A(1:end-1)*A(2:end) ' polynomial evaluation: a0+a1*x+...+ak*x^k y = A*2.^(0:k) '; sigmoid(x,W,b) (x: dims:1xD, W: 1xD, b:1x1) 1/(1+exp( -(W*x‘+b) )) sigmoid(x,W,b) (x: NxD, W: 1xD, b:1x1) 1./(1+exp( -(W*x‘+b) ))

Vectorization cont. Exercise weight update in logistic regression y is a Nx1 row vector of labels x is a NxD matrix of data W is a 1XD row vector W = W + rate * x' *(y-1./(1+exp( -(W*x' +b) ))) (Be careful to match the inner dimension of matrix multiplications)

Plot plot line type, color, symbol plot(x,y); plot(y); plot(A) line type, color, symbol title, xlabel, legend, xlim, hold on/off log-scale: semilogx, semilogy, loglog hist, bar, stem, surf, scatter

Script/Function Script Function Debugging a batch of commands grouped in a .m file share the same workspace with the command line Function keyword: function input, output function name determined by the file name useful functions: nargin, nargout, exist Debugging