📄 approximation.m
字号:
axes(handles.axes11);
km = 1:handles.kfold;
bar(km,error,'r');
%stop the timer
handles.stop = 1;
stop(timer1);
delete(timer1);
guidata(hObject, handles);
function [error,u,w]=train(handles)
ld =str2num(get(handles.learn_edit,'string'));
% vd =str2num(get(handles.valid_edit,'string'));
% td =str2num(get(handles.test_edit,'string'));
ld = cast(ld/handles.kfold-0.5,'int16') * handles.kfold;
x= rand(2,ld);
x=(x-0.5)*(1.57/0.5);
x1=x(1,:);
x2 =x(2,:);
%get the mean and variance of the training data
mean_value1 = mean(x1);
mean_value2 = mean(x2);
var1=std(x1);
var2 =std(x2);
%preprocess the data to get 0 mean and 1 standard deviation
x1 = (x1-mean_value1)/var1;
x2 = (x2-mean_value2)/var2;
F = 20+x1.^2-10*cos(2*pi*x1)+x2.^2-10*cos(2*pi*x2);
testnum=ld/handles.kfold;
spread = str2num(get(handles.spread_edit,'string'));
if (handles.kfold==1)
P=[x1; x2];
T = F;
[u1,w1] = trainlinear(P,T);
u=u1;
w=w1;
error = ones(1,handles.kfold)*0;
return;
end
k1 =1;
errormax = 1000000;
errormin = 0;
error=ones(1,handles.kfold);
for k= 1:handles.kfold
takeoutk1 = x1(:,k1:k1+testnum-1);
takeoutk2 = x2(:,k1:k1+testnum-1);
takeoutF = F(:,k1:k1+testnum-1);
x=x1;
y=x2;
z = F;
x(:,k1:k1+testnum-1)=[];
y(:,k1:k1+testnum-1)=[];
z(:,k1:k1+testnum-1)=[];
P=[x;y];
[u1,w1] = trainlinear(P,z);
k1=k1+testnum;
if (k==1)
% net2 = net1;
u=u1;
w=w1;
end
t = [takeoutk1;takeoutk2];
tr = simlinear(t,u1,w1);
error(1,k) = sum((takeoutF - tr).^2);
if (error(1,k)<errormax)
errormin=error;
errormax = error;
u=u1;
w=w1;
else
u=u1;
w=w1;
end
end
function timer1_callback_fcn(obj, event,handles,hObject,wb)
% errordlg('stop now','Input Error');
if(handles.stop==1)
return;
end
hello = obj.tasksExecuted;
set(handles.timer_text,'string',num2str(hello));
%
% if( handles.stop == 1)
% set(handles.timer_text,'string','Done !');
% handles.stop = 0;
% guidata(hObject, handles);
% stop(obj);
% delete(obj);
% end
% --- Executes during object creation, after setting all properties.
function train_pushbutton_CreateFcn(hObject, eventdata, handles)
% hObject handle to train_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu 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 selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject handle to popupmenu1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns popupmenu1 contents as cell array
% contents{get(hObject,'Value')} returns selected item from popupmenu1
value = get(hObject,'value')
if(value ==1)
handles.kfold=value;
else
handles.kfold = value+3;
end
guidata(hObject, handles);
% --- Executes during object creation, after setting all properties.
function checkbox3_CreateFcn(hObject, eventdata, handles)
% hObject handle to checkbox3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% --- Executes during object creation, after setting all properties.
function checkbox4_CreateFcn(hObject, eventdata, handles)
% hObject handle to checkbox4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% --- Executes during object creation, after setting all properties.
function valid_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to valid_edit (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
function valid_edit_Callback(hObject, eventdata, handles)
% hObject handle to valid_edit (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 valid_edit as text
% str2double(get(hObject,'String')) returns contents of valid_edit as a double
% --------------------------------------------------------------------
function uipanel10_SelectionChangeFcn(hObject, eventdata, handles)
% hObject handle to uipanel10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
switch get(hObject,'Tag')
case 'fast_radiobutton'
handles.user_selection = 1;
handles.interval = 0.1;
case 'medium_radiobutton'
handles.user_selection = 2;
handles.interval = 0.05;
case 'full_radiobutton'
handles.user_selection = 3;
handles.interval = 0.01;
end
guidata(hObject, handles);
% --- Executes on button press in checkbox3.
function checkbox3_Callback(hObject, eventdata, handles)
% hObject handle to checkbox3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox3
% --- Executes on button press in checkbox4.
function checkbox4_Callback(hObject, eventdata, handles)
% hObject handle to checkbox4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of checkbox4
% --- Executes during object creation, after setting all properties.
function timer_text_CreateFcn(hObject, eventdata, handles)
% hObject handle to timer_text (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% --- Executes during object creation, after setting all properties.
function axes6_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes6 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes6
% --- Executes during object creation, after setting all properties.
function axes12_CreateFcn(hObject, eventdata, handles)
% hObject handle to axes12 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes12
% --- Executes during object creation, after setting all properties.function axes5_CreateFcn(hObject, eventdata, handles)% hObject handle to axes5 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: place code in OpeningFcn to populate axes5
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -