[SOLVED] math matlab graph software network theory Lecture 6:

$25

File Name: math_matlab_graph_software_network_theory_Lecture_6:.zip
File Size: 489.84 KB

5/5 - (1 vote)

Lecture 6:
Modelling in MATLAB: Introduction
Objectives for today:
Aim of sessions
Describe first two assignments or at least the first

Models of Judgement and Choice
This lecture: Mix of model description and MATLAB implementation for the Wednesday workshop
Today:
Discussion of why modelling usefulnecessaryIntroduction to MATLAB
First parts of assignment

Additional source may be useful: Chapters 14 for basics; 9 for plots; 68 also useful

For getting more serious.
FarrellLewandowsky
BusemeyerDiederich

Need to know
The code we cover in the overheads includes all the commands you must know for the assignments
So you wont need to use all the code covered in the book
But the book contains additional information that may be useful
Work through code on overheads in the workshop sessions

What is Cognitive Modelling?
Expressing psychological ideas as simple mathematical or computational models
Implementing psychological models in form of computer programme
Compare the models to empirical data Why might we want to do this?

Aims of Practicals
Be able to think like a modeller!
A skill rather than knowledge
Handson experience
Be able to implement and explore mathematical and
computational models in literature
Be able to express your own ideas in form of simple
model using MATLAB
Be able to fit model to data, and evaluate fit
Be able to compare models

Reasons for Modelling 1
Building a model forces you to be specific; assumptions have to be spelled out explicitly
Clarify new ideas
With a purely verbal description of a model, its easy to miss crucial parts of the problem
Intuition is a poor guide to problem difficulty

Reasons for Modelling 2
Models are complex; their behaviour may be unpredictable until you simulate them
Models may exhibit surprising behaviour
Emergent properties
Models make unambiguous predictions
Easier to falsify problem of looking for confirming evidence Public nature of modelless room for disagreement

Approaches to Cognitive Modelling
Here we will be concerned with:
Expressing psychological ideas as simple mathematical models
Implementing psychological models in form of computer programme
Fitting models to empirical data
Not directly concerned with:
Artificial Intelligence
Expert Systems
General cognitive architectures ACTR
Neural networks but will mention connectionism

Artificial Intelligence
Perhaps cognition is computation and is hardware independent much argument here
We can look at the software independently of the hardware multiple levels of descriptionbut are they really independent?
Minsky 1968: artificial intelligence is the science of making machines do things that would require intelligence if done by men
cf. aerodynamics flying things; thinking things

Expert Systems
Expert systems:
Medical diagnosisFinancial advice
To substitute for human experts Knowledge engineering
Capture experts knowledge as system of rules No claim for psychological reality

Assignment Part 1:
of 4; all due after end of term
How does the subjective magnitude of a stimulus increase as a function of actual stimulus magnitude?

Assignment Part 1:
of 4; all due after end of term
How does the subjective magnitude of a stimulus increase as a function of actual stimulus magnitude?
Fechners Law: Subjective magnitude is a logarithmic function of actual stimulus magnitude:
Sk LogI
where Ssubjective magnitude; I is stimulus intensity; k is a constant
Stevens Law: Subjective magnitude is a power function of actual stimulus magnitude:
SkIa
where Ssubjective magnitude; I is stimulus intensity; k and a are constants

Assignment Part 1 ideally next week
1 Familiarisation with MATLAB
ConsulttheMATLABhelpanddemofilesifneeded
2 Draw graphs
Forstimulusenergiesrangingbetween1and100,plotagraphillustrating
the different predictions of Fechners Law and Stevens Law, using
parameter values that enable the comparison to be clear.
Plotasecondgraphillustratingtheeffectsofvaryingtheaparameterin
Stevens Law
3 Compare model and data
Calculate the RMSD root mean square deviation between model Stevens
Law and data overleaf for various parameter values
FindbyhandapproximateparametervaluesthatminimiseRMSDwewill
look at functions and optimisation later
Abouthalfapageofcommentarydescribingresultsandnotinganyissues arising
Deadline: This is just part of the assignment for the module; others will follow next week. Additional guidelines will be available on Moodle later.

