Answered step by step
Verified Expert Solution
Link Copied!

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.
%1st column of C should be "stretch", expressed as a ratio.
%2nd column of C should be "stress", expressed in kilopascals (KPa).
% Each row should be an observation
C = load('../Data/billiar.csv');
n = size(C,1);
p = size(C,2);
% As in the in-class exercise,
% divide the data into the independent variable 'x',
% and dependent variable 'y'.
% In this case, the second column of the data
%(i.e., 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 (y-intercept) parameter.
% Call the design matrix 'X'. It should be composed of
% the values in x (the first column),
% and a n-by-1 vector of all ones (the second column).
X =%
% We're now going to set up to perform a nonlinear regression using many
% locally-linear 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 locally-linear 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 100 total locations.
m =100;
% 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
% evenly-spaced reference values.
x_min =%
x_max =%
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
z_hat = zeros(m,1);
% In preparation for the iteration we need to perform
% in the service of nonlinear regression,
% create a vector for storing regression parameters
b_hat = zeros(m,2);
% Iterate over every test point
for itor =1:%
% 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 2000.
W = zeros(n,n);
for jtor =1:%
W(jtor,jtor)=%
end
% Get regression coefficients using your function regress_fit_weighted
b_local =%
% Store the local coefficient in the vector you created above
% for that purpose.
b_hat(itor,:)=%
% 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.
z_hat(itor)=%
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 1.6 stretch ratio.
% This indicates the locally-linear 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 #4.
[~, ind]= min((T(:,1)-1.6).^2);
t_min = T(ind,1)-0.1;
t_max = T(ind,1)+0.1;
z_hat_min =[t_min 1]*b_hat(ind,:)';
z_hat_max =[t_max 1]*b_hat(ind,:)';
plot([t_min t_max],[z_hat_min z_hat_max],'r','linewidth',3)
% 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Professional Microsoft SQL Server 2012 Administration

Authors: Adam Jorgensen, Steven Wort

1st Edition

1118106881, 9781118106884

More Books

Students also viewed these Databases questions

Question

Determine the amplitude and period of each function.

Answered: 1 week ago

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago