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

zeta = 1/350;
cdata = [cpoint; cstop];
mydata = cpoint;
mysize = size(mydata);
csize = size(cdata);
dm = ones(mysize(1),1)*mean(cdata);
%mydata = mydata - dm;

myodata = cstop;
myosize = size(myodata);
my3data = cwave;
my3size = size(my3data);
%myodata = myodata - dm;

choosa = sum(M(1:choose, :));
choosb = sum(M(choose+1:2*choose, :));
choosc = sum(M((2*choose)+1:3*choose, :));
thisc = choosa;
thatc = choosb;
otherc = choosc;
right = 0;
wrong = 0;
maybe = 0;
ct = 0;
count = 0;
mylgamma = [];
cvha = [];
cvhb = [];
cvhc = [];

%for x = 1:mysize(1)
%for x = 1:mysize(1)
while(count < 150)
	if(rand(1) > .67)
		x = floor(rand(1)*mysize(1))+1;
		thisc = choosa;
		thatc = choosb;
		otherc = choosc;
		me = mydata(x,:);
		cat = 1;
	elseif(rand(1) > .5)
		x = floor(rand(1)*myosize(1))+1;
		thisc = choosb;
		thatc = choosa;
		otherc = choosc;
		me = myodata(x,:);
		cat = 2;
	else
		x = floor(rand(1)*myosize(1))+1;
		thisc = choosc;
		thatc = choosa;
		otherc = choosb;
		me = my3data(x,:);
		cat = 3;
	end
	for d= 1:dsize(1)
		mylgamma(d) = kernel(me, data(d,:));
	end
	A = lgamma(1,:)'*lgamma(1,:);
	dis = sum(sum(A.*prekern))-2*sum(lgamma(1,:).*mylgamma);
	best = dis;
	bclust = 1;
	distance(x, 1) = dis;
	for c = 2:nclust
		A = lgamma(c,:)'*lgamma(c,:);
		dis = sum(sum(A.*prekern))-2*sum(lgamma(c,:).*mylgamma);
		distance(x, c) = dis;
		if(dis < best)
			best = dis;
			bclust = c;
		end
	end
%	dclass = [dclass; me bclust];
	if(cat == 1)
		cvha = [cvha; bclust];
	elseif(cat ==2)
		cvhb = [cvhb; bclust];
	else
		cvhc = [cvhc; bclust];
	end

	if(thisc(bclust) > thatc(bclust))
		right = right+1;
	else
		wrong = wrong+1;
	end
%	[wrong./(right+wrong) right wrong]
	count
	count = count+1;
end
docv3