Matthew Gray

MAS.622 Problem Set 2 March 5, 1998

Problem 1

Part a

Some definitions: ω_{1}: “Good” iddb ω_{2}: “Bad” iddb x_{1}: NDIR measurement x_{2}: NDCR measurement x: vector of x_{1} and x_{2} so, P (ω_{1}) = .8 P (ω_{2}) = .2

The distributions of measurements for good and bad iddbs is shown in Figure 1.

Figure 1: Distributions of x for good (left) and bad (right) iddbs

We are looking for a discriminant between good and bad, so we will use a Bayesian discriminant function, g(x).

g_{i}(x) = x^{t}W_{i}x + w_{i}^{t}x + w_{i0}  (1)

The constants for Mr. Beeblebrox’s case are best calculated by the following matlab code:

sigmag = [4 0; 0 9];
sigmab = [9 0; 0 16];
mug = [0; 0];
mub = [8; 10];
Wg = (-1/2)*inv(sigmag);
Wb = (-1/2)*inv(sigmab);
wg = inv(sigmag)*mug;
wb = inv(sigmab)*mub;
wg0 = (-1/2)*mug'*inv(sigmag)*mug - (1/2)*log(norm(sigmag))+ log(.8);
wb0 = (-1/2)*mub'*inv(sigmab)*mub - (1/2)*log(norm(sigmab))+ log(.2);

This yields values of W_{g} = ( \begin{matrix}−\frac{1}{8} & 0 \\ 0 & −\frac{1}{18} \end{matrix} ), W_{b} = ( \begin{matrix}−\frac{1}{18} & 0 \\ 0 & −\frac{1}{32} \end{matrix} ), w_{g} = ( 2_{\frac{10}{9}} ), w_{b} = ( \begin{matrix}0 \\ 0 \end{matrix} ),

w_{g0} = −14.8773, and w_{b0} = −2.9957. This yields a discriminant surface g_{g}(x) = g_{b}(x) of

5x_{1}^{2} + \frac{7x_{2}^{2}}{4} − 144x_{1} − 80x_{2} + 855.4752 = 0  (2)

which is an equation for an elipse, as seen in Figure 2.

Figure 2: Decision regions for iddbs. Blue is good, red is bad.

A decision function can be evaluated, g_{g}(x) − g_{b}(x) > 0 to identify good iddbs. For Mr. Beeblebrox’s data, if the left hand side of the above equation is above zero, the iddb is good. If it is below zero, it is bad.

Part b

Given these added costs for misclassification, we now want to approve (classify as ω_{1}) a iddb only if \frac{p(x|ω_{1})}{p(x|ω_{2})} > \frac{(λ_{12}−λ_{22})P (ω_{2})}{(λ_{21}−λ_{11})P (ω_{1})}. In Mr. Beeblerox’s case (assuming he refunds the money in cases where defective units were sold): λ_{11} = 0 λ_{12} = 25000 λ_{21} = 5000 λ_{22} = 5000 P (ω_{1}) = .8 P (ω_{2}) = .2

so we want

\frac{p(x|ω_{1})}{p(x|ω_{2})} > \frac{20000P (ω_{2})}{5000P (ω_{1})}  (3)

where

p(x|ω_{i}) = \frac{1}{2π|Σ_{i}|^{\frac{1}{2}}} e^{− \frac{1}{2} (x−μi)^{t}Σ_{i}^{−1}(x−μi)}  (4)

we can take the log of both sides of Equation 3, which becomes g_{1}(x) − g_{2}(x) > log(4) = 1.3863. This is the same answer as part a, but the threshold is 1.3836 instead of 0. This means the ellipse in which a iddb is classified as good is smaller, in order to offset the penalty of liability cases. The new decision curve is shown in Figure 3.

Figure 3: Decision regions for iddbs, considering liability. Blue is good, red is bad.

Part c

The percentage of iddbs sold (classified as ω_{1}) that are bad for a given threshold will be

∫_{R_{1}} p(ω_{2}|x)dx  (5)

Numerically calculating this integral over a range of thresholds yields the curve seen in Figure 5. The irregularities are a result of the numerical integration.

Figure 4: Rate of defective sold units as a function of decision threshold in Equation 2

