Home > TNNT_1_07 > FrontEnd > gradient_tester.m

gradient_tester

PURPOSE ^

GRADIENT_TESTER creates a GUI for testing the gradient

SYNOPSIS ^

function varargout = gradient_tester(varargin)

DESCRIPTION ^

GRADIENT_TESTER creates a GUI for testing the gradient

Description:
Function to create a GUI for testing the gradient on previously trained
networks. This function is adapted from code automatically generated by
the Matlab GUIDE tool.

Syntax:
gradient_tester;
GradientTesterHandle=gradient_tester;

Input Parameters:
o None

Output Parameters:
o GradientTesterHandle: Handle to the GUI figure. The UserData of the GUI
    is a 1x3 cell array containing the network object, the cell array of
    input spike times and the cell array of output spike times.

Example:
>> GradientTesterHandle=gradient_tester;
>> Temp=get(GradientTesterHandle,'UserData');
>> ThNN=Temp{1}

See also theta_neuron_network

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = gradient_tester(varargin)
0002 %GRADIENT_TESTER creates a GUI for testing the gradient
0003 %
0004 %Description:
0005 %Function to create a GUI for testing the gradient on previously trained
0006 %networks. This function is adapted from code automatically generated by
0007 %the Matlab GUIDE tool.
0008 %
0009 %Syntax:
0010 %gradient_tester;
0011 %GradientTesterHandle=gradient_tester;
0012 %
0013 %Input Parameters:
0014 %o None
0015 %
0016 %Output Parameters:
0017 %o GradientTesterHandle: Handle to the GUI figure. The UserData of the GUI
0018 %    is a 1x3 cell array containing the network object, the cell array of
0019 %    input spike times and the cell array of output spike times.
0020 %
0021 %Example:
0022 %>> GradientTesterHandle=gradient_tester;
0023 %>> Temp=get(GradientTesterHandle,'UserData');
0024 %>> ThNN=Temp{1}
0025 %
0026 %See also theta_neuron_network
0027 
0028 %Copyright (C) 2008 Sam McKennoch <Samuel.McKennoch@loria.fr>
0029 
0030 
0031 % Begin initialization code - DO NOT EDIT
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 % End initialization code - DO NOT EDIT
0049 
0050 
0051 % --- Executes just before Gradient_Tester is made visible.
0052 function Gradient_Tester_OpeningFcn(hObject, eventdata, Handles, varargin)
0053 % This function has no output args, see OutputFcn.
0054 % hObject    handle to figure
0055 % eventdata  reserved - to be defined in a future version of MATLAB
0056 % Handles    structure with Handles and user data (see GUIDATA)
0057 % varargin   command line arguments to Gradient_Tester (see VARARGIN)
0058 
0059 % Choose default command line output for Gradient_Tester
0060 Handles.output = hObject;
0061 
0062 % Update Handles structure
0063 guidata(hObject, Handles);
0064 
0065 % UIWAIT makes Gradient_Tester wait for user response (see UIRESUME)
0066 % uiwait(Handles.figure1);
0067 set(hObject,'Name','Gradient Tester');
0068 
0069 % --- Outputs from this function are returned to the command line.
0070 function varargout = Gradient_Tester_OutputFcn(hObject, eventdata, Handles) 
0071 % varargout  cell array for returning output args (see VARARGOUT);
0072 % hObject    handle to figure
0073 % eventdata  reserved - to be defined in a future version of MATLAB
0074 % Handles    structure with Handles and user data (see GUIDATA)
0075 
0076 % Get default command line output from Handles structure
0077 varargout{1} = Handles.output;
0078 
0079 
0080 
0081 function New_Weight_Callback(hObject, eventdata, Handles)
0082 % hObject    handle to New_Weight (see GCBO)
0083 % eventdata  reserved - to be defined in a future version of MATLAB
0084 % Handles    structure with Handles and user data (see GUIDATA)
0085 
0086 % Hints: get(hObject,'String') returns contents of New_Weight as text
0087 %        str2double(get(hObject,'String')) returns contents of New_Weight as a double
0088 
0089 
0090 % --- Executes during object creation, after setting all properties.
0091 function New_Weight_CreateFcn(hObject, eventdata, Handles)
0092 % hObject    handle to New_Weight (see GCBO)
0093 % eventdata  reserved - to be defined in a future version of MATLAB
0094 % Handles    empty - Handles not created until after all CreateFcns called
0095 
0096 % Hint: edit controls usually have a white background on Windows.
0097 %       See ISPC and COMPUTER.
0098 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0099     set(hObject,'BackgroundColor','white');
0100 end
0101 
0102 
0103 % --- Executes on selection change in Training_Pattern.
0104 function Training_Pattern_Callback(hObject, eventdata, Handles)
0105 % hObject    handle to Training_Pattern (see GCBO)
0106 % eventdata  reserved - to be defined in a future version of MATLAB
0107 % Handles    structure with Handles and user data (see GUIDATA)
0108 
0109 % Hints: contents = get(hObject,'String') returns Training_Pattern contents as cell array
0110 %        contents{get(hObject,'Value')} returns selected item from Training_Pattern
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 % --- Executes during object creation, after setting all properties.
0122 function Training_Pattern_CreateFcn(hObject, eventdata, Handles)
0123 % hObject    handle to Training_Pattern (see GCBO)
0124 % eventdata  reserved - to be defined in a future version of MATLAB
0125 % Handles    empty - Handles not created until after all CreateFcns called
0126 
0127 % Hint: popupmenu controls usually have a white background on Windows.
0128 %       See ISPC and COMPUTER.
0129 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0130     set(hObject,'BackgroundColor','white');
0131 end
0132 
0133 
0134 % --- Executes on button press in Load_Simulation.
0135 function Load_Simulation_Callback(hObject, eventdata, Handles)
0136 % hObject    handle to Load_Simulation (see GCBO)
0137 % eventdata  reserved - to be defined in a future version of MATLAB
0138 % Handles    structure with Handles and user data (see GUIDATA)
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 % --- Executes on button press in Gradient_Compare.
0168 function Gradient_Compare_Callback(hObject, eventdata, Handles)
0169 % hObject    handle to Gradient_Compare (see GCBO)
0170 % eventdata  reserved - to be defined in a future version of MATLAB
0171 % Handles    structure with Handles and user data (see GUIDATA)
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 %Weight Compare
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 %Weight Compare
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 % --- Executes on button press in Gradient_Step_Size.
0232 function Gradient_Step_Size_Callback(hObject, eventdata, Handles)
0233 % hObject    handle to Gradient_Step_Size (see GCBO)
0234 % eventdata  reserved - to be defined in a future version of MATLAB
0235 % Handles    structure with Handles and user data (see GUIDATA)

Generated on Wed 02-Apr-2008 15:16:32 by m2html © 2003