+ All Categories
Home > Documents > PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open...

PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open...

Date post: 02-Jun-2020
Category:
Upload: others
View: 5 times
Download: 0 times
Share this document with a friend
98
PSY8219 : Week 12 Homework 10 Due Wednesday at 1pm Homework 12 Due Wednesday November 28 at 1pm Readings for Today Attaway Chapter 13 (section on GUIs) Readings for Next Week None
Transcript
Page 1: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

PSY8219 : Week 12

Homework 10 Due Wednesday at 1pm

Homework 12 Due Wednesday November 28 at 1pm

Readings for Today

Attaway Chapter 13 (section on GUIs)

Readings for Next Week

None

Page 2: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

Graphical User Interfaces (GUIs)

http://www.mathworks.com/help/pdf_doc/matlab/buildgui.pdf

Page 3: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

GUIs in Matlab

let you get inputs from users or interact with graphical objects

Two ways to create GUIs: 1) GUIDE, the MATLAB Graphical User Interface Development Environment, provides interactive tools for creating GUIs 2) programming directly using GUI functions

Page 4: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

GUIs in Matlab

GUIs are built within Matlab figures

fh=figure('Visible','off','Position',[11sxsy],...'Color','white','Name','AnexampleGUI');

size of figureinvisible while we create

figure handle

Page 5: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

Formatting

You need to realize the internally Matlab has a hierarchical representation of figures.

root

figure

GUIobjects

axes

plotobjects

otherobjects

Page 6: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

GUIs in Matlab

GUIs are built within Matlab figures

fh=figure('Visible','off','Position',[11sxsy],...'Color','white','Name','AnexampleGUI');

.

.

.

movegui(fh,'center');set(fh,'Visible','on');

move to the center of the screen

make the figure visible

Page 7: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

GUIs in Matlab

uicontrol is one key routine for building GUIs

uicontrol(fh,'Style','text','Units','Normalized',... 'Position',[.05.80.2.1],'FontSize',18,...'String','SubjectName','BackgroundColor','white');

Page 8: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

GUIs in Matlab

uicontrol is one key routine for building GUIs

uicontrol(fh,'Style','text','Units','Normalized',... 'Position',[.05.80.2.1],'FontSize',18,...'String','SubjectName','BackgroundColor','white');

figure handle

Page 9: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

GUIs in Matlab

uicontrol is one key routine for building GUIs

uicontrol(fh,'Style','text','Units','Normalized',... 'Position',[.05.80.2.1],'FontSize',18,...'String','SubjectName','BackgroundColor','white');

what kind of GUI control

'text','sliders','radiobutton','popupmenu',etc.

Page 10: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

GUIs in Matlab

uicontrol is one key routine for building GUIs

uicontrol(fh,'Style','text','Units','Normalized',... 'Position',[.05.80.2.1],'FontSize',18,...'String','SubjectName','BackgroundColor','white');

use normalized (percent) units

Page 11: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

GUIs in Matlab

uicontrol is one key routine for building GUIs

uicontrol(fh,'Style','text','Units','Normalized',... 'Position',[.05.80.2.1],'FontSize',18,...'String','SubjectName','BackgroundColor','white');

where this text will go and how big it is 5% on x, 80% on y, 20% high, 10% wide

Page 12: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

GUIs in Matlab

uicontrol is one key routine for building GUIs

uicontrol(fh,'Style','text','Units','Normalized',... 'Position',[.05.80.2.1],'FontSize',18,...'String','SubjectName','BackgroundColor','white');

this is the value of the text to display

Page 13: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

GUIs in Matlab

uicontrol is one key routine for building GUIs

snameh=uicontrol(fh,'Style','edit',... 'Units','Normalized',... 'Position',[.30.83.4.1],'FontSize',18);

editable text box

Page 14: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

GUIs in Matlab

uicontrol is one key routine for building GUIs

snameh=uicontrol(fh,'Style','edit',... 'Units','Normalized',... 'Position',[.30.83.4.1],'FontSize',18);

control handle, important to read out value

Page 15: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

GUIs in Matlab

uicontrol is one key routine for building GUIs

snameh=uicontrol(fh,'Style','edit',... 'Units','Normalized',... 'Position',[.30.83.4.1],'FontSize',18);...sname=get(snameh,'String');

