-
Notifications
You must be signed in to change notification settings - Fork 11
Description
Hello. Thanks for this Tensorial approach. I have one question.
It seems "Terminal_Set()" constructor is not working. I want to define four 2x2 tensors in my terminal. I'll be grateful if you let me know the correct syntax to define the terminal.
def` calc_fit(**kwargs):
# read parameters
population = kwargs.get('population')
generation = kwargs.get('generation')
tensors = kwargs.get('tensors')
f_path = kwargs.get('f_path')
_stf = kwargs.get('stf')
target = kwargs.get('target')
fn = f_path + "gen_" + str(generation).zfill(5)
fitness = []
times = []
best_ind = 0
# set objective function according to min/max
fit = 0
condition = lambda: (fit < max_fit) # minimizing
max_fit = float('inf')
for i in range(len(tensors)):
start_ind = time.time()
fit = tf_rmse(tensors[i], target).numpy()
if condition():
max_fit = fit
best_ind = i
times.append((time.time() - start_ind) * 1000.0)
fitness.append(fit)
population[i]['fitness'] = fit
#if generation == gens:
# save_image(tensors[best_ind], best_ind, fn, 2)
return` population, population[best_ind]`
Different types of function sets
normal_set = {'add', 'sub'}
if __name__ == "__main__":
# GP params
dev = '/gpu:0' # device to run, write '/cpu_0' to tun on cpu
gens = 250
pop_size = 2500
tour_size = 3
mut_rate = 0.1
cross_rate = 0.9
max_tree_dep = 10
max_init_depth = 10
elite_size = 1 # 0 to turn off
runs = 1 # Number of average runs
# problems
optimal_solution = tf.convert_to_tensor(F) #F is a (19828, 2, 2) tensor
terminal
indexing_variables = 3
domain_range = [19828, 2, 2]
my_terminal_set = Terminal_set(indexing_variables, domain_range)
my_terminal_set.add_to_set("T_1", tf.convert_to_tensor(T_1, shape=(19828, 2, 2)))
my_terminal_set.add_to_set("T_2", tf.convert_to_tensor(T_2, shape=(19828, 2, 2)))
my_terminal_set.add_to_set("T_3", tf.convert_to_tensor(T_3, shape=(19828, 2, 2)))
my_terminal_set.add_to_set("T_4", tf.convert_to_tensor(T_4, shape=(19828, 2, 2)))
problems = [optimal_solution] # Add to run more problems
# Domains dimensions
test_cases = [[19828, 2, 2]]
for p in problems:
for res in test_cases:
for r in range(runs):
#seeds = random.randint(0, 0x7fffffff)
seeds = 39485793482 # reproducibility
# create engine
engine = Engine(terminal_set=my_terminal_set,
fitness_func=calc_fit,
population_size=pop_size,
tournament_size=tour_size,
mutation_rate=mut_rate,
crossover_rate=cross_rate,
max_tree_depth=max_tree_dep,
target_dims=res,
target=optimal_solution,
#elitism=elite_size,
method='ramped half-and-half',
max_init_depth=max_init_depth,
objective='minimizing',
device=dev,
stop_criteria='generation',
stop_value=gens,
effective_dims=2,
min_domain=-0.5,
max_domain=0.5,
operators=normal_set,
seed=seeds,
save_to_file=10,
save_graphics=False,
show_graphics=False,
write_log=False,
write_gen_stats=False,
read_init_pop_from_file=None)
# run evolutionary process
engine.run()
error:
NameError: name 'Terminal_set' is not defined