Code covered by the BSD License  

Highlights from
Neural Network add-in for PSORT

3.66667

3.7 | 3 ratings Rate this file 98 Downloads (last 30 days) File Size: 352 KB File ID: #29565
image thumbnail

Neural Network add-in for PSORT

by

 

28 Nov 2010 (Updated )

This add-in allows a Neural Network to be trained by Particle Swarm Optimization technique.

| Watch this File

File Information
Description

This add-in to the PSO Research toolbox (Evers 2009) aims to allow an artificial neural network (ANN or simply NN) to be trained using the Particle Swarm Optimization (PSO) technique (Kennedy, Eberhart et al. 2001).

This add-in acts like a bridge or interface between MATLAB’s NN toolbox and the PSO Research Toolbox. In this way, MATLAB’s NN functions can call the NN add-in, which in turn calls the PSO Research toolbox for NN training.

This approach to training a NN by PSO treats each PSO particle as one possible solution of weight and bias combinations for the NN (Settles and Rylander ; Rui Mendes 2002; Venayagamoorthy 2003). The PSO particles therefore move about in the search space aiming to minimise the output of the NN performance function.

The author acknowledges that there already exists code for PSO training of a NN (Birge 2005), however that code was found to work only with MATLAB version 2005 and older. This NN-addin works with newer versions of MATLAB till versions 2010a.

HELPFUL LINKS:
1. This NN add-in only works when used with the PSORT found at, http://www.mathworks.com/matlabcentral/fileexchange/28291-particle-swarm-optimization-research-toolbox.

2. The author acknowledges the modification of code used in an old PSO toolbox for NN training found at http://www.mathworks.com.au/matlabcentral/fileexchange/7506.

3. User support and contact information for the author of this NN add-in can be found at http://www.tricia-rambharose.com/

ACKNOWLEDGEMENTS
The author acknowledges the support of advisors and fellow researchers who supported in various ways to better her understanding of PSO and NN which lead to the creation of this add-in for PSO training of NNs. The acknowledged are as follows:
* Dr. Alexander Nikov - Senior lecturer and Head of Usaility Lab, UWI, St. Augustine, Trinidad, W.I. http://www2.sta.uwi.edu/~anikov/
* Dr. Sabine Graf - Assistant Professor, Athabasca University, Alberta, Canada. http://scis.athabascau.ca/scis/staff/faculty.jsp?id=sabineg
* Dr. Kinshuk - Professor, Athabasca University, Alberta, Canada. http://scis.athabascau.ca/scis/staff/faculty.jsp?id=kinshuk
* Members of the iCore group at Athabasca University, Edmonton, Alberta, Canada.

Acknowledgements

Particle Swarm Optimization Toolbox and Particle Swarm Optimization Research Toolbox inspired this file.

Required Products Neural Network Toolbox
MATLAB release MATLAB 7.10 (R2010a)
Other requirements This add-in has been testing and found to work well with MATLAB versions 2008, 2009 and 2010a.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (25)
06 Aug 2014 Ellen