read out value typed in

Page 16: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

GUIs in Matlab

uicontrol is one key routine for building GUIs

llh=uicontrol(fh,'Style','slider',...'Units','Normalized','Position',[.42.24.50.2],... 'Min',minl,'Max',maxl,'Value',minl,...'SliderStep',[.1.2],'CallBack',@llcallback);

control handle, important to read out value

Page 17: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

GUIs in Matlab

uicontrol is one key routine for building GUIs

llh=uicontrol(fh,'Style','slider',...'Units','Normalized','Position',[.42.24.50.2],... 'Min',minl,'Max',maxl,'Value',minl,...'SliderStep',[.1.2],'CallBack',@llcallback);

slider

Page 18: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

GUIs in Matlab

uicontrol is one key routine for building GUIs

llh=uicontrol(fh,'Style','slider',...'Units','Normalized','Position',[.42.24.50.2],... 'Min',minl,'Max',maxl,'Value',minl,...'SliderStep',[.1.2],'CallBack',@llcallback);

min, max, and starting value

Page 19: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

GUIs in Matlab

uicontrol is one key routine for building GUIs

llh=uicontrol(fh,'Style','slider',...'Units','Normalized','Position',[.42.24.50.2],... 'Min',minl,'Max',maxl,'Value',minl,...'SliderStep',[.1.2],'CallBack',@llcallback);

function called any time control element used

Page 20: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

GUIs in Matlab

uicontrol is one key routine for building GUIs

llh=uicontrol(fh,'Style','slider',...'Units','Normalized','Position',[.42.24.50.2],... 'Min',minl,'Max',maxl,'Value',minl,...'SliderStep',[.1.2],'CallBack',@llcallback);

ll=round(get(llh,'Value'));

read out the number based on slider position

Page 21: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

GUIs in Matlab

>>get(llh) BackgroundColor=[0.9294120.9294120.929412] Callback=[(1by1)function_handlearray] CData=[] Enable=on Extent=[000.006666670.008] FontAngle=normal FontName=Helvetica FontSize=[10] FontUnits=points FontWeight=normal ForegroundColor=[000]… Parent=[1] Selected=off SelectionHighlight=on Tag= Type=uicontrol UIContextMenu=[] UserData=[] Visible=on

justlikefigurehandlesyoucangetandsetparticularvalues

Page 22: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

GUIs in Matlab

llh=uicontrol(fh,'Style','slider',...'Units','Normalized','Position',[.42.24.50.2],... 'Min',minl,'Max',maxl,'Value',minl,...'SliderStep',[.1.2],'CallBack',@llcallback);llth=uicontrol(fh,'Style','text',...'Units','Normalized','Position',[.30.35.08.1],... 'FontSize',18,'String',num2str(minl),...'BackgroundColor','white');

functionllcallback(source,eventdata) ll=get(llh,'Value'); set(llth,'String',num2str(round(ll)));end

slider

showvalueofslider

Page 23: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

GUIs in Matlab

llh=uicontrol(fh,'Style','slider',...'Units','Normalized','Position',[.42.24.50.2],... 'Min',minl,'Max',maxl,'Value',minl,...'SliderStep',[.1.2],'CallBack',@llcallback);llth=uicontrol(fh,'Style','text',...'Units','Normalized','Position',[.30.35.08.1],... 'FontSize',18,'String',num2str(minl),...'BackgroundColor','white');

functionllcallback(source,eventdata) ll=get(llh,'Value'); set(llth,'String',num2str(round(ll)));end

getvalueofslider

Page 24: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

GUIs in Matlab

llh=uicontrol(fh,'Style','slider',...'Units','Normalized','Position',[.42.24.50.2],... 'Min',minl,'Max',maxl,'Value',minl,...'SliderStep',[.1.2],'CallBack',@llcallback);llth=uicontrol(fh,'Style','text',...'Units','Normalized','Position',[.30.35.08.1],... 'FontSize',18,'String',num2str(minl),...'BackgroundColor','white');

functionllcallback(source,eventdata) ll=get(llh,'Value'); set(llth,'String',num2str(round(ll)));end updatetextdisplayofvalue

Page 25: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

GUIs in Matlab

