function example_kscc
% Sample data from the paper "Kernel Spectral Curvature Clustering".

% References:
% Guangliang Chen, Stefan Atev and Gilad Lerman, "Kernel Spectral Curvature
%    Clustering (KSCC)", Proc. of IEEE International Conference on Computer
%    Vision (ICCV 2009), pages 765--772, September 2009, Kyoto, Japan
% Kernel Spectral Curvature Clustering,
%    <http://www.math.duke.edu/~glchen/kscc.html>

% Copyright 2013 Levente Hunyadi

if 1
    str = load('five_circles', 'X');
    X = (str.X)';
    k = 5;
    cluster_manifold(X, k, 'neighborhood_size', 10, 'fit_function', @fit_circlefit, 'affinity_attenuation', 5);
end

if 1
    str = load('conics', 'X');
    X = (str.X)';
    k = 4;
    cluster_manifold(X, k, 'neighborhood_size', 2, 'fit_function', @quad2dfit_koopmans, 'affinity_attenuation', 50);
end

if 1
    str = load('three_spheres', 'X');
    X = (str.X)';
    k = 3;
    cluster_manifold(X, k, 'fit_function', @fit_ellipsoidfit);
end

function [theta,mu] = fit_circlefit(X)

[center,radius,residuals] = circlefit(X(1,:),X(2,:));
theta = ellipse_ex2im(center(1),center(2),radius,radius,0);
mu = sum(residuals.^2) / numel(residuals);

function [theta,mu] = fit_spherefit(X)

[center,radius,residuals] = spherefit(X(1,:),X(2,:),X(3,:));
theta = [0 0 0 0 0 0 0 0 0 0];
mu = sum(residuals.^2) / numel(residuals);

function [theta,mu] = fit_ellipsoidfit(X)

theta = ellipsoidfit_koopmans(X);
mu = 0;