|
291 | 291 | alpha_operator, _ = create_operator_masks(gene_seq_alpha, gene_seq_alpha, pb) |
292 | 292 | mutation_seq_1 = generate_chromosome(chromosome1.toolbox) |
293 | 293 |
|
294 | | - |
295 | 294 | @inbounds @simd for i in eachindex(gene_seq_alpha) |
296 | 295 | gene_seq_alpha[i] = alpha_operator[i] == 1 ? mutation_seq_1.genes[i] : gene_seq_alpha[i] |
297 | 296 | end |
|
311 | 310 |
|
312 | 311 | @inline function reverse_insertion!(chromosome::Chromosome) |
313 | 312 | start_1 = rand(chromosome.toolbox.gen_start_indices) |
314 | | - insert_pos = rand(start_1:(start_1+chromosome.toolbox.head_len-1)) |
315 | | - insert_sym = rand(chromosome.toolbox.tailsyms) |
316 | | - chromosome.genes[insert_pos] = insert_sym |
| 313 | + rolled_array = circshift(chromosome.genes[start_1:chromosome.toolbox.head_len-1], rand(1:chromosome.toolbox.head_len-1)) |
| 314 | + chromosome.genes[start_1:chromosome.toolbox.head_len-1] = rolled_array |
317 | 315 | end |
318 | 316 |
|
319 | 317 | @inline function compute_fitness(elem::Chromosome, operators::OperatorEnum, x_data::AbstractArray{T}, y_data::AbstractArray{T}, loss_function::Function, |
|
334 | 332 | @inline function genetic_operations!(space_next::Vector{Chromosome}, i::Int, toolbox::Toolbox) |
335 | 333 | #allocate them within the space - create them once instead of n time |
336 | 334 | space_next[i:i+1] = replicate(space_next[i], space_next[i+1], toolbox) |
337 | | - rand_space = rand(11) |
| 335 | + rand_space = rand(13) |
338 | 336 |
|
339 | 337 |
|
340 | 338 | if rand_space[1] < toolbox.gep_probs["one_point_cross_over_prob"] |
|
380 | 378 | if rand_space[11] < toolbox.gep_probs["inversion_prob"] |
381 | 379 | gene_insertion!(space_next[i+1]) |
382 | 380 | end |
| 381 | + |
| 382 | + if rand_space[12] < toolbox.gep_probs["inversion_prob"] |
| 383 | + reverse_insertion!(space_next[i]) |
| 384 | + end |
| 385 | + |
| 386 | + if rand_space[13] < toolbox.gep_probs["inversion_prob"] |
| 387 | + reverse_insertion!(space_next[i+1]) |
| 388 | + end |
| 389 | + |
383 | 390 | end |
384 | 391 |
|
385 | 392 | function runGep(epochs::Int, |
|
0 commit comments