0001 function varargout = gradient_tester(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 gui_Singleton = 1;
0033 gui_State = struct('gui_Name', mfilename, ...
0034 'gui_Singleton', gui_Singleton, ...
0035 'gui_OpeningFcn', @Gradient_Tester_OpeningFcn, ...
0036 'gui_OutputFcn', @Gradient_Tester_OutputFcn, ...
0037 'gui_LayoutFcn', [] , ...
0038 'gui_Callback', []);
0039 if nargin && ischar(varargin{1})
0040 gui_State.gui_Callback = str2func(varargin{1});
0041 end
0042
0043 if nargout
0044 [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
0045 else
0046 gui_mainfcn(gui_State, varargin{:});
0047 end
0048
0049
0050
0051
0052 function Gradient_Tester_OpeningFcn(hObject, eventdata, Handles, varargin)
0053
0054
0055
0056
0057
0058
0059
0060 Handles.output = hObject;
0061
0062
0063 guidata(hObject, Handles);
0064
0065
0066
0067 set(hObject,'Name','Gradient Tester');
0068
0069
0070 function varargout = Gradient_Tester_OutputFcn(hObject, eventdata, Handles)
0071
0072
0073
0074
0075
0076
0077 varargout{1} = Handles.output;
0078
0079
0080
0081 function New_Weight_Callback(hObject, eventdata, Handles)
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091 function New_Weight_CreateFcn(hObject, eventdata, Handles)
0092
0093
0094
0095
0096
0097
0098 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0099 set(hObject,'BackgroundColor','white');
0100 end
0101
0102
0103
0104 function Training_Pattern_Callback(hObject, eventdata, Handles)
0105
0106
0107
0108
0109
0110
0111
0112 val=get(hObject,'Value');
0113 data=get(Handles.figure1,'UserData');
0114 ti=data{2};
0115 td=data{3};
0116
0117 set(Handles.ti,'String',num2str(ti{val}));
0118 set(Handles.td,'String',num2str(td{val}));
0119
0120
0121
0122 function Training_Pattern_CreateFcn(hObject, eventdata, Handles)
0123
0124
0125
0126
0127
0128
0129 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0130 set(hObject,'BackgroundColor','white');
0131 end
0132
0133
0134
0135 function Load_Simulation_Callback(hObject, eventdata, Handles)
0136
0137
0138
0139
0140 C=filesep;
0141 cd('Results');
0142 [filename, pathname] = uigetfile('*.mat', 'Pick a Simulation Result');
0143 cd('..');
0144 set(Handles.Title,'String',['Gradient Tester: ',filename]);
0145 Handles_temp=Handles;
0146 load([pathname, filename]);
0147 Handles=Handles_temp;
0148 clear Handles_temp;
0149 temp_p={};
0150 NumPatterns=length(TrainingResults.tsCurrent);
0151 for j=1:NumPatterns
0152 temp_p{j}=j;
0153 end
0154 set(Handles.Training_Pattern,'Value',1);
0155 set(Handles.Training_Pattern,'String',temp_p);
0156 set(Handles.ti,'String',num2str(tiAll{1}));
0157 set(Handles.td,'String',num2str(tdAll{1}));
0158
0159 NumInputs=length(ThNN.InputNeurons);
0160 NumOutputs=length(ThNN.OutputNeurons);
0161 NumNeurons=length(ThNN.Neurons);
0162 NumHidden=NumNeurons-(NumInputs+NumOutputs);
0163 set(Handles.TNN_Structure,'String',num2str([NumInputs NumHidden NumOutputs]));
0164
0165 set(Handles.figure1,'UserData',{ThNN,tiAll,tdAll});
0166
0167
0168 function Gradient_Compare_Callback(hObject, eventdata, Handles)
0169
0170
0171
0172
0173 Data=get(Handles.figure1,'UserData');
0174 ThNN=Data{1};
0175 tiAll=Data{2};
0176 tdAll=Data{3};
0177 Val=get(Handles.Training_Pattern,'Value');
0178
0179 TrainingParams.GradientStep=str2num(get(Handles.Gradient_Step_Size,'String'));
0180 if get(Handles.Param_Weights,'Value')==1
0181 TrainingParams.DelayEnable=0;
0182 else
0183 TrainingParams.DelayEnable=1;
0184 end
0185 TrainingParams.NoiseLevel=0;
0186
0187 if get(Handles.Reinitialize_Weights,'Value')==1 && get(Handles.Param_Weights,'Value')==1
0188 WeightsTemp=ceil(abs(ThNN.Weights));
0189 WeightsIni=str2num(get(Handles.New_Weight,'String'));
0190 ThNN.Weights=((1+(1e-2)*randn(size(WeightsTemp)))*WeightsIni).*WeightsTemp;
0191 elseif get(Handles.Reinitialize_Weights,'Value')==1
0192 DelaysTemp=ceil(abs(ThNN.Delays));
0193 DelaysIni=str2num(get(Handles.New_Weight,'String'));
0194 ThNN.Delays=((1+(1e-2)*randn(size(DelaysTemp)))*DelaysIni).*DelaysTemp;
0195 end
0196
0197 TrainingParams.NumericalGradient=0;
0198 [TrainingResults, ts]=calculate_gradient(ThNN,TrainingParams,tiAll{Val},tdAll{Val});
0199 DEDWCalc=TrainingResults.DEDW;
0200 DEDTauCalc=TrainingResults.DEDTau;
0201 S=sparse(TrainingResults.DEDW);
0202 [A,B,D]=find(S);
0203 DEDWCalcDisplay=[A B D];
0204 S=sparse(TrainingResults.DEDTau);
0205 [A,B,D]=find(S);
0206 DEDTauCalcDisplay=[A B D];
0207
0208 TrainingParams.NumericalGradient=1;
0209 [TrainingResults, ts]=calculate_gradient(ThNN,TrainingParams,tiAll{Val},tdAll{Val});
0210 DEDWNum=TrainingResults.DEDW;
0211 DEDTauNum=TrainingResults.DEDTau;
0212 S=sparse(TrainingResults.DEDW);
0213 [A,B,D]=find(S);
0214 DEDWNumDisplay=[A B D];
0215 S=sparse(TrainingResults.DEDTau);
0216 [A,B,D]=find(S);
0217 DEDTauNumDisplay=[A B D];
0218
0219 if get(Handles.Param_Weights,'Value')==1
0220 set(Handles.Gradient_MSE,'String',num2str(sqrt(mean((DEDWNumDisplay(:,3)-DEDWCalcDisplay(:,3)).^2))));
0221 set(Handles.Calculated_Gradient,'String',num2str(DEDWCalcDisplay),'Value',1);
0222 set(Handles.Numerical_Gradient,'String',num2str(DEDWNumDisplay),'Value',1);
0223 else
0224 set(Handles.Gradient_MSE,'String',num2str(sqrt(mean((DEDTauNumDisplay(:,3)-DEDTauCalcDisplay(:,3)).^2))));
0225 set(Handles.Calculated_Gradient,'String',num2str(DEDTauCalcDisplay),'Value',1);
0226 set(Handles.Numerical_Gradient,'String',num2str(DEDTauNumDisplay),'Value',1);
0227 end
0228
0229
0230
0231
0232 function Gradient_Step_Size_Callback(hObject, eventdata, Handles)
0233
0234
0235