first steps of the gradient descent chapter

This commit is contained in:
2015-11-08 01:53:49 +01:00
parent 51f3cad5ee
commit 520acdabcb
5 changed files with 192 additions and 14 deletions

View File

@@ -1,6 +1,11 @@
function error = lsq_error(parameter, x, y)
% parameter(1) is the slope
% parameter(2) is the intercept
% Objective function for fitting a linear equation to data.
%
% Arguments: parameter, vector containing slope and intercept (1st and 2nd element)
% x, the input values
% y, the measured system output
%
% Retruns: the estimation error in terms of the mean sqaure error
f_x = x .* parameter(1) + parameter(2);
error = mean((f_x - y).^2);
y_est = x .* parameter(1) + parameter(2);
error = meanSquareError(y, y_est);

View File

@@ -0,0 +1,9 @@
function error = meanSquareError(y, y_est)
% Function calculates the mean sqauare error between observed and predicted values.
%
% Agruments: y, the observed values
% y_est, the predicted values.
%
% Returns: the error in the mean-square-deviation sense.
error = mean((y - y_est).^2);