Comparing model and data
Suppose that we choose some particular values of a and k.
We then want to see what the models predictions are for the subjective
intensities of the following sensory magnitudes:
stimuli2 4 6 8 10 12
Suppose then we do an experiment to find the actual subjective intensities in human participants, and we obtain the following:
data1.1 1.5 2.1 2.5 2.9 3.2
What values of a and k will minimise RMSD?
In MATLAB:
sdmodeldata. 2;
rmsdsqrtmeansd;

MATLAB
MATLAB
A highlevel language
Good for data visualisation
Good for dealing with vectors and matrices
Learning MATLAB
Best way is to play about with it
I will introduce essential basic commands
The online help facility is very good
Online tutorials included with MATLAB are good; use them! Or type help topic at command line e.g. type help plot
Try typing demo at command line
I will sometimes use inefficient but transparent program structure to illustrate bad practice!

MATLAB Basics 1
Can give commands interactively or in program:
First, Interactive: Type into command window
Try typing in the following, each followed by the return key:
2
36
Adjhadhj i.e., nonsense323 squared
434 cubed
Log100
log100
pi
642
123
MATLAB good for working with vectors lists of numbers
Enclose within square brackets:1 8 5 9 2
Any name without spaces is fine as long as not special for MATLAB

MATLAB Basics 2
Most of the time we will be working with variables.
Try typing in the following, each followed by the return key:
A3 A5 B10 AB
A AA3 A
The principle is the same vectors lists of numbers
Try typing in the following, each followed by the return key:
V1 8 5 9 2VV2
V
WV2
W
Any name is fine as long as not special for MATLAB:
tricia 5 4 3 2 1 fredtriciaW plotfred

MATLAB Basics 3
Opening MATLAB; creating and saving a program
often we want to make and keep a list of instructions
Open MATLAB
Choose new from menu m filea program is called a script Make a program:
clear all
this is my first program
n1:100
an3
Save the program and note where it is being saved
no spaces or special chars in name; name must end in .m, e.g.
firstprog.mRun it
Close MATLAB
Open MATLAB again, open the program, and run it. Make some changes!

MATLAB Basics 4
Make a new program; save and run it:
clear all
linda1 5 3 7 9;
tricia6 5 5 2 8;
tricia
tricia100
linda
Note: the;prevents the vector printing out try it out, with and without the semicolons

Notes
1 RUN commandgreen arrow or from menu in editor window recent versions of MATLAB
1 Older versions of MATLAB e.g., 2018 do everything we will need and are faster to load
2 University has a site license; can put MATLAB on your own laptop
3 If you get error message:
click Add to path

MATLAB Basics 5
Data visualisation: Many graphing commands. Try adding these to your program and see what happens:
clf
plotlinda
draws a basic graph of the values in linda
plotlinda,om
draws the same graph with an o symbol in magenta colour
plotlinda,tricia
draws a graph plotting linda against tricia
hold on
keeps an old graph in place so you can draw a new one on top
clears any graphs; good to have at top of program

MATLAB Basics 6
We can add vectors, or carry out other simple operations
studentslindatricia
Or multiply them by a constant
newtriciatricia3
We can change a vector without making a new one
lindalinda10
We can specify an element within a vector
linda
linda2
tricia3
Try all the above in your program

Vectors practice
Be clear about accessing individual elements of vectors
The following commands can be done in the command window
mydata3 7 0 9 4 3 8;
Output display the 3rd element
Add 4 onto the fourth element of mydata, and display mydata
Make mydata2 equal to mydata3
Plot a graph of mydata2
Make A equal to the sum of the second element from mydata and the fourth element of mydata2
What is A ?

We can use loops to repeat an operation on different elements of a vector. Such loops are not efficient in MATLAB but are transparent so we will use them sometimes
Lets make a new program to square each number in a vector:
anything after ais ignored by MATLAB comments
clear all clears all variables
clf clears the graphs
gordon2 5 6 1 9;
for n1:5
gordon2ngordonn2;
end
same effect, much better operate on vectors directly:
gordon3gordon.2; the . meansdo for each element
gordon
plotgordon3

