diff --git a/ex8/estimateGaussian.m b/ex8/estimateGaussian.m index 35ed72f..38d20a8 100644 --- a/ex8/estimateGaussian.m +++ b/ex8/estimateGaussian.m @@ -1,11 +1,11 @@ function [mu sigma2] = estimateGaussian(X) -%ESTIMATEGAUSSIAN This function estimates the parameters of a +%ESTIMATEGAUSSIAN This function estimates the parameters of a %Gaussian distribution using the data in X -% [mu sigma2] = estimateGaussian(X), +% [mu sigma2] = estimateGaussian(X), % The input X is the dataset with each n-dimensional data point in one row % The output is an n-dimensional vector mu, the mean of the data set % and the variances sigma^2, an n x 1 vector -% +% % Useful variables [m, n] = size(X); @@ -21,16 +21,9 @@ sigma2 = zeros(n, 1); % should contain variance of the i-th feature. % - - - - - - - - +mu = 1/m * sum(X)'; +sigma2 = 1/m * sum(bsxfun(@minus, X, mu').^2)'; % ============================================================= - end