function [risk, eps1, eps2] = lab2_bayeserror(D1, D2, abc, t)

if isreal(t)
	% calculate the correctly classified cl1 and cl2
	cumD1 = normcdf(t, D1.Mean, D1.Sigma);
	cumD2 = normcdf(t, D2.Mean, D2.Sigma);
	if abc(1) >= 0
		eps1 = cumD1(1) + 1 - cumD1(2);
		eps2 = cumD2(2) - cumD2(1);
	else
		eps1 = cumD1(2) - cumD1(1);
		eps2 = cumD2(1) + 1 - cumD2(2);
	end

else
	% there are no roots -> everything classified into one class
	if abc(1) > 0
		eps1 = 1; eps2 = 0;
	else
		eps1 = 0; eps2 = 1;
	end

end

% Bayesian risk
risk = 1 - D1.Prior*eps1 - D2.Prior*eps2;

% integrals of p(x|1) over L_2 and p(x|2) over L_1
eps1 = 1 - eps1;
eps2 = 1 - eps2;
