Skip to content

Commit e10be15

Browse files
author
Maximilian Reißmann
committed
refine transpos
1 parent 0cf6d05 commit e10be15

File tree

2 files changed

+46
-4
lines changed

2 files changed

+46
-4
lines changed

src/Entities.jl

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,40 @@ end
697697
end
698698

699699

700+
"""
701+
gene_transposition!(chromosome::Chromosome, len::Int=5)
702+
703+
Swaps two small segments of genes between two positions within the same chromosome, preserving their order but changing their context. This implements a swap to achieve transposition by exchanging the source and target regions.
704+
705+
# Arguments
706+
- `chromosome::Chromosome`: Target chromosome (mutable struct)
707+
- `len::Int=3`: Length of segment to transpose (default: 5)
708+
709+
"""
710+
@inline function gene_transposition!(chromosome::Chromosome, len::Int=5)
711+
toolbox = chromosome.toolbox
712+
head_len = toolbox.head_len
713+
gene_len = head_len * 2 + 1
714+
gen_start_indices = toolbox.gen_start_indices
715+
716+
# Get start positions
717+
source_start = rand(gen_start_indices)
718+
target_start = rand(gen_start_indices)
719+
720+
# Ensure segment length is valid
721+
segment_len = min(len, gene_len - 1)
722+
723+
# Randomly select source and target positions within gene bounds
724+
source_pos = rand(source_start+head_len:(source_start + gene_len-segment_len))
725+
target_pos = rand(target_start+head_len:(target_start + gene_len-segment_len))
726+
727+
# Perform in-place swap to avoid allocations
728+
for i in 0:(segment_len - 1)
729+
chromosome.genes[source_pos + i], chromosome.genes[target_pos + i] = deepcopy(chromosome.genes[target_pos + i]), deepcopy(chromosome.genes[source_pos + i])
730+
end
731+
end
732+
733+
700734
"""
701735
genetic_operations!(space_next::Vector{Chromosome}, i::Int, toolbox::Toolbox)
702736
@@ -738,7 +772,7 @@ Modify chromosome genes in place
738772
@inline function genetic_operations!(space_next::Vector{Chromosome}, i::Int, toolbox::Toolbox; generation::Int64, max_generation::Int64, parents::Vector{Chromosome})
739773
#allocate them within the space - create them once instead of n time
740774
space_next[i:i+1] = replicate(space_next[i], space_next[i+1], toolbox)
741-
rand_space = rand(15)
775+
rand_space = rand(20)
742776

743777

744778
if rand_space[1] < toolbox.gep_probs["one_point_cross_over_prob"]
@@ -794,13 +828,21 @@ Modify chromosome genes in place
794828
end
795829

796830
if rand_space[14] < toolbox.gep_probs["reverse_insertion_tail"]
797-
reverse_insertion_tail!(space_next[i+1])
831+
reverse_insertion_tail!(space_next[i])
798832
end
799833

800834
if rand_space[15] < toolbox.gep_probs["reverse_insertion_tail"]
801835
reverse_insertion_tail!(space_next[i+1])
802836
end
803837

838+
if rand_space[16] < toolbox.gep_probs["gene_transposition"]
839+
reverse_insertion_tail!(space_next[i])
840+
end
841+
842+
if rand_space[18] < toolbox.gep_probs["gene_transposition"]
843+
reverse_insertion_tail!(space_next[i+1])
844+
end
845+
804846
end
805847

806848
@inline function prob_equation_djl(chromosome::Chromosome, coeff_count::Int, prob_data_set::AbstractArray)

src/RegressionWrapper.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,10 @@ const GENE_COMMON_PROBS = Dict{String,AbstractFloat}(
267267
"fusion_prob" => 0.0,
268268
"fusion_rate" => 0.0,
269269
"inversion_prob" => 0.1,
270-
"insertion_prob" => 0.0,
270+
"insertion_prob" => 0.1,
271271
"reverse_insertion" => 0.1,
272272
"reverse_insertion_tail" => 0.0,
273-
"gene_transposition" => 0.0,
273+
"gene_transposition" => 0.1,
274274
"gene_averaging_prob" => 0.0,
275275
"gene_averaging_rate" => 0.05,
276276
"mating_size" => 0.7)

0 commit comments

Comments
 (0)