[regression] finished gradient section

This commit is contained in:
2020-12-18 23:37:17 +01:00
parent fefe1c3726
commit ca54936245
4 changed files with 113 additions and 109 deletions

View 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

View 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')