Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Particle Swarm Optimization refactor #68

Merged
merged 14 commits into from
Nov 11, 2022

Conversation

Garion9
Copy link
Collaborator

@Garion9 Garion9 commented Nov 10, 2022

Description

Done a big refactor of PSO Algorithm, including better consistency with other algorithms, better logging through probes, parallelisation (simple, but still) and code comments with explanations and examples.

Linked issues

Possibly closes #10 and closes #13

Important implementation details

I'm quite happy with how Probes for PSO turned out - I believe they offer quite a lot of flexibility in terms of logging algorithm's results.

Copy link
Collaborator

@kkafar kkafar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job 🎉

I left some notes below but generally it can be shipped.

Moreover I want to discuss following topics:

Probe implementation

I really like your idea to use composition to separate logging policy (time based, iteration based, etc.) from logging format (csv, json, etc.). I believe this it the way to go and maybe we should consider moving this code from pso module to some common / shared or something like that, because other algorithms could also make use of that.

The problem I have is that we are storing information from each generation in RAM and this could lead to some big issues with memory efficiency. Imagine that some computation is running for couple of days with logger granularity of 10 generations => I'm not sure, but I can see it meaning few GBs of RAM being occupied only by logging system. I can also see why it is bad idea to flush data to file every single time we get log request -- this could lead to massive performance penalties. Generally I think that we should go for some kind of middle ground like batching. We could store some arbitrary number of log records in buffer and dump it to disk only after buffer is full.

This comment applies to whole logging system and concerns every algorithm.

I would also prefer to create separate issue (task) for this and discuss the topic further there, rather than introducing more changes in this PR as it already is big and touches more than one thing (PSO, probes, examples...).

use crate::ga::*;
use crate::pso::*;
use crate::ff::*;
use crate::ff::auxiliary::*;
use crate::ff::probe::console_probe::ConsoleProbe;
use crate::pso::builder::PSOAlgorithmBuilder;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's completely fine for now, but I'm leaving this comment to remind us that we should discuss naming conventions. E.g. whether we should name it pso::builder::PSOAlgorithmBuilder or pso::builder::Builder. Same goes for calling our algorithm's implementations literally "Algorithm": "PSOAlgorithm" instead of just "PSO". The same considerations apply to every other algorithm. I will consider starting a discussion on this topic.

src/pso.rs Outdated Show resolved Hide resolved
src/pso/builder.rs Outdated Show resolved Hide resolved
src/pso/probe/iteration_count_probe.rs Outdated Show resolved Hide resolved
src/pso/probe/mod.rs Outdated Show resolved Hide resolved
src/pso/probe/multi_probe.rs Outdated Show resolved Hide resolved
src/pso/probe/timed_probe.rs Outdated Show resolved Hide resolved
for i in 0..self.particles.len() {
self.particles[i].update_velocity(&self.best_position, inertia_weight, cognitive_coefficient, social_coefficient);
}
self.particles.par_iter_mut()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we can leave it for now, but I think we should left parallelization out until we have some benchmarking system implemented. Moreover we should discuss introduction of parallelism with our client, to discuss whether there are any expectations.

}

impl CsvProbe {
pub fn new(generations: usize) -> CsvProbe {
pub fn new(filename: &'static str) -> CsvProbe {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it would be fine to take ownership here, but it is up to you.

Garion9 and others added 6 commits November 11, 2022 18:36
Co-authored-by: Kacper Kafara <kacperkafara@gmail.com>
Co-authored-by: Kacper Kafara <kacperkafara@gmail.com>
Co-authored-by: Kacper Kafara <kacperkafara@gmail.com>
Co-authored-by: Kacper Kafara <kacperkafara@gmail.com>
Co-authored-by: Kacper Kafara <kacperkafara@gmail.com>
Co-authored-by: Kacper Kafara <kacperkafara@gmail.com>
@Garion9 Garion9 merged commit 5610b7c into master Nov 11, 2022
@Garion9 Garion9 deleted the particle_swarm_optimization_refactor branch November 11, 2022 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Code documentation for PSO Finish loggers for pso
2 participants