Module: FeldtRuby::Optimize::DE_CrossoverStrategy_Binomial

Included in:
DEOptimizer_Best_1_Bin, DEOptimizer_Rand_1_Bin
Defined in:
lib/feldtruby/optimize/differential_evolution.rb

Overview

This is the classic binomial DE///bin crossover.

Instance Method Summary collapse

Instance Method Details

#crossover_donor_and_target(targetVector, donorVector, targetVectorIndex) ⇒ Object



133
134
135
136
137
138
139
140
141
142
# File 'lib/feldtruby/optimize/differential_evolution.rb', line 133

def crossover_donor_and_target(targetVector, donorVector, targetVectorIndex)
	num_variables = donorVector.size
	jrand = rand_int(num_variables)
	trial_vector = targetVector.clone.to_a		# We use the targetVector values as a starting point
	trial_vector[jrand] = donorVector[jrand]	# Always copy one random var to ensure some difference.
	num_variables.times do |j|
		trial_vector[j] = donorVector[j] if rand() <= crossover_rate(j) # Copy with crossover_rate probability
	end
	candidate_from_array(trial_vector)
end