Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remerge mainline changes #2

Open
wants to merge 50 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
ecaebd4
Populations can be pickled
peter-ch Jan 9, 2018
9192674
Being able to set Genome traits [not done yet]
peter-ch Jan 22, 2018
9607553
Bugfixes
peter-ch Feb 18, 2018
08331c2
Conflicts
peter-ch May 11, 2018
9b02757
Changed to use emplace_back() project wide
peter-ch Aug 17, 2018
632d401
Species now have internal changeable parameters, new parameter for th…
peter-ch Aug 19, 2018
5dec58d
Some refactoring, new parameter [WIP]
peter-ch Aug 19, 2018
c4a000d
Fixes, refactoring
peter-ch Aug 19, 2018
19b4262
Speciation allows arbitrary metrics (in Python), new ConstraintTrials…
peter-ch Aug 21, 2018
8e09224
bugfix
peter-ch Sep 21, 2018
3154e9a
A few bugfixes
peter-ch Feb 24, 2019
6cc80c6
various stuff related to GP
peter-ch Feb 25, 2019
fe45990
Speedups #1
peter-ch Feb 25, 2019
b2e63b2
Speedup #2
peter-ch Feb 25, 2019
5623241
Speedup #2.5
peter-ch Feb 25, 2019
2e65ab0
Speedup #2.6
peter-ch Feb 25, 2019
6dad365
New parameter in genome constructor and bugfixes
peter-ch Feb 25, 2019
3a1445b
Tiny fixes and tests
peter-ch Feb 25, 2019
2584ce0
Little change
peter-ch Feb 25, 2019
1b0b6fd
Trait mutations forced to be different
peter-ch Feb 25, 2019
f1adf29
Bugfix WIP
peter-ch Feb 25, 2019
7e4f5f7
Crossover improvements
peter-ch Feb 25, 2019
b774fec
Fixes.
peter-ch Feb 25, 2019
e2ef4f0
...
peter-ch Feb 25, 2019
7674061
Merge branch 'dev' into full_lineage_report
peter-ch Feb 25, 2019
700363d
bugfix
peter-ch Feb 25, 2019
c79ef90
Inputs don't participate in mating or data copying
peter-ch Feb 25, 2019
902aa7f
Small mutation bugfix
peter-ch Feb 26, 2019
464c037
Various fixes
peter-ch Feb 27, 2019
fcf000d
Updates
peter-ch Feb 28, 2019
dc1de9a
Speciation bugfixes
peter-ch Mar 5, 2019
a511d4e
Bugfixes
peter-ch Mar 5, 2019
5d26484
Generational mode fix
peter-ch Mar 5, 2019
889809a
Fixed Mutate_RemoveSimpleNeuron
peter-ch Mar 5, 2019
03aaf70
Population ID accessible from Python
peter-ch Apr 9, 2019
5d0cd80
pyclasset added
peter-ch Jun 20, 2019
d0afd6d
Fixed merge conflicts
peter-ch Jun 20, 2019
36ba8d6
1231243
peter-ch Jun 21, 2019
b60cb23
wtf src/Genome.cpp was missing
peter-ch Aug 25, 2019
c2dafd2
Attempt to resolve conflicts
peter-ch Aug 26, 2019
0dc93aa
Fixes
peter-ch Aug 26, 2019
79f52dd
Updates
peter-ch Jun 14, 2020
8053099
GenomeInitStruct added
peter-ch Aug 3, 2020
0e45812
bugfix
peter-ch Aug 3, 2020
51832d1
no need to specify ID in genome constructor
peter-ch Aug 3, 2020
e7199fd
parameter changes
peter-ch Aug 13, 2020
8c28ecf
small updates
peter-ch Jul 11, 2023
afc5a19
update
peter-ch Mar 28, 2024
0252842
update
peter-ch Mar 28, 2024
7e3d9e3
Merge branch 'genome_init_struct'
peter-ch Mar 28, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 59 additions & 39 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,57 +1,77 @@
cmake_minimum_required(VERSION 3.3)
project(MultiNEAT)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")

if(MINGW OR CYGWIN)
add_definitions(-O3)
endif()

#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wa,-mbig-obj")

find_package(PythonLibs REQUIRED)
include(FindPythonLibs)
#set(Boost_Path "C:/boost/include")

#set(BOOST_ROOT "C:\\Boost")
#set(BOOSTROOT "C:\\Boost")

add_definitions("-DMS_WIN64")