The threshold necassary to comply with the possible legislation would be 6.8. Depending on the penalties proscribed in the legislation, I would propose a full fledged risk analysis, as the added sales gained by slightly lowering the may more than cover the penalties for exceeding the proscribed 0.01consideration has not yet considered penalties and such analysis is not covered under my current contract with Mr. Beeblebrox.

Problem 2

Part a

Using the following matlab code, the within class scatter was calculated.

for i = 1:3
if(i == 1)
trainset = train1;
else if(i==2)

trainset = train2;
else
trainset = train3;
end
end
[rows cols] = size(trainset);
m = mean(trainset);
for r = 1:rows
tmp = trainset(r,:)-m;
Sw = Sw+(tmp'*tmp);
end
end

The between class scatter was calculated with:

Sb = 0;
allmean = mean([mean(train1) mean(train2) mean(train3)]);
for i = 1:3
if(i == 1)
trainset = train1;
else if(i==2)
trainset = train2;
else
trainset = train3;
end
end
[rows cols] = size(trainset);
Sb = Sb + rows * ((mean(trainset)-allmean)'*(mean(trainset)-allmean));
end

I didn’t like the way you told me to calculate the W matrix, so I did [vec val] = eig(inv(Sw)*Sb); W = [vec(:,1) vec(:,2)]; (after checking that the first to eigenvectors in vec were the ones with the highest eigenvalues). I did it your way to, just to make sure we both got the same answer. We did. The resultant projection is in Figure ??.

Part b

Using the estimated parameters of the gaussian distributions a classifier was constructed. The decision boundaries for the classifier are seen in Figure 6. The error rates were relatively low; for class 1, there were no misclassifications of the test data, for class 2 there were 3 misclassifications (all as class 3), and for class 3 there were 5 misclassifications (3 as class 2 and 2 as class 1). The test points are seen in Figure 6 as well. Not all points are shown, as some are off the graph.

Part c

Assuming a constant covariance, the discriminants all become linear, as seen in Figure 7. The noise in the corners is due to numerical errors. This classifier performs marginally worse than the

Figure 5: Class 1 is in blue x’s, class 2 in red +’s, and class 3 in green x’s

Figure 6: Class 1 is in green, Class 2 in blue and Class 3 in red. The test points appear as blue x’s, black +’s and white *’s for classes 1, 2 and 3, respectively classifier from part b, misclassifying 2 additional class 2 points as class 3. This is to be expected, as we are using a generalized covariance.

Figure 7: Class 1 is in green, Class 2 in blue and Class 3 in red. The test points appear as blue x’s, black +’s and white *’s for classes 1, 2 and 3, respectively

Problem 3

I have chosen to discuss scenario 1. If the cow photos are not all taken in the same position, such that they are in the same place in the frame, I would apply a match filter of the average cow over the space of translations and small rotations to get the cow image into a standard configuration. Given this image, I would calculate the eigencows for the data set, and project the training cow images on to this space, at which point I would calculate a Fisher linear discriminant to distinguish the cows. Assuming all the cows have different names and are all equally likely to be in a situation which demands their identification, and equal prior would be assigned across all possible cows. Of course, if some set of the cows (say the bulls) are less likely to be brought into the arch for identification, their prior would adjusted appropriately. Costs for the decisions would be assigned, most likely one-zero costs, unless there were particular errors that were more critical to avoid. Testing would be done by taking a second set of test photos of the cows and cross-validating. This entire exercise is done under the assumption that the cows are in fact distinguishable based on the patterns on their backs. It is certainly possible that many cows would be essentially identical. If the rancher has primarily Holsteins, it may work out ok, but if he’s got primarily Angus’s, he may be in trouble and should consider radiotagging. Further, drastic changes in lighting or cleanliness of the cattle could cause the system to fail altogether. Finally, a cow trained in the system as a calf that matures could become unidentifiable or easily misclassified. The calf problem could be addressed by not including them in the original sample, or adding some scaling to the initial filter, assuming that the pattern on the cow’s back will scale as the cow does. The lighting and cleanliness issues are most practically addressed by improving mechanisms to assure consistent lighting, and maybe a hose to clean the cattle. Failing that, training data should include as much in the way of expected variations in these parameters as possible. If the cows are not in fact distinguishable, as it might be in the case of Angus’, other measurements might be taken, or ideally a radiotagging scheme. Unique brands could provide an identifiable feature at lower cost.