Another Example
A new MATLAB command: sqrtx gives the square root of x. Make a new program:
clear all
mydata3 7 0 9 4 3 8;
newvector0 0 0 0 0 0 0;
or, better: newvectorzeros1,7;
for i1:7for values of i between 1 and 7
newvectorisqrtmydatai; sqrt each element
end
or, better: newvectormydata..5;
newvector this just prints out newvector
plotnewvector

clear all
model1.42.02.42.8 3.23.5
data1.1 1.52.12.52.93.2
error0;
for n1:6
errorerrormodelndatan2;
end
better: errorerrormodeldata.2
error

MATLAB Practical 2
Part 1:
Range Frequency Theory Assignment Part 2
Part 2:
Matrices in MATLAB
Function minimisation to choose parameters
The fminsearch command

Implementing Range Frequency Theory in MATLAB
Overview of model Parducci: Range Frequency Theory
Talk about how to implement RFT

What is Range Frequency Theory?
Range Frequency Theory RFT
A simple mathematical model of subjective magnitude judgement of stimuli in a context very different to FechnerStevens approach
How loud is this sound? 17 scale How heavy is this weight?
Originally developed in psychophysics Parducci; 1960s Now being applied to judgement of other quantities:
How satisfied are you with your wage? How expensive is this price?
How attractive is this face?
How overweight do you feel?
Same model RFT seems to apply to judgements of social and economic stimuli recent and ongoing work

Illustration of RFT frequency cf. rank
Two distributions of prices:
Here magnitudes are prices. The mean reference price is the same in both distributions; will prices X and Y receive different attractiveness ratings in the different distributions? answer: Yes!

But example: Distribution of Rewards
Case A:
You are paid at 10 per hour 90 of the time
You are paid nothing per hour 10 of the time
Case B:
You are paid at 10 per hour 90 of the timeYou are paid at 20 per hour 10 of the time

But example: Distribution of Rewards
Case A:
You are paid at 10 per hour 90 of the time
You are paid nothing per hour 10 of the time
Case B:
You are paid at 10 per hour 90 of the timeYou are paid at 20 per hour 10 of the time
Intuition: Would people prefer Case A even though mean income is lower Parducci, 1968?

Range Frequency Theory: Application to Prices
The rated attractiveness of a target price depends on two things:
The range position of the target pricehow far up the range from the lowest contextual price to the highest contextual price is the target price?
The ranked position of the target priceis the target price the second cheapest, the fifth cheapest, etc?
The final rated attractiveness is simply a weighted combination of range value and relative rank
This model does very well at predicting price attractiveness ratings quantitatively

Range Frequency Theory: Equations
Suppose N5 stimuli, ranked in order: 2458 12
What will be judgement given to 8? Si is the ith stimulus 8S4
Ri is the range value of S4: 82122.6
Fi is the frequency value relative rank: 4151.75
Ji is the subjective magnitude of Si. Suppose w is 0.3:
J40.30.60.7.750.705
Ri SiSminSmaxSmin Fi Ranki 1N1
JiwRi 1 wFi
w is a weighting parameter. High values of w give more weight to the range component, and less weight to the frequency component

Assignment Part 2: Data to Model 1
Each of the four lists of 11 numbers over gives a set of hypothetical prices for a product
For each of the four distributions separately:
Determine the predicted judged expensiveness of each price according to RFT with parameter w set to 0.5. Predicted judgements should be on a scale between 1 and 7
Plot graphs to illustrate the predictions
Explore and briefly describe the effects of varying w

Data to Model 2
Unimodal
284246 49 52 55 58 61 64 68 82
Bimodal
283134 38 42 55 68 72 76 79 82
Positive skew
282931 33 36 39 43 48 55 65 82
Negative skew
284555 62 67 71 74 77 79 81 82

Modelling Strategy
Steps for each distribution after entering data etc:
Calculate range values for each price make vector
Calculate frequency values for each price make vector
Calculate RFT prediction for each price make vector
The RFT values will vary between 0 and 1. These need to be transformed into predicted ratings between 1 and 7
Draw the graphs; examine effect of varying the w parameter

So far.
1 Enteringcommandsintothecommandwindow interactively
2 Savingsetsofcommandsasascriptprogramusingthe editor
This week:
3 UsingfunctionstoextendMATLAB
see also Rosenbaum book