once created a GUI is a standalone object – you need to interrogate it explicitly via its handles, or let it impact your program via its callback functions

MainProgram GUI

usehandlestoaccessGUIdata

GUIcanchangeglobalvariables

Page 26: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

GUIs in Matlab

Week12_GUI.m

keeps GUI open until all data entered and user presses OK

Week12_Figure.m

creates a GUI that is simply closed by clicking it closed in principle, you could essentially create something that acted like a full-blown program with menus and multiple windows all spawned by callback functions attached to GUI elements

Page 27: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply
Page 28: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

Optimization and Curve Fitting

Page 29: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

LinearRegressionModel

vs

NonlinearStatistical,Cognitive,NeuralModel

slopeandinterceptparametersarecalculatedusingclosed-formmathematicalexpressions

modelparameterscanbeestimatedusingavarietyofsearch/optimizationapproaches

Page 30: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

Week12_Figure.m

imagine trying to fit data by adjusting all the parameters by hand

Page 31: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

motion coherence

accu

racy

fittingapsychometricfunctiontoobserveddata

whatvaluesofα, β, γ, λ providethebestaccountoftheobserveddata?

P(correct | x) = γ + (1− λ − γ )F(x;α ,β )F(x;α ,β ) = 1− exp(−(x / β )α )

Page 32: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

motion coherence

accu

racy

e.g.,whatvalueofcoherencegiveschanceperformance

fittingapsychometricfunctiontoobserveddata

Page 33: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

motion coherence

accu

racy

luminance #1

luminance #2

motion coherence

luminance #1

luminance #2

isthesamepsychometricfunctionobservedwhenanothervariableismanipulated(ornot)?

isthethresholdsignificantlyhigherinoneconditionthantheother?

Page 34: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

amount of learning (n)

resp

onse

tim

e

fitapowerlawfunctiontoalearningcurve

RT (n) = A + Bn−C

Page 35: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

amount of learning (n)

resp

onse

tim

e

isapowerlaworanexponentiallawabetterfunction?

vs.RT (n) = A + Bn−C RT (n) = A + Be−C (n−1)

Page 36: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

Zhang,W.,&Luck,S.J.(2008).Discretefixed-resolutionrepresentationsinvisualworkingmemory.Nature,453,233-235.

Page 37: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

usedtocharacterizeVWMinagivencondition

probabilityanitemisstoredinVWM

fidelityofthememory

meancontentofthememory

Prob(x | µ,σ ,Pm ) = Pmecos(x−µ )/σ

2π I0 (1 /σ )+ (1− Pm )

12π

µ,σ ,Pm

Page 38: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

StochasticAccumulationofEvidenceModels

perceptual processing

time

motorresponse

time

z

adrift

TR TM

Page 39: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

Different kinds of models

• purely mathematical / statistical models – nonlinear regression

– power law of learning

– psychometric function

• hybrid mathematical / process model – mixture models of power law functions

– mixture model of VWM

• process / mechanistic model (cognitive or neural) – diffusion model of perceptual decision making

– temporal context model of memory

Page 40: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

optimizationandparameterestimation

model

Page 41: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

optimizationandparameterestimation

model

parameters

Page 42: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

optimizationandparameterestimation

model

parameters

prediction

Page 43: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

optimizationandparameterestimation

model

parameters

prediction data≡

Page 44: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

optimizationandparameterestimation

model

parameters

prediction data≡

weneedtofindparametersthatcausethemodeltomakepredictionsthatmatchthedata

Page 45: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

optimizationandparameterestimation

social,behavioral,orneuralprocess

parameters

unknownandunobservable observable

data

Page 46: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

optimizationandparameterestimation

social,behavioral,orneuralprocess

parameters data

modelofthatprocess

observableunknownandunobservable

hypothesized

perhapsoneofseveralcompetingmodelsbeingconsidered

Page 47: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

optimizationandparameterestimation

social,behavioral,orneuralprocess

parameters data

modelofthatprocess predictionparameters

observableunknownandunobservable

hypothesized

generated

Page 48: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

optimizationandparameterestimation

social,behavioral,orneuralprocess

parameters data

modelofthatprocess predictionparameters

observableunknownandunobservable

hypothesized

generated

maximizethecorrespondence

