git-svn-id: http://moon:8086/svn/matlab/trunk@91 801c6759-fa7c-4059-a304-17956f83a07c
25 lines
771 B
Matlab
25 lines
771 B
Matlab
function [f,g] = linear_regression(theta, X,y)
|
|
%
|
|
% Arguments:
|
|
% theta - A vector containing the parameter values to optimize.
|
|
% X - The examples stored in a matrix.
|
|
% X(i,j) is the i'th coordinate of the j'th example.
|
|
% y - The target value for each example. y(j) is the target for example j.
|
|
%
|
|
|
|
m=size(X,2);
|
|
n=size(X,1);
|
|
|
|
f=0;
|
|
g=zeros(size(theta));
|
|
|
|
%
|
|
% TODO: Compute the linear regression objective by looping over the examples in X.
|
|
% Store the objective function value in 'f'.
|
|
%
|
|
% TODO: Compute the gradient of the objective with respect to theta by looping over
|
|
% the examples in X and adding up the gradient for each example. Store the
|
|
% computed gradient in 'g'.
|
|
|
|
%%% YOUR CODE HERE %%%
|