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

Issue in PSO? #3

Open
denisbogol opened this issue Mar 27, 2024 · 0 comments
Open

Issue in PSO? #3

denisbogol opened this issue Mar 27, 2024 · 0 comments

Comments

@denisbogol
Copy link

Hi,

I was just studying the code and came across the following function:

  Particle findLBest(int index) {
    std::vector<Particle> neighbours;
    if (index == 0) {
      neighbours.push_back(particles_.back());
    } else {
      neighbours.push_back(particles_[index - 1]);
    }

    if (index == particles_.size() - 1) {
      neighbours.push_back(particles_.front());
    } else {
      neighbours.push_back(particles_[index + 1]);
    }

    Particle lbest = *(std::max_element(neighbours.begin(), neighbours.begin(), Particle::cmp));

    return lbest;
  }

max_element is calling for range neighbours.begin(), neighbours.begin() which doesn't make sense. Moreover, even if you use the full range, there will only be 2 neighboring particles in it, meaning the current particle itself is ignored when calculating the local best.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant