initial commit in branch developing

This commit is contained in:
wls2002
2023-05-11 19:04:56 +08:00
parent acc9eab64a
commit e2a5117554
41 changed files with 133 additions and 43 deletions

8
.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,8 @@
# 默认忽略的文件
/shelf/
/workspace.xml
# 基于编辑器的 HTTP 客户端请求
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

42
.idea/deployment.xml generated Normal file
View File

@@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PublishConfigData" remoteFilesAllowedToDisappearOnAutoupload="false">
<serverData>
<paths name="dengsh@10.16.33.46:22">
<serverdata>
<mappings>
<mapping local="$PROJECT_DIR$" web="/" />
</mappings>
</serverdata>
</paths>
<paths name="lishuang@10.16.2.22:22">
<serverdata>
<mappings>
<mapping local="$PROJECT_DIR$" web="/" />
</mappings>
</serverdata>
</paths>
<paths name="lishuang@10.16.2.22:22 password">
<serverdata>
<mappings>
<mapping local="$PROJECT_DIR$" web="/" />
</mappings>
</serverdata>
</paths>
<paths name="root@124.71.72.72:22">
<serverdata>
<mappings>
<mapping local="$PROJECT_DIR$" web="/" />
</mappings>
</serverdata>
</paths>
<paths name="root@124.71.72.72:22 password">
<serverdata>
<mappings>
<mapping local="$PROJECT_DIR$" web="/" />
</mappings>
</serverdata>
</paths>
</serverData>
</component>
</project>

View File

@@ -0,0 +1,34 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="DuplicatedCode" enabled="false" level="WEAK WARNING" enabled_by_default="false">
<Languages>
<language minSize="97" name="Python" />
</Languages>
</inspection_tool>
<inspection_tool class="PyPep8Inspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="E722" />
</list>
</option>
</inspection_tool>
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="N812" />
<option value="N801" />
<option value="N806" />
<option value="N803" />
</list>
</option>
</inspection_tool>
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredIdentifiers">
<list>
<option value="tests.jax_learn_2022_10_23.*" />
</list>
</option>
</inspection_tool>
</profile>
</component>

View File

@@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

4
.idea/misc.xml generated Normal file
View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="jax_env" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml generated Normal file
View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/neatax.iml" filepath="$PROJECT_DIR$/.idea/neatax.iml" />
</modules>
</component>
</project>

12
.idea/neatax.iml generated Normal file
View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="jax_env" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
<component name="PyDocumentationSettings">
<option name="format" value="PLAIN" />
<option name="myDocStringFormat" value="Plain" />
</component>
</module>

6
.idea/vcs.xml generated Normal file
View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -193,6 +193,13 @@ def pop_analysis(pop_nodes, pop_connections, input_keys, output_keys):
return res return res
@jit
def count(nodes, connections):
node_cnt = jnp.sum(~jnp.isnan(nodes[:, 0]))
connections_cnt = jnp.sum(~jnp.isnan(connections[0, :, :]))
return node_cnt, connections_cnt
@jit @jit
def add_node(new_node_key: int, nodes: Array, connections: Array, def add_node(new_node_key: int, nodes: Array, connections: Array,
bias: float = 0.0, response: float = 1.0, act: int = 0, agg: int = 0) -> Tuple[Array, Array]: bias: float = 0.0, response: float = 1.0, act: int = 0, agg: int = 0) -> Tuple[Array, Array]:

View File

@@ -7,7 +7,7 @@ import numpy as np
from .species import SpeciesController from .species import SpeciesController
from .genome import expand, expand_single from .genome import expand, expand_single
from .function_factory import FunctionFactory from .function_factory import FunctionFactory
from .genome.genome import count
class Pipeline: class Pipeline:
""" """

Binary file not shown.

Binary file not shown.

View File

@@ -1,21 +1,5 @@
import jax
import jax.numpy as jnp import jax.numpy as jnp
import numpy as np
from jax import random
from jax import vmap, jit
from functools import partial
from examples.time_utils import using_cprofile EMPTY_NODE = jnp.full((1, 5), jnp.nan)
print(EMPTY_NODE)
@jit
def func(x, y):
return x + y
a, b, c = jnp.array([1]), jnp.array([2]), jnp.array([3])
li = [a, b, c]
cpu_li = jax.device_get(li)
print(cpu_li)

View File

@@ -6,35 +6,14 @@ from time_utils import using_cprofile
from problems import Sin, Xor, DIY from problems import Sin, Xor, DIY
# xor_inputs = np.array([[0, 0], [0, 1], [1, 0], [1, 1]], dtype=np.float32)
# xor_outputs = np.array([[0], [1], [1], [0]])
#
#
# def evaluate(forward_func: Callable) -> List[float]:
# """
# :param forward_func: (4: batch, 2: input size) -> (pop_size, 4: batch, 1: output size)
# :return:
# """
# outs = forward_func(xor_inputs)
# outs = jax.device_get(outs)
# fitnesses = 4 - np.sum((outs - xor_outputs) ** 2, axis=(1, 2))
# return fitnesses.tolist() # returns a list
# @using_cprofile # @using_cprofile
@partial(using_cprofile, root_abs_path='/mnt/e/neat-jax/', replace_pattern="/mnt/e/neat-jax/") @partial(using_cprofile, root_abs_path='/mnt/e/neat-jax/', replace_pattern="/mnt/e/neat-jax/")
def main(): def main():
config = Configer.load_config() config = Configer.load_config()
# config.neat.population.pop_size = 50
problem = Xor() problem = Xor()
# problem = Sin()
# problem = DIY(func=lambda x: (np.sin(x) + np.exp(x) - x ** 2) / (np.cos(x) + np.sqrt(x)) - np.log(x + 1))
problem.refactor_config(config) problem.refactor_config(config)
pipeline = Pipeline(config, seed=0) pipeline = Pipeline(config, seed=0)
best_nodes, best_connections = pipeline.auto_run(problem.evaluate) pipeline.auto_run(problem.evaluate)
# print(best_nodes, best_connections)
# func = pipeline.function_factory.ask_batch_forward(best_nodes, best_connections)
# problem.print(func)
if __name__ == '__main__': if __name__ == '__main__':

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -57,9 +57,9 @@
"compatibility_weight_coefficient": 0.5, "compatibility_weight_coefficient": 0.5,
"single_structural_mutation": "False", "single_structural_mutation": "False",
"conn_add_prob": 0.5, "conn_add_prob": 0.5,
"conn_delete_prob": 0.5, "conn_delete_prob": 0,
"node_add_prob": 0.2, "node_add_prob": 0.2,
"node_delete_prob": 0.2 "node_delete_prob": 0
}, },
"species": { "species": {
"compatibility_threshold": 2.5, "compatibility_threshold": 2.5,