?? mlp_iris_class.m
字號:
% hObject handle to Etah (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');endfunction Etay_Callback(hObject, eventdata, handles)% hObject handle to Etay (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of Etay as text% str2double(get(hObject,'String')) returns contents of Etay as a doubleinput = str2num(get(hObject,'String')); %checks to see if input is empty. if so, default input1_editText to zeroif (isempty(input)) set(hObject,'String','0')endguidata(hObject, handles);% --- Executes during object creation, after setting all properties.function Etay_CreateFcn(hObject, eventdata, handles)% hObject handle to Etay (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');endfunction MSE_lim_Callback(hObject, eventdata, handles)% hObject handle to MSE_lim (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Hints: get(hObject,'String') returns contents of MSE_lim as text% str2double(get(hObject,'String')) returns contents of MSE_lim as a doubleinput = str2num(get(hObject,'String'));iris_data.dat %checks to see if input is empty. if so, default input1_editText to zeroif (isempty(input))iris_data.dat set(hObject,'String','0')endguidata(hObject, handles);% --- Executes during object creation, after setting all properties.function MSE_lim_CreateFcn(hObject, eventdata, handles)% hObject handle to MSE_lim (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');end%% --- Executes on button press in Classify.function Classify_Callback(hObject, eventdata, handles)% hObject handle to Classify (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)set1_ir = str2num(get(handles.set1_LR,'String')) ;set1_ur = str2num(get(handles.set1_UR,'String'));set2_ir = str2num(get(handles.set2_LR,'String'));set2_ur = str2num(get(handles.set2_UR,'String'));set3_ir = str2num(get(handles.set3_LR,'String'));set3_ur = str2num(get(handles.set3_UR,'String'));set1_ir2 = str2num(get(handles.set1_LR_td,'String'));set1_ur2 = str2num(get(handles.set1_UR_td,'String'));set2_ir2 = str2num(get(handles.set2_LR_td,'String'));set2_ur2 = str2num(get(handles.set2_UR_td,'String'));set3_ir2 = str2num(get(handles.set3_LR_td,'String'));set3_ur2 = str2num(get(handles.set3_UR_td,'String'));in_ir = str2num(get(handles.Input_LR,'String'));in_ur = str2num(get(handles.Input_UR,'String'));out_ir = str2num(get(handles.Output_LR,'String'));out_ur = str2num(get(handles.Output_UR,'String'));L = str2num(get(handles.Hidden_Nodes,'String'));etay = str2num(get(handles.Etay,'String'));etah = str2num(get(handles.Etah,'String'));MSE_thr = str2num(get(handles.MSE_lim,'String'));%load iris_data.dat; %Incorporate din UI%a= iris_data;global aDim = size(a);p = (in_ur-in_ir) + 2 ; %number of input + biasm = (out_ur-out_ir) + 1 ; % no. of output% Training data setD11=a(set1_ir:set1_ur,in_ir:in_ur);D12=a(set2_ir:set2_ur,in_ir:in_ur);D13=a(set3_ir:set3_ur,in_ir:in_ur);Np = (in_ur-in_ir) + 1 ; % No. of inputs excluding biasD1=[D11; D12 ;D13] ; % Training data set (INPUT)Dim2 = size(D1);X11=a(set1_ir:set1_ur,out_ir:out_ur);X12=a(set2_ir:set2_ur,out_ir:out_ur);X13=a(set3_ir:set3_ur,out_ir:out_ur);X1=[X11; X12 ;X13]/10; % Training data set (Normalised OUTPUT) Dim3 = size(X1);% Normalising Inputpmin=min(D1);pmax=max(D1);for i=1:Dim2(1) d1(i,:)=D1(i,:)-pmin;end;x=(0.9-0.1)./(pmax-pmin);for i=1:Np pin(:,i)=x(i)*d1(:,i)+0.1;end%N=Dim2(1);X= [pin'; ones(1,N)]; % add bias input 1Wh = 0.25*randn(L-1,p)/p;Wy = 0.25*randn(m,L)/L;MSE=10.0; %Initialise some random value but greater than test aim valuewhile(MSE>=MSE_thr) H = ones(L-1,N)./(1+exp(-Wh*X)); % f(net) Hp = H.*(1-H); % f_prime(net) hidden H=[H;ones(1,N)]; % add bias 1 Y = tanh(Wy*H); % output = fj(netj)(semilinear activation function) Yp=1-Y.^2; % f_prime(net) output Ey = X1' - Y; % error in output JJ = (sum((Ey.*Ey)'))'; MSE = sum(JJ)/(N*Dim3(2)) %#ok<NOPTS> % Mean square error in output delY = Ey.*Yp; % error*f_prime(net) dWy = delY*H'; % Gradient output layer weight Eh = Wy(:,1:L-1)'*delY; % error in output from hidden layer delH=Eh.*Hp; dWh = delH*X'; % Gradient output layer weight Wy= Wy + etay*dWy; % Output layer weight correction Wh = Wh + etah*dWh; % Hidden layer weight correction end dataTrain(3,3) = 0; % classify for p = 1:N for i = 1:3 if X1(p)*10 == i for j = 1:3 if round(Y(p)*10) == j dataTrain(i,j) = dataTrain(i,j)+1; break end end end end end % Testing of ModelD21=a(set1_ir2:set1_ur2,in_ir:in_ur); % Test InputD22=a(set2_ir2:set2_ur2,in_ir:in_ur);D23=a(set3_ir2:set3_ur2,in_ir:in_ur);D2=[D21; D22 ;D23];X21=a(set1_ir2:set1_ur2,out_ir:out_ur); % Test outputX22=a(set2_ir2:set2_ur2,out_ir:out_ur);X23=a(set3_ir2:set3_ur2,out_ir:out_ur);X2=[X21; X22 ;X23];Dim = size(D2);N=Dim(1);% Normalising Test Inputpmin=min(D2);pmax=max(D2);for i=1:N d2(i,:)=D2(i,:)-pmin;end;x=(0.9-0.1)./(pmax-pmin);for i=1:Np pin2(:,i)=x(i)*d2(:,i)+0.1;endX= [pin2'; ones(1,N)]; % add bias input 1H = ones(L-1,N)./(1+exp(-Wh*X));H=[H;ones(1,N)]; % add bias 1 Y2 = tanh(Wy*H); dataTest(3,3) = 0; % classify for p = 1:N for i = 1:3 if X2(p) == i for j = 1:3 if round(Y2(p)*10) == j dataTest(i,j) = dataTest(i,j)+1; break end end end end endc = num2str(dataTrain(1,1));set(handles.tr11,'String',c);guidata(hObject, handles);c = num2str(dataTrain(1,2));set(handles.tr12,'String',c);guidata(hObject, handles);c = num2str(dataTrain(1,3));set(handles.tr13,'String',c);guidata(hObject, handles);c = num2str(dataTrain(2,1));set(handles.tr21,'String',c);guidata(hObject, handles);c = num2str(dataTrain(2,2));set(handles.tr22,'String',c);guidata(hObject, handles);c = num2str(dataTrain(2,3));set(handles.tr23,'String',c);guidata(hObject, handles);c = num2str(dataTrain(3,1));set(handles.tr31,'String',c);guidata(hObject, handles);c = num2str(dataTrain(3,2));set(handles.tr32,'String',c);guidata(hObject, handles);c = num2str(dataTrain(3,3));set(handles.tr33,'String',c);guidata(hObject, handles);c = num2str(dataTest(1,1));set(handles.tt11,'String',c);guidata(hObject, handles);c = num2str(dataTest(1,2));set(handles.tt12,'String',c);guidata(hObject, handles);c = num2str(dataTest(1,3));set(handles.tt13,'String',c);guidata(hObject, handles);c = num2str(dataTest(2,1));set(handles.tt21,'String',c);guidata(hObject, handles);c = num2str(dataTest(2,2));set(handles.tt22,'String',c);guidata(hObject, handles);c = num2str(dataTest(2,3));set(handles.tt23,'String',c);guidata(hObject, handles);c = num2str(dataTest(3,1));set(handles.tr31,'String',c);guidata(hObject, handles);c = num2str(dataTest(3,2));set(handles.tt32,'String',c);guidata(hObject, handles);c = num2str(dataTest(3,3));set(handles.tt33,'String',c);guidata(hObject, handles);% --- If Enable == 'on', executes on mouse press in 5 pixel border.% --- Otherwise, executes on mouse press in 5 pixel border or over text4.function text4_ButtonDownFcn(hObject, eventdata, handles)% hObject handle to text4 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -