Scilab Home Page | Wiki | Bug Tracker | Forge | Mailing List Archives | Scilab Online Help | File Exchange
ATOMS : Particle Swarm Optimization Toolbox details
Login with GitLab

Particle Swarm Optimization Toolbox

The PSO on Scilab
(13730 downloads for this version - 25935 downloads for all versions)
Details
Version
0.8
Author
Sébastien SALMON
Owner Organization
Optimization Command & Control Systems
Maintainers
Samuel Gougeon
Michael BAUDIN
sebastien salmon
Administrator ATOMS
Dependency
Creation Date
July 12, 2018
Source created on
Scilab 6.0.x
Binaries available on
Scilab 5.5.x:
Windows 64-bit Windows 32-bit Linux 64-bit Linux 32-bit macOS
Scilab 6.0.x:
Windows 64-bit Windows 32-bit Linux 64-bit Linux 32-bit macOS
Scilab 6.1.x:
Windows 64-bit Windows 32-bit Linux 64-bit Linux 32-bit macOS
Install command
--> atomsInstall("PSO")
Description
            
PURPOSE
-------
This document introduces the Particle Swarm Optimization (PSO) in Scilab. 

The PSO method, published by Kennedy and Eberhart in 1995, is based on a
population of points at first stochastically deployed on a search field.

Each member of this particle swarm could be a solution of the optimization
problem. 

This swarm flies in the search field (of D dimensions) and each member of it is
attracted by its personal best solution and by the best solution of its
neighbours. Each particle has a memory storing all data relating to its flight
(location, speed and its personal best solution). 

It can also inform its neighbours, i.e. communicate its speed and position. This
ability is known as socialisation. For each iteration, the objective function is
evaluated for every member of the swarm. 

Then the leader of the whole swarm can be determined: it is the particle with
the best personal solution. The process leads at the end to the best global
solution. 

This direct search method does not require any knowledge 
of the objective function derivatives.

The PSO is a meta-heuristic optimization process created by Kennedy and Eberhart
in 1995.

Three PSO are implanted in this toolbox : 
 * the "Inertia Weight Model" by Shi & Eberhart in 1998, 
 * the "Radius",
 * the "BSG-Starcraft" by the author.

AUTHOR
------
Sébastien Salmon was a mecatronics research engineer and a PhD. student at the
M3M - UTBM. 
He uses the PSO for actuator optimization and inverse parameter identification.
Now, he is creating its own company specialized in optimization.

Please cite the author when using modificated PSO (Radius and/or
BSG-Starcraft).
Please contact the author if your are satisfied of this works (or not) and if
you find some bugs ;) . 

Dependencies
------------
This module depends on the apifun module.

Bibliography
------------
 * Kennedy, J. and Eberhart, R. C. (1995). Particle swarm optimization.  Proc.
IEEE Int'l. Conf. on Neural Networks, IV, 1942–1948.  Piscataway, NJ: IEEE
Service Center.
 * Shi, Y. and Eberhart, R. C. (1998a). Parameter selection in particle swarm
optimization.  In Evolutionary Programming VII: Proc. EP98, New York:
Springer-Verlag, pp. 591-600.
 * Shi, Y. and Eberhart, R. C. (1998b).  A modified particle swarm optimizer. 
Proceedings of the IEEE International Conference on Evolutionary Computation,
69-73. Piscataway, NJ: IEEE Press.
 * Salmon, S. (May 2012), Caractérisation, identification et optimisation des
systèmes mécaniques complexes par mise en œuvre de simulateurs hybrides
matériels/logiciels, PhD Thesis, UTBM, Belfort, France.

Authors
-------
 * Copyright (C) 2012 - Optimization Command & Control Systems - Sebastien
Salmon
 * Copyright (C) 2010 - 2012 - M3M - UTBM - Sebastien Salmon
 * Copyright (C) 2011 - DIGITEO - Michael Baudin

Licence
-------
Released in Creative Commons CC-BY-NC-SA.
http://creativecommons.org/licenses/by-nc-sa/2.0/

CHANGES 0.7 => 0.8
==================
* First binary releases for Scilab 5.5 and for Scilab 6.0
* builder.sce can now build with both Scilab 5 and Scilab 6
* The dependence on the apifun module was not formally set
* PSO.start now checks that apifun is loaded.
* The library of macros is renamed from PSO_Toolboxlib to PSOlib.
* In PSO_bsg_starcraft() PSO_bsg_starcraft_radius(), 
  PSO_inertial(), and PSO_inertial_radius() :
  - A save('PSO_#_save',..) call was unsafe and unused. It is canceled:
    . pwd() is not always writable.
    . There were some syncronization issues (writing while the same
      file was being closed from the previous save() call).
  - When the provided speed_factor or radius is scalar while a row
    is expected, it was not replicated. Fixed.
            
Files (4)
[156.84 kB]
Source code archive

[94.23 kB]
OS-independent binary for Scilab 5.5.x

[136.89 kB]
OS-independent binary for Scilab 6.0.x

[136.89 kB]
OS-independent binary for Scilab 6.1.x

News (0)
Comments (3)     Leave a comment 
Comment from Mark Dresser -- December 4, 2018, 04:18:14 AM    
I attempted to run the help example for PSO_inertial verbatim on Scilab 6.0.0, Windows 7
x64 and 
got the following error:

at line   138 of function PSO_inertial ( 
C:\Users\MARK\AppData\Roaming\Scilab\SCILAB~1.0\atoms\x64\PSO\0.8\macros\PSO_inertial.sci
line 145 
)
at line    32 of executed file D:\_Work\xxxxxx\xxxxxxx\PSO test.sce

