choosa = sum(M(1:choose, :));
choosb = sum(M(choose+1:2*choose, :));
thisc = choosa;
thatc = choosb;
decsrf = [];
xv = [];
mygamma = [];

for d = 1:dsize(1)
	magn(d) = kernel(data(d,:), data(d,:));
end

rng = 12;
scale = rng/6;
offs = 1.5*scale;

for x = 1:rng
	x
	xv(x) = (x-offs)/scale;
	for y = 1:rng
		me = [(x-offs)/scale (y-offs)/scale];
		me
		for d= 1:dsize(1)
			mygamma(d) = kernel(me, data(d,:));
		end
		A = gamma(1,:)'*gamma(1,:);
		dis = sum(sum(A.*prekern))-2*sum(gamma(1,:).*mygamma);
	best = dis;
	bclust = 1;
	distance(x, 1) = dis;
	for c = 2:nclust
		A = gamma(c,:)'*gamma(c,:);
		dis = sum(sum(A.*prekern))-2*sum(gamma(c,:).*mygamma);
		distance(x, c) = dis;
		if(dis < best)
			best = dis;
			bclust = c;
		end
	end
	[x y bclust]
	decsrf(x,y) = bclust;
	end
end

%hold off; plot(cpoint(:,1), cpoint(:,2), 'x'); hold on; plot(cstop(:,1), cstop(:,2), 'red*')
hold off; plot(c1d(:,1), c1d(:,2), 'blue+'); hold on; plot(c2d(:,1), c2d(:,2), 'red+')
plot(cpoint(:,1), cpoint(:,2), 'bluex');
plot(cstop(:,1), cstop(:,2), 'redx')
surf(xv, xv, decsrf-1-nclust); shading('interp')
view([0 90]);