%
% computing the conditional mean of c(3,.)
% conditional on c(1,.) and c(2,.)
% 

load data.txt;

c = data;

n = length(c);

% Fix the bandwidth

w1 = 2;
w2 = 2;
ro = 0;

% Creates a grid of points for the c_1 c_2

xx = 0:.5:2;
yy = 0:.5:2;

m1 = length(xx);
m2 = length(yy);

z = zeros(n);

% Estimate kernel condtiional mean on the grid
% using a quadratic kernel 

for i=1:m1

	for j=1:m2

	
	
		u1 = (c(:,1)-xx(i))/w1; 
		u2 = (c(:,2)-yy(j))/w2;
		u =  u1.*u1 + u2.*u2 + ro*u1.*u2;
		w = (2-u).*(u <= 2);
		ff = w'*c(:,3); 
		s = sum(u<=2);

		if (s>0)
		 f(i,j) = ff/s;
		end

	
	end
end



