function P = lsq_robust_bayes(F,pri_gud,avg_gud,dev_gud,avg_bad,...
    dev_bad,verbose)

%Computes the `a posteriori' probability of a data point being a
%inlier, using Bayes's formula.

%Assumes that {F} is the function sample for some data point, and
%that {pri_gud} is the `a priori' probability of that being an inlier.

%The inliers and outliers are assumed to have Gaussian distributions with 
%means {avg_gud,avg_bad} and deviations {dev_gud,dev_bad},respectively.

%Normalized displacement of {F} from inlier average.
d_gud = (F - avg_gud)/dev_gud; 
if (d_gud > 6.0)
    P = 0;
end

%Normalized displacement of {F} from outlier average.
d_bad = (F - avg_bad)/dev_bad; 
if (d_bad > 6.0)
    P = 1;
end

%Apply Bayes's formula:
pri_bad = 1 - pri_gud;
%Prob of {F} assuming inlier, times {sqrt(2*PI)}:
Pc_gud = exp(-d_gud*d_gud/2)/dev_gud;
%Prob of {F} assuming outlier, times {sqrt(2*PI)}:
Pc_bad = exp(-d_bad*d_bad/2)/dev_bad;
PP_gud = pri_gud*Pc_gud;
PP_bad = pri_bad*Pc_bad;
P = PP_gud/(PP_gud + PP_bad);


