update a lot, take a break
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from tensorneat.pipeline import Pipeline
|
||||
from tensorneat import algorithm, genome, problem, common
|
||||
from tensorneat import algorithm, genome, problem
|
||||
from tensorneat.common import ACT
|
||||
|
||||
algorithm = algorithm.NEAT(
|
||||
pop_size=10000,
|
||||
@@ -8,7 +9,8 @@ algorithm = algorithm.NEAT(
|
||||
genome=genome.DefaultGenome(
|
||||
num_inputs=3,
|
||||
num_outputs=1,
|
||||
output_transform=common.ACT.sigmoid,
|
||||
max_nodes=7,
|
||||
output_transform=ACT.sigmoid,
|
||||
),
|
||||
)
|
||||
problem = problem.XOR3d()
|
||||
@@ -25,3 +27,20 @@ state = pipeline.setup()
|
||||
state, best = pipeline.auto_run(state)
|
||||
# show result
|
||||
pipeline.show(state, best)
|
||||
|
||||
# visualize the best individual
|
||||
network = algorithm.genome.network_dict(state, *best)
|
||||
algorithm.genome.visualize(network, save_path="./imgs/xor_network.svg")
|
||||
|
||||
# transform the best individual to latex formula
|
||||
from tensorneat.common.sympy_tools import to_latex_code, to_python_code
|
||||
|
||||
sympy_res = algorithm.genome.sympy_func(
|
||||
state, network, sympy_output_transform=ACT.obtain_sympy(ACT.sigmoid)
|
||||
)
|
||||
latex_code = to_latex_code(*sympy_res)
|
||||
print(latex_code)
|
||||
|
||||
# transform the best individual to python code
|
||||
python_code = to_python_code(*sympy_res)
|
||||
print(python_code)
|
||||
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
|
Before Width: | Height: | Size: 89 KiB After Width: | Height: | Size: 18 KiB |
File diff suppressed because one or more lines are too long
@@ -1,13 +1,9 @@
|
||||
import networkx as nx
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
# 创建一个空白的有向图
|
||||
G = nx.DiGraph()
|
||||
|
||||
# 添加边
|
||||
G.add_edge('A', 'B')
|
||||
G.add_edge('A', 'C')
|
||||
G.add_edge('B', 'C')
|
||||
G.add_edge('C', 'D')
|
||||
|
||||
# 绘制有向图
|
||||
h = np.zeros(3)
|
||||
o = np.zeros(4)
|
||||
h[0] = -tanh(0.540486*i[0] + 1.04397*i[1] + 0.58006*i[10] + 0.658223*i[11] - 0.9918*i[12] - 0.01919*i[13] + 0.194062*i[14] + 0.903314*i[15] - 1.906567*i[2] - 1.666336*i[3] + 0.653257*i[4] + 0.580191*i[5] + 0.177264*i[6] + 0.830688*i[7] - 0.855676*i[8] + 0.326538*i[9] + 2.465507)
|
||||
h[1] = -tanh(1.441044*i[0] - 0.606109*i[1] - 0.736058*i[10] + 0.60264*i[11] - 0.837565*i[12] + 2.018719*i[13] + 0.327097*i[14] + 0.098963*i[15] + 0.403485*i[2] - 0.680547*i[3] + 0.349021*i[4] - 1.359364*i[5] + 0.351466*i[6] + 0.450447*i[7] + 2.102749*i[8] + 0.680605*i[9] + 0.593945)
|
||||
h[2] = -tanh(1.350645*i[0] - 0.281682*i[1] + 0.332992*i[10] + 0.703457*i[11] + 1.290286*i[12] - 1.059887*i[13] - 1.114513*i[14] + 0.446127*i[15] + 1.103008*i[2] + 1.080698*i[3] - 0.89471*i[4] + 0.103146*i[5] - 0.828767*i[6] + 0.609362*i[7] - 0.765917*i[8] + 0.047898*i[9] + 0.649254)
|
||||
o[0] = -1.307307*h[0] - 0.985838*h[1] - 0.746408*h[2] + 0.245725
|
||||
o[1] = 0.64947*h[0] + 2.865669*h[1] + 1.185759*h[2] - 1.347174
|
||||
o[2] = 2.030407*h[0] + 1.001914*h[1] - 1.041287*h[2] + 0.301639
|
||||
o[3] = 0.717661*h[0] + 0.653905*h[1] - 1.387949*h[2] - 1.200779
|
||||
Reference in New Issue
Block a user