dau_wyt asked . 2021-07-07

Artificial Neural Network Prediction Code in Matlab, please help !!!

Dear ! I have a data set with a column is rainfall and the next column is water level (1992-2006) as:
https://docs.google.com/file/d/0By5tEg03EXCpd09rcG5hTWRzMHM/edit I would like to ask your about what are the Inputs values and Target Values? My friend told me that to Predict water level in the future is not need Rainfall data but only need Water level for recent years ago. I am confusing about that since Neural Network is needing an Input and Target values. I have a code for predict water level but rely on the input data has known, within 1992-2006 only. What I am need is using data from 1992-2006 to predict in the year 2014 example. I know you are very excellent about that, please fix again help me the code, thanks.
 
 
    % Data_Inputs=xlsread('1.xls'); % Import file

    %The training data sample are randmonized by using the function'randperm'
    %Shuffling_Inputs=Data_Inputs(randperm(end),1:2); % integers (training sample) 

    Training_Set=Data_Inputs(1:end,1);%specific training set

    Target_Set=Data_Inputs(1:end,2); %specific target set

    Input=Training_Set'; %Convert to row

    Target=Target_Set'; %Convert to row

    X = con2seq(Input); %Convert to cell

    T = con2seq(Target); %Convert to cell

    %%2. Data preparation

    N = 365; % Multi-step ahead prediction

    % Input and target series are divided in two groups of data:
    % 1st group: used to train the network

    inputSeries  = X(1:end-N);

    targetSeries = T(1:end-N);

    inputSeriesVal  = X(end-N+1:end);

    targetSeriesVal = T(end-N+1:end); 
    % Create a Nonlinear Autoregressive Network with External Input
    delay = 2;
    inputDelays = 1:2;
    feedbackDelays = 1:2;
    hiddenLayerSize = 100;
    net = narxnet(inputDelays,feedbackDelays,hiddenLayerSize);

    % Prepare the Data for Training and Simulation
    % The function PREPARETS prepares timeseries data for a particular network,
    % shifting time by the minimum amount to fill input states and layer states.
    % Using PREPARETS allows you to keep your original time series data unchanged, while
    % easily customizing it for networks with differing numbers of delays, with
    % open loop or closed loop feedback modes.
    [inputs,inputStates,layerStates,targets] = preparets(net,inputSeries,{},targetSeries);

    % Setup Division of Data for Training, Validation, Testing
    net.divideParam.trainRatio = 70/100;
    net.divideParam.valRatio = 15/100;
    net.divideParam.testRatio = 15/100;

    % Train the Network
    [net,tr] = train(net,inputs,targets,inputStates,layerStates);

    % Test the Network
    outputs = net(inputs,inputStates,layerStates);
    errors = gsubtract(targets,outputs);
    performance = perform(net,targets,outputs)

    % View the Network
    view(net)

    % Plots
    % Uncomment these lines to enable various plots.
    %figure, plotperform(tr)
    %figure, plottrainstate(tr)
    %figure, plotregression(targets,outputs)
    %figure, plotresponse(targets,outputs)
    %figure, ploterrcorr(errors)
    %figure, plotinerrcorr(inputs,errors)

    % Closed Loop Network
    % Use this network to do multi-step prediction.
     % The function CLOSELOOP replaces the feedback input with a direct
    % connection from the outout layer.
    netc = closeloop(net);
    netc.name = [net.name ' - Closed Loop'];
    view(netc)
    [xc,xic,aic,tc] = preparets(netc,inputSeries,{},targetSeries);
    yc = netc(xc,xic,aic);
    closedLoopPerformance = perform(netc,tc,yc)

    % Early Prediction Network
    % For some applications it helps to get the prediction a timestep early.
    % The original network returns predicted y(t+1) at the same time it is given y(t+1).
    % For some applications such as decision making, it would help to have predicted
    % y(t+1) once y(t) is available, but before the actual y(t+1) occurs.
    % The network can be made to return its output a timestep early by removing one delay
    % so that its minimal tap delay is now 0 instead of 1.  The new network returns the
    % same outputs as the original network, but outputs are shifted left one timestep.
    nets = removedelay(net);
    nets.name = [net.name ' - Predict One Step Ahead'];
    view(nets)
    [xs,xis,ais,ts] = preparets(nets,inputSeries,{},targetSeries);
    ys = nets(xs,xis,ais);
    earlyPredictPerformance = perform(nets,ts,ys)

    %%5. Multi-step ahead prediction

    inputSeriesPred  = [inputSeries(end-delay+1:end),inputSeriesVal];

    targetSeriesPred = [targetSeries(end-delay+1:end), con2seq(nan(1,N))];

    [Xs,Xi,Ai,Ts] = preparets(netc,inputSeriesPred,{},targetSeriesPred);

    yPred = netc(Xs,Xi,Ai);

    perf = perform(net,yPred,targetSeriesVal);

    figure;

    plot([cell2mat(targetSeries),nan(1,N);
      nan(1,length(targetSeries)),cell2mat(yPred);
      nan(1,length(targetSeries)),cell2mat(targetSeriesVal)]')

    legend('Original Targets','Network Predictions','Expected Outputs');

neural network , prediction , matlab , programming

Expert Answer

Prashant Kumar answered . 2024-12-21 02:33:07

1. Plot
 
 
    a. Rainfall vs time
    b. Water Level vs time
    c. Water Level vs Rainfall
    d. Autocorrelation function of Water Level
    e. Crosscorrelation function of Water Level and Rainfall

 2. Calculate

    a. Significant values and lags of the Water Level autocorrelation function
    b. Significant values and lags of the Water-Level/Rainfall crosscorrelation function

 3. Determine which time-series functions yield the best predictions. DO NOT use the default 'dividerand' which destroys correlations. Use 'divideblock'.

     a. Timedelaynet
     b. Narnet
     c. Narxnet

 4. If b and/or c have a satisfactory openloop performance, close the 
  loop and continue training with the original data.


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.