Skip to content

Commit c2dafd2

Browse files
committed
Attempt to resolve conflicts
2 parents b60cb23 + d0afd6d commit c2dafd2

25 files changed

Lines changed: 3068 additions & 2370 deletions

CMakeLists.txt

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ find_package(Boost COMPONENTS
1313
date_time
1414
system
1515
filesystem
16-
python3
16+
python36
17+
numpy36
1718
serialization)
1819
if(Boost_FOUND)
1920
include_directories(${Boost_INCLUDE_DIRS})
@@ -23,35 +24,33 @@ include_directories(${PYTHON_INCLUDE_DIRS})
2324

2425
add_definitions(-DUSE_BOOST_PYTHON)
2526
add_definitions(-DUSE_BOOST_RANDOM)
27+
add_definitions(-DVDEBUG)
28+
29+
add_executable(MultiNEAT ${PROJECT_SOURCE_DIR}/src/Assert.h
30+
${PROJECT_SOURCE_DIR}/src/Genes.h
31+
${PROJECT_SOURCE_DIR}/src/Genome.cpp
32+
${PROJECT_SOURCE_DIR}/src/Genome.h
33+
${PROJECT_SOURCE_DIR}/src/Innovation.cpp
34+
${PROJECT_SOURCE_DIR}/src/Innovation.h
35+
${PROJECT_SOURCE_DIR}/src/Main.cpp
36+
${PROJECT_SOURCE_DIR}/src/NeuralNetwork.cpp
37+
${PROJECT_SOURCE_DIR}/src/NeuralNetwork.h
38+
${PROJECT_SOURCE_DIR}/src/Parameters.cpp
39+
${PROJECT_SOURCE_DIR}/src/Parameters.h
40+
${PROJECT_SOURCE_DIR}/src/PhenotypeBehavior.cpp
41+
${PROJECT_SOURCE_DIR}/src/PhenotypeBehavior.h
42+
${PROJECT_SOURCE_DIR}/src/Population.cpp
43+
${PROJECT_SOURCE_DIR}/src/Population.h
44+
${PROJECT_SOURCE_DIR}/src/PythonBindings.cpp
45+
${PROJECT_SOURCE_DIR}/src/Random.cpp
46+
${PROJECT_SOURCE_DIR}/src/Random.h
47+
${PROJECT_SOURCE_DIR}/src/Species.cpp
48+
${PROJECT_SOURCE_DIR}/src/Species.h
49+
${PROJECT_SOURCE_DIR}/src/Substrate.cpp
50+
${PROJECT_SOURCE_DIR}/src/Substrate.h
51+
${PROJECT_SOURCE_DIR}/src/Utils.cpp
52+
${PROJECT_SOURCE_DIR}/src/Utils.h
53+
${PROJECT_SOURCE_DIR}/src/Traits.h
54+
${PROJECT_SOURCE_DIR}/src/Traits.cpp)
2655

27-
set(SOURCE_FILES
28-
src/Assert.h
29-
src/Genes.h
30-
src/Genome.cpp
31-
src/Genome.h
32-
src/Innovation.cpp
33-
src/Innovation.h
34-
src/Main.cpp
35-
src/NeuralNetwork.cpp
36-
src/NeuralNetwork.h
37-
src/Parameters.cpp
38-
src/Parameters.h
39-
src/PhenotypeBehavior.cpp
40-
src/PhenotypeBehavior.h
41-
src/Population.cpp
42-
src/Population.h
43-
src/PythonBindings.cpp
44-
src/Random.cpp
45-
src/Random.h
46-
src/Species.cpp
47-
src/Species.h
48-
src/Substrate.cpp
49-
src/Substrate.h
50-
src/Utils.cpp
51-
src/Utils.h
52-
src/Traits.h
53-
src/Traits.cpp)
54-
55-
56-
add_executable(MultiNEAT ${SOURCE_FILES})
5756
target_link_libraries(MultiNEAT ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} pthread)

MultiNEAT/__init__.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,29 @@ def ZipFitness(genome_list, fitness_list):
2121
try:
2222
import networkx as nx
2323

24-
def Genome2NX(g):
24+
def Genome2NX(g, with_inputs=False, with_weights=False):
2525

2626
nts = g.GetNeuronTraits()
27-
lts = g.GetLinkTraits()
27+
lts = g.GetLinkTraits(with_weights)
2828
gr = nx.DiGraph()
2929

