From 5694fada70bf0669c7e0b2d1172e522c5424dac1 Mon Sep 17 00:00:00 2001 From: Davis King Date: Wed, 11 Feb 2015 07:55:42 -0500 Subject: [PATCH] Added spectral_cluster() example --- examples/kkmeans_ex.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/examples/kkmeans_ex.cpp b/examples/kkmeans_ex.cpp index 39c36f65a..76ea33cb0 100644 --- a/examples/kkmeans_ex.cpp +++ b/examples/kkmeans_ex.cpp @@ -1,7 +1,7 @@ // The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt /* This is an example illustrating the use of the kkmeans object - from the dlib C++ Library. + and spectral_cluster() routine from the dlib C++ Library. The kkmeans object is an implementation of a kernelized k-means clustering algorithm. It is implemented by using the kcentroid object to represent @@ -11,7 +11,8 @@ a svm classifier finds non-linear decision surfaces. This example will make points from 3 classes and perform kernelized k-means - clustering on those points. + clustering on those points. It will also do the same thing using spectral + clustering. The classes are as follows: - points very close to the origin @@ -141,6 +142,13 @@ int main() cout << "num dictionary vectors for center 1: " << test.get_kcentroid(1).dictionary_size() << endl; cout << "num dictionary vectors for center 2: " << test.get_kcentroid(2).dictionary_size() << endl; + + // Finally, we can also solve the same kind of non-linear clustering problem with + // spectral_cluster(). The output is a vector that indicates which cluster each sample + // belongs to. Just like with kkmeans, it assigns each point to the correct cluster. + std::vector assignments = spectral_cluster(kernel_type(0.1), samples, 3); + cout << mat(assignments) << endl; + }