Attachment 'U03_test_function_handle_kmeans.m'
Download 1 function U03_test_function_handle_kmeans
2 %U03_TEST_FUNCTION_HANDLE_KMEANS Test function handling of kmeans
3 %
4 % This example shows how function handling works. The function simple_prog
5 % is passed to your function with @simple_prog . You can call it using
6 % feval, for example in your function (where the parameter is called
7 % prog_fun):
8 %
9 % feval(prog_fun, X, mu, r)
10 %
11 %usage
12 % U03_test_function_handle_kmeans
13 %
14 %author
15 % saputra@cs.tu-berlin.de
16
17 % generate data set
18 mu_1 = [-4; 0];
19 mu_2 = [4; 0];
20 mu_3 = [0; sqrt(48)];
21 ns = 50;
22 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))];
23
24 kmeans(X, 3, 100, @simple_prog);
25
26 function simple_prog(X, mu, r)
27
28 obj = sum(sqrt(sum((X - mu(:, r)) .^ 2, 1)));
29 fprintf('Objective function: %f\n', obj);
Attached Files
To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.You are not allowed to attach a file to this page.