Skip to content

Commit

Permalink
added paralelised experiments
Browse files Browse the repository at this point in the history
  • Loading branch information
cipri-tom committed Jan 27, 2017
1 parent 26c4fbb commit 373aa24
Show file tree
Hide file tree
Showing 4 changed files with 382 additions and 0 deletions.
300 changes: 300 additions & 0 deletions scripts/main.ipynb

Large diffs are not rendered by default.

29 changes: 29 additions & 0 deletions scripts/policy_threaded.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# because multiprocessing Pool cannot run in interactive mode, we put it in a file

from multiprocessing import Pool
from starter import Agent
import numpy as np

def make_and_run(init_w):
d = 8
w = np.full((3,d,d), init_w)
a = Agent(side_size=d, weights=w)
for e in range(50):
a.episode()
return a.escape_times

def main():
p = Pool(6)
# init_w -- 12 examples of each
# agents = [0] * 12
agents = [0] * 12
results = []

for res in p.map(make_and_run, agents):
results.append(res)

print(results)

if __name__ == "__main__":
main()

26 changes: 26 additions & 0 deletions scripts/tau_threaded.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# because multiprocessing Pool cannot run in interactive mode, we put it in a file

from multiprocessing import Pool
from starter import Agent
import numpy as np

def make_and_run(tau):
a = Agent(tau=tau)
for e in range(50):
a.episode()
return a.escape_times

def main():
p = Pool(6)
# tau -- 12 examples of each
agents = [0.0] * 12
results = []

for res in p.map(make_and_run, agents):
results.append(res)

print(results)

if __name__ == "__main__":
main()

27 changes: 27 additions & 0 deletions scripts/threaded.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# because multiprocessing Pool cannot run in interactive mode, we put it in a file

from multiprocessing import Pool
from starter import Agent

def make_and_run(size):
a = Agent(side_size=size)
for e in range(60):
a.episode()
# if 5 times in a row we escape in less than 150 steps
if e > 5 and sum(a.escape_times[-5:]) / 5 < 150:
break
return [size, e]

def main():
p = Pool(6)
episodes_per_size = []

# 5 agents of each size from 6 -> 11
for res in p.map(make_and_run, sorted(list(range(7,12)) * 5)):
episodes_per_size.append(res)

print(episodes_per_size)

if __name__ == "__main__":
main()

0 comments on commit 373aa24

Please sign in to comment.