From 658c62f94914076acbbb4d112b083fc34592d821 Mon Sep 17 00:00:00 2001 From: A-lamo Date: Tue, 19 Nov 2024 18:05:50 +0100 Subject: [PATCH 1/9] CMAKE fixed --- CMakeLists.txt | 4 ++-- cereal | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4711de3..853ee42 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,7 +54,7 @@ if(NOT SKBUILD) PRIVATE PUBLIC $ $ - cereal/include) + $) # Not doing this anymore because not all package managers have it. # target_link_libraries(MultiNEAT PUBLIC cereal::cereal) @@ -149,7 +149,7 @@ else() target_compile_definitions(_multineat PUBLIC PYTHON_BINDINGS) # Not doing this anymore because not all package managers have it. #target_link_libraries(_multineat PUBLIC cereal::cereal) - target_include_directories(_multineat PUBLIC cereal/include) + target_include_directories(_multineat PUBLIC $) install(TARGETS _multineat DESTINATION .) diff --git a/cereal b/cereal index ebef1e9..d1fcec8 160000 --- a/cereal +++ b/cereal @@ -1 +1 @@ -Subproject commit ebef1e929807629befafbb2918ea1a08c7194554 +Subproject commit d1fcec807b372f04e4c1041b3058e11c12853e6e From 361378620025dd8489d7fc9c69d633a36b284310 Mon Sep 17 00:00:00 2001 From: A-lamo Date: Wed, 29 Jan 2025 12:46:50 +0100 Subject: [PATCH 2/9] BuildCPPN --- setup.py | 23 +++++++++-------------- src/Genome.cpp | 12 ++++++------ src/Genome.h | 2 +- src/NeuralNetwork.cpp | 13 +++++++------ src/python/Genome.cpp | 2 +- 5 files changed, 24 insertions(+), 28 deletions(-) diff --git a/setup.py b/setup.py index b340c65..b102d1f 100755 --- a/setup.py +++ b/setup.py @@ -1,21 +1,16 @@ -import sys - -try: - from skbuild import setup -except ImportError: - print( - "Please update pip, you need pip 10 or greater,\n" - " or you need to install the PEP 518 requirements in pyproject.toml yourself", - file=sys.stderr, - ) - raise +from skbuild import setup setup( name="multineat", - version="0.12", # Update version in conda/meta.yaml as well - packages=["multineat"], - cmake_install_dir="multineat", + version="0.13", + description="MultiNEAT Python", url="https://github.com/ci-group/MultiNEAT", long_description=open("README.md").read(), long_description_content_type="text/markdown", + packages=["multineat"], # Python package name + package_dir={"": "src/python"}, # Path to Python source files + cmake_args=[ + "-DSKBUILD=ON", # Ensure CMake recognizes it's being built with scikit-build + ], + python_requires="==3.11", ) diff --git a/src/Genome.cpp b/src/Genome.cpp index bd17ead..47c73c9 100644 --- a/src/Genome.cpp +++ b/src/Genome.cpp @@ -291,7 +291,7 @@ namespace NEAT m_ID = a_ID; int t_innovnum = 1, t_nnum = 1; - + // override seed_type if 0 hidden units are specified if ((a_SeedType == 1) && (a_NumHidden == 0)) { @@ -487,7 +487,7 @@ namespace NEAT // Start very minimally - connect a random input to each output // Also connect the bias to every output for (unsigned int i = 0; i < a_NumOutputs; i++) - { + { int t_inp_id = t_RNG.RandInt(1, a_NumInputs - 1); int t_bias_id = a_NumInputs; int t_outp_id = a_NumInputs + 1 + i; @@ -807,7 +807,7 @@ namespace NEAT bool Genome::HasLoops() { NeuralNetwork net; - BuildPhenotype(net); + BuildCPPN(net); // convert the net to a Boost::Graph object Graph graph(NumNeurons()); @@ -837,7 +837,7 @@ namespace NEAT // This builds a fastnetwork structure out from the genome - void Genome::BuildPhenotype(NeuralNetwork &a_Net) const + void Genome::BuildCPPN(NeuralNetwork &a_Net) const { // first clear out the network a_Net.Clear(); @@ -989,7 +989,7 @@ namespace NEAT // Begin querying the CPPN // Create the neural network that will represent the CPPN NeuralNetwork t_temp_phenotype(true, rng); - BuildPhenotype(t_temp_phenotype); + BuildCPPN(t_temp_phenotype); t_temp_phenotype.Flush(); // To ensure network relaxation @@ -3669,7 +3669,7 @@ namespace NEAT NeuralNetwork t_temp_phenotype(true, rng); - BuildPhenotype(t_temp_phenotype); + BuildCPPN(t_temp_phenotype); // Find Inputs to Hidden connections. for (unsigned int i = 0; i < input_count; i++) diff --git a/src/Genome.h b/src/Genome.h index 93559b1..6f67417 100644 --- a/src/Genome.h +++ b/src/Genome.h @@ -294,7 +294,7 @@ namespace NEAT void SetOffspringAmount(double a_oa); // This builds a fastnetwork structure out from the genome - void BuildPhenotype(NeuralNetwork &net) const; + void BuildCPPN(NeuralNetwork &net) const; // Projects the phenotype's weights back to the genome void DerivePhenotypicChanges(NeuralNetwork &a_Net); diff --git a/src/NeuralNetwork.cpp b/src/NeuralNetwork.cpp index 1d45125..9ef70b0 100644 --- a/src/NeuralNetwork.cpp +++ b/src/NeuralNetwork.cpp @@ -263,10 +263,11 @@ NeuralNetwork::NeuralNetwork() // clean up other neuron data as well for (unsigned int i = 0; i < m_neurons.size(); i++) { - m_neurons[i].m_a = 1; + m_neurons[i].m_a = 0.5; // default 1 m_neurons[i].m_b = 0; - m_neurons[i].m_timeconst = m_neurons[i].m_bias = - m_neurons[i].m_membrane_potential = 0; + m_neurons[i].m_timeconst = 0; + m_neurons[i].m_bias = 0; + m_neurons[i].m_membrane_potential = 0; } Clear(); } @@ -339,15 +340,15 @@ void NeuralNetwork::Activate() // this will happen. for (unsigned int i = 0; i < m_connections.size(); i++) { - m_neurons[m_connections[i].m_target_neuron_idx].m_activesum += - m_connections[i].m_signal; + m_neurons[m_connections[i].m_target_neuron_idx].m_activesum += m_connections[i].m_signal; } // Now loop nodes_activesums, pass the signals through the activation function // and store the result back to nodes_activations // also skip inputs since they do not get an activation - for (unsigned int i = m_num_inputs; i < m_neurons.size(); i++) + for (unsigned int i = m_num_inputs; i < m_neurons.size(); i++) { double x = m_neurons[i].m_activesum; + // std::cout << "active sum, i.e x = " << x << std::endl; m_neurons[i].m_activesum = 0; // Apply the activation function double y = 0.0; diff --git a/src/python/Genome.cpp b/src/python/Genome.cpp index 3bd5ab8..4913b62 100644 --- a/src/python/Genome.cpp +++ b/src/python/Genome.cpp @@ -43,7 +43,7 @@ void export_Genome(pybind11::module_& mod) { .def("PrintAllTraits", &Genome::PrintAllTraits) - .def("BuildPhenotype", &Genome::BuildPhenotype) + .def("BuildCPPN", &Genome::BuildCPPN) .def("BuildHyperNEATPhenotype", &Genome::BuildHyperNEATPhenotype) .def("BuildESHyperNEATPhenotype", &Genome::BuildESHyperNEATPhenotype) From 849dcb8b8f0c487918d5d2000d382f779cfe4f3d Mon Sep 17 00:00:00 2001 From: A-lamo Date: Thu, 30 Jan 2025 12:43:52 +0100 Subject: [PATCH 3/9] hopefully fixed setup.py --- setup.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/setup.py b/setup.py index b102d1f..5d310ec 100755 --- a/setup.py +++ b/setup.py @@ -1,16 +1,21 @@ -from skbuild import setup +import sys + +try: + from skbuild import setup +except ImportError: + print( + "Please update pip, you need pip 10 or greater,\n" + " or you need to install the PEP 518 requirements in pyproject.toml yourself", + file=sys.stderr, + ) + raise setup( name="multineat", - version="0.13", - description="MultiNEAT Python", - url="https://github.com/ci-group/MultiNEAT", + version="0.12", # Update version in conda/meta.yaml as well + packages=["multineat"], + cmake_install_dir="multineat", + url="https://github.com/A-lamo/MultiNEAT", long_description=open("README.md").read(), long_description_content_type="text/markdown", - packages=["multineat"], # Python package name - package_dir={"": "src/python"}, # Path to Python source files - cmake_args=[ - "-DSKBUILD=ON", # Ensure CMake recognizes it's being built with scikit-build - ], - python_requires="==3.11", ) From ba8fd61dfea11d6d8ca60bf5f37079c4e73af2d1 Mon Sep 17 00:00:00 2001 From: A-lamo Date: Thu, 30 Jan 2025 12:46:08 +0100 Subject: [PATCH 4/9] Reverted CMakeLists.txt and cereal to prev state. --- CMakeLists.txt | 4 ++-- cereal | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 853ee42..4711de3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,7 +54,7 @@ if(NOT SKBUILD) PRIVATE PUBLIC $ $ - $) + cereal/include) # Not doing this anymore because not all package managers have it. # target_link_libraries(MultiNEAT PUBLIC cereal::cereal) @@ -149,7 +149,7 @@ else() target_compile_definitions(_multineat PUBLIC PYTHON_BINDINGS) # Not doing this anymore because not all package managers have it. #target_link_libraries(_multineat PUBLIC cereal::cereal) - target_include_directories(_multineat PUBLIC $) + target_include_directories(_multineat PUBLIC cereal/include) install(TARGETS _multineat DESTINATION .) diff --git a/cereal b/cereal index d1fcec8..a56bad8 160000 --- a/cereal +++ b/cereal @@ -1 +1 @@ -Subproject commit d1fcec807b372f04e4c1041b3058e11c12853e6e +Subproject commit a56bad8bbb770ee266e930c95d37fff2a5be7fea From cb54a053eba9f34a8650af37e6b579964d016c26 Mon Sep 17 00:00:00 2001 From: A-lamo Date: Thu, 6 Feb 2025 15:34:22 +0100 Subject: [PATCH 5/9] replace url with ci-group url --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 5d310ec..b340c65 100755 --- a/setup.py +++ b/setup.py @@ -15,7 +15,7 @@ version="0.12", # Update version in conda/meta.yaml as well packages=["multineat"], cmake_install_dir="multineat", - url="https://github.com/A-lamo/MultiNEAT", + url="https://github.com/ci-group/MultiNEAT", long_description=open("README.md").read(), long_description_content_type="text/markdown", ) From 5bbe79b0c4661baec76c7a2af4e4ae16ba5e7bb9 Mon Sep 17 00:00:00 2001 From: A-lamo Date: Thu, 6 Feb 2025 16:14:23 +0100 Subject: [PATCH 6/9] Added a test to check if multineat is downloaded properly. --- test_multineat.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 test_multineat.py diff --git a/test_multineat.py b/test_multineat.py new file mode 100644 index 0000000..bb801c5 --- /dev/null +++ b/test_multineat.py @@ -0,0 +1,5 @@ +import multineat + +genotype = multineat.Genome() + +print(genotype) \ No newline at end of file From 0c2b8ce1b563736b9307e31c2c8db91216312bf0 Mon Sep 17 00:00:00 2001 From: A-lamo Date: Thu, 6 Feb 2025 16:20:58 +0100 Subject: [PATCH 7/9] updated test --- tests/python/test_raw_genome.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/python/test_raw_genome.py b/tests/python/test_raw_genome.py index 0ca9cf1..a486861 100755 --- a/tests/python/test_raw_genome.py +++ b/tests/python/test_raw_genome.py @@ -65,7 +65,7 @@ def parameters(): return params def activate_network(self, genome, _input=None): - genome.BuildPhenotype(self._net) + genome.BuildCPPN(self._net) _input = np.array([1, 2, 3], dtype=float) if _input is None else _input self._net.Input(_input) self._net.ActivateAllLayers() From 6170a872ec6d5aaa7aa28696e7df19c3c0dafee4 Mon Sep 17 00:00:00 2001 From: A-lamo Date: Thu, 6 Feb 2025 16:27:35 +0100 Subject: [PATCH 8/9] Still changing tests to match new variable name BuildCPPN. --- tests/python/test_xor.py | 2 +- tests/xor/main.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/python/test_xor.py b/tests/python/test_xor.py index b2020b4..e268122 100755 --- a/tests/python/test_xor.py +++ b/tests/python/test_xor.py @@ -14,7 +14,7 @@ class XorTest(unittest.TestCase): def test_xor(self): def evaluate(genome): net = NEAT.NeuralNetwork() - genome.BuildPhenotype(net) + genome.BuildCPPN(net) error = 0 diff --git a/tests/xor/main.cpp b/tests/xor/main.cpp index e59499d..995478b 100644 --- a/tests/xor/main.cpp +++ b/tests/xor/main.cpp @@ -29,7 +29,7 @@ double xortest(Genome& g) double f = 0; NeuralNetwork net; - g.BuildPhenotype(net); + g.BuildCPPN(net); static const std::vector< std::vector< double > > inputs { {0.0,0.0,1.0}, From 34c5be52cf70a69ee022b58624ca4c8f878529af Mon Sep 17 00:00:00 2001 From: A-lamo Date: Thu, 6 Feb 2025 16:35:47 +0100 Subject: [PATCH 9/9] trying to fix CMakeList --- CMakeLists.txt | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4711de3..ab56630 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,12 +49,19 @@ if(NOT SKBUILD) add_library(MultiNEAT SHARED ${SOURCE_FILES}) + # target_include_directories( + # MultiNEAT + # PRIVATE + # PUBLIC $ + # $ + # cereal/include) + target_include_directories( - MultiNEAT - PRIVATE - PUBLIC $ - $ - cereal/include) + MultiNEAT + PRIVATE + PUBLIC $ + $ + $) # Not doing this anymore because not all package managers have it. # target_link_libraries(MultiNEAT PUBLIC cereal::cereal)