[regression] finished gradient section
This commit is contained in:
14
regression/code/meanSquaredGradientCubic.m
Normal file
14
regression/code/meanSquaredGradientCubic.m
Normal file
@@ -0,0 +1,14 @@
|
||||
function dmsedc = meanSquaredGradientCubic(x, y, c)
|
||||
% The gradient of the mean squared error for a cubic relation.
|
||||
%
|
||||
% Arguments: x, vector of the x-data values
|
||||
% y, vector of the corresponding y-data values
|
||||
% c, the factor for the cubic relation.
|
||||
%
|
||||
% Returns: the derivative of the mean squared error at c.
|
||||
|
||||
h = 1e-5; % stepsize for derivatives
|
||||
mse = meanSquaredErrorCubic(x, y, c);
|
||||
mseh = meanSquaredErrorCubic(x, y, c+h);
|
||||
dmsedc = (mseh - mse)/h;
|
||||
end
|
||||
9
regression/code/plotcubicgradient.m
Normal file
9
regression/code/plotcubicgradient.m
Normal file
@@ -0,0 +1,9 @@
|
||||
cs = 2.0:0.1:8.0;
|
||||
mseg = zeros(length(cs));
|
||||
for i = 1:length(cs)
|
||||
mseg(i) = meanSquaredGradientCubic(x, y, cs(i));
|
||||
end
|
||||
|
||||
plot(cs, mseg)
|
||||
xlabel('c')
|
||||
ylabel('gradient')
|
||||
Reference in New Issue
Block a user