minimizethediscrepancy

Page 49: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

optimizationandparameterestimation

social,behavioral,orneuralprocess

parameters data

modelofthatprocess predictionparameters

observableunknownandunobservable

hypothesized

byadjustingtheseparameters

maximizethecorrespondence

minimizethediscrepancy

generated

Page 50: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

optimizationandparameterestimation

social,behavioral,orneuralprocess

parameters data

modelofthatprocess predictionparameters

observableunknownandunobservable

hypothesized

byadjustingtheseparameters

maximizethecorrespondence

minimizethediscrepancy

generated

ifwe’veoptimizedcompetingmodels,wecanstatisticallydeterminewhethersomemodelspredictbetterthanothers

Page 51: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

optimizationandparameterestimation

social,behavioral,orneuralprocess

parameters data

modelofthatprocess predictionparameters

observableunknownandunobservable

hypothesized

byadjustingtheseparameters

maximizethecorrespondence

minimizethediscrepancy

generated

ifwe’veoptimizedcompetingmodels,wecanstatisticallydeterminewhethersomemodelspredictbetterthanothers

Page 52: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

optimizationandparameterestimation

social,behavioral,orneuralprocess

parameters data

modelofthatprocess predictionparameters

observableunknownandunobservable

hypothesized

byadjustingtheseparameters

maximizethecorrespondence

minimizethediscrepancy

generated

sometimes,parameterscanbesetbasedononesetofdataandused(withoutfitting)foranothersituation…

Page 53: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

measuresofcorrespondenceordiscrepancy

Someexamples(oftencalled“objectivefunctions”)

Sum-of-SquaredError(SSE)

Correlation

χ2

Likelihood various

SSE = (obsi − prdi )2

i∑

r =(obsi − obs)(prdi − prd)

i∑(obsi − obs)

2

i∑ (prdi − prd)

2

i∑

χ 2 = (obsi − prdi )2

prdii∑

minimized

maximized

minimized

maximized

someobjectivefunctionsaremoreconducivetostatisticaltests

Page 54: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

p

SSEwithonlyoneparameter,wewanttofindthevalueofparameterpthatmakestheSSEassmallaspossible–bestfittingvalueofp

optimal valueofp

smallestSSE

One-parameter model

Page 55: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

p1

p2

SSE

valuesofp1andp2thatminimizeSSE

Two-parameter model

Page 56: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

Three-parameter (or more) model

cannot visualize graphically, but the concept is the same …

what values of parameters minimize SSE (or maximize correlation, or maximize likelihood)

Page 57: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

Page 58: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

BruteForce:GridSearch

tryeverycombinationofparametersandkeeptheonethatminimizes/maximizesyourobjectivefunction(e.g.,SSE)

Page 59: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

BruteForce:GridSearch

tryeverycombinationofparametersandkeeptheonethatminimizes/maximizesyourobjectivefunction(e.g.,SSE)

basically,it'sthesameprogrammingyouwouldusetographthefunction,onlythatyou'realsotryingtofindthemin

Page 60: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

BruteForce:GridSearch

tryeverycombinationofparametersandkeeptheonethatminimizes/maximizesyourobjectivefunction(e.g.,SSE)

parameter 1

para

met

er 2

likeanearlierhomeworkproblem

Page 61: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

BruteForce:GridSearch

tryeverycombinationofparametersandkeeptheonethatminimizes/maximizesyourobjectivefunction(e.g.,SSE)

okayformodelswithdiscrete-valuedparameters…whentheyhavecontinuousvaluesitisimpossibletotryeverycombination

okayformodelswithacoupleofparameters…impossibleformodelswithdozensorhundredsofparameters

Page 62: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

BruteForce:GridSearch

imaginewehaveamodelwith5parameters…

andforeachparameterwearegoingtoevaluate100valuesofit…

Howmanytotalevaluationsisthat?

Page 63: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

BruteForce:GridSearch

imaginewehaveamodelwith5parameters…

andforeachparameterwearegoingtoevaluate100valuesofit…

Howmanytotalevaluationsisthat?

1005or1010=10,000,000,000

Isthatalot?Wellitdepends.

Page 64: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

BruteForce:GridSearch

imaginewehaveamodelwith5parameters…