set(Boost_USE_STATIC_LIBS OFF) # only find static libs
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)
find_package(Boost COMPONENTS
date_time
system
filesystem
python3
serialization)
set(Boost_USE_STATIC_RUNTIME OFF)

find_package(BOOST COMPONENTS REQUIRED
system
python
numpy
date_time
filesystem
serialization)

if(Boost_FOUND)
message(STATUS "It works!")
include_directories(${Boost_INCLUDE_DIRS})
link_directories("C:/Boost/lib")
endif()


include_directories(${PYTHON_INCLUDE_DIRS})

add_definitions(-DUSE_BOOST_PYTHON)
#add_definitions(-DUSE_BOOST_NUMPY)
add_definitions(-DUSE_BOOST_RANDOM)
#add_definitions(-DVDEBUG)


add_executable(MultiNEAT ${PROJECT_SOURCE_DIR}/src/Assert.h
${PROJECT_SOURCE_DIR}/src/Genes.h
${PROJECT_SOURCE_DIR}/src/Genome.cpp
${PROJECT_SOURCE_DIR}/src/Genome.h
${PROJECT_SOURCE_DIR}/src/Innovation.cpp
${PROJECT_SOURCE_DIR}/src/Innovation.h
${PROJECT_SOURCE_DIR}/src/Main.cpp
${PROJECT_SOURCE_DIR}/src/NeuralNetwork.cpp
${PROJECT_SOURCE_DIR}/src/NeuralNetwork.h
${PROJECT_SOURCE_DIR}/src/Parameters.cpp
${PROJECT_SOURCE_DIR}/src/Parameters.h
${PROJECT_SOURCE_DIR}/src/PhenotypeBehavior.cpp
${PROJECT_SOURCE_DIR}/src/PhenotypeBehavior.h
${PROJECT_SOURCE_DIR}/src/Population.cpp
${PROJECT_SOURCE_DIR}/src/Population.h
${PROJECT_SOURCE_DIR}/src/PythonBindings.cpp
${PROJECT_SOURCE_DIR}/src/Random.cpp
${PROJECT_SOURCE_DIR}/src/Random.h
${PROJECT_SOURCE_DIR}/src/Species.cpp
${PROJECT_SOURCE_DIR}/src/Species.h
${PROJECT_SOURCE_DIR}/src/Substrate.cpp
${PROJECT_SOURCE_DIR}/src/Substrate.h
${PROJECT_SOURCE_DIR}/src/Utils.cpp
${PROJECT_SOURCE_DIR}/src/Utils.h
${PROJECT_SOURCE_DIR}/src/Traits.h
${PROJECT_SOURCE_DIR}/src/Traits.cpp)

set(SOURCE_FILES
src/Assert.h
src/Genes.h
src/Genome.cpp
src/Genome.h
src/Innovation.cpp
src/Innovation.h
src/Main.cpp
src/NeuralNetwork.cpp
src/NeuralNetwork.h
src/Parameters.cpp
src/Parameters.h
src/PhenotypeBehavior.cpp
src/PhenotypeBehavior.h
src/Population.cpp
src/Population.h
src/PythonBindings.cpp
src/Random.cpp
src/Random.h
src/Species.cpp
src/Species.h
src/Substrate.cpp
src/Substrate.h
src/Utils.cpp
src/Utils.h
src/Traits.h
src/Traits.cpp)


add_executable(MultiNEAT ${SOURCE_FILES})
target_link_libraries(MultiNEAT ${Boost_LIBRARIES} ${PYTHON_LIBRARIES} pthread)
target_link_libraries(MultiNEAT
"ws2_32"
${BOOST_LIBRARIES}
${PYTHON_LIBRARIES})
84 changes: 84 additions & 0 deletions CMakeLists_MinGW64.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
cmake_minimum_required(VERSION 3.3)
project(MultiNEAT)


if(MINGW OR CYGWIN)
add_definitions(-O3)
endif()

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wa,-mbig-obj")

find_package(PythonLibs REQUIRED)
include(FindPythonLibs)
#set(Boost_Path "C:/boost/include")

#set(BOOST_ROOT "C:\\Boost")
#set(BOOSTROOT "C:\\Boost")

#add_definitions("-DMS_WIN64")

set(Boost_USE_STATIC_LIBS OFF) # only find static libs
set(Boost_USE_MULTITHREADED ON)
set(Boost_USE_STATIC_RUNTIME OFF)

find_package(BOOST COMPONENTS REQUIRED
system
python36
numpy36
date_time
filesystem
serialization)