3030
for i, tp, traits in nts:
31-
gr.add_node( i, **traits)
32-
33-
for inp, outp, traits in lts:
34-
gr.add_edge( inp, outp, **traits )
31+
if with_inputs:
32+
gr.add_node( i, **traits)
33+
else:
34+
# don't add traits on inputs
35+
if tp != 'input':
36+
gr.add_node( i, **traits)
37+
else:
38+
gr.add_node( i )
39+
40+
if not with_weights:
41+
for inp, outp, traits in lts:
42+
gr.add_edge( inp, outp, **traits)
43+
else:
44+
for inp, outp, traits, w in lts:
45+
t = {**traits, 'w':w}
46+
gr.add_edge( inp, outp, **t)
3547

3648
gr.genome_traits = g.GetGenomeTraits()
3749

MultiNEAT/viz.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,12 @@ def AlmostEqual(a, b, margin):
3030
except:
3131
print('Install NumPy for visualization')
3232

33-
3433
try:
3534
import cv2
3635
cvnumpy_installed = True
3736
except:
3837
print ('Tip: install the OpenCV computer vision library (2.0+) with '
39-
'Python bindings')
40-
print (' to get convenient neural network visualization to NumPy '
41-
'arrays')
38+
'Python bindings to get convenient neural network visualization to NumPy arrays.')
4239
cvnumpy_installed = False
4340

4441
try:

examples/ball_keeper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ def main():
298298

299299

300300
g = NEAT.Genome(0, 6, 0, 2, False,
301-
NEAT.ActivationFunction.TANH, NEAT.ActivationFunction.UNSIGNED_SIGMOID, 0, params, 0)
301+
NEAT.ActivationFunction.TANH, NEAT.ActivationFunction.UNSIGNED_SIGMOID, 0, params, 0, 1)
302302
pop = NEAT.Population(g, params, True, 1.0, rnd.randint(0, 1000))
303303

304304
best_genome_ever = None

examples/gym/lunar_lander.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import pickle
99
import numpy as np
1010
import cv2
11+
from tqdm import tqdm
1112

1213
rng = NEAT.RNG()
1314
rng.TimeSeed()
@@ -72,7 +73,7 @@
7273
render_during_training = 0
7374

7475
g = NEAT.Genome(0, 8 +1, 0, 4, False,
75-
NEAT.ActivationFunction.TANH, NEAT.ActivationFunction.TANH, 0, params, 0)
76+
NEAT.ActivationFunction.TANH, NEAT.ActivationFunction.TANH, 0, params, 0, 1)
7677
pop = NEAT.Population(g, params, True, 1.0, rnd.randint(0, 1000))
7778

7879

@@ -129,7 +130,7 @@ def do_trial():
129130

130131
for generation in range(20):
131132

132-
for i_episode, genome in enumerate(NEAT.GetGenomeList(pop)):
133+
for i_episode, genome in tqdm(enumerate(NEAT.GetGenomeList(pop))):
133134

134135
net = NEAT.NeuralNetwork()
135136
genome.BuildPhenotype(net)

examples/gym/walker.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,33 @@
88
import random as rnd
99
import pickle
1010
import numpy as np
11+
from tqdm import tqdm
1112
import cv2
1213

1314
substrate = NEAT.Substrate([(-1, -1), (-1, 0), (-1, 1)],
1415
[(0, -1), (0, 0), (0, 1)],
1516
[(1, 0)])
1617

17-
substrate.m_allow_input_hidden_links = False;
18-
substrate.m_allow_input_output_links = False;
19-
substrate.m_allow_hidden_hidden_links = False;
20-
substrate.m_allow_hidden_output_links = False;
21-
substrate.m_allow_output_hidden_links = False;
22-
substrate.m_allow_output_output_links = False;
23-
substrate.m_allow_looped_hidden_links = False;
24-
substrate.m_allow_looped_output_links = False;
18+
substrate.m_allow_input_hidden_links = False
19+
substrate.m_allow_input_output_links = False
20+
substrate.m_allow_hidden_hidden_links = False
21+
substrate.m_allow_hidden_output_links = False
22+
substrate.m_allow_output_hidden_links = False
23+
substrate.m_allow_output_output_links = False
24+
substrate.m_allow_looped_hidden_links = False
25+
substrate.m_allow_looped_output_links = False
2526

26-
substrate.m_allow_input_hidden_links = True;
27-
substrate.m_allow_input_output_links = False;
28-
substrate.m_allow_hidden_output_links = True;
29-
substrate.m_allow_hidden_hidden_links = False;
27+
substrate.m_allow_input_hidden_links = True
28+
substrate.m_allow_input_output_links = False
29+
substrate.m_allow_hidden_output_links = True
30+
substrate.m_allow_hidden_hidden_links = False
3031

31-
substrate.m_hidden_nodes_activation = NEAT.ActivationFunction.SIGNED_SIGMOID;
32-
substrate.m_output_nodes_activation = NEAT.ActivationFunction.UNSIGNED_SIGMOID;
32+
substrate.m_hidden_nodes_activation = NEAT.ActivationFunction.SIGNED_SIGMOID
33+
substrate.m_output_nodes_activation = NEAT.ActivationFunction.UNSIGNED_SIGMOID
3334

