Answered step by step
Verified Expert Solution
Question
1 Approved Answer
% Load Prof. Billiar's data. % Store the loaded data in matrix called C . % 1 st column of C should be stretch, expressed
Load Prof. Billiar's data.
Store the loaded data in matrix called C
st column of C should be "stretch", expressed as a ratio.
nd column of C should be "stress", expressed in kilopascals KPa
Each row should be an observation
C loadDatabilliarcsv;
n sizeC;
p sizeC;
As in the inclass exercise,
divide the data into the independent variable x
and dependent variable y
In this case, the second column of the data
ie stress will be the dependent variable.
We will predict the dependent variable on the basis of the
stretch ratio, which is our independent variable.
Rename these vectors x and y accordingly.
y
x
Augment the data, creating a design matrix that will
allow us to get the offset yintercept parameter.
Call the design matrix X It should be composed of
the values in x the first column
and a nby vector of all ones the second column
X
We're now going to set up to perform a nonlinear regression using many
locallylinear regression models, as we talked about this week.
Like we saw in lecture, the first step in this process is to
define a set of reference points in feature space, at which
we want to perform a locallylinear fit using weighted linear regression.
In the present case, the references points are simply values
of the independent variable: stretch ratio.
Create a variable m describing how many reference points you'd like
to consider. Use at least total locations.
m ;
Use Matlab's 'min' and 'max' functions to find the
smallest and largest observed value of stretch in the data.
Use Matlab's 'linspace' function to create a vector t of
evenlyspaced reference values.
xmin
xmax
t
Augment the data, creating a design matrix called T
As with X above, T should be composed of
your reference value vector, just created, and a vector of all ones.
T
In preparation for the iteration we need to perform
in the service of nonlinear regression,
create a vector for storing estimated function values
zhat zerosm;
In preparation for the iteration we need to perform
in the service of nonlinear regression,
create a vector for storing regression parameters
bhat zerosm;
Iterate over every test point
for itor :
For each reference point, calculate similarity from current
test point to all stretch values, stored in X
Store those values on the diagonal of a weight matrix W
Use the function 'gaussiankernel', supplied for you,
to calculate the similarities.
A good value for the kernel parameter value h is
W zerosnn;
for jtor :
Wjtorjtor
end
Get regression coefficients using your function regressfitweighted
blocal
Store the local coefficient in the vector you created above
for that purpose.
bhatitor:
Use the regression coefficients just obtained to
estimate the stress values at the current point.
Store the estimated value in the vector you created above.
zhatitor
end
Make a scatter plot of the stretch and stress data
figure
scatter
hold on
Scatter plot the estimated stress values, obtained above
Plot a short red line, centered at stretch ratio.
This indicates the locallylinear fit at that location.
This is tricky, so I'll supply the code for you.
Please make an effort to understand what's going on here,
because you'll need it in Objective #
~ ind minT:;
tmin Tind;
tmax Tind;
zhatmin tmin bhatind:;
zhatmax tmax bhatind:;
plottmin tmaxzhatmin zhatmaxr'linewidth',
As a final touch, add a grid, axis labels and title, as before.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started