Class: DRP::SearchAlgorithms::PSO::ParticleSwarmOptimizer
- Inherits:
-
AbstractParticleSwarmOptimizer
- Object
- AbstractParticleSwarmOptimizer
- DRP::SearchAlgorithms::PSO::ParticleSwarmOptimizer
- Defined in:
- lib/pso.rb
Instance Attribute Summary
Attributes inherited from AbstractParticleSwarmOptimizer
#global_best_error, #global_best_vector
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(swarm_size, vector_size, rebirth = 0.0) ⇒ ParticleSwarmOptimizer
constructor
A new instance of ParticleSwarmOptimizer.
Constructor Details
#initialize(swarm_size, vector_size, rebirth = 0.0) ⇒ ParticleSwarmOptimizer
Returns a new instance of ParticleSwarmOptimizer.
133 134 135 136 137 138 139 |
# File 'lib/pso.rb', line 133 def initialize swarm_size, vector_size, rebirth = 0.0 @global_best_error = VERY_LARGE_NUMBER @num_reborn = (swarm_size * rebirth).to_i @rebirth_index = 0 super swarm_size, vector_size init_particles Particle end |
Instance Method Details
#each ⇒ Object
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/pso.rb', line 141 def each rebirth best_this_time = VERY_LARGE_NUMBER @particles.each do |p| v = p.vector error = yield v if error < @global_best_error @global_best_vector = v.dup @global_best_error = error end if error < best_this_time best_this_time = error end p.optimize error p.roam end #puts best_this_time end |