Beispiel #1
0
                          n_generations=n_gen,
                          n_elites=1,
                          stats=stats,
                          hall_of_fame=hof,
                          verbose=True)

print("Evolution times were:\n\nStarted:\t", startDT, "\nEnded:   \t",
      str(datetime.datetime.now()))

print(hof[0])

best_ind = hof[0]

print(best_ind)

symplified_best = gep.simplify(best_ind)
print(symplified_best)
if enable_ls:
    print(best_ind.a.dtype, best_ind.b.dtype)
    symplified_best = best_ind.a * symplified_best + best_ind.b
    print(symplified_best)

key = '''
Using GEP to predict the PDE t11 = -0.0006245609035064359*S*ux cs=0.18
-0.0007710628438351062 --cs=0.2
Our symbolic regression process found the following equation offers our best prediction:

'''

print('\n', key, '\t', str(symplified_best))
# **Let's check the best individuals ever evolved.**

# In[15]:

print(hof[0])

# # *[optional]* Post-processing: simplification and visualization
# ## Symbolic simplification of the final solution
# The original solution seems a little complicated, which may contain many redundancies, for example, `protected_div(x, x)` is just 1. We can perform symbolic simplification of the final result by `geppy.simplify` which depends on `sympy` package.

# In[16]:

for i in range(3):
    ind = hof[i]
    symplified_model = gep.simplify(ind)
    if LINEAR_SCALING:
        symplified_model = ind.a * symplified_model + ind.b
    print('Symplified best individual {}: '.format(i))
    print(symplified_model)

# As we can see from the above simplified expression, the *truth model* has been successfully found. Due to the existence of Gaussian noise, the minimum mean absolute error (MAE) is still not zero even the best individual represents the true model.

# ## Visualization
# If you are interested in the expression tree corresponding to the individual, i.e., the genotype/phenotype system, *geppy* supports tree visualization by the `graph` and the `export_expression_tree` functions:
#
# - `graph` only outputs the nodes and links information to describe the tree topology, with which you can render the tree with tools you like;
# - `export_expression_tree` implements tree visualization with data generated by `graph` internally using the `graphviz` package.

# In[17]:
Beispiel #3
0
plt.xlabel('Generation')
plt.ylabel('Max / Average Fitness')
plt.title('Max and Average fitness over Generations')
plt.show()

# Present our Work and Conclusions
# Symbolic simplification of the final solution
# The symbolic tree answer may contain many redundancies, for example,
# `protected_div(x, x)` is just 1. We can perform symbolic simplification
# of the final result by `geppy.simplify` which depends on `sympy` package.
# We can also leverage sympy to better present our work to others

# print the best symbolic regression we found
#best_ind = Hof_save[0][0]
best_ind = hof[0]
symplified_best = gep.simplify(best_ind)
best_func = toolbox.compile(best_ind)

# convergence
plt.figure()
plt.plot(Max_evolution[0])

temp = np.zeros(N_eval)
for i in range(N_eval):
    print("Hof_save:", Hof_save[i][0])
    temp[i] = Max_evolution[i][-1]

# display
#shear_test = np.linspace(np.min(shear),np.max(shear),num=10000)
#plt.figure()
#plt.semilogx(df.Pi1,10*np.log10(df.PiF),color='b',marker='.',linestyle=' ')
Beispiel #4
0
# start evolution
start = time.time()
pop, log = multigep.gep_multi(pop,
                              toolbox,
                              n_generations=n_gen,
                              n_elites=3,
                              stats=stats,
                              hall_of_fame=hof,
                              verbose=True)
end = time.time()
time_spent = round(end - start, 2)
print("time spent: {} s".format(time_spent),
      "= {} min".format(round(time_spent / 60, 2)),
      "= {} h".format(round(time_spent / 3600, 2)))

print('\nSymplified best individual: ')
symplified_best_list = []
result_list = []
for i in range(len(hof)):
    symplified_best = gep.simplify(hof[i], sym_map)
    if symplified_best not in symplified_best_list:
        symplified_best_list.append(symplified_best)
        result = mpse.capture_test(func=np.vectorize(toolbox.compile(hof[i])),
                                   loop=loop,
                                   pursuer=1)
        print(result, '  ', symplified_best)
        result_list.append(result)

print('\n', len(symplified_best_list), 'different items')
for i in range(len(symplified_best_list)):
    print("\'" + str(symplified_best_list[i]) + "\', #" + str(result_list[i]))