Code covered by the BSD License  

Highlights from
Complement Coding

image thumbnail
from Complement Coding by Massimiliano Versace
Complement Coding can be used to preprocess and normalize neural network input.

complement_example(varargin)
function varargout = complement_example(varargin)
% complement_example M-file for complement_example.fig
%      complement_example, by itself, creates a new complement_example or raises the existing
%      singleton*.
%
%      H = complement_example returns the handle to a new complement_example or the handle to
%      the existing singleton*.
%
%      complement_example('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in complement_example.M with the given input arguments.
%
%      complement_example('Property','Value',...) creates a new complement_example or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before complement_example_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to complement_example_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help complement_example

% Last Modified by GUIDE v2.5 07-May-2009 14:41:51

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @complement_example_OpeningFcn, ...
                   'gui_OutputFcn',  @complement_example_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before complement_example is made visible.
function complement_example_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to complement_example (see VARARGIN)

% Choose default command line output for complement_example
handles.output = hObject;

% initialize radio button choice
handles.input_choice = 'GUI';

% make all handle properties available
set(0,'HideUndocumented','off');

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes complement_example wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = complement_example_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


%======================================================================


%----------------------------------------------------------------------
% Run Button
%----------------------------------------------------------------------
%
% --- Executes on button press in pushbutton_run.
function pushbutton_run_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_run (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% handles.xcomp is a vector containing the results of the
% Complement_Code run.  The first half of the vector contains
% the normalized (or truncated) feature values, and the
% second half of the vector contains their complements.
handles.xcomp = Complement_Code(handles.vals,handles.mins,handles.maxs);

% number of features
size_xcomp = size(handles.xcomp);
nvals = size_xcomp(2)/2;

% retrieve current table data
tabledata = get(handles.tablehandle,'Data');

% replace last 2 columns of table with calculated data
a  = handles.xcomp(1:nvals);          % normalized features
ac = handles.xcomp(nvals+1:2*nvals);  % complements
table2data(:,1) = a;
table2data(:,2) = ac;
set(handles.table2handle,'Data',table2data);

% plot a
hbar1 = subplot(1,2,1,'Parent',handles.plot_panel);
bar([1 2 3 4 5],a);
hxl1 = xlabel('Feature');
hyl1 = ylabel('a');
set(hyl1,'Rotation',0);
set(hyl1,'FontWeight','bold');
set(hxl1,'FontWeight','bold');
axis([0 6 0 1.1]);
grid;

% plot ac
hbar2 = subplot(1,2,2,'Parent',handles.plot_panel);
bar([1 2 3 4 5],ac);
hxl2 = xlabel('Feature');
hyl2 = ylabel('{a_c}');
set(hyl2,'Rotation',0)
set(hyl2,'FontWeight','bold');
set(hxl2,'FontWeight','bold');
axis([0 6 0 1.1]);
grid;

guidata(hObject,handles);


%----------------------------------------------------------------------
% Close Button
%----------------------------------------------------------------------
%
% --- Executes on button press in close_button.
function close_button_Callback(hObject, eventdata, handles)
% hObject    handle to close_button (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
close


%----------------------------------------------------------------------
% Input Value Table Help Button
%----------------------------------------------------------------------
%
% --- Executes on button press in pushbutton_help.
function pushbutton_help_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton_help (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

helpstring = 'Each feature has a min and max value associated ';
helpstring = [helpstring 'with it that is used for normalization. '];
helpstring = [helpstring 'Change any feature, min, or max values '];
helpstring = [helpstring 'as desired, hitting a carriage return '];
helpstring = [helpstring 'after each change.  Then hit '];
helpstring = [helpstring 'the Run button.  The results will appear in '];
helpstring = [helpstring 'the table, and will be plotted in the '];
helpstring = [helpstring 'lower part of the window.  When '];
helpstring = [helpstring 'you are finished, hit the Close button'];
helpdlg(helpstring,'How to Run');

% --- Executes during object creation, after setting all properties.
function text27_CreateFcn(hObject, eventdata, handles)
% hObject    handle to text27 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

%----------------------------------------------------------------------
% Change Table Values Based on User Input;
% executes whenever a cell in the table is modified
%----------------------------------------------------------------------
%
% --- Executes when entered data in editable cell(s) in input_table.
function input_table_CellEditCallback(hObject, eventdata, handles)
% hObject    handle to input_table (see GCBO)
% eventdata  structure with the following fields (see UITABLE)
%	Indices: row and column indices of the cell(s) edited
%	PreviousData: previous data for the cell(s) edited
%	EditData: string(s) entered by the user
%	NewData: EditData or its converted form set on the Data property. Empty if Data was not changed
%	Error: error string when failed to convert EditData to appropriate value for Data
% handles    structure with handles and user data (see GUIDATA)
i = eventdata.Indices(1);   % indices of modified cell
j = eventdata.Indices(2);
if (j==1)
    handles.vals(i) = str2num(eventdata.EditData);
elseif (j==2)
    handles.mins(i) = str2num(eventdata.EditData);
else
    handles.maxs(i) = str2num(eventdata.EditData);
end
guidata(hObject,handles);


%----------------------------------------------------------------------
% Create Input Table and Initialize with Default Values
%----------------------------------------------------------------------
%
% --- Executes during object creation, after setting all properties.
function input_table_CreateFcn(hObject, eventdata, handles)
% hObject    handle to input_table (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
handles.tablehandle = hObject;
x = get(hObject,'Data');
handles.vals = x(:,1)';
handles.mins = x(:,2)';
handles.maxs = x(:,3)';
guidata(hObject,handles);


%----------------------------------------------------------------------
% Create Output Table and Initialize with Zeros
%----------------------------------------------------------------------
%
% --- Executes during object creation, after setting all properties.
function output_table_CreateFcn(hObject, eventdata, handles)
% hObject    handle to output_table (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
handles.table2handle = hObject;
xout = get(hObject,'Data');
handles.a  = xout(:,1)';
handles.ac = xout(:,2)';
guidata(hObject,handles);


% --- Executes during object creation, after setting all properties.
function how_to_run_CreateFcn(hObject, eventdata, handles)
% hObject    handle to how_to_run (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 bar_a_CreateFcn(hObject, eventdata, handles)
% hObject    handle to bar_a (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 bar_a


% --- Executes during object creation, after setting all properties.
function plot_panel_CreateFcn(hObject, eventdata, handles)
% hObject    handle to plot_panel (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called
handles.plot_panel = hObject;
guidata(hObject,handles);


% --- Executes during object creation, after setting all properties.
function uipanel_main_CreateFcn(hObject, eventdata, handles)
% hObject    handle to uipanel_main (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called


Contact us at files@mathworks.com