[regression] objective function section done

This commit is contained in:
2020-12-16 09:25:01 +01:00
parent be79d450df
commit 1b14bca164
7 changed files with 31 additions and 45 deletions

View File

@@ -1,12 +0,0 @@
function mse = meanSquaredError(x, y, parameter)
% Mean squared error between a straight line and data pairs.
%
% Arguments: x, vector of the input values
% y, vector of the corresponding measured output values
% parameter, vector containing slope and intercept
% as the 1st and 2nd element, respectively.
%
% Returns: mse, the mean-squared-error.
mse = mean((y - x * parameter(1) - parameter(2)).^2);
end

View File

@@ -0,0 +1,11 @@
function mse = meanSquaredError(x, y, c)
% Mean squared error between data pairs and a cubic relation.
%
% Arguments: x, vector of the input values
% y, vector of the corresponding measured output values
% c, the factor for the cubic relation.
%
% Returns: mse, the mean-squared-error.
mse = mean((y - c*x.^3).^2);
end

View File

@@ -10,6 +10,6 @@ yest = c * x.^3;
y = yest + noise*randn(n, 1);
% compute mean squared error:
mse = mean((y - y_est).^2);
mse = mean((y - yest).^2);
fprintf('the mean squared error is %g kg^2\n', mse))
fprintf('the mean squared error is %.0f kg^2\n', mse)