[regression] objective function section done
This commit is contained in:
@@ -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
|
||||
11
regression/code/meanSquaredErrorCubic.m
Normal file
11
regression/code/meanSquaredErrorCubic.m
Normal 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
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user