34-
substrate.m_with_distance = True;
35+
substrate.m_with_distance = True
3536

36-
substrate.m_max_weight_and_bias = 8.0;
37+
substrate.m_max_weight_and_bias = 8.0
3738

3839
try:
3940
x = pickle.dumps(substrate)
@@ -129,7 +130,7 @@ def main():
129130
generations = 10
130131

131132
g = NEAT.Genome(0, 24 + 1 + 1, 0, 4, False,
132-
NEAT.ActivationFunction.TANH, NEAT.ActivationFunction.TANH, 0, params, 0)
133+
NEAT.ActivationFunction.TANH, NEAT.ActivationFunction.TANH, 0, params, 0, 1)
133134
pop = NEAT.Population(g, params, True, 1.0, rnd.randint(0, 1000))
134135
hof = []
135136
maxf_ever = 0
@@ -142,7 +143,7 @@ def main():
142143
#args = [x for x in NEAT.GetGenomeList(pop)]
143144
#dv.block=True
144145
#fitnesses = dv.map_sync(evaluate_genome, args)
145-
for _, genome in enumerate(NEAT.GetGenomeList(pop)):
146+
for _, genome in tqdm(enumerate(NEAT.GetGenomeList(pop))):
146147
fitness = evaluate_genome(env, genome, trials)
147148
fitnesses.append(fitness)
148149
for genome, fitness in zip(NEAT.GetGenomeList(pop), fitnesses):
@@ -184,10 +185,10 @@ def do_trial(env, net, render_during_training):
184185
net.Flush()
185186

186187
f = 0
187-
for t in range(300):
188+
for t in range(500):
188189

189190
if render_during_training:
190-
time.sleep(0.001)
191+
#time.sleep(0.001)
191192
env.render()
192193

193194
# interact with NN

setup.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/python3
22

3-
from __future__ import print_function
3+
#from __future__ import print_function
44
from setuptools import setup, Extension
55
import sys
66
import os
@@ -23,8 +23,8 @@ def _single_compile(obj):
2323
list(multiprocessing.pool.ThreadPool(N).imap(_single_compile,objects))
2424
return objects
2525

26-
import distutils.ccompiler
27-
distutils.ccompiler.CCompiler.compile=parallelCCompile
26+
#import distutils.ccompiler
27+
#distutils.ccompiler.CCompiler.compile=parallelCCompile
2828

2929

3030
''' Note:
@@ -57,7 +57,8 @@ def getExtensions():
5757
'src/Utils.cpp']
5858

5959
extra = ['-march=native',
60-
'-g'
60+
'-mtune=native',
61+
'-g',
6162
]
6263

6364
if platform == 'darwin':
@@ -112,19 +113,25 @@ def getExtensions():
112113
if is_python_2:
113114
libs += ['boost_python', "boost_numpy"]
114115
else:
115-
libs += ['boost_python3', "boost_numpy3"] # in Ubuntu 14 there is only 'boost_python-py34'
116+
# with boost 1.67 you need boost_python3x and boost_numpy3x where x is python version 3.x
117+
libs += ['boost_python36', "boost_numpy36"] # in Ubuntu 14 there is only 'boost_python-py34'
116118

117119
# for Windows with mingw
118120
# libraries= ['libboost_python-mgw48-mt-1_58',
119121
# 'libboost_serialization-mgw48-mt-1_58'],
120122
# include_dirs = ['C:/MinGW/include', 'C:/Users/Peter/Desktop/boost_1_58_0'],
121123
# library_dirs = ['C:/MinGW/lib', 'C:/Users/Peter/Desktop/boost_1_58_0/stage/lib'],
122-
extra.extend(['-DUSE_BOOST_PYTHON', '-DUSE_BOOST_RANDOM'])
123-
extensionsList.append(Extension('MultiNEAT._MultiNEAT',
124-
sources,
125-
libraries=libs,
126-
extra_compile_args=extra)
127-
)
124+
extra.extend(['-DUSE_BOOST_PYTHON', '-DUSE_BOOST_RANDOM', #'-O0',
125+
#'-DVDEBUG',
126+
])
127+
exx = Extension('MultiNEAT._MultiNEAT',
128+
sources,
129+
libraries=libs,
130+
extra_compile_args=extra)
131+
print(dir(exx))
132+
print(exx)
133+
print(exx.extra_compile_args)
134+
extensionsList.append(exx)
128135
else:
129136
raise AttributeError('Unknown tool: {}'.format(build_sys))
130137

0 commit comments

Comments
 (0)