关于神经网络matlab代码的问题

时间:2011-01-17 02:23:39

标签: matlab

嗨,我发现这个代码的某个地方信息很少。 它假设是一个反向传播神经网络代码。 但似乎缺乏重量和偏见之类的东西。 代码是否正确?是火车反向传播神经网络吗? 感谢

    % --- Executes on button press in pushbutton6.

    %~~~~~~~~~~~[L1 L2 1];first hidden layer,second & output layer~~~~~
    layer = [11 15 1];
    myepochs = 30;
    attemption = 1; %i;
    mytfn = {'tansig' 'tansig' 'purelin'};

    %~~~~~~load data~~~~~~~~~~~~~~~~~~~~~~~
    m = xlsread('D:\MATLAB\datatrain.csv');   

    %~~~~~~convert the data in Matrix form~~~~
    [row,col] = size(m);          

    P = m(1:row,1:10)';


    T1 = m(1:row, col)';   % target data for training...last column


    net = newff([minmax(P)],layer,mytfn,'trainlm');  %nnet 
     net.trainParam.epochs = myepochs;   % how many time newff will repeat the training
     net.trainParam.showWindow = true;
     net.trainParam.showCommandLine = true;
     net = train(net,P,T1);  % start training newff with input P and target T1

     Y = sim(net,P);   % training

     save 'net7' net;


   % --- Executes on button press in pushbutton4. 

   %~~~~~~load data~~~~~~~~~~~~~~~~~~~~~~~
    mt = xlsread('D:\MATLAB\datatest.csv');  

    %~~~~~~convert the data in Matrix form~~~~
    [row1,col1] = size(mt);     
    Pt= mt(1:row1,1:10)';
    Tt = mt(1:row1, col1)';  

    load 'net7' -mat;
    Yt= sim(net,Pt); 

     %~~~~~~~final result of the neural network~~~~~~~~
    [r,c]=size(Yt);
    result=Yt(c);


    if result>0.7
        error=1-result;
        set(handles.edit39,'String','yes')
        set(handles.edit40,'String',num2str(error))
        set(handles.edit41,'String','Completed')
        data1=[num2str(result) ];   
        fid = fopen('D:\MATLAB\record.csv','a+'); 
        fprintf(fid,[data1,'\n']);
        fclose(fid);


    else
        set(handles.edit39,'String','no')
        set(handles.edit40,'String',num2str(result))
        set(handles.edit41,'String','Completed')
        data1=[num2str(result) ];           
        fid = fopen('D:\MATLAB\record.csv','a+'); 
        fprintf(fid,[data1,'\n']);
        fclose(fid);
    end    

1 个答案:

答案 0 :(得分:0)

代码是正确的。神经网络权重和偏差存储在net结构中,您可以通过net.IWnet.LW结构访问它们。偏差存储在net.b内。此代码使用输入P和目标T1训练网络,在训练期间将其分解为训练,测试和验证子集。有关培训过程的详细信息,请查看文档。