Hi everyone, I also am using this toolbox but get the same error as most of you. I am using Matlab version 2013b. Tricia, could you please assist. Error is as follows:
Error using ==> trainpso at 54
Unrecognized code.
Error in ==> network.subsasgn>setTrainFcn at 2016
net.trainParam = feval(trainFcn,'defaultParam');
Error in ==> network.subsasgn>network_subsasgn at 462
if isempty(err), [net,err]=setTrainFcn(net,trainFcn); end
Error in ==> network.subsasgn at 11
net = network_subsasgn(net,subscripts,v,netname);
Error in ==> NN_training_demo at 20
net.trainFcn = 'trainpso'; %set the NN training function to use a PSO approach.
The name 'trainpso' is used for consistency with previous research (B. Birge,
2005

02 May 2014 Narin Sovann

Hi every body,
I am using Nueral Network add-in for PSORT. it works very well when it trains networks with RegPSO algorithm (George Evers) for the NN_train_demo.m. But when i apply it for my problem, the error of output is quit high (the same input variables for ANNs training by BP algorithms is 1.81% but ANNs training by PSO(RegPSO) is more than 20% not acceptable).
any suggestions, please help

regards,
Narin

04 Aug 2013 Sébastien Martin

A good Toolbox for Matlab 7, I upgraded it to Matlab 8, let me know if you are interested.
Thanks

20 Apr 2013 sehrish

Hello Tricia
I'd like to test out your addin but i get the following error in Matlab 2012a
??? Error using ==> trainpso at 54
Unrecognized code.
Error in ==> network.subsasgn>setTrainFcn at 2016
net.trainParam = feval(trainFcn,'defaultParam');
Error in ==> network.subsasgn>network_subsasgn at 462
if isempty(err), [net,err]=setTrainFcn(net,trainFcn); end
Error in ==> network.subsasgn at 11
net = network_subsasgn(net,subscripts,v,netname);
Error in ==> NN_training_demo at 20
net.trainFcn = 'trainpso'; %set the NN training function to use a PSO approach.
The name 'trainpso' is used for consistency with previous research (B. Birge,
2005)
How to fix this error?

12 Feb 2013 AMINU

Hi
am using NN_training_demo nad getting the same problem with psotrain it seems unidentifed by NN toolbox. i run it on matlab 2012a. my PSO toolbox was obtained from the same link provided above by Tricia. please help

03 Sep 2012 Muhammad Qamar RAZA

Dear Tricia Rambharose
i am also using same toolbox and your add in but i facing some many errors.
when i compile trainpso file that gives
trainpso
Error using trainpso (line 25)
Not enough input arguments.
(in code)
function [net, tr] = trainpso(net, tr, trainV, valV, testV, varargin)

and when i use this tool box to train the network for my own model even working on trainlm but doesn't work on trainpso and gives following error.

SWITCH expression must be a scalar or string constant.

Error in network/subsref (line 140)
switch (subs)

Error in trainpso (line 65)
max_perf_inc = net.trainParam.max_perf_inc;

Error in LoadScriptNN (line 84)
net = trainpso(net, trainX', trainY');

pleas reply me asap.
i am very very very grateful to you for this.
i am waiting for reply

Thank you

26 May 2012 anjaneya

hi tricia,
whats the expected performance goal for a network trained by PSO so that a correlation coefficient of 0.97 can be achieved?

21 Dec 2011 rekoba

hi Tricia thanks for you code but i have this error

??? Error using ==> trainpso at 54
Unrecognized code.

Error in ==> network.subsasgn>setTrainFcn at 2016
net.trainParam = feval(trainFcn,'defaultParam');

Error in ==> network.subsasgn>network_subsasgn at 462
if isempty(err),
[net,err]=setTrainFcn(net,trainFcn); end

Error in ==> network.subsasgn at 11
net = network_subsasgn(net,subscripts,v,netname);

Error in ==> NN_training_demo at 20
net.trainFcn = 'trainpso'; %set the NN training
function to use a PSO approach. The name 'trainpso' is
used for consistency with previous research (B. Birge,
2005)

30 Nov 2011 chan

Hi Tricia,

Thank for ur reply. i tried to run the original code again but still get error~ ==''

========================================
Neural Network (NN) settings:
NN training function:trainpso
NN layers:2
NN training goal:0.001
NN maximum epochs:1000
NN maximum time:Inf
Plot PSO training:1
AUTOMATIC INPUT VALIDATION

Switch "OnOff_graph_fg_mean" is active, but "num_trials" == 1. In other words, you have chosen to graph the mean function value per iteration over multiple trials, but no mean will be generated since only one trial is to be conducted. The graph of mean behavior will not take effect. If your intention was to graph the function value of the global best over one trial, please activate switch "OnOff_graph_fg" instead.

Any of graphing switches "OnOff_graph_ObjFun_f_vs_2D", "OnOff_swarm_trajectory", or "OnOff_phase_plot" which were active have been de-activated since they are not yet compatible with the NN objective. You may subscribe to updates at www.georgeevers.org/pso_research_toolbox.htm to be notified when this functionality becomes available.

Since "OnOff_swarm_trajectory," "OnOff_phase_plot," or "OnOff_graph_x" is active, "OnOff_xhist" has been activated automatically so that "xhist" will be maintained from which to generate the desired graph(s).

PSO settings:
Local Best (Lbest) PSO
35 iterations maximum
Position clamping inactive.
Velocity reset inactive.
Velocities clamped to 50% of the range on each dimension.
History, "ghist," of global bests active.
History, "lhist," of local bests active.
History, "phist," of personal bests active.
History, "fhist," of all function values active.
History, "xhist," of all positions active.
History, "vhist," of all velocities active.
1 trial(s)
5 particles
Inertia weight linearly varied from 0.9 to 0.4 per grouping.
Cognitive acceleration coefficient, c1: 1.49618
Social acceleration coefficient, c2: 1.49618
NN: 9 dimensions
Symmetric Initialization: [-1,1]
Threshold required for success: 0
"OnOff_Terminate_Upon_Success" inactive.

??? Undefined function or method 'RandStream' for input arguments of type 'char'.

Error in ==> Reg_Methods_0And1 at 16
RandStream.setDefaultStream ...

Error in ==> RegPSO_main at 240
Reg_Methods_0And1

Error in ==> Display_Settings at 236
RegPSO_main

Error in ==> Input_Validation at 304
Display_Settings
Error in ==> Objectives at 298
Input_Validation

Error in ==> Control_Panel at 584
Objectives %This script associates handle "ObjFun" with the

Error in ==> trainpso at 110
Control_Panel; % Call to PSO Research Toolbox

Error in ==> network.train at 219
[net,tr] = feval(net.trainFcn,net,tr,trainV,valV,testV);

Error in ==> NN_training_demo at 32
[net,tr] = train(net,P,T); %train NN

>>
=========================================

i did not make any modification and just follow the instructions inside README.pdf.

How? Please help me..Thank Thank~

23 Nov 2011 Tricia Rambharose

Hi Chan,

I tried the code again with Matlab 2008a and it works fine for me. Your error simply means that in the function 'trainpso.m' the variable 'net' can not be found or read. This will happen if a call to 'clear net' or 'clear all' was made.

I advise you to train using the original code again and becareful when making modifications.

Good luck!

22 Nov 2011 chan

Hi Tricia,

Thanks for this. I am using Matlab R2008a
while running this code, I am getting this error.

??? Reference to a cleared variable net.

Error in ==> trainpso at 113
net = setx(net, NN_wb);%Set network with new weights and bias

Error in ==> network.train at 219
[net,tr] = feval(net.trainFcn,net,tr,trainV,valV,testV);

Error in ==> NN_training_demo at 32
[net,tr] = train(net,P,T); %train NN

AND i already try several times the solution below:
1. Download the PSO toolbox at http://www.mathworks.com/matlabcentral/fileexchange/28291-particle-swarm-optimization-research-toolbox.
2. Unzip the downloaded file.
3. On the MATLAB interface go to file -> set path -> add with subfolders. Then find the location of the unzipped downloaded file. -> Save

BUT, still get same errors. Please help me

Kind regards
chan

13 Oct 2011 ondrej

regarding the error:

??? Undefined function or variable "g".

Error in ==> trainpso at 112
....

Hey Tricia
the thing is I dont know how I fixed it .

I am only aware I just once again set paths. And it worked. But I
definitely did that a couple of times before.
So there is not much to share there.

I hoped the addin would allow me for metaoptimization e.g. finding an
optimal learning rate, momentum etc.
As a learner it underperformes the best learning algs that are part of
the mworks nn toolbox ;(
maybe its just upon my datasets.

But thx again for making it available appreciated. U can republish
this on fileexchange if u want (or i can do it if u like(?)).

br
O

28 Sep 2011 sheetal kundra

hii tricia

i executed ur neural network addin for pso on matlab version R2010a. but got following error. see if u can help me out

??? Undefined function or variable "g".

Error in ==> trainpso at 112
NN_wb = g(1, :); %g hold the position vector of the PSO result. Each call
to RegPSO_main clears the values in g

Error in ==> network.train at 216
[net,tr] = feval(net.trainFcn,net,tr,trainV,valV,testV);

Error in ==> NN_training_demo at 32
[net,tr] = train(net,P,T); %train NN

18 Jul 2011 Abdullah M. Hafiz

Ok, I figured that out. It's just the issue with the older version that I am not having with the newer one. Please ignore my previous email.

Thanks very much for your NN add-in :)

12 Jul 2011 ondrej

hi Tricia have u figured out that BUG?

11 Jul 2011 Abdullah M. Hafiz

Hello Tricia,

I am using Matlab 7.6.0 R2008a .

I am getting this error, while running this code:

??? Undefined function or method 'RandStream' for input arguments of type 'char'.

Error in ==> Reg_Methods_0And1 at 16
RandStream.setDefaultStream ...

Error in ==> RegPSO_main at 240
Reg_Methods_0And1

Error in ==> Display_Settings at 236
RegPSO_main

Error in ==> Input_Validation at 304
Display_Settings
Error in ==> Objectives at 298
Input_Validation

Error in ==> Control_Panel at 584
Objectives %This script associates handle "ObjFun" with the

Error in ==> trainpso at 110
Control_Panel; % Call to PSO Research Toolbox

Error in ==> network.train at 219
[net,tr] = feval(net.trainFcn,net,tr,trainV,valV,testV);

Error in ==> NN_training_demo at 32
[net,tr] = train(net,P,T); %train NN

Could you please let me know, how to resolve it. Your prompt reply would greatly be appreciated.

Regards,
Abdullah

28 Jun 2011 Tricia Rambharose

Thanks for informing me of this error. I will work on this and get back to you asap.

28 Jun 2011 ondrej

Hi Tricia,
got the same error as Krystian

one more thing i tested it on matlab 2009b, 2011a (win7 32bit)...same thing

28 Jun 2011 ondrej

ehm I just noticed Krystian has the same problem,
one more thing i tested it on matlab 2009b, 2011a (win7 32bit)...same thing

21 Jun 2011 Tricia Rambharose

Hi Krystian,

Thank you for the question. Yes it seems to be a small compatibility issue. By now have you fixed this? If not I will work on fixing it asap and get back to you.

21 Mar 2011 Krystian

Hello Tricia

I'd like to test out your addin but i get the following error in Matlab 2010b

??? Error using ==> trainpso at 54
Unrecognized code.

Error in ==> network.subsasgn>setTrainFcn at 2016
net.trainParam = feval(trainFcn,'defaultParam');

Error in ==> network.subsasgn>network_subsasgn at 462
if isempty(err), [net,err]=setTrainFcn(net,trainFcn); end

Error in ==> network.subsasgn at 11
net = network_subsasgn(net,subscripts,v,netname);

Error in ==> NN_training_demo at 20
net.trainFcn = 'trainpso'; %set the NN training function to use a PSO approach.
The name 'trainpso' is used for consistency with previous research (B. Birge,
2005)

I think thats a compatiblity issue with the latest NN Toolbox. I compared your 'trainpso' with 'trainlm' and they have a different arguments. Do you have any idea how to fix this problem

Best Regards
Krystian

21 Mar 2011 Krystian

I meant 2010b of course :)

