abdulkader asked . 2021-07-01

does anyone know why this neural network is not giving the right target values?

%a=imread('A.bmp');
%a=imresize(a,[6,5]);
%a=imresize(a,[1,30]);
inp=[0 0 1 0 0 0 0 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 1 1 1 0 0 0 1];
out=[1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0];
net= newff(inp,out,10)
tol = 0.001;               % Error tolerance
%net.trainParam.show = 50;
net.trainParam.lr = 0.007;
net.trainParam.epochs = 500;
net.trainParam.alpha = 0.5;
%net.trainParam.goal = 1e-5;
[net,tr]=train(net,inp,out);
a=sim(net,inp)

neural network , backpropagation , matlab , deep learning

Expert Answer

Prashant Kumar answered . 2024-04-18 00:37:58

% Weird data set:

 plot(input,target,'o')
The data does not represent points from reasonable function. The target says" Regardless of the input, if the output is 0, your error will only be 3.33%".
Looking at an escalation of models (H=0:9) shows that the Linear model (H=0, NN with no hidden layer) is the best with a coefficient of determination (Wikipedia/R-squared) of only 0.0264. It is only slightly better than the constant output = 0 model.
 close all, clear all, clc

 N =30
 input  = [0 0 1 0 0 0 0 1 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 1 1 1 0 0 0 1]; 
 target = [ 1, zeros( 1,N-1)];

% The simplest model is the constant output model that outputs the mean of the target regardless of the input.

 y00   = (1/N)*ones(1,N); % 0.0333*ones(1,30)
 e00   = target-y00;     ; % [ 0.9667, -0.0333*ones(1,29)]
 MSE00 = mse(target-y00)       % 0.0322

% The next simplest is the linear model

 W0    =  target/[ ones(1,N) ; input ] % W0 = [ 0.0588 -0.0588 ]
 y0    =  W0 * [ ones(1,N) ; input ];  % y0 =  0.0588*(1-input)
 e0    =  target-y0;     ;             % [ 0.9412, -y0(2:end)]
 MSE0  =  mse(target-y0)               % 0.0314  Not much better than constant model
 R20   = 1 - MSE0/MSE00                %  0.0264   VERY BAD FIT

% Neural Model

 [ I N ] = size(input)                                 % [ 1 30 ]
 [ O N ] = size(target)                              % [ 1 30 ]
 Neq = N*O                                             % 30 =  No. of equations
% Nw = (I+1)*H+(H+1)*O = 1+3*H       % No. of unknown weights

% No overfitting Neq > Nw==> H <= Hub (upper bound)

 Hub  = -1+ceil( (Neq-O) / ( I+O+1) )  % 9
 Hmax = 9
 dH   = 1
 Hmin = 0  % Linear Model
 numH = length(Hmin:dH:Hmax) % 10

 Ntrials = 10
 rng(0)
 j=0

 for h=Hmin:dH:Hmax
    j=j+1
    if h==0
        net = patternnet([]);
        Nw = (I+1)*O
    else
        net = patternnet(h);
        Nw = (I+1)*h+(h+1)*O
    end

    for i=1:Ntrials
       net = configure(net, input,target);
       net.divideFcn = 'dividetrain';            % Default 'dividerand' is much worse
       [net tr y e ] = train(net,input,target);
       R2(i,j) = 1 - mse(e)/MSE00;
    end
 end
 R2 = R2   % 0.0264* ones(Ntrials,numH)     Same as Linear

 


Not satisfied with the answer ?? ASK NOW

Frequently Asked Questions

MATLAB offers tools for real-time AI applications, including Simulink for modeling and simulation. It can be used for developing algorithms and control systems for autonomous vehicles, robots, and other real-time AI systems.

MATLAB Online™ provides access to MATLAB® from your web browser. With MATLAB Online, your files are stored on MATLAB Drive™ and are available wherever you go. MATLAB Drive Connector synchronizes your files between your computers and MATLAB Online, providing offline access and eliminating the need to manually upload or download files. You can also run your files from the convenience of your smartphone or tablet by connecting to MathWorks® Cloud through the MATLAB Mobile™ app.

Yes, MATLAB provides tools and frameworks for deep learning, including the Deep Learning Toolbox. You can use MATLAB for tasks like building and training neural networks, image classification, and natural language processing.

MATLAB and Python are both popular choices for AI development. MATLAB is known for its ease of use in mathematical computations and its extensive toolbox for AI and machine learning. Python, on the other hand, has a vast ecosystem of libraries like TensorFlow and PyTorch. The choice depends on your preferences and project requirements.

You can find support, discussion forums, and a community of MATLAB users on the MATLAB website, Matlansolutions forums, and other AI-related online communities. Remember that MATLAB's capabilities in AI and machine learning continue to evolve, so staying updated with the latest features and resources is essential for effective AI development using MATLAB.

Without any hesitation the answer to this question is NO. The service we offer is 100% legal, legitimate and won't make you a cheater. Read and discover exactly what an essay writing service is and how when used correctly, is a valuable teaching aid and no more akin to cheating than a tutor's 'model essay' or the many published essay guides available from your local book shop. You should use the work as a reference and should not hand over the exact copy of it.

Matlabsolutions.com provides guaranteed satisfaction with a commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been empanelled after extensive research and quality check.

Matlabsolutions.com provides undivided attention to each Matlab assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work done at the best price in industry.