2012-04-16 16 views
0

新しいMatlabです。
誰かが私に次のコードを説明することはできますか?このコードは、私が内蔵されているが、BpTrainingProcess()に対応ニューラルネットワークツールボックスを見つけることができませんmatlabコードの説明

N = xlsread('data.xls','Sheet1'); 
N = N(1:150,:); 
UN = xlsread('data.xls','Sheet2'); 
UN = UN(1:150,:); 
traindata = [N ; UN]; 
save('traindata.mat','traindata'); 
label = []; 
for i = 1 : size(N,1)*2 
if(i <= size(N,1)) 
%  label = [label ;sum(traindata(i,:))/size(traindata(i,:),2)]; 
    label = [label ;sum(traindata(i,:))/10]; 
else 
%  label = [label ;sum(traindata(i,:))/size(traindata(i,:),2)]; 
    label = [label ;sum(traindata(i,:))/10]; 
end 
end 
weightMat = BpTrainingProcess(4,0.0001,0.1,0.9,15,[size(traindata,1) 1],traindata,label); 

答えて

0

ニューラルネットワークを訓練するために使用されているので、これはあなたがへのローカルアクセス権を持っているファイルである必要があります(または、から入手する必要がありますあなたにこのコードを書いた人)。 Neural Networkのツールボックス関数へのいくつかの関数呼び出しを組み合わせるか、おそらくバックプロパゲーショントレーニングメソッドの元の実装である可能性があります。

そうでなければ、コードにはいくつかの欠点があります。 1つは、内部のif-else文が実際に何かをしているようには見えません。コメントアウトされた行でさえ、まったく役に立たないif-else設定を残します。 if-elseは、ExcelファイルのSheet1から読み込まれたデータとSheet2から読み込まれたデータの異なるラベル正規化を行うことを目的としています。たぶんそれはあなたのために重要ですが、現在プログラムでは起こっていません。

最後に、コードでは空の配列labelが使用され、空の配列に行が追加されます。これは、すでに多くの行があることを既に知っているので、不要です(合計でsize(N,1)*2 = 150*2 = 300行までです)。label=zeros(300,1)を簡単に設定して、forループの各繰り返しで通常のインデックスを使用することもできます。label(i) = ...。しかし、間違いなく問題はるかに300行のデータセットのために(各行の長さがあまり大きくないと仮定)しません。私は以下のコードに次のドキュメントを置く

。ここ

% The functionn 'xlsread()' reads data from an Excel file. 
% Here it is storing the values from Sheet 1 of the file 'data.xls' 
% into the variable N, and then using the syntax N = N(1:150,:) to 
% change N from being all of the data into being only the first 
% 150 rows of the data 
N = xlsread('data.xls','Sheet1'); 
N = N(1:150,:); 

% Now do the same thing for Sheet 2 from the Excel file. 
UN = xlsread('data.xls','Sheet2'); 
UN = UN(1:150,:); 

% This concatenates the two different data arrays together, making 
% one large array where N is the top half and UN is the bottom half. 
% This is basically just stacking N on top of UN into one array. 
traindata = [N ; UN]; 

% This saves a copy of the newly stacked array into the Matlab data file 
% 'traindata.mat'. From now on, you should be able to load the data from 
% this file, without needing to read it from the Excel sheet above. 
save('traindata.mat','traindata'); 

% This makes an empty array which will have new things appended to it below. 
label = []; 

% Because UN and N have the same number of rows, then the training data 
% has twice as many rows. So this sets up a for loop that will traverse 
% all of these rows of the training data. The 'size()' function can be 
% used to get the different dimensions of an array. 
for i = 1 : size(N,1)*2 

    % Here, an if statement is used to check if the current row number, i, 
    % is less than or equal to than the number of rows in N. This implies 
    % that this part of the if-statement is only for handling the top half 
    % of 'trainingdata', that is, the stuff coming from the variable N. 

    if(i <= size(N,1)) 
     % The line below was already commented out. Maybe it had an old use 
     % but is no longer needed? 
     % label = [label ;sum(traindata(i,:))/size(traindata(i,:),2)]; 

     % This syntax will append new rows to the variable 'label', which 
     % started out as an empty array. This is usually bad practice, memory-wise 
     % and also for readability. 

     % Here, the sum of the training data is being computed, and divided by 10 
     % in every case, and then appended as a new row in 'label'. Hopefully, 
     % if you are familiar with the data, you will know why the data in 'N' 
     % always needs to be divided by 10. 
     label = [label ;sum(traindata(i,:))/10]; 

    % Otherwise, if i > # of rows then handle the data differently. 
    % Really this means the code below treats only data from the variable UN. 
    else 
     % The line below was already commented out. Maybe it had an old use 
     % but is no longer needed? 
     % label = [label ;sum(traindata(i,:))/size(traindata(i,:),2)]; 

     % Just like above, the data is being divided by 10. Given that there 
     % is nothing different about the code here, and how it modifies 'label' 
     % there is no need for the if-else statements, and they only waste time. 
     label = [label ;sum(traindata(i,:))/10]; 

    % This is needed to show the end of the if-else block. 
    end 

% This is needed to show the end of the for-loop. 
end 


% This appears to be a Back-Propagation Neural Network training function. 
% This doesn't match any built-in Matlab function I can find, but you might 
% check in the Neural Network toolbox to see if the local function 
% BpTrainingProcess is a wrapper for a collection of built-in training functions. 

weightMat = BpTrainingProcess(4, 0.0001, 0.1, 0.9, 15, 
           [size(traindata,1) 1], traindata,label); 

バックプロパゲーショントレーニングのためのMATLABニューラルネットワークツールボックス関数の例にはlinkがあります。そのドキュメントを参照して、類似しているかどうか確認したい場合がありますBpTrainingProcess()の内部。

+0

ありがとう – darsha