07 Dec 2010 Tricia Rambharose

Hi Manish,

You get this error because you need to download the PSO toolbox and set the path in MATLAB. This is explained in the README file in this add-in, however for your convenience here is what you need to do to fix this error:
1. Download the PSO toolbox at http://www.mathworks.com/matlabcentral/fileexchange/28291-particle-swarm-optimization-research-toolbox.

2. Unzip the downloaded file.

3. On the MATLAB interface go to file -> set path -> add with subfolders. Then find the location of the unzipped downloaded file. -> Save

By following these steps MATLAB should recognise the Control_panel function.

Lte me know if this helps.

07 Dec 2010 Manish

Hi Tricia,

Thanks for this. I am using Matlab 2009 7.9.0 R2009b .

while running this code, I am getting this error.

Undefined function or variable 'Control_Panel'.

Error in ==> trainpso at 110
Control_Panel; % Call to PSO Research Toolbox

Error in ==> network.train at 216
[net,tr] =
feval(net.trainFcn,net,tr,trainV,valV,testV);

Error in ==> NN_training_demo at 32
[net,tr] = train(net,P,T); %train NN

Could you let me know.

Kind regards
Manish

29 Nov 2010 Tricia Rambharose

Good day users,

As stated in the description, this NN add-in facilitates NN training by PSO. This add-in was created for use with the PSO toolbox found at http://www.mathworks.com/matlabcentral/fileexchange/28291-particle-swarm-optimization-research-toolbox.

For more information about my research interest see http://www.tricia-rambharose.com/

Please feel free to contact me for support on NN training using PSO.

Regards,
Tricia

Updates
09 Jan 2011

Updates made to include an acknowledgements section of the description.

11 Jan 2011

Updated job titles of Acknowledged professors.

Contact us