andforeachparameterwearegoingtoevaluate100valuesofit…

Howmanytotalevaluationsisthat?

1005or1010=10,000,000,000

Isthatalot?Wellitdepends.

Ifittakes1nanosecond(10-9seconds)perevaluation,thenitwouldtakeonly10secondstodoall1010evaluations…butthatwouldhavetobeaverysimplemodel

Page 65: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

BruteForce:GridSearch

imaginewehaveamodelwith5parameters…

andforeachparameterwearegoingtoevaluate100valuesofit…

Howmanytotalevaluationsisthat?

1005or1010=10,000,000,000

Isthatalot?Wellitdepends.

Ifittakes100seconds(102seconds)perevaluation,thenitwouldtakenearly32,000yearstodoalltheevaluations…

wearetestingsomeneuralmodelsthattakefarlongerthanthattorun

Page 66: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

BruteForce:GridSearch

imaginewehaveamodelwith5parameters…

andforeachparameterwearegoingtoevaluate100valuesofit…

Howmanytotalevaluationsisthat?

1005or1010=10,000,000,000

Isthatalot?Wellitdepends.

Ifittakes100seconds(102seconds)perevaluation,thenitwouldtakenearly32,000yearstodoalltheevaluations…evenifweranthison1000processors,itwouldtake32years

Page 67: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

Calculus

formathematicallysimplemodelsandobjectivefunctions,youcansometimesoptimizeusingcalculus…

Page 68: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

Calculus

SSE(p)

dSSE(p)dp

derivativeofafunctionisanotherfunctionthatspecifiestheslopeofthatfunction

Page 69: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

Calculus

SSE(p)

dSSE(p)dp

derivativeofafunctionisanotherfunctionthatspecifiestheslopeofthatfunction

Page 70: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

Calculus

SSE(p)

dSSE(p)dp

derivativeofafunctionisanotherfunctionthatspecifiestheslopeofthatfunction

Page 71: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

Calculus

SSE(p)

dSSE(p)dp

minimizingormaximizingstartswithfindinganyplacesonthefunctionwherethederivativeiszero

Page 72: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

Calculus

SSE(p)dSSE(p)dp

= 0 canoftenbedoneanalytically,solvingforvaluesofp

Page 73: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

Calculus

p1

p2

SSE

∂SSE(p1)∂p1

= 0 ∂SSE(p2)∂p2

= 0and

Page 74: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

Hill-climbingAlgorithms

Page 75: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

SSE(p)

Hill-climbingAlgorithms

Page 76: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

SSE(p)

Hill-climbingAlgorithms

Page 77: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

SSE(p)

Hill-climbingAlgorithms

Page 78: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

SSE(p)

Hill-climbingAlgorithms

Page 79: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

SSE(p)

Hill-climbingAlgorithms

Page 80: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

SSE(p)

Hill-climbingAlgorithms

Page 81: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

SSE(p)

Hill-climbingAlgorithms

Page 82: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

SSE(p)

Hill-climbingAlgorithms

Page 83: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

SSE(p)

Hill-climbingAlgorithms

Page 84: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

SSE(p)

Hill-climbingAlgorithms

Page 85: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

Hill-climbingAlgorithms

Enrico Fermi and Nicholas Metropolis used one of the first digital computers, the Los Alamos Maniac, to determine which values of certain theoretical parameters (phase shifts) best fit experimental data (scattering cross sections). They varied one theoretical parameter at a time by steps of the same magnitude, and when no such increase or decrease in any one parameter further improved the fit to the experimental data, they halved the step size and repeated the process until the steps were deemed sufficiently small. Their simple procedure was slow but sure, and several of us used it on the Avidac computer at the Argonne National Laboratory for adjusting six theoretical parameters to fit the pion-proton scattering data we had gathered using the University of Chicago synchrocyclotron [7].

W. C. Davidon, Variable Metric Method for Minimization, Tech. Rep. 5990, Argonne National Laboratory, Argonne, IL, 1959.

these techniques only emerged 60 years ago (Calculus was invented 400 years ago)

Page 86: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

abriefsurveyofoptimizationmethods

Hill-climbingAlgorithms

