143 lines
3.2 KiB
Plaintext
143 lines
3.2 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": "<algorithm.neat.genome.default.DefaultGenome at 0x7f6709872650>"
|
|
},
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"import jax, jax.numpy as jnp\n",
|
|
"from algorithm.neat import *\n",
|
|
"from utils import Act, Agg\n",
|
|
"genome = DefaultGenome(\n",
|
|
" num_inputs=27,\n",
|
|
" num_outputs=8,\n",
|
|
" max_nodes=100,\n",
|
|
" max_conns=200,\n",
|
|
" node_gene=DefaultNodeGene(\n",
|
|
" activation_options=(Act.tanh,),\n",
|
|
" activation_default=Act.tanh,\n",
|
|
" ),\n",
|
|
" output_transform=Act.tanh,\n",
|
|
")\n",
|
|
"state = genome.setup()\n",
|
|
"genome"
|
|
],
|
|
"metadata": {
|
|
"collapsed": false,
|
|
"ExecuteTime": {
|
|
"end_time": "2024-06-09T12:08:22.569123400Z",
|
|
"start_time": "2024-06-09T12:08:19.331863800Z"
|
|
}
|
|
},
|
|
"id": "b2b214a5454c4814"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"outputs": [],
|
|
"source": [
|
|
"state = state.register(data=jnp.zeros((1, 27)))\n",
|
|
"# try to save the genome object\n",
|
|
"import pickle\n",
|
|
"\n",
|
|
"with open('genome.pkl', 'wb') as f:\n",
|
|
" genome.__dict__[\"state\"] = state\n",
|
|
" pickle.dump(genome, f)"
|
|
],
|
|
"metadata": {
|
|
"collapsed": false,
|
|
"ExecuteTime": {
|
|
"end_time": "2024-06-09T12:09:01.943445900Z",
|
|
"start_time": "2024-06-09T12:09:01.919416Z"
|
|
}
|
|
},
|
|
"id": "28348dfc458e8473"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 13,
|
|
"outputs": [],
|
|
"source": [
|
|
"# try to load the genome object\n",
|
|
"with open('genome.pkl', 'rb') as f:\n",
|
|
" genome = pickle.load(f)\n",
|
|
" state = genome.state\n",
|
|
" del genome.__dict__[\"state\"]"
|
|
],
|
|
"metadata": {
|
|
"collapsed": false,
|
|
"ExecuteTime": {
|
|
"end_time": "2024-06-09T12:10:28.621539400Z",
|
|
"start_time": "2024-06-09T12:10:28.612540100Z"
|
|
}
|
|
},
|
|
"id": "c91be9fe3d2b5d5d"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 15,
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": "State ({'data': Array([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,\n 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]], dtype=float32)})"
|
|
},
|
|
"execution_count": 15,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"state"
|
|
],
|
|
"metadata": {
|
|
"collapsed": false,
|
|
"ExecuteTime": {
|
|
"end_time": "2024-06-09T12:10:34.103124Z",
|
|
"start_time": "2024-06-09T12:10:34.096124300Z"
|
|
}
|
|
},
|
|
"id": "6852e4e58b81dd9"
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"outputs": [],
|
|
"source": [],
|
|
"metadata": {
|
|
"collapsed": false
|
|
},
|
|
"id": "97a50322218a0427"
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 2
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython2",
|
|
"version": "2.7.6"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|