Rita asked . 2021-08-04

how to use two separate files for ANN?

Hi, I would like to use two separate files for ANN.one file for training and the other file for test of data.Here is for the one input.
 
inputs = ii';
targets = f';
inputGap = ig;
targetGap = fg;
    hiddenLayerSize = j;
         net = fitnet(hiddenLayerSize);
   net.inputs{1}.processFcns = {'removeconstantrows','mapminmax'};
        net.outputs{2}.processFcns = {'removeconstantrows','mapminmax'};
        net.divideFcn = 'dividerand';  
        net.divideMode = 'sample';  
        net.divideParam.trainRatio = 70/100;
        net.divideParam.valRatio = 15/100;
        net.divideParam.testRatio = 15/100;
        net.trainFcn = 'trainlm';  
        net.performFcn = 'mse';         
        % Train the Network
        [net,tr] = train(net,inputs,targets);
        outputs = net(inputs);
        errors = gsubtract(targets,outputs);
        performance = perform(net,targets,outputs);
         valTargets = targets  .* tr.valMask{1};
        testTargets = target  .* tr.testMask;
        trainPerformance = perform(net,trainTagets,outputs);
        testPerformance = perform(net,testTargets,outputs);
        out1.net = net;
        out1.inputs = inputs;
        out1.targets = targets;

 

ann , training , separate training ...

Expert Answer

Prashant Kumar answered . 2024-12-21 03:21:59

1- I wanted to fill some data that I missed during measurement by ANN and using some parameters which may impact on my target data. Inputgap are those data(8 parameters) that may be helpful to fill the gap.
 
Please do not refer to input variables and output variables as parameters. Parameters are entities that stay constant during the process:
 
outputs = f(inputs,parameters).
> 2- size of my input is 1525 data and size of gap is 666(target).
 
Still not clear: Apparently I need some physical insight:
 
 What are your inputs, parameters and targets?

size(targets) = [ 1  859]    
size(inputs)  = [ 8 1525]  
==> size(inputs) = [ 8 859] for net training?
    size(inputs) = [ 8 666] for estimating missing data?
> 3- I wanted to try several H. I think(I am not sure if it is correct)If I use from 4 to 2n+3 for H (which n is my 8 parameters) would be enough to get the high mse and R-squared .
 
Not sure where you got that estimate. If the target plot is relatively smooth you will need at least one hidden node for each local extremum.
 
 [ I   N ] = size(inputs)
 [ O N ]= size(targets)
 Ntrn = round(0.7*N)   % approx fitnet default
 Ntrneq = Ntrn*O         % No. training equations

% No. of unknown weights to estimate for H hidden nodes

 Nw = (I+1)*H+(H+1)*O 
 Ntrneq >= Nw when H <= Hub where
 Hub = floor( (Ntrneq-O)/(I+O+1)) % Hidden Node upper bound
>4. since I have 60 artificial gap scenarios to prove that ANN can be a good method to simulate my missing data I need to test R2 and TsetReg. Actually 0.7 was the highest amount that I think might get from ANN.
 
Correction: if output vs target slope is R = 0.7, then R2 is only 0.49.
 
If you have to set a goal, try R2 >= 0.995 i.e., mse(error) <= 0.005*var(targets,1) via
 
 net.trainParam.goal =  0.005*var(targets,1)  % 1-dim target
If the net can't do it your computer will not explode.
 
First try Ntrials = 10. If need be, you can always design more.
 
4- Honestly I thought it can give me the answer sooner!! But unfortunetly after running 8 months I could not get a good result for "mse" comparing to linear interpolation!! but r squared was a little bit better in ANN method. my data was for six years (2191 data which has 666 gaps)and because I could get a good result with running all of the data I have decided to use 4 years data for training and 2 years for testing.probably in this way I could get a good result.but unfortunately I don't know how to write the script for introducing one file (4 years)as a training and another file(2 years)as a testing to ANN. Thanks for your help and time.
 
It is as simple as
 
 savednet = save(net);
 ...
 loadednet = load(savednet);
 newoutput = loadednet(newinput)

 


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.