Using MATLAB for Matrix Operations
So far we have used MATLAB for vectors single rows of numbers. But much of the power of MATLAB comes from using twodimensional arrays of numbers
These can be entered in two ways. At the command line try the following:
mynums11 2 3; 4 9 6; 7 8 9
and
mynums21 2 3 496
7 8 9

Referring to Elements
Similar to vectors, but specify both the row first then the column
Now try the following at the command line:
mynums13,2
mynums12,3
As before we can add elements and subtract and multiply by single numbers. Try:
mynums23
mynums1mynums2

Plotting Arrays
We can make 3D plots using surf and mesh
surfmynums1
meshmynums2
Try rotating them circular arrow menu item
We can refer to whole rows or columns using : to mean all
the elements:
mynums1:,2
mynums23,:
Often each row of the array might be used represent the data from a single participant, or the stimuli for a particular condition

Choosing Parameters
We often want to calculate how well a model fits some data e.g. Stevens Law
Create a new program script in editor window that goes through the following steps Let us start off by assuming that k is 3 and a0.1
clear all
k3;a0.1;
Make a vector energies corresponding to the light energies
energies5 10 15 20 25 30 35 40;
Make a vector data that contains the magnitude judgements
data3.24.45.25.35.45.86.06.5;

Choosing Parameters
Create a new vector model that predicts the subjective magnitudes of each light The a below raises to the power a; the . means do it it for each element
modelkenergies.a;
Calculate the sum of squared differences between the model and the data
RSSsummodeldata.2
The answer should be: 15.4
Now try different values of k and a. What values of k and a give the best model fit i.e. reduce the summed squared error to as small a value as possible?

Your programme should look like this:
clear all
k3;a0.1;
energies5 10 15 20 25 30 35 40;
data3.24.45.25.35.45.86.06.5;
modelkenergies.a;
RSSsum modeldata.2

The error surface
How can we calculate the bestfitting values of k and a without trying out every possible value by hand?
Here is an error surface when a is 0.1 and k varies:

The fminsearch command
There is a command fminsearch that will do this for
us.
But first we have to write our program as a function that will take k and a as input and output the corresponding summed squared error
We can then apply fminsearch to this function

Functions
MATLAB is built around functions; you can write your own for any sequence of commands that you frequently use
For example, consider the existing MATLAB function
sqrtx
This calculates the square root of any number Try typing: sqrt9 into the command window

Creating a function
We can write your own function for any sequence of commands that you frequently use
Let is write a function that takes any number as input, and outputs the CUBE of the number, plus 7
Call the function cubeseven.m This is very easy

Creating a function
1 Make a new file in the editor that looks like this
function outputcubeseveninput
outputinput37;
2 Save it as cubeseven.m
3 Try and run it it wont because it is a functionadd to path if necessary

Creating a function
function outputcubeseveninput
outputinput37;

Creating a function
function outputcubeseveninput
outputinput37;

Creating a function
function outputcubeseveninput
outputinput37;

Creating a function
4 You should now be able to call it from the command line. Try:
cubeseven3
cubeseven6

Creating a function
Let us now write a function that takes k and a as input, and outputs RSS summed squared error
Call the function lightprog.m
The input V is now a two element vector where the elements are k and a

Writing the function lightprog.m
function RSSlightprogV;
kV1; aV2;
energies5 10 15 20 25 30 35 40;
data3.24.45.25.35.45.86.06.5;
modelkenergies.a;
RSSsummodeldata.2

Using lightprog.m
Now we can use our new function lightprog.m in two ways
1. We can use it from the command window we could also use it in a program. Try typing:
lightprog2 .1
This gives the summed squared error when k is 2 and a is 1. Try it with different values of a and k
Note: Try to run the functionit wont work because it is a function but will prompt you to change the path
2. We can use it as input to fminsearch as follows:
fminsearchlightprog,1 1
This should find the k and a that give the lowest RSS
The vector 1 1 gives it a starting pointtry different starting points and see if it always converges on the same best answer

Function Minimisation
The fminsearch function does fairly simple gradientdescent minimisation
It may find local minima so try different starting points

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] math matlab graph software network theory Lecture 6:
$25