Submatrix incorrectly defined.

Any suggestions?

Thanks. Mark
Answer from Samuel Gougeon -- December 6, 2018, 02:21:48 AM    
Hello Mark,

I am able to reproduce this error with Scilab 6.0.1 on Windows 7 64 bits.
However, it is no longer the case with Scilab 6.0.2- (6.0-branch).

This bug was likely due to a more general Scilab bug that has been recently fixed.
You may try yourself with a more recent Scilab version, as available there:
https://build.scilab.org/view/Scilab%206.0/job/scilab-6.0-windows-64/

Regards
Samuel
Comment from Mark Dresser -- June 12, 2019, 08:23:18 PM    
It has taken a while but I've put together a cost function with correctly formatted 
input and output vectors and am trying to run the optimization function.

After a varying number of iterations, I get this error message:

Iter #22, Fbest=4.638324e+04, gbest=[0.0001384 -0.0001374 4.457D+09]
at line   262 of function PSO_inertial ( 
C:\Users\Mark\AppData\Roaming\Scilab\SCILAB~2.2\atoms\x64\PSO\0.8\macros\PSO_inertial.s
ci line 269 )
at line   174 of executed file D:\_work\Thermal Sequencer\S-H PSO test.sce

min: Wrong type for input argument #1: A real matrix expected.

I am running Scilab 6.0.2 on both Windows 7,64 bit and Windows 10,64 bit and I have 
tried both the PSO_inertial function and the PSO_bsg_starcraft function with similar 
results in all 4 cases.

Sometimes rather than the error message, Scilab just crashes.  On Windows 10, Scilab 
just vanishes without a trace and on Windows 7 I get a Windows message "Scilab 6.0.2 
(GUI) has stopped working..."

The fact that it gets through up to 22 iterations before the error occurs suggests that 
my cost function is not completely wrong.  Scilab shouldn't just crash if my data is 
somehow out of range.

Any thoughts on how to proceed will be welcome.

Mark

Answer from Samuel Gougeon -- June 12, 2019, 08:50:07 PM    
> It has taken a while but I've put together a cost function with correctly formatted 
> input and output vectors and am trying to run the optimization function.
> 
> After a varying number of iterations, I get this error message:
> 
> Iter #22, Fbest=4.638324e+04, gbest=[0.0001384 -0.0001374 4.457D+09]
> at line   262 of function PSO_inertial ( 
> 
C:\Users\Mark\AppData\Roaming\Scilab\SCILAB~2.2\atoms\x64\PSO\0.8\macros\PSO_inertial.s
> ci line 269 )
> at line   174 of executed file D:\_work\Thermal Sequencer\S-H PSO test.sce
> 
> min: Wrong type for input argument #1: A real matrix expected.

You may add a pause just before calling min(), and see what is in the data.
They likely become of type complex. Just disp(isreal(F)), and see max(abs(imag(F))).
In brief, debug ;) The only way to go on, since your input data are not publicly 
available.

> I am running Scilab 6.0.2 on both Windows 7,64 bit and Windows 10,64 bit and I have 
> tried both the PSO_inertial function and the PSO_bsg_starcraft function with similar 
> results in all 4 cases.
> 
> Sometimes rather than the error message, Scilab just crashes.  On Windows 10, Scilab 
> just vanishes without a trace and on Windows 7 I get a Windows message "Scilab
> 6.0.2 
> (GUI) has stopped working..."
> 
> The fact that it gets through up to 22 iterations before the error occurs suggests 
that
> 
> my cost function is not completely wrong.  Scilab shouldn't just crash if my data is 
> somehow out of range.

Sure. Scilab 6.0.x is still VERY unstable. Unfortunately it is not a pure PSO issue.
And for the time being, Scilab 6.1.0-master is even worse.
Answer from Mark Dresser -- June 13, 2019, 05:18:58 PM    
Thanks for the response Samuel.

I got it to work by switching to Scilab v5.5.2 and adding the following code snippet before

calling the min function.
        //---------------------------------------------------
        // Search for the minimum of the swarm
        //---------------------------------------------------
        if ~isreal(F) then
//            save('last F','F','j');
            F = real(F);
//        else    
//            save('real F','F','j');
        end
        [C,I] = min(F(:, :, j));

There are several places it would need to be added to fix all of the PSO variants.  

I was able to see that F is real for several iterations then at some random iteration it 
becomes not real.  I don't understand why it is happening and I'm not sure that my solution
is 
mathematically sound but it seems to work for my data.

Both my test script and my data set are of reasonable size and I can supply them if anyone

wishes to pursue the issue further.

Scilab v6.0.2 is still crashing but not leaving enough evidence for me to determine where
in 
the code it is happening.

Should I be submitting this to bugzilla?

Mark
Comment from Valentin Wiesner -- December 27, 2023, 09:42:23 PM    
Hi, 
I maybe have a dump question, but as I understand, the bounds should mark the max and min
value of the optimization space. Shouldn't be the xopt or the fopt values somewhere in
this range? 

I just tried some numbers to understand the code and the bounds are -100 100 but the
results for xopt are somwhere around -1K to -70M. 

My costf is simply f=sum(x,"c")

Side Note: 
The random generator didn't seem to work so i changed it.
grand('setsd',getdate('s'));      ----->   
grand('setsd',1);

Beside that I changed nothing. 


Running on Scilab 6.1.1
I would be happy to get some help on what I mixed up. 
Leave a comment
You must register and log in before leaving a comment.
Login with GitLab
Email notifications
Send me email when this toolbox has changes, new files or a new release.
You must register and log in before setting up notifications.