I'm implementing an Adaline algorithm where all inputs are 1x5526 and the output is a number from 1 to 10. I have this two functions defined and worked outside the Manipulate environment:
test[in_, weights_] := (a = Round[Total[Most[weights]*Most[in]] + Last[weights]]; Return[a])
train[in_, out_, alpha_, delta_] := ((*uweights holds also the bias with 1*)
sizePattern = Length[in[[1]]];
sizeOutput = 1;
Length[out];
uweights = ConstantArray[0, {sizePattern}];
dweights = {};
flag = True;
cont = 0;
Error = {};
While[flag == True && cont < 10000,
flag = False;
perror = 0;
cont++;
(*Checking each input-output*)
For[i = 1, i <= 1(*Dimensions[out][[1]]*), i++,
(*Checking each neuron*)
For[k = 1, k <= Length[out](*Dimensions[out][[2]]*), k++,
est = Total[Most[uweights]*Most[in[[k]]]] + Last[uweights];
If[out[[k]] + delta <= est || out[[k]] - delta >= est,
(*Print["Estimated different"] ;*)
flag = True;
dweights = alpha*1*(out[[k]] - est)*Most[in[[k]]];
dbias = alpha*1*(out[[k]] - est);
perror = perror + .5*(out[[k]] - est)^2;
uweights = uweights + Flatten[{dweights, dbias}]]]]];
Return[uweights])
In these lines, they gave the amount of good answer I get with these weights:
AbsoluteTiming[w = train[Samples, AOutput, 0.00001, 0.4];]
uweights = w;
Report = Table[test[Samples[[i]], w], {i, 30}];
Count[Table[Report[[i]] == AOutput[[i]], {i, 30}], True]
{28.516558, Null}
30
The problem emerges when I put the functions test and train inside the Manipulate environment:
Manipulate[
Grid[{{Text@Style["Saída ", "Large"]}, {Text@Style[answer, "Large"],
Text@Style[" ", "Large"]},
{ArrayPlot[ArrayReshape[Samples[[dato]], {85, 65}]]},
(*This line was add to verify if train is working!!!*)
{weights // MatrixForm}}],
{{weights, {}}, ControlType -> None},
{{answer, {}}, ControlType -> None},
{{dato, 1}, ControlType -> None},
{{alpha, 0.00001, "Learning rate "}, 0.0000001, .0001, 0.0000005,
Appearance -> "Labeled"},
{{delta, 0.5, "Error range "}, 0.01, 0.5, 0.01,
Appearance -> "Labeled"},
Row[{PopupMenu[Dynamic[NumberPicked], Range[0, 9]],
PopupMenu[
Dynamic[FontType], {1 -> "Comics", 2 -> "Times", 3 -> "Calibri"}]}],
Row[{Button["Train", weights = train[Samples, AOutput, alpha, delta],
Background -> Yellow, ImageSize -> Medium],
Style[" ", 14],
Button["Test",
If[FontType == 1,
Switch[NumberPicked, 0, dato = 1, 1, dato = 4, 2, dato = 7, 3,
dato = 10, 4, dato = 13, 5, dato = 16, 6, dato = 19, 7,
dato = 22, 8, dato = 25, 9, dato = 28]];
If[FontType == 2,
Switch[NumberPicked, 0, dato = 2, 1, dato = 5, 2, dato = 8, 3,
dato = 11, 4, dato = 14, 5, dato = 17, 6, dato = 20, 7,
dato = 23, 8, dato = 26, 9, dato = 29]];
If[FontType == 3,
Switch[NumberPicked, 0, dato = 3, 1, dato = 6, 2, dato = 9, 3,
dato = 12, 4, dato = 15, 5, dato = 18, 6, dato = 21, 7,
dato = 24, 8, dato = 27, 9, dato = 30]];
answer = test[Samples[[dato]], weights],
Background -> Green, ImageSize -> Medium]}]]
And the output is this:
After push the button train, it seems that the train function was executed, but no values are returned as you can see below the zero. I appreciate any help with this! maybe it seems a silly mistake but I cannot see it.
Dynamic@weights? – wxffles Apr 30 '14 at 04:02traincalculation takes longer than 5 seconds the button will be timing out. You might need to use theMethod -> "Queued"option. – Simon Woods Apr 30 '14 at 20:32