TI-85 Gaussian Classifier

Here’s a TI-85 program for the final that calculates the Mean Matrix, Covariances, Cv inverse, and the probability. I split it apart into two programs so that you can easily write down the answers and set your variables.

To calculate Mean, Covariance and Cv Inverse, enter the following into the program menu (I named mine GMEAN). The results are in variables called S and C (Cv Inverse is trivial to compute).



Prompt MAT
dim MAT->D
D(1)->N
D(2)->D
MAT(1)*0->S
For(I,1,N,1)
MAT(I)+S->S
End
S*(1/N)->S
[[S]]->S
Disp "MEAN"
Disp S
Pause
((1/N)*(MAT(T)*MAT))-S(T)*S->C
Disp "Cv"
Disp C
Pause
Disp "Cv Inv"
Disp C-1

Then, to calculate the probability (this one is called PRB on mine):

Disp "X, MEAN, COV"
Prompt X,S,C
(X-S)*(C-1)*(X-S)(T)->EXP
e^(-.5*EXP(1,1))->EXP
Disp "EXP"
Disp EXP
Pause
(1/((2PI)^(D/2)*(det C)^0.5))*EXP->P
Disp "Probability"
Disp P

To use this, enter your samples as a matrix. If we were using values from the slides:

C1={X1=[1 0 1]T, X2=[1 0 0]T, X3=[1 1 0]T, X4=[0 0 0]T}
and
C2={X1=[0 0 1]T, X2=[0 1 1]T, X3=[1 1 1]T, X4=[0 1 0]T}

Enter the following into the calculator:


[[1,0,1][1,0,0][1,1,0][0,0,0]]->MAT1
[[0,0,1][0,1,1][1,1,1][0,1,0]]->MAT2
GMEAN
MAT=?MAT1

It will output the mean, C, and C-1. Now store these values (this is the “training” phase of the classifier).


S->S1
C->C1

Do a similar thing for MAT2 (store in S2 and C2).

Finally, run PRB. It will ask for X (which is the point you are trying to find the probability for). Enter this as a Dx1 matrix, like this [[0,0,0]] or, if you want to test the values in MAT1, like this: [[MAT1(1)]]. This gives you the 1st vector of MAT1 converted into a Matrix (matrix is a different data type than a vector on the TI-85). Also, it asks for the Covariance and Mean. Enter C1 or C2 and S1 or S2.

Then, you should get the probability and the exponent.

The only thing this program DOESN’T do is calculate P(C1) and P(C2) when you do the final testing

P(C1)P(X|C1) > P(C2)P(X|C2)

Just be careful of that when you run the program in class, but I doubt that he’ll give us mismatching number of samples on the final. GOOD LUCK EVERYONE!!!!

Leave a Reply