NSCS 344, Week 8

Assignment: Least-squares model fitting

*** Due date: Start of class in Week 9 ***

Part 1: Make a function to compute the mean squared error (3 points)

Part 2: Plot the mean squared error as a function of sigma (3 points)

Part 3: Use fmincon to automatically find the minimum of the error function (4 points)

Part 4: Use fmincon to fit a softmax function with two parameters (2 Extra Credit points)

Extend your model to include two parameters
Use fmincon to fit both σ (which determines β) and θ. To fit more than one parameter you will need to define your likelihood function to have two free parameters
function error = twoParameterSoftmax(rsk, EV_risky, EV_safe, sigma, theta)
and your function handle slightly differently too ...
fHandle = @(x) twoParameterSoftmax(rsk, EV_risky, EV_safe, x(1), x(2));
Then you'll need a vector of starting points, lower bounds and upper bounds, to give a starting point, lower bound and upper bound for each of the parameters (σ and θ)
LB = [0 -inf]; % lower bound 0 for sigma, -inf for theta
UB = [inf inf]; % upper bound inf for sigma, inf for theta
X0 = [1 0]; % initial condition 1 for sigma, 0 for theta
After all of this, you call fmincon in exactly the same way, but instead of giving you a single best fitting parameter, the output is a vector of best fitting parameters.