Enrico Fermi and Nicholas Metropolis used one of the first digital computers, the Los Alamos Maniac, to determine which values of certain theoretical parameters (phase shifts) best fit experimental data (scattering cross sections). They varied one theoretical parameter at a time by steps of the same magnitude, and when no such increase or decrease in any one parameter further improved the fit to the experimental data, they halved the step size and repeated the process until the steps were deemed sufficiently small. Their simple procedure was slow but sure, and several of us used it on the Avidac computer at the Argonne National Laboratory for adjusting six theoretical parameters to fit the pion-proton scattering data we had gathered using the University of Chicago synchrocyclotron [7].

W. C. Davidon, Variable Metric Method for Minimization, Tech. Rep. 5990, Argonne National Laboratory, Argonne, IL, 1959.

these techniques only emerged 60 years ago (Calculus was invented 400 years ago)

Page 87: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

p1

p2

SSE

Page 88: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply
Page 89: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

howmanypointsdoyouneedtoevaluatewitheachstep?

2 parameters

21 3

4

567

8

abriefsurveyofoptimizationmethods

SimpleHillClimbing

Page 90: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

N parameters

5 parameters

10 parameters

3N-1 evaluations per step

242 evaluations per step

59049 evaluations per step

this ends up being inefficient because you can need to take 1000’s of steps

howmanypointsdoyouneedtoevaluatewitheachstep?

abriefsurveyofoptimizationmethods

SimpleHillClimbing

Page 91: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

Kolda, T.G., Lewis, R.M., & Torczon, V. (2003). Optimization by direct search: New perspectives on some classical and modern methods. SIAM Review, 45, 385-482.

Kelley, C.T. (1999). Iterative Methods for Optimization. SIAM. Chapters 6-8.

abriefsurveyofoptimizationmethods

Moresophisticatedalgorithms

Page 92: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

OptimizationToolboxhttp://www.mathworks.com/help/pdf_doc/optim/optim_tb.pdf

GlobalOptimizationToolboxhttp://www.mathworks.com/help/pdf_doc/gads/gads_tb.pdf

CurveFittingToolboxhttp://www.mathworks.com/help/pdf_doc/curvefit/curvefit.pdf

Page 93: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

MATLAB:fminsearch(…)

http://en.wikipedia.org/wiki/Nelder-Mead_method

http://www.scholarpedia.org/article/Nelder-Mead_algorithm

abriefsurveyofoptimizationmethods

Nelder-MeadeSimplex

Page 94: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

[opt fit] = fminsearch(@myfun,p0)

params fit

change params to try to decrease fit

myfun()

Page 95: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

p0=-2;[optfit]=fminsearch(@myfun1,p0);fprintf('p0=%5.2f\toptimalp=%5.2f\tf(p)=%6.3f\n',… p0,opt,fit);

functiony=myfun1(x) y=-humps(x); end

Week12_fmin.m

Page 96: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

p0=[-20];[optfit]=fminsearch(@myfun2,p0);

functionz=myfun2(x,y) z=3*(1-x(:,1)).^2.*exp(-(x(:,1).^2)-(x(:,2)+1).^2)...-10*(x(:,1)/5-x(:,1).^3-x(:,2).^5).*... exp(-x(:,1).^2-x(:,2).^2)... -1/3*exp(-(x(:,1)+1).^2-x(:,2).^2);end

Week12_fmin2.m

Page 97: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

p0=[1023];[optfit]=fminsearch(@myfun3,p0);

functionSSE=myfun3(p)%calculuatemodelpredictionsgivenparametervectorp

%thencalculateSSEcomparingpredictionstodata

%returnSSEasthevaluetominimizeend

thiscouldbeanonlinearfunctionifyouarecurvefittingorthiscouldbeaneuralorcognitivemodelifyouaretheorizing

Page 98: PSY8219 : Week 12catlab.psy.vanderbilt.edu/.../Week12/Week12.pdf · Week12_GUI.m keeps GUI open until all data entered and user presses OK Week12_Figure.m creates a GUI that is simply

p0=[351431];[optfit]=fminsearch(@myfun4,p0);

functionlnL=myfun4(p)%calculuatemodelpredictionsgivenparametervectorp

%thencalculatelnLcomparingpredictionstodata

%return-lnLasthevaluetominimizeend

maximizingissimply-minimizing


Recommended