diff --git a/src/Entities.jl b/src/Entities.jl index d226ff5..fc6818f 100644 --- a/src/Entities.jl +++ b/src/Entities.jl @@ -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 diff --git a/src/Gep.jl b/src/Gep.jl index 92716b1..198fb14 100644 --- a/src/Gep.jl +++ b/src/Gep.jl @@ -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 diff --git a/src/RegressionWrapper.jl b/src/RegressionWrapper.jl index 05faf71..c682d21 100644 --- a/src/RegressionWrapper.jl +++ b/src/RegressionWrapper.jl @@ -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, @@ -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} @@ -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 @@ -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 diff --git a/src/Sbp.jl b/src/Sbp.jl index e68b852..b5acd76 100644 --- a/src/Sbp.jl +++ b/src/Sbp.jl @@ -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 @@ -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 @@ -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 @@ -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}[], @@ -728,7 +730,7 @@ mutable struct TempComputeTree vector_dimension, tokenDto, length(depend_on), - -1) + -1,true) end end @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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") diff --git a/test/Main_min_bench.jl b/test/Main_min_bench.jl index cfccdf1..6f7e2a5 100644 --- a/test/Main_min_bench.jl +++ b/test/Main_min_bench.jl @@ -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)