From 4bc9a2b246e1a84e87e176db8aa63296f028f2b2 Mon Sep 17 00:00:00 2001 From: neingeist Date: Wed, 26 Nov 2014 02:15:27 +0100 Subject: [PATCH] Estimate Gaussian --- ex8/estimateGaussian.m | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) 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