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
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,7 @@ inputs = (x1,x2,u1,u2,u3)
size(a_pred[1]) != size(a[1]) && return (typemax(Float64),)

loss = norm(a_pred .- a)
return (loss,)
else
return (elem.fitness,)
elem.fitness = (loss,)
end
end
fit!(regressor, epochs, population_size, loss_new)
Expand Down
6 changes: 2 additions & 4 deletions examples/Main_min_example_mo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,10 @@ regressor = GepRegressor(number_features; number_of_objectives=2)
try
if isnan(mean(elem.fitness)) || validate
y_pred = elem.compiled_function(x_data', regressor.operators_)
return (get_loss_function("mse")(y_data, y_pred), length(elem.expression_raw)*0.01)
else
return elem.fitness
elem.fitness = (get_loss_function("mse")(y_data, y_pred), length(elem.expression_raw)*0.01)
end
catch e
return (typemax(Float64),typemax(Float64))
elem.fitness = (typemax(Float64),typemax(Float64))
end
end

Expand Down
10 changes: 5 additions & 5 deletions paper/ConstraintViaSBP.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function main()
@show ("Current case: ", case_name)
#gep_params
epochs = 1000
population_size = 200
population_size = 500

results = DataFrame(Seed=[],
Name=String[], NoiseLeve=String[], Fitness=Float64[], Equation=String[], R2_test=Float64[],
Expand Down Expand Up @@ -129,21 +129,21 @@ function main()
try
if isnan(mean(elem.fitness)) || validate
y_pred = elem.compiled_function(x_train', regressor.operators_)
return (get_loss_function("mse")(y_train, y_pred),)
elem.fitness = (get_loss_function("mse")(y_train, y_pred),)
else
return (elem.fitness, length(elem.expression_raw) * elem.fitness)
elem.fitness = (elem.fitness, length(elem.expression_raw) * elem.fitness)
#return (elem.fitness,)
end
catch e
return (typemax(Float64),typemax(Float64))
elem.fitness = (typemax(Float64),typemax(Float64))
end
end


#perform the regression by entering epochs, population_size, the feature cols, the target col and the loss function
fit!(regressor, epochs, population_size, x_train', y_train;
x_test=x_test', y_test=y_test', target_dimension=target_dim,
loss_fun="mse", break_condition=break_condition)
loss_fun="mse", break_condition=break_condition, correction_amount=0.5)

end_time = (time_ns() - start_time) / 1e9
elem = regressor.best_models_[1]
Expand Down
17 changes: 7 additions & 10 deletions src/Gep.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,10 @@ Returns the computed fitness value (loss) or crash_value if computation fails
try
if isnan(mean(elem.fitness)) || validate
y_pred = elem.compiled_function(evalArgs.x_data, evalArgs.operators)
return (evalArgs.loss_function(evalArgs.y_data, y_pred),)
else
return elem.fitness
elem.fitness = (evalArgs.loss_function(evalArgs.y_data, y_pred),)
end
catch e
return (evalArgs.crash_value,)
elem.fitness = (evalArgs.crash_value,)
end
end

Expand Down Expand Up @@ -342,16 +340,15 @@ The evolution process stops when either:
Threads.@threads for i in eachindex(population[1:population_size])
if isnan(mean(population[i].fitness))
key = join(population[i].expression_raw, ",")
cache_value = get(fit_cache, key, nothing)

if isnothing(cache_value)
population[i].fitness = compute_fitness(population[i], evalStrategy)
cache_value = key in keys(fit_cache)
if !(cache_value)
compute_fitness(population[i], evalStrategy)
lock(cache_lock)
fit_cache[key] = population[i].fitness
fit_cache[key] = population[i].fitness
unlock(cache_lock)
else
atomic_add!(same, 1)
population[i].fitness = cache_value
population[i].fitness = toolbox.fitness_reset[1]
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion tutorial/JGEP_demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
"#define the \n",
"regressor = GepRegressor(number_features)\n",
"\n",
"fit!(regressor, epochs, population_size, x_data, y_data; loss_fun=\"mse\")\n",
"fit!(regressor, epochs, population_size, x_data', y_data; loss_fun=\"mse\")\n",
"\n",
"pred = regressor(x_data')\n",
"\n",
Expand Down