In [1]:
# visualization libraries
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
# plot the visuals in ipython
%matplotlib inline
In [2]:
from pypge.benchmarks import explicit
prob = explicit.Lipson_02()
print prob['name'], prob['eqn']
print prob['xpts'].shape
plt.plot(prob['xpts'][0], prob['ypure'], 'r.')
plt.show()
plt.plot(prob['xpts'][0], prob['ypts'], 'b.')
plt.show()
In [ ]:
from pypge.search import PGE
from pypge import expand
from pypge import fitness_funcs as FF
import sympy
pge = PGE(
system_type = "explicit",
search_vars = "y",
usable_vars = prob['xs_str'],
usable_funcs = [sympy.exp, sympy.cos, sympy.sin, sympy.Abs],
# usable_funcs = [sympy.cos, sympy.sin],
pop_count = 3,
peek_count = 9,
peek_npts = 100,
max_iter = 6,
print_timing = True,
log_details = True,
fitness_func = FF.normalized_size_score
)
pge.fit(prob['xpts'], prob['ypts'])
In [4]:
final_paretos = pge.get_final_paretos()
print len(final_paretos)
final_list = [item for sublist in final_paretos for item in sublist]
print len(final_list), "\n\n"
In [5]:
pge_szs = [m.size() for m in final_list]
pge_scr = [m.score for m in final_list]
pge_evar = [1.0 - m.evar for m in final_list]
pge_szs_f = [m.size() for m in final_paretos[0]]
pge_scr_f = [m.score for m in final_paretos[0]]
pge_evar_f = [1.0 - m.evar for m in final_paretos[0]]
plt.plot(pge_szs, pge_scr, 'b.', pge_szs_f, pge_scr_f, 'ro')
plt.show()
plt.plot(pge_szs, pge_evar, 'b.', pge_szs_f, pge_evar_f, 'ro')
plt.show()
In [9]:
from pypge.evaluate import Eval
for best_m in final_paretos[0]:
print best_m
y_pred = Eval(best_m, pge.vars, prob['xpts'])
plt.plot(prob['xpts'][0], prob['ypts'], 'r.',prob['xpts'][0], y_pred, 'b.')
plt.show()
In [ ]:
from sympy import *
import networkx as nx
G = pge.GRAPH
n_nodes = G.number_of_nodes()
n_edges = G.number_of_edges()
print n_nodes, n_edges
print nx.info(G)
print nx.density(G)
bins = nx.degree_histogram(G)
# pos=nx.graphviz_layout(G,prog="twopi",root=pge.root_model)
# nx.draw_networkx(G,pos,with_labels=False,node_size=30)
# nx.draw_circular(G,with_labels=False,node_size=30)
# pos=nx.shell_layout(G,pge.iter_expands)
# nx.draw_networkx(G,pos,with_labels=False,node_size=30)
plt.yscale('log')
plt.bar(range(0,len(bins)),bins)
plt.draw()