function U03_test_function_handle_kmeans
%U03_TEST_FUNCTION_HANDLE_KMEANS           Test function handling of kmeans
%
% This example shows how function handling works. The function simple_prog
% is passed to your function with @simple_prog . You can call it using
% feval, for example in your function (where the parameter is called
% prog_fun):
% 
% feval(prog_fun, X, mu, r)
%
%usage
%  U03_test_function_handle_kmeans
%
%author
%  saputra@cs.tu-berlin.de

% generate data set
mu_1 = [-4; 0];
mu_2 = [4; 0];
mu_3 = [0; sqrt(48)];
ns = 50;
X = [(randn(2, ns) + repmat(mu_1, 1, ns)) (randn(2, ns) + repmat(mu_2, 1, ns)) (randn(2, ns) + repmat(mu_3, 1, ns))];

kmeans(X, 3, 100, @simple_prog);

function simple_prog(X, mu, r)

obj = sum(sqrt(sum((X - mu(:, r)) .^ 2, 1)));
fprintf('Objective function: %f\n', obj);
