W1 = -0.109866 W2 = -0.0534655 W3 = 4.92944 W4 = -2.04734
W5 = 10.2339 W6 = -1495.09 W7 = 3336.49 W8 = 7372.98
W9 = -9143.53 W10 = 48.8937 W11 = 240.958 W12 = -3386.21
W13 = 8904.6 W14 = 3339.1 W15 = 0.874638 W16 = -7978.42
W17 = 4586.22 W18 = 1931.89 W19 = -6518.14
Perceptron | Potential | Activation |
---|---|---|
H1,1 | W15 + X1W1 + X2W2 + X3W3 + X4W4 | LOGISTIC |
H1,2 | W16 + X1W5 + X2W6 + X3W7 + X4W8 | LOGISTIC |
H2,1 | W17 + H1,1W9 + H1,2W10 | SOFTMAX |
H2,2 | W18 + H1,1W11 + H1,2W12 | SOFTMAX |
H2,3 | W19 + H1,1W13 + H1,2W14 | SOFTMAX |
PRO mlff_pattern_classification_ex1, test_arch_str
@CMAST_COMMON
n_patterns =150
n_inputs =4 ; four inputs, all continuous
n_nominal =0 ; no nominal input attributes
n_continuous =4 ; one continuous input attribute
n_outputs =3 ; total number of output perceptrons
act_fcn = [1, 1, 1]
classification = LONARR(n_patterns)
unscaledX = FLTARR(n_patterns)
scaledX = FLTARR(n_patterns)
contAtt = FLTARR(n_patterns,n_continuous)
mean = FLTARR(n_continuous)
s = FLTARR(n_continuous)
PRINT,"***************************************************"
PRINT," IRIS CLASSIFICATION EXAMPLE-PATTERN CLASSIFICATION"
PRINT,"***************************************************"
irisData = STATDATA(3)
;
; Set up the continuous attribute input array, contAtt(),
; and the network target classification array,
; classification(), using the above raw data matrix.
classification(*) = LONG(irisData(*,0)-1)
contAtt(*,*) = irisData(*,1:4)
; Scale continuous input attributes using z-score method.
FOR j=0L, n_continuous-1 DO BEGIN
unscaledX(*) = contAtt(*,j);
scaledX = SCALE_FILTER(unscaledX, 2,$
Return_center_spread=centerspread)
contAtt(*,j) = scaledX(*)
mean(j) = centerspread(0)
s(j) = centerspread(1)
ENDFOR
PRINT,"Scale Parameters: "
FOR j=0L, n_continuous-1 DO BEGIN
PRINT,"Var ",STRTRIM(j+1,2),$
" Mean = ",STRING(mean(j),Format="(f10.5)"),$
" S = ",STRING(s(j),Format="(f10.5)")
ENDFOR
; Restore the saved network from
; MLFF_CLASSIFICATION_TRAINER example 2
filename = "iris_classification_"+test_arch_str+".sav"
restore, Filename=filename
; Use pattern classification routine to classify training
; patterns using trained network.
classProb = MLFF_PATTERN_CLASSIFICATION(network,$
n_patterns, 0L, contAtt,$
Pred_class=predicted_class)
; Print class predictions
prtLabel ="Predicted_Class | P(0) P(1) P(2)"
dashes ="-------------------------------------------"
PRINT, prtLabel
PRINT, dashes
FOR i=0L, n_patterns-1 DO BEGIN
PRINT,STRTRIM(predicted_class(i),2),$
" | ",$
STRING(classProb(i,0),Format="(f6.4)")," ",$
STRING(classProb(i,1),Format="(f6.4)")," ",$
STRING(classProb(i,2),Format="(f6.4)")
IF (i EQ 49 OR i EQ 99) THEN BEGIN
PRINT,prtLabel
PRINT,dashes
ENDIF
ENDFOR
END
******************************************************
IRIS CLASSIFICATION EXAMPLE - PATTERN CLASSIFICATION
******************************************************
Scale Parameters:
Var 1 Mean = 5.84333 S = 0.82807
Var 2 Mean = 3.05733 S = 0.43587
Var 3 Mean = 3.75800 S = 1.76530
Var 4 Mean = 1.19933 S = 0.76224
Predicted_Class | P(0) P(1) P(2)
-------------------------------------------
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
0 | 1.0000 0.0000 0.0000
Predicted_Class | P(0) P(1) P(2)
-------------------------------------------
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
1 | 0.0000 1.0000 0.0000
Predicted_Class | P(0) P(1) P(2)
-------------------------------------------
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
2 | 0.0000 0.0000 1.0000
PRO mlff_pattern_classification_ex2
n_cat =9 ; 9 nominal input attributes
n_categorical =27 ; 9 Encoded = 27 categorical inputs
n_classes =2 ; positive or negative
n_outputs =1 ; binary classification
; Get tic-tac-toe data
inputData = STATDATA(10)
n_patterns = (SIZE(inputData,/Dim))(0)
n_var = (SIZE(inputData,/Dim))(1)
classification = LONARR(n_patterns)
PRINT,""
PRINT,"****************************************************"
PRINT,"* TIC-TAC-TOE BINARY CLASSIFICATION EXAMPLE *"
PRINT,"****************************************************"
; Allocate memory for categoricalATT array
categoricalAtt = LONARR(n_patterns,n_categorical)
; Populate categoricalAtt from catAtt using binary encoding
nomTempIn = LONARR(n_patterns)
m=0L
FOR i=0L, n_cat-1 DO BEGIN
nomTempIn(*) = inputData(*,i)+1;
nomTempOut = UNSUPERVISED_NOMINAL_FILTER(nomTempIn, $
N_classes=nClass)
FOR k=0L, nClass-1 DO BEGIN
categoricalAtt(*,m) = nomTempOut(*,k)
m = m+1
ENDFOR
ENDFOR
; Set up the classification array, classification()
classification(*) = inputData(*,n_var-1);
network = MLFF_NETWORK_INIT(n_categorical, n_outputs)
network = MLFF_NETWORK(network, Create_hidden=8)
network = MLFF_NETWORK(network,/Link_all)
RANDOMOPT,set=5555
; Train Classification Network
trainStats = MLFF_CLASSIFICATION_TRAINER(network,$
classification, categoricalAtt, 0L, $
StageI=[30L, n_patterns], /NoStageII,$
/LogisticTable, $
Init_weights_method=IMSLS_EQUAL)
; Use pattern classification routine to classify training
; patterns using trained network. This will reproduce
; the results returned in predicted_class().
classProb = MLFF_PATTERN_CLASSIFICATION(network, $
n_patterns, categoricalAtt, 0L,$
/LogisticTable, $
Pred_class=predictedClass)
; Printing Classification Predictions
PRINT,"****************************************************"
PRINT,"Classification Minimum Cross-Entropy Error: ", $
STRING(trainStats(0),Format="(f8.6)")
PRINT,"Classification Error Rate: ",$
STRING(trainStats(5),Format="(f8.6)")
PRINT,"****************************************************"
PRINT," "
PRINT,"PRINTING FIRST TEN PREDICTIONS FOR EACH TARGET CLASS"
PRINT,"*****************************************************"
PRINT," |TARGET|PREDICTED| | *"
PRINT,"PATTERN |CLASS | CLASS | P(class=0) | P(class=1)*"
PRINT,"*****************************************************"
FOR k=0L, n_classes-1 DO BEGIN
FOR i=k*627, (k*627+10)-1 DO BEGIN
PRINT,STRTRIM(i+1,2)," | ",$
STRTRIM(classification(i),2)," | ",$
STRTRIM(predictedClass(i),2)," | ", $
STRING(classProb(i,0),Format="(f8.6)")," ",$
STRING(classProb(i,1),Format="(f8.6)")
ENDFOR
PRINT,""
ENDFOR
END
*******************************************************
* TIC-TAC-TOE BINARY CLASSIFICATION EXAMPLE *
*******************************************************
*******************************************************
Classification Minimum Cross-Entropy Error: 0.000126
Classification Error Rate: 0.000000
*******************************************************
PRINTING FIRST TEN PREDICTIONS FOR EACH TARGET CLASS
*******************************************************
|TARGET|PREDICTED| | *
PATTERN |CLASS | CLASS | P(class=0) | P(class=1) *
*******************************************************
1 | 1 | 1 | 0.000000 1.000000
2 | 1 | 1 | 0.000000 1.000000
3 | 1 | 1 | 0.000002 0.999998
4 | 1 | 1 | 0.000000 1.000000
5 | 1 | 1 | 0.000000 1.000000
6 | 1 | 1 | 0.000000 1.000000
7 | 1 | 1 | 0.000000 1.000000
8 | 1 | 1 | 0.000000 1.000000
9 | 1 | 1 | 0.000000 1.000000
10 | 1 | 1 | 0.000000 1.000000
628 | 0 | 0 | 1.000000 0.000000
629 | 0 | 0 | 1.000000 0.000000
630 | 0 | 0 | 1.000000 0.000000
631 | 0 | 0 | 1.000000 0.000000
632 | 0 | 0 | 1.000000 0.000000
633 | 0 | 0 | 1.000000 0.000000
634 | 0 | 0 | 1.000000 0.000000
635 | 0 | 0 | 1.000000 0.000000
636 | 0 | 0 | 1.000000 0.000000
637 | 0 | 0 | 1.000000 0.000000