Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Entities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ Updates chromosome's compiled_function and related fields
chromosome.fitness = chromosome.toolbox.fitness_reset[2]
chromosome.compiled = true
catch e
@error "something went wrong" exception = (e, catch_backtrace())
#@error "something went wrong" exception = (e, catch_backtrace())
chromosome.fitness = chromosome.toolbox.fitness_reset[1]
end
end
Expand Down
2 changes: 1 addition & 1 deletion src/Gep.jl
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ The evolution process stops when either:

if epoch < epochs
if length(fits_representation[1]) == 1
selectedMembers = tournament_selection(fits_representation[1:mating_size], mating_size, tourni_size)
selectedMembers = tournament_selection(fits_representation, mating_size, tourni_size)
else
selectedMembers = nsga_selection(fits_representation)
end
Expand Down
14 changes: 7 additions & 7 deletions src/RegressionWrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ Dictionary containing default probabilities and parameters for genetic algorithm
These values can be adjusted to fine-tune the genetic algorithm's behavior.
"""
const GENE_COMMON_PROBS = Dict{String,AbstractFloat}(
"one_point_cross_over_prob" => 0.4,
"one_point_cross_over_prob" => 0.5,
"two_point_cross_over_prob" => 0.3,
"mutation_prob" => 1.0,
"mutation_rate" => 0.1,
Expand All @@ -274,9 +274,9 @@ const GENE_COMMON_PROBS = Dict{String,AbstractFloat}(
"fusion_prob" => 0.1,
"fusion_rate" => 0.2,
"inversion_prob" => 0.1,
"reverse_insertion" => 0.05,
"reverse_insertion_tail" => 0.05,
"mating_size" => 0.5)
"reverse_insertion" => 0.1,
"reverse_insertion_tail" => 0.1,
"mating_size" => 0.7)

const SymbolDict = OrderedDict{Int8,Int8}
const CallbackDict = Dict{Int8,Function}
Expand Down Expand Up @@ -753,8 +753,8 @@ function fit!(regressor::GepRegressor, epochs::Int, population_size::Int, loss_f
optimization_epochs::Int=100,
hof::Int=3,
correction_epochs::Int=1,
correction_amount::Real=0.05,
opt_method_const::Symbol=:cg,
correction_amount::Real=0.3,
opt_method_const::Symbol=:nd,
target_dimension::Union{Vector{Float16},Nothing}=nothing,
cycles::Int=10, max_iterations::Int=150, n_starts::Int=5,
break_condition::Union{Function,Nothing}=nothing
Expand Down Expand Up @@ -827,7 +827,7 @@ function fit!(regressor::GepTensorRegressor, epochs::Int, population_size::Int,
regressor.toolbox_,
evalStrat;
hof=hof,
tourni_size=max(Int(ceil(population_size * 0.03)), 3)
tourni_size=max(Int(ceil(population_size * 0.003)), 3)
)

regressor.best_models_ = best
Expand Down
31 changes: 18 additions & 13 deletions src/Sbp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const FAILURE_RECURSION_SIZE = -21
const STD_DIM_SIZE = 7
const ZERO_DIM = zeros(Float16, STD_DIM_SIZE)
const EMPTY_DIM = Float16[typemax(Float16) for _ in 1:STD_DIM_SIZE]
const F16_LOWER_BOUND = eps(Float16)

using OrderedCollections
using Random
Expand Down Expand Up @@ -126,11 +127,11 @@ function mul_unit_backward(u1::Vector{Float16}, u2::Vector{Float16}, expected_di
elseif has_inf16(u1)
return expected_dim .- u2, u2
else
if isapprox(u1, u2, atol=eps(Float16))
if isapprox(u1, u2, atol=F16_LOWER_BOUND)
lr = expected_dim .- expected_dim .÷ 2
rl = expected_dim .- lr
return lr, rl
elseif isapprox(u1, expected_dim, atol=eps(Float16))
elseif isapprox(u1, expected_dim, atol=F16_LOWER_BOUND)
return u1, expected_dim .- u1
else
return expected_dim .- u2, u2
Expand Down Expand Up @@ -159,11 +160,11 @@ function div_unit_backward(u1::Vector{Float16}, u2::Vector{Float16}, expected_di
elseif has_inf16(u1)
return expected_dim .+ u2, u2
else
if isapprox(u1, u2, atol=eps(Float16))
if isapprox(u1, u2, atol=F16_LOWER_BOUND)
lr = expected_dim .- expected_dim .÷ 2
rl = .-(expected_dim .+ lr)
return lr, rl
elseif isapprox(u1, expected_dim, atol=eps(Float16))
elseif isapprox(u1, expected_dim, atol=F16_LOWER_BOUND)
return u1, .-(expected_dim .+ u1)
else
return expected_dim .+ u2, u2
Expand Down Expand Up @@ -718,6 +719,7 @@ mutable struct TempComputeTree
tokenDto::TokenDto
depend_on_total_number::Int
exchange_len::Int
modified::Bool

function TempComputeTree(symbol::Int8,
depend_on::Vector{T}=Union{TempComputeTree,Int8}[],
Expand All @@ -728,7 +730,7 @@ mutable struct TempComputeTree
vector_dimension,
tokenDto,
length(depend_on),
-1)
-1,true)
end
end

Expand All @@ -750,6 +752,7 @@ function flush!(tree::TempComputeTree)
end

function calculate_vector_dimension!(tree::TempComputeTree)
!tree.modified && return tree.vector_dimension
tdto = tree.tokenDto
tokenLib = tdto.tokenLib
point_operations = tdto.point_operations
Expand All @@ -765,7 +768,7 @@ function calculate_vector_dimension!(tree::TempComputeTree)
function_op = tokenLib.physical_operation_dict[][tree.symbol]
tree.vector_dimension = function_op(dims...)
end

tree.modified = false
return tree.vector_dimension
end

Expand Down Expand Up @@ -794,8 +797,9 @@ function enforce_changes!(tree::TempComputeTree, expected_dim::Vector{Float16},
return false
end
tree.depend_on[index] = rand(exchange_symbol)
tree.modified = true
calculate_vector_dimension!(tree)
return calculate_distance(tree.vector_dimension, expected_dim) < eps(Float16)
return calculate_distance(tree.vector_dimension, expected_dim) < F16_LOWER_BOUND

end

Expand Down Expand Up @@ -867,9 +871,10 @@ function enforce_changes!(tree::TempComputeTree, expected_dim::Vector{Float16};
if new_tree isa TempComputeTree
tree.symbol = new_tree.symbol
tree.depend_on = new_tree.depend_on
tree.modified = true
calculate_vector_dimension!(tree)
end
return calculate_distance(tree.vector_dimension, expected_dim) < eps(Float16)
return calculate_distance(tree.vector_dimension, expected_dim) < F16_LOWER_BOUND
end


Expand Down Expand Up @@ -912,7 +917,7 @@ function find_closest(distance::Vector{Float16},
for key in all_keys
if min_len <= key[2] <= expression_len
sim = calculate_darityistance(distance, key[1])
sim < eps(Float16) && return rand(lib[key])
sim < F16_LOWER_BOUND && return rand(lib[key])
end
end
end
Expand Down Expand Up @@ -1010,7 +1015,7 @@ function propagate_necessary_changes!(
return false
end

if !has_inf16(tree.vector_dimension) && isapprox(tree.vector_dimension, expected_dim, atol=eps(Float16))
if !has_inf16(tree.vector_dimension) && isapprox(tree.vector_dimension, expected_dim, atol=F16_LOWER_BOUND)
return true
end

Expand All @@ -1024,7 +1029,7 @@ function propagate_necessary_changes!(
ret_val = handle_unary_operation(tree, expected_dim, distance_to_change)
end
calculate_vector_dimension!(tree)
return ret_val && isapprox(tree.vector_dimension, expected_dim, atol=eps(Float16))
return ret_val && isapprox(tree.vector_dimension, expected_dim, atol=F16_LOWER_BOUND)
end


Expand Down Expand Up @@ -1228,7 +1233,7 @@ See also: [`TempComputeTree`](@ref), [`SBPUtils.propagate_necessary_changes!`](@
distance = calculate_distance(target_dimension, calculate_vector_dimension!(tree))

temp_tree = tree
if distance < eps(Float16)
if distance < F16_LOWER_BOUND
for (count, index) in enumerate(reverse(start_indices))
if index != start_indices[1]
genes[count] = temp_tree.symbol
Expand All @@ -1240,7 +1245,7 @@ See also: [`TempComputeTree`](@ref), [`SBPUtils.propagate_necessary_changes!`](@
end
end

return distance, distance < eps(Float16)
return distance, distance < F16_LOWER_BOUND
end

function get_feature_dims_json(json_data::Dict{String,Any}, features::Vector{String}, case_name::String; dims_identifier::String="dims")
Expand Down
8 changes: 4 additions & 4 deletions test/Main_min_bench.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ using BenchmarkTools
Random.seed!(1)

#Define the iterations for the algorithm and the population size
epochs = 100
population_size = 20
epochs = 101
population_size = 100

#Number of features which needs to be inserted
number_features = 2

x_data = randn(Float64, 10000, number_features)
y_data = @. x_data[:,1] * x_data[:,1] + x_data[:,1] * x_data[:,2] - 2 * x_data[:,2] * x_data[:,2] * rand()
x_data = randn(Float64, 1000, number_features)
y_data = @. x_data[:,1] * x_data[:,1] + x_data[:,1] * x_data[:,2] - 2 * x_data[:,2] * x_data[:,2]

#define the
regressor = GepRegressor(number_features)
Expand Down