From 189bec36effb36e31454f67745553ebe83372916 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lucas=20Garc=C3=ADa=20Rodr=C3=ADguez?= Date: Sat, 3 Sep 2016 10:36:05 +0200 Subject: [PATCH] Interface rename and code cleanup Renaming 'generichopfieldnet' to 'hopfieldnet' and cleaning unused code in tsphopfieldnet. --- .../{generichopfieldnet.m => hopfieldnet.m} | 22 +++--- @hopfieldnet/isValidSetting.m | 6 +- @tsphopfieldnet/sim.m | 15 +--- @tsphopfieldnet/train.m | 24 +++---- @tsphopfieldnet/tsphopfieldnet.m | 25 +++---- Hopfield Net TSP solver.prj | 34 ++++----- Hopfield Network Toolbox.prj | 71 +++++++++---------- help/html/helptoc.xml | 2 +- 8 files changed, 85 insertions(+), 114 deletions(-) rename @hopfieldnet/{generichopfieldnet.m => hopfieldnet.m} (79%) diff --git a/@hopfieldnet/generichopfieldnet.m b/@hopfieldnet/hopfieldnet.m similarity index 79% rename from @hopfieldnet/generichopfieldnet.m rename to @hopfieldnet/hopfieldnet.m index bb82a1e..4224f08 100644 --- a/@hopfieldnet/generichopfieldnet.m +++ b/@hopfieldnet/hopfieldnet.m @@ -1,5 +1,5 @@ -classdef generichopfieldnet < hopfieldnetwork - %GENERICHOFIELDNETWORK Continuous Hopfield Network (CHN) +classdef hopfieldnet < hopfieldnetwork + %HOFIELDNETWORK Continuous Hopfield Network (CHN) properties (GetAccess = public, SetAccess = public) name = 'Continuous Hopfield Network (CHN)'; @@ -8,7 +8,7 @@ end methods - function net = generichopfieldnet(P, q, A, b, Aeq, beq, options) + function net = hopfieldnet(P, q, A, b, Aeq, beq, options) % Solving the GQKP % min{1/2 * v' * P * v + q' * v} % subject to @@ -18,19 +18,19 @@ % v_{n+k} belongs to [0,1], k = 1,..., m1 if nargin < 6 || nargin > 7 - error('generichopfieldnet:IncorrectInputArguments','Please provide proper input arguments to generichopfieldnet: P, q, R, b (and options)'); + error('hopfieldnet:IncorrectInputArguments','Please provide proper input arguments to hopfieldnet: P, q, R, b (and options)'); else % asserting inputs - assert(isa(P,'double'), 'generichopfieldnet:invalid_datatype', 'P must be double.'); - assert(isa(q,'double'), 'generichopfieldnet:invalid_datatype', 'q must be double.'); - assert(isa(A,'double'), 'generichopfieldnet:invalid_datatype', 'A must be double.'); - assert(isa(b,'double'), 'generichopfieldnet:invalid_datatype', 'b must be double.'); - assert(isa(Aeq,'double'), 'generichopfieldnet:invalid_datatype', 'Aeq must be double.'); - assert(isa(beq,'double'), 'generichopfieldnet:invalid_datatype', 'beq must be double.'); + assert(isa(P,'double'), 'hopfieldnet:invalid_datatype', 'P must be double.'); + assert(isa(q,'double'), 'hopfieldnet:invalid_datatype', 'q must be double.'); + assert(isa(A,'double'), 'hopfieldnet:invalid_datatype', 'A must be double.'); + assert(isa(b,'double'), 'hopfieldnet:invalid_datatype', 'b must be double.'); + assert(isa(Aeq,'double'), 'hopfieldnet:invalid_datatype', 'Aeq must be double.'); + assert(isa(beq,'double'), 'hopfieldnet:invalid_datatype', 'beq must be double.'); end if nargin < 7 - options = generichopfieldnet.createOptions(); + options = hopfieldnet.createOptions(); end % Creating net object from parent class diff --git a/@hopfieldnet/isValidSetting.m b/@hopfieldnet/isValidSetting.m index 542e091..4cb108b 100644 --- a/@hopfieldnet/isValidSetting.m +++ b/@hopfieldnet/isValidSetting.m @@ -1,18 +1,18 @@ function isValidSetting(property,value) - invalidDataTypeID = 'generichopfieldnet:invalid_datatype'; + invalidDataTypeID = 'hopfieldnet:invalid_datatype'; switch property case {'trainFcn', 'simFcn'} assert(isa(value,'char'), invalidDataTypeID, [property, ' must be char.']); end - invalidValueID = 'generichopfieldnet:invalid_value'; + invalidValueID = 'hopfieldnet:invalid_value'; switch property case 'trainFcn' - assert(strcmp('traingty',value), invalidValueID, 'Training function (parametrization) must be ''traingty'''); + assert(strcmp('traingty',value), invalidValueID, 'Training function (parametrization) must be ''trainty'''); case 'simFcn' assert(strcmp('euler',value) || strcmp('talavan-yanez',value), invalidValueID, 'Simulation function must be ''euler'' or ''talavan-yanez'''); diff --git a/@tsphopfieldnet/sim.m b/@tsphopfieldnet/sim.m index b73f017..16cf34e 100644 --- a/@tsphopfieldnet/sim.m +++ b/@tsphopfieldnet/sim.m @@ -38,13 +38,6 @@ [net,V,~,iter] = simDivideConquer(net,V,U); end - elseif strcmp(net.simFcn,'talavan-yanez-n') - if nargin < 2 - [net,V,~,iter] = simTalavanYanezVarN(net); - else - [net,V,~,iter] = simTalavanYanezVarN(net,V,U); - end - else error('tsphopfieldnet:UnknownsimFcn', 'Unknown training algorithm'); end @@ -52,6 +45,7 @@ if ~isempty(net.cities.fixedCities{1}) net.cities.d = aux_d; end + if ~any(strcmp({ST.name},'saddle')) net = computeTour(net,V,iter); net.results.compTime = toc(timeID); @@ -460,7 +454,7 @@ iter = net.results.itersReached + netPhase2.results.itersReached - 1; if plotPhases - if isempty(net.results.tourLength); + if isempty(net.results.tourLength); %#ok init(net); net = computeTour(net,V,iter); % Needed for plot phase1 + phase2 to output correctly else @@ -699,10 +693,7 @@ (net.trainParam.A + net.trainParam.B) * V - ... net.trainParam.C * sumV - ... net.trainParam.D * dVpVn; - if isfield(net.trainParam,'F') - TV = TV + net.trainParam.F * (net.cities.d * bsxfun(@minus, sumVrow, V) - dVpVn); - % net.trainParam.F * net.cities.d * (repmat(sumVrow,1,net.trainParam.N) - V - V(:,deltaPrev) - V(:,deltaNext)); - end + else % HAY QUE TRABAJAR ESTO reOrder = reshape(flipud(reshape(1:2*net.trainParam.K,2,net.trainParam.K)),2*net.trainParam.K,1); termA = repmat(sumVrow,1,size(V,2)) - V; diff --git a/@tsphopfieldnet/train.m b/@tsphopfieldnet/train.m index d5f646b..6c37669 100644 --- a/@tsphopfieldnet/train.m +++ b/@tsphopfieldnet/train.m @@ -17,24 +17,16 @@ net.trainParam.D = 1/net.trainParam.dU; net.trainParam.rho = net.trainParam.dL/net.trainParam.dU; - if ~isfield(net.trainParam, 'F') - net.trainParam.Np = net.trainParam.N - net.trainParam.K + 3 / net.trainParam.C; + net.trainParam.Np = net.trainParam.N - net.trainParam.K + 3 / net.trainParam.C; - if net.trainParam.K == 0 - net.trainParam.B = 3 + net.trainParam.C; - net.trainParam.A = net.trainParam.B - net.trainParam.rho; - else - net.trainParam.A = 3 + net.trainParam.C; - net.trainParam.B = net.trainParam.A + net.trainParam.rho; - end + if net.trainParam.K == 0 + net.trainParam.B = 3 + net.trainParam.C; + net.trainParam.A = net.trainParam.B - net.trainParam.rho; else - net.trainParam.Np = net.trainParam.N - 1 + 3 / net.trainParam.C - (net.trainParam.N - 4)*(net.trainParam.F/net.trainParam.C)*net.trainParam.dL + 1; + net.trainParam.A = 3 + net.trainParam.C; + net.trainParam.B = net.trainParam.A + net.trainParam.rho; + end - net.trainParam.B = 3 + net.trainParam.F*(net.trainParam.dU*(net.trainParam.N - 2) - net.trainParam.dL*(net.trainParam.N - 4)) - net.trainParam.C + 2*net.trainParam.C; - net.trainParam.A = net.trainParam.B - net.trainParam.D*net.trainParam.dL - net.trainParam.F*net.trainParam.dU; - - end - net.trainParam = orderfields(net.trainParam); else net.trainFcn = 'trainty'; @@ -42,4 +34,4 @@ 'Please, train the network using train(net)']); end -end \ No newline at end of file +end diff --git a/@tsphopfieldnet/tsphopfieldnet.m b/@tsphopfieldnet/tsphopfieldnet.m index 1714a6b..f4cba52 100644 --- a/@tsphopfieldnet/tsphopfieldnet.m +++ b/@tsphopfieldnet/tsphopfieldnet.m @@ -7,7 +7,7 @@ end methods (Sealed = true) - function net = tsphopfieldnet(networkSize, networkParameters, options) + function net = tsphopfieldnet(networkSize, networkParameter, options) if nargin < 2 || nargin > 3 error('tsphopfieldnet:IncorrectInputArguments','Please provide proper input arguments to tsphopfieldnet: networkSize, C (and options)'); @@ -15,19 +15,13 @@ % networkSize assertion done in hopfieldnetwork constructor assert(networkSize > 1, 'tsphopfieldnet:invalid_value', '''networkSize'' must be greater than 2.'); - assert(numel(networkParameters) > 0 & numel(networkParameters) <= 2, 'networkParameters must be 1 or 2: ''C'' or ''C and F''.') + assert(numel(networkParameter) == 1, 'networkParameters must be 1: ''C''.') - C = networkParameters(1); + C = networkParameter(1); assert(isa(C,'double'), 'tsphopfieldnet:invalid_datatype', '''C'' must be double.'); assert(C > 0, 'tsphopfieldnet:invalid_value', '''C'' must be greater than 0.'); - % If using parameter F in the model - if numel(networkParameters) > 1 - F = networkParameters(2); - assert(isa(F,'double'), 'tsphopfieldnet:invalid_datatype', [F, ' must be double.']); - assert(F >= 0, 'tsphopfieldnet:invalid_value', '''F'' must be greater than or equal to 0.'); - end - end + end if nargin < 3 options = tsphopfieldnet.createOptions(); @@ -53,13 +47,10 @@ net.cities = orderfields(net.cities); net.trainParam.C = C; - if exist('F','var') - net.trainParam.F = F; - end -% if size(net.cities.coords,1) ~= net.trainParam.N -% error('Mismatch between number of coordinates, distance matrix and neurons'); -% end + if size(net.cities.coords,1) ~= net.trainParam.N + error('Mismatch between number of coordinates, distance matrix and neurons'); + end % Initialize results; net = init(net); @@ -75,6 +66,7 @@ net = verifyIfValidSubtours(net); [net,V,U] = fixedCities(net); thisCity = city(net,cityPosition); + [modifiedDistance,Ng] = neighbourDistance(net, tau_or_p); end methods (Hidden = true, Access = protected) @@ -89,7 +81,6 @@ p = modulo(m,n); loggingV(iter,V,dU); chain = createChain(cities); - [modifiedDistance,Ng] = neighbourDistance(net, tau_or_p); end methods (Static = true, Hidden = true, Access = protected) diff --git a/Hopfield Net TSP solver.prj b/Hopfield Net TSP solver.prj index 6ce4acb..c02650d 100644 --- a/Hopfield Net TSP solver.prj +++ b/Hopfield Net TSP solver.prj @@ -1,5 +1,5 @@ - + Hopfield Net TSP solver Lucas García Rodríguez lucasgarciarodriguez@ucm.es @@ -26,11 +26,11 @@ Find more information in the documentation of the toolbox or in the <a href=" 19 - 8.6 - 10.1 + 9.0 + 10.2 - E:\Users\Lucas\Documents\GitHub\HopfieldNetworkToolbox + E:\Users\Lucas\Documents\Math\PhD\sandbox\hopfield_network\trunk\code d605def3-3010-4890-ac40-cf704be9aed1 @@ -338,36 +338,36 @@ Find more information in the documentation of the toolbox or in the <a href=" - E:\Users\Lucas\Documents\GitHub\HopfieldNetworkToolbox + E:\Users\Lucas\Documents\Math\PhD\sandbox\hopfield_network\trunk\code - C:\Program Files\MATLAB\R2015b + C:\Program Files\MATLAB\R2016a - - + + - + true - + - + true - + - + true - + - + true - + @@ -379,7 +379,7 @@ Find more information in the documentation of the toolbox or in the <a href=" false false false - 6.1 + 6.2 false true win64 diff --git a/Hopfield Network Toolbox.prj b/Hopfield Network Toolbox.prj index ecd6a65..e89c5cb 100644 --- a/Hopfield Network Toolbox.prj +++ b/Hopfield Network Toolbox.prj @@ -1,5 +1,5 @@ - + Hopfield Network Toolbox Lucas García Rodríguez lucasgarciarodriguez@ucm.es @@ -7,20 +7,11 @@ A Hopfield Network Toolbox for MATLAB The Hopfield Network Toolbox can solve combinatorial optimization problems by using Hopfield Neural Networks. The Hopfield Network Toolbox is focused in Continuous Hopfield Networks. ${PROJECT_ROOT}\help\html\hopfieldnet.png - 1.1.1 + 1.1.2 ${PROJECT_ROOT}\Hopfield Network Toolbox.mltbx - - MATLAB - Statistics and Machine Learning Toolbox - - - 1 - 19 - - - 8.6 - 10.1 - + + + 9468a56e-2dfa-48c1-b681-f168f0815c88 % List files contained in your toolbox folder that you would like to exclude @@ -54,35 +45,35 @@ BuildInstructions.m <exampleCategory name="Solving the Traveling Salesman Problem using Hopfield Networks"> <example name="Solving the TSP with cities in Polygon Vertices" type="html"> <file type="source">/help/html/Example_tspUsingRegularPolygons.html</file> - <file type="main">/help/Example_tspUsingRegularPolygons.m</file> + <file type="main">E:/Users/Lucas/Documents/MATLAB/Add-Ons/Toolboxes/Hopfield Network Toolbox/code/help/Example_tspUsingRegularPolygons.m</file> <file type="thumbnail">/help/html/Example_tspUsingRegularPolygons.png</file> <file type="image">/help/html/Example_tspUsingRegularPolygons_01.png</file> <file type="image">/help/html/Example_tspUsingRegularPolygons_02.png</file> </example> <example name="Solving the TSP with TSPLIB cities" type="html"> <file type="source">/help/html/Example_tspUsingTSPLIB.html</file> - <file type="main">/help/Example_tspUsingTSPLIB.m</file> + <file type="main">E:/Users/Lucas/Documents/MATLAB/Add-Ons/Toolboxes/Hopfield Network Toolbox/code/help/Example_tspUsingTSPLIB.m</file> <file type="thumbnail">/help/html/Example_tspUsingTSPLIB.png</file> <file type="image">/help/html/Example_tspUsingTSPLIB_01.png</file> <file type="image">/help/html/Example_tspUsingTSPLIB_02.png</file> </example> <example name="Solving the TSP provided the problem's coordinates" type="html"> <file type="source">/help/html/Example_tspUsingCoords.html</file> - <file type="main">/help/Example_tspUsingCoords.m</file> + <file type="main">E:/Users/Lucas/Documents/MATLAB/Add-Ons/Toolboxes/Hopfield Network Toolbox/code/help/Example_tspUsingCoords.m</file> <file type="thumbnail">/help/html/Example_tspUsingCoords.png</file> <file type="image">/help/html/Example_tspUsingCoords_01.png</file> <file type="image">/help/html/Example_tspUsingCoords_02.png</file> </example> <example name="Solving the TSP provided the distance matrix" type="html"> <file type="source">/help/html/Example_tspUsingDistance.html</file> - <file type="main">/help/Example_tspUsingDistance.m</file> + <file type="main">E:/Users/Lucas/Documents/MATLAB/Add-Ons/Toolboxes/Hopfield Network Toolbox/code/help/Example_tspUsingDistance.m</file> <file type="thumbnail"/> </example> </exampleCategory> <exampleCategory name="Improving Hopfield Network performance when applied to the TSP"> <example name="Reduce the free parameter C" type="html"> <file type="source">/help/html/Example_tspReducingC.html</file> - <file type="main">/help/Example_tspReducingC.m</file> + <file type="main">E:/Users/Lucas/Documents/MATLAB/Add-Ons/Toolboxes/Hopfield Network Toolbox/code/help/Example_tspReducingC.m</file> <file type="thumbnail">/help/html/Example_tspReducingC.png</file> <file type="image">/help/html/Example_tspReducingC_01.png</file> <file type="image">/help/html/Example_tspReducingC_02.png</file> @@ -90,12 +81,12 @@ BuildInstructions.m </example> <example name="Appropriate starting point" type="html"> <file type="source">/help/html/Example_tspSaddlePoint.html</file> - <file type="main">/help/Example_tspSaddlePoint.m</file> + <file type="main">E:/Users/Lucas/Documents/MATLAB/Add-Ons/Toolboxes/Hopfield Network Toolbox/code/help/Example_tspSaddlePoint.m</file> <file type="thumbnail"/> </example> <example name="A Divide-and-Conquer Scheme" type="html"> <file type="source">/help/html/Example_tspDivideConquer.html</file> - <file type="main">/help/Example_tspDivideConquer.m</file> + <file type="main">E:/Users/Lucas/Documents/MATLAB/Add-Ons/Toolboxes/Hopfield Network Toolbox/code/help/Example_tspDivideConquer.m</file> <file type="thumbnail">/help/html/Example_tspDivideConquer.png</file> <file type="image">/help/html/Example_tspDivideConquer_01.png</file> </example> @@ -106,23 +97,29 @@ BuildInstructions.m ${PROJECT_ROOT}\Hopfield Net TSP solver.mlappinstall ${PROJECT_ROOT}\help\info.xml + + + + + - E:\Users\Lucas\Documents\GitHub\HopfieldNetworkToolbox + E:\Users\Lucas\Documents\Math\PhD\sandbox\hopfield_network\trunk\code - ${PROJECT_ROOT}\@generichopfieldnet + ${PROJECT_ROOT}\@hopfieldnet ${PROJECT_ROOT}\@hopfieldnetwork ${PROJECT_ROOT}\@tsphopfieldnet ${PROJECT_ROOT}\@tsphopfieldnetApp ${PROJECT_ROOT}\@tsplib ${PROJECT_ROOT}\help ${PROJECT_ROOT}\Hopfield Net TSP solver.mlappinstall - ${PROJECT_ROOT}\LICENSE + ${PROJECT_ROOT}\Phase1_PossibleSaddlePoint + ${PROJECT_ROOT}\ReleaseNotes.txt ${PROJECT_ROOT}\setup_TSPLIB.m ${PROJECT_ROOT}\TSPFiles @@ -130,36 +127,36 @@ BuildInstructions.m - E:\Users\Lucas\Documents\GitHub\HopfieldNetworkToolbox\Hopfield Network Toolbox.mltbx + E:\Users\Lucas\Documents\Math\PhD\sandbox\hopfield_network\trunk\code\Hopfield Network Toolbox.mltbx - C:\Program Files\MATLAB\R2015b + C:\Program Files\MATLAB\R2016a - - + + - + true - + - + true - + - + true - + - + true - + @@ -171,7 +168,7 @@ BuildInstructions.m false false false - 6.1 + 6.2 false true win64 diff --git a/help/html/helptoc.xml b/help/html/helptoc.xml index 3fc56c3..ff8044f 100644 --- a/help/html/helptoc.xml +++ b/help/html/helptoc.xml @@ -49,7 +49,7 @@