if(Boost_FOUND)
message(STATUS "It works!")
include_directories(${Boost_INCLUDE_DIRS})
link_directories("C:/Boost/lib")
endif()


include_directories(${PYTHON_INCLUDE_DIRS})

add_definitions(-DUSE_BOOST_PYTHON)
add_definitions(-DUSE_BOOST_NUMPY)
add_definitions(-DUSE_BOOST_RANDOM)
#add_definitions(-DVDEBUG)


add_executable(MultiNEAT ${PROJECT_SOURCE_DIR}/src/Assert.h
${PROJECT_SOURCE_DIR}/src/Genes.h
${PROJECT_SOURCE_DIR}/src/Genome.cpp
${PROJECT_SOURCE_DIR}/src/Genome.h
${PROJECT_SOURCE_DIR}/src/Innovation.cpp
${PROJECT_SOURCE_DIR}/src/Innovation.h
${PROJECT_SOURCE_DIR}/src/Main.cpp
${PROJECT_SOURCE_DIR}/src/NeuralNetwork.cpp
${PROJECT_SOURCE_DIR}/src/NeuralNetwork.h
${PROJECT_SOURCE_DIR}/src/Parameters.cpp
${PROJECT_SOURCE_DIR}/src/Parameters.h
${PROJECT_SOURCE_DIR}/src/PhenotypeBehavior.cpp
${PROJECT_SOURCE_DIR}/src/PhenotypeBehavior.h
${PROJECT_SOURCE_DIR}/src/Population.cpp
${PROJECT_SOURCE_DIR}/src/Population.h
${PROJECT_SOURCE_DIR}/src/PythonBindings.cpp
${PROJECT_SOURCE_DIR}/src/Random.cpp
${PROJECT_SOURCE_DIR}/src/Random.h
${PROJECT_SOURCE_DIR}/src/Species.cpp
${PROJECT_SOURCE_DIR}/src/Species.h
${PROJECT_SOURCE_DIR}/src/Substrate.cpp
${PROJECT_SOURCE_DIR}/src/Substrate.h
${PROJECT_SOURCE_DIR}/src/Utils.cpp
${PROJECT_SOURCE_DIR}/src/Utils.h
${PROJECT_SOURCE_DIR}/src/Traits.h
${PROJECT_SOURCE_DIR}/src/Traits.cpp)

target_link_libraries(MultiNEAT
"ws2_32"
# ${BOOST_LIBRARIES}
"boost_system-mgw81-mt-x64-1_71"
"boost_filesystem-mgw81-mt-x64-1_71"
"boost_serialization-mgw81-mt-x64-1_71"
"boost_date_time-mgw81-mt-x64-1_71"
"boost_random-mgw81-mt-x64-1_71"
"boost_python36-mgw81-mt-x64-1_71"
"boost_numpy36-mgw81-mt-x64-1_71"
${PYTHON_LIBRARIES} pthread)
11 changes: 8 additions & 3 deletions MultiNEAT.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MultiNEAT", "MultiNEAT.vcproj", "{826B4E58-F9C4-45F1-BFE3-4E8B16D37AA6}"
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.1082
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MultiNEAT", "MultiNEAT.vcxproj", "{826B4E58-F9C4-45F1-BFE3-4E8B16D37AA6}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -17,4 +19,7 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {57264A91-576A-4F26-B2AA-727EE1EAED34}
EndGlobalSection
EndGlobal
24 changes: 18 additions & 6 deletions MultiNEAT/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,29 @@ def ZipFitness(genome_list, fitness_list):
try:
import networkx as nx

def Genome2NX(g):
def Genome2NX(g, with_inputs=False, with_weights=False):

nts = g.GetNeuronTraits()
lts = g.GetLinkTraits()
lts = g.GetLinkTraits(with_weights)
gr = nx.DiGraph()

for i, tp, traits in nts:
gr.add_node( i, **traits)

for inp, outp, traits in lts:
gr.add_edge( inp, outp, **traits )
if with_inputs:
gr.add_node( i, **traits)
else:
# don't add traits on inputs
if tp != 'input':
gr.add_node( i, **traits)
else:
gr.add_node( i )

if not with_weights:
for inp, outp, traits in lts:
gr.add_edge( inp, outp, **traits)
else:
for inp, outp, traits, w in lts:
t = {**traits, 'w':w}
gr.add_edge( inp, outp, **t)

gr.genome_traits = g.GetGenomeTraits()

Expand Down
5 changes: 1 addition & 4 deletions MultiNEAT/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,12 @@ def AlmostEqual(a, b, margin):
except:
print('Install NumPy for visualization')


