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
9 changes: 0 additions & 9 deletions src/Entities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -313,15 +313,6 @@ Compiles chromosome's genes into executable function - using the types from the
# Effects
Updates chromosome's compiled_function and related fields
"""

"""
fitness(chromosome::Chromosome)

Get chromosome's fitness value.

# Returns
Fitness value or tuple
"""
@inline function compile_expression!(chromosome::Chromosome; force_compile::Bool=false)
if !chromosome.compiled || force_compile
try
Expand Down
4 changes: 2 additions & 2 deletions src/RegressionWrapper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -716,8 +716,8 @@ function fit!(regressor::GepRegressor, epochs::Int, population_size::Int, x_trai
opt_method=opt_method_const, max_iterations=max_iterations, n_restarts=n_starts)
population[1].fitness = (result,)
population[1].compiled_function = eqn
catch
@show "Ignored constant opt."
catch e
@show "Ignored constant opt." e
end
end

Expand Down
1 change: 0 additions & 1 deletion src/TensorOps.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module TensorRegUtils

using Flux, LinearAlgebra, OrderedCollections, ChainRulesCore, Tensors, PrecompileTools


# Abstract base type with parametric types for improved type stability
abstract type AbstractOperationNode{T} end

Expand Down
21 changes: 15 additions & 6 deletions src/Util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,8 @@ end
@inbounds begin
history.train_loss[epoch] = train_loss
history.val_loss[epoch] = val_loss
#history.train_mean[epoch] = tuple_agg(fit_vector,mean)
#history.train_std[epoch] = tuple_agg(fit_vector, std)
history.train_mean[epoch] = tuple_agg(fit_vector, mean)
history.train_std[epoch] = tuple_agg(fit_vector, std)
end
end
end
Expand Down Expand Up @@ -660,12 +660,13 @@ See also: [`DynamicExpressions.Node`](@ref), [`Optim.optimize`](@ref), [`LineSea
)

nconst = count_constant_nodes(node)
baseline = loss(node)

if nconst == 0
return node, 0.0
return node, baseline
end

baseline = loss(node)

best_node = deepcopy(node)
best_loss = baseline

Expand All @@ -689,11 +690,19 @@ See also: [`DynamicExpressions.Node`](@ref), [`Optim.optimize`](@ref), [`LineSea
end
end
end
#needs to be revised!
x0, refs = get_scalar_constants(current_node)


function opt_step(x::AbstractVector)
set_scalar_constants!(current_node,x, refs)
loss(current_node)
end

result = Optim.optimize(loss, current_node, algorithm, optimizer_options)
result = Optim.optimize(opt_step, x0, algorithm, optimizer_options)

if result.minimum < best_loss
best_node = result.minimizer
best_node = current_node
best_loss = result.minimum
end
end
Expand Down
4 changes: 2 additions & 2 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 = 10
epochs = 100
population_size = 20

#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]
y_data = @. x_data[:,1] * x_data[:,1] + x_data[:,1] * x_data[:,2] - 2 * x_data[:,2] * x_data[:,2] * rand()

#define the
regressor = GepRegressor(number_features)
Expand Down