MATLAB: Problem with Neural Networks

Deep Learning Toolboxneural network

Hi all!!
I'm new with Matlab, and i've got a problem with the parameters of my neural network. In my case, i have 1000 inputs of size 27. My output is a boolean.
– How to choose the number of hidden layers, and the number of neurons in my layers?
– How to choose the training function?
I built a neural network with 6 neurons on each of my 3 hidden layers (at random :p). I launched the training with the 'trainlm' function. But when the training is finished (after 3 iterations??), i've got weird values: mu = 10^100, grad = 10^-31, and my results are around 0.5 (whereas it must be a boolean …)
From where does the problem come ?
Thanks all ^^
PS: here is a part of my code:
hiddenSizes = [6 6 6];
trainFcn = 'trainlm';
net = feedforwardnet(hiddenSizes,trainFcn);
net.trainParam.epochs = 10000;
net.trainParam.min_grad = 0;
net.trainParam.goal = 0;
net.trainParam.mu_max = 10^100;
net.trainParam.mu = 0.001;
net.trainParam.max_fail = 100;
net.layers{:}.transferFcn = 'logsig';
net2 = train(net,inputs,targets);
outputs = net2(inputs);

Best Answer

1. One hidden layer is sufficient
2. Find the smallest suitable no. of hidden nodes by trial and error
3. Use fitnet,tansig, purelin and trainlm for regression and curvefitting
4. Use patternnet, tansig, softmax or logsig and trainscg for classification and pattern recognition
5. To obtain a boolean output with softmax or logsig, use round.
6. Use as many defaults as possible (e.g., net.trainParam.*)
7. First try the documentation examples and demos that are the closest to your problem. Then search the newsgroup and ansers for similar problems that were solved.
Hope this helps
Greg