try:
import cv2
cvnumpy_installed = True
except:
print ('Tip: install the OpenCV computer vision library (2.0+) with '
'Python bindings')
print (' to get convenient neural network visualization to NumPy '
'arrays')
'Python bindings to get convenient neural network visualization to NumPy arrays.')
cvnumpy_installed = False

try:
Expand Down
4 changes: 2 additions & 2 deletions _MultiNEAT.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -920,8 +920,8 @@ cdef class Genome:
def BuildHyperNEATPhenotype(self, NeuralNetwork net, Substrate subst):
self.thisptr.BuildHyperNEATPhenotype(deref(net.thisptr), deref(subst.thisptr))

def BuildESHyperNEATPhenotype(Genome self, NeuralNetwork a_net, Substrate subst, Parameters params):
self.thisptr.BuildESHyperNEATPhenotype(deref(a_net.thisptr), deref(subst.thisptr), deref(params.thisptr))
#def BuildESHyperNEATPhenotype(Genome self, NeuralNetwork a_net, Substrate subst, Parameters params):
# self.thisptr.BuildESHyperNEATPhenotype(deref(a_net.thisptr), deref(subst.thisptr), deref(params.thisptr))

def Save(self, str a_filename):
self.thisptr.Save(a_filename)
Expand Down
Empty file modified conda/build.sh
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion conda/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package:
name: multineat
version: 0.5 # Update version in setup.py as well
version: 0.6 # Update version in setup.py as well

build:
number:
Expand Down
Empty file modified conda/run_test.sh
100755 → 100644
Empty file.
177 changes: 15 additions & 162 deletions examples/PythonObjectTraits.ipynb

Large diffs are not rendered by default.

12 changes: 7 additions & 5 deletions examples/TestNEAT_xor.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,27 +104,29 @@ def evaluate(genome):
params.AllowClones = True

def getbest(i):
g = NEAT.Genome(0, 3, 0, 1, False, NEAT.ActivationFunction.UNSIGNED_SIGMOID,
NEAT.ActivationFunction.UNSIGNED_SIGMOID, 0, params, 0)
gi = NEAT.GenomeInitStruct()
gi.NumInputs = 3
g = NEAT.Genome(params, gi)
pop = NEAT.Population(g, params, True, 1.0, i)
pop.RNG.Seed(int(time.clock()*100))
pop.RNG.Seed(int(time.perf_counter()*100))

generations = 0
for generation in range(1000):
for generation in range(300):
genome_list = NEAT.GetGenomeList(pop)
fitness_list = EvaluateGenomeList_Serial(genome_list, evaluate, display=False)
NEAT.ZipFitness(genome_list, fitness_list)
pop.Epoch()
generations = generation
best = max(fitness_list)
print('gen:', generation, 'best:',best)
if best > 15.0:
break

return generations


gens = []
for run in range(100):
for run in range(1000):
gen = getbest(run)
gens += [gen]
print('Run:', run, 'Generations to solve XOR:', gen)
Expand Down
5 changes: 3 additions & 2 deletions examples/TestTraits.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,9 @@ def custom_constraint(genome):
params.CustomConstraints = custom_constraint

# the seed genome and test population
g = NEAT.Genome(0, 3, 0, 1, False, NEAT.ActivationFunction.UNSIGNED_SIGMOID,
NEAT.ActivationFunction.UNSIGNED_SIGMOID, 0, params, 0)
gi = NEAT.GenomeInitStruct()
gi.NumInputs = 3
g = NEAT.Genome(params, gi)
pop = NEAT.Population(g, params, True, 1.0, rnd.randint(0, 100))
pop.RNG.Seed(int(time.clock()*100))

Expand Down
2 changes: 1 addition & 1 deletion examples/ball_keeper.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def main():


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

best_genome_ever = None
Expand Down
5 changes: 3 additions & 2 deletions examples/gym/lunar_lander.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pickle
import numpy as np
import cv2
from tqdm import tqdm

rng = NEAT.RNG()
rng.TimeSeed()
Expand Down Expand Up @@ -72,7 +73,7 @@
render_during_training = 0

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


Expand Down Expand Up @@ -129,7 +130,7 @@ def do_trial():

for generation in range(20):

for i_episode, genome in enumerate(NEAT.GetGenomeList(pop)):
for i_episode, genome in tqdm(enumerate(NEAT.GetGenomeList(pop))):

net = NEAT.NeuralNetwork()
genome.BuildPhenotype(net)
Expand Down
Loading