Skip to content

Commit

Permalink
Merge branch 'master' of github.com:riveSunder/carles_game
Browse files Browse the repository at this point in the history
  • Loading branch information
riveSunder committed Jul 7, 2021
2 parents 34d3992 + 255a9df commit 235cd19
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 61 deletions.
3 changes: 1 addition & 2 deletions docs/_config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

title: Carle's Game
title: Carle's Game Blog
theme: minima
#theme: jekyll-theme-minimal
logo: /carles_game/assets/flying_brain.png
Expand Down
2 changes: 1 addition & 1 deletion docs/_posts/2021-06-17-update.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ categories: updates
---

<div align="center">
<img src="/carles_game/assets/judgy_alien.png">
<img src="https://raw.githubusercontent.com/riveSunder/carles_game/master/assets/judgy_alien.png" width=30%>
</div>

### Carle's Game blog moved to [https://rivesunder.github.io/carles_game](https://rivesunder.github.io/carles_game)
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

# Carle's Game Blog
<!-- # Carle's Game Blog-->

## An Open-Ended Challenge in Simple Complexity, Exploration, and Machine Creativity

Expand Down
48 changes: 47 additions & 1 deletion game_of_carle/agents/toggle.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def get_params(self):
def set_params(self, params):

self.toggles = params.reshape(1, 1, \
self.toggle_width, self.toggle_width)
self.toggle_height, self.toggle_width)

self.toggles = np.clip(self.toggles, 0.0, 1.0)

Expand All @@ -78,6 +78,52 @@ def reset(self):

self.first_step = True

class BilateralToggle(Toggle):

def __init__(self, **kwargs):

super(BilateralToggle, self).__init__(**kwargs)

def initialize_policy(self):

self.toggle_width = 16
self.toggle_height = 32

self.width_padding = (self.action_width - self.toggle_width)
self.height_padding = (self.action_height - self.toggle_height)

self.toggles = (np.random.rand(1, 1, \
self.toggle_height, self.toggle_width))

def action_padding(self, action):

padded = torch.zeros(1, 1, self.action_height, self.action_width)

padded[:,:, 16:48, 16:16+self.toggle_width] = action

for ii in range(self.toggle_width):

padded[:,:,16:48, 16+self.toggle_width + ii] =\
action[:,:,:, self.toggle_width - ii-1]

return padded


def forward(self, obs):

if self.first_step:
action = torch.tensor(self.toggles > 0.5).float().to(self.my_device)
action = self.action_padding(action)
action *= torch.ones(self.instances, 1, \
self.action_height, self.action_width).to(self.my_device)

self.first_step = False
else:
action = torch.zeros(self.instances, 1, \
self.action_height, self.action_width).to(self.my_device)

return action

if __name__ == "__main__":

env = CARLE()
Expand Down
35 changes: 6 additions & 29 deletions notebooks/interactive_evolution.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"outputs": [],
"source": [
"from IPython.core.display import display, HTML\n",
"display(HTML(\"<style>.container { width:80% !important; }</style>\"))\n",
"display(HTML(\"<style>.container { width:100% !important; }</style>\"))\n",
"\n",
"import os\n",
"\n",
Expand All @@ -22,7 +22,7 @@
"from game_of_carle.agents.grnn import ConvGRNN\n",
"from game_of_carle.agents.carla import CARLA\n",
"from game_of_carle.agents.harli import HARLI\n",
"from game_of_carle.agents.toggle import Toggle\n",
"from game_of_carle.agents.toggle import Toggle, BilateralToggle\n",
"from game_of_carle.algos.cma import CMAPopulation\n",
"\n",
"import bokeh\n",
Expand Down Expand Up @@ -50,13 +50,12 @@
"\n",
"env = CARLE(instances=2, device=\"cpu\", height=128, width=128) \n",
"\n",
"my_path = \"../policies/interactive_evolution_\"\n",
"my_path = \"../policies/interactive_evolution_face_\"\n",
"\n",
"# Choose from agent policy architectures HARLI, CARLA, or Toggle\n",
"# CARLA seems to be the trickiest at the moment. As a deterministic policy it is difficult for it to recover from\n",
"# a policy which yields little to no action.\n",
"agent = CMAPopulation(BilateralToggle, device=\"cpu\", save_path=my_path, lr=.1, population_size=16)\n",
"\n",
"agent = CMAPopulation(Toggle, device=\"cpu\", save_path=my_path, lr=.1, population_size=16)"
"my_rules = \"B3/S345678\"\n",
"env.rules_from_string(my_rules)"
]
},
{
Expand All @@ -79,9 +78,6 @@
" \n",
" with torch.no_grad():\n",
" \n",
" env.birth = [3]\n",
" env.survive = [2, 3]\n",
" \n",
" global agent\n",
" \n",
" global obs\n",
Expand Down Expand Up @@ -477,25 +473,6 @@
"\n",
"show(modify_doc) "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e8c13135",
"metadata": {},
"outputs": [],
"source": [
"for ii in range(agent.population_size):\n",
" print(agent.population[ii].hallucinogen)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1d78b3ed",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Loading

0 comments on commit 235cd19

Please sign in to comment.