how to rewrite this for feedforward neural network for with 52 inputs and 2 output that predict emission rate not for digits, where i get an error of In an assignment A(:) = B, the number of elements in A and B must be the same. Error in line36

2 ビュー (過去 30 日間)
Mary Abdu
Mary Abdu 2018 年 12 月 29 日
回答済み: Reff 2020 年 4 月 19 日
sweep=[3,5:5:50]; %parameter values to test
scores=zeros(length(sweep),1); %pre-allcation
models=cell(length(sweep),1); %pre-allcation
load('inputs.mat');
load('outputs.mat');
load('newinputs.mat');
load('newoutputs.mat');
in=inputs; % loads inputs into variable 'in'
t=outputs; % loads outputs into variable 't'
in_test=newinputs; % loads test inputs into variable 'in_test'
t_test=newoutput; % loads test inputs into variable 't_test'
%training function:
net.trainFcn = 'trainlm';
%transfer functions:
net.layers{1}.transferFcn = 'tansig';
net.layers{2}.transferFcn = 'purelin';
net.trainParam.epochs = 100000;
for i=1:length(sweep)
hiddenlayersize=sweep(i); %number of hidden layer neurons
net=patternnet(hiddenlayersize);
net.divideFcn = 'dividerand'; % Divide data randomly
net.divideMode = 'sample'; % Divide up every sample
net.divideParam.trainRatio=0.7;
net.divideParam.valRatio=0.15;
net.divideParam.testRatio=0.15;
%training the network
net = train(net,in,t);
%simulating the outputs
y=sim(net,in);
%store the trained network
models{i}=net;
%prediction to test the network
pre=net(in_test);
%prediction labels
scores(i)=sum(t_test==pre)/length(t_test); %accuracy
end
%plot accuracy versus number of neorons in the hidden layer
figure
plot(sweep,scores,'.-')
xlabel('number of hidden neurons')
ylabel('accuracy')
title('number of hidden neurons vs.accuracy')

回答 (2 件)

Greg Heath
Greg Heath 2018 年 12 月 30 日
編集済み: Greg Heath 2019 年 1 月 3 日
Replace the " == " in
scores(i)=sum(t_test==pre)/length(t_test); %accuracy
with a minus sign
WHOOPS !!!
I misread the text. I was thinking of an error measure to minimize of the form
errorscore(i) = sum( abs( t_test - pre )/ length(t_test) )
Hope this helps.
*Thank you for formally accepting my answer*
Greg
  1 件のコメント
Mary Abdu
Mary Abdu 2018 年 12 月 30 日
still not work i think the problem is with the dimention of scores (i) that it is dimention is 11x1

サインインしてコメントする。


Reff
Reff 2020 年 4 月 19 日
hi,
what is means of paramater?
  1. sweep=[3,5:5:50]; %parameter values to test
  2. scores=zeros(length(sweep),1); %pre-allcation
  3. models=cell(length(sweep),1); %pre-allcation

カテゴリ

Help Center および File ExchangeSequence and Numeric Feature Data Workflows についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by