How do I know the number of the hidden nodes in ANN ?

S
simran · Jul 2, 2021 · 1.9K views
Question
Hi All having an ANN network , in I inputs and O outputs, how do we know the number of hidden nodes? is it related to the number of hidden layers ? when designing an I H O topology , when you set the Hmax and Hmin and dH , you can change the number of trials by changing any of the Hmin , Hmax or even dH what is the main rule ? and advised relation between dH and Hmin ? should they be specific numbers ?
Expert Answer
Profile picture of Kshitij Singh
Kshitij Singh PhD Expert
Answered Aug 31, 2026
[I N ] = size(input)         % size("I"nput)

[O N ] = size(target)        % size("O"utput)

Ntrn   = N - 2*round(0.15*N) % Default no. of training examples ~ 0.7*N

Ntrneq = Ntrn*O              % No. of training equations 

Nw     = (I+1)*H +(H+1)*O    % No. of unknown weights for H = number of hidden nodes
Overfitting ( Nw > Ntrneq ) allows decreased performance on nontraining (e.g., val, test and unseen) data
Since H > ( Ntrneq -O )/(I+O+1) for overfitting, one training strategy is H <= Hub or preferably, H << Hub where
 
     Hub = -1 + ceil( (Ntrneq - O) / (I+O+1) ) % integer H
My training strategy:
Minimize the number of hidden nodes subject to the constraint that the mean-square-error is less than 1 percent of the mean target variance
 
     net.trainPerform.goal = 0.01*mean(var(target',1)))
Very often this is accomplished by trial and error subject to
 
 
     0 <= Hmin <= H <= Hmax <= Hub
However, sometimes it is necessary to exceed Hub. The mitigation for this is
 
 
     Validation Stopping and/or regularization (e.g., msereg or TRAINBR}
100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!