In [1]:
import plotly
import numpy as np 
import plotly.plotly as py  
import plotly.tools as tls   
import plotly.graph_objs as go
plotly.tools.set_credentials_file(username='jamesjlong90', api_key='lc5ruh00ym', stream_ids=['uuvmw9qmk3'])
import datetime
stream_ids = tls.get_credentials_file()['stream_ids']
print(stream_ids)
# Get stream id from stream id list 
stream_id = stream_ids[0]

# Make instance of stream id object 
stream_1 = go.Stream(
    token=stream_id,  # link stream id to 'token' key
    maxpoints=512      # keep a max of 80 pts on screen
)
# Initialize trace of streaming plot by embedding the unique stream_id
trace1 = go.Scatter(
    x=[],
    y=[],
    fillcolor = [],
    mode='lines+markers',
    stream=stream_1         # (!) embed stream id, 1 per trace
)
data = go.Data([trace1])

# Add title to layout object
layout = go.Layout(title='Time Series')

# Make a figure object
fig = go.Figure(data=data, layout=layout)

# Send fig to Plotly, initialize streaming plot, open new tab
py.iplot(fig, filename='python-streaming')

# We will provide the stream link object the same token that's associated with the trace we wish to stream to
s = py.Stream(stream_id)

# We then open a connection
s.open()


['uuvmw9qmk3']
High five! You successfuly sent some data to your account on plotly. View your plot in your browser at https://plot.ly/~jamesjlong90/0 or inside your plot.ly account where it is named 'python-streaming'

In [2]:
from agent import *

In [3]:
import asyncio
from qlearn import QLearn
from sarsa import Sarsa
import itertools
import functools
import json
import random
import sklearn
"""define our agent"""
#======states=========#
battery = range(6)
#hour = range(24)
sleeping = [True, False]
all_vars = [battery,sleeping]
states = itertools.product(*all_vars)
battery_index = 0
sleeping_index = 1

#======actions========#
def go_to_sleep(old):
    new = list(old)
    new[sleeping_index] = True
    #new[battery_index] = new[battery_index]+1
    #if new[battery_index] >=10:
    #    new[battery_index] = 10
    return tuple(new)

def wakeup(old_w):
    new_w = list(old_w)
    new_w[sleeping_index] = False
    #new_w[battery_index]=new_w[battery_index]-1
    #if new_w[battery_index] <0:
    #    new_w[battery_index] = 0
    return tuple(new_w)
actions_states = {i:[go_to_sleep, wakeup] for i in states}
#####rewards###########

def state_rewards(state1, state2):
	if state2[battery_index] == 0:
		return -10
	elif not state1[sleeping_index] and not state2[sleeping_index]:
		return 1
	else:
		return 0
	###initial state###
initial_state = (2,True)
#monkey patch to write state to plot
#monkey patch to write state to plot
day = 0
new_output_q = asyncio.Queue()
def write_to_stream(self, state):
    try:
        self.iteration+=1
    except:
        self.iteration = 0
    #s.write(dict(x=self.inc, y=state[battery_index]))
    new_output_q.put_nowait({'x':self.iteration, 'y':state[battery_index]})
    return
Agent.state_writer = write_to_stream
agent = Agent(actions_states, state_rewards, initial_state, wakeup, Sarsa)
print('agent defined')
"""now define our environment"""
#=====autonomous actions=======#

@asyncio.coroutine
def battery_action():
    battery = 0
    sleeping = 1
    sunny = True
    def adjust_battery(is_sunny, old_pow):
        new_pow = list(old_pow)
        if new_pow[sleeping]:
            new_pow[battery] += (1 + is_sunny*1) #increase by 1 if not sunny, by 2 if sunny
        else:
            new_pow[battery] -= (2 - is_sunny*1) #decrease by 2 if not sunny, 1 if sunny
        if new_pow[battery]<=0:
            new_pow[battery] = 0
            new_pow[sleeping] = True
        if new_pow[battery]>=5:
            new_pow[battery] = 5
            new_pow[sleeping] = False
        return tuple(new_pow)
    while True:
        if random.random()<0.1:
            sunny = not sunny
        adjust_battery_sunny = functools.partial(adjust_battery, sunny)
        yield from asyncio.sleep(1)
        yield from sensing_q.put((1,adjust_battery_sunny))
        print('sensing q: ', sensing_q.qsize())

#======reactions to agent actions==========#
def reaction_func(state1,state2, action):
	return state2
env_reactions = {'go_to_sleep':reaction_func, 'wakeup':reaction_func}
env  = Environment(env_reactions,[battery_action])
#======custom plotting====================#
#======custom plotting====================#
@asyncio.coroutine
def plot():
    while True:
        d = yield from new_output_q.get()
        s.write(dict(x=d['x'], y=d['y']))
"""now run the simulation"""
loop = asyncio.get_event_loop()
sensing_q.put_nowait((1,wakeup))
tasks = [agent.experience_environment(), env.react_to_action(), plot()]
for i in env.env_actions:
	tasks.append(i())
def loop_stopper():
	loop.stop()
loop.call_later(100, loop_stopper) 
loop.run_until_complete(asyncio.wait(tasks))
loop.close()


agent defined
learning:  (2, True) <function wakeup at 0x7f227be6a598> (2, False) 0
put it on the q
learning:  (2, False) <function go_to_sleep at 0x7f227be84f28> (2, True) 0
put it on the q
learning:  (2, True) <function wakeup at 0x7f227be6a598> (2, False) 0
put it on the q
no change in state (2, False) (2, False)
sensing q:  1
learning:  (2, False) <function wakeup at 0x7f227be6a598> (1, False) 1
put it on the q
learning:  (1, False) <function go_to_sleep at 0x7f227be84f28> (1, True) 0
put it on the q
learning:  (1, True) <function wakeup at 0x7f227be6a598> (1, False) 0
put it on the q
no change in state (1, False) (1, False)
sensing q:  1
learning:  (1, False) <function wakeup at 0x7f227be6a598> (0, True) -10
put it on the q
learning:  (0, True) <function wakeup at 0x7f227be6a598> (0, False) -10
put it on the q
no change in state (0, False) (0, False)
sensing q:  1
learning:  (0, False) <function wakeup at 0x7f227be6a598> (0, True) -10
put it on the q
no change in state (0, True) (0, True)
sensing q:  1
learning:  (0, True) <function go_to_sleep at 0x7f227be84f28> (2, True) 0
put it on the q
no change in state (2, True) (2, True)
sensing q:  1
learning:  (2, True) <function go_to_sleep at 0x7f227be84f28> (4, True) 0
put it on the q
no change in state (4, True) (4, True)
sensing q:  1
learning:  (4, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (4, False) 1
put it on the q
learning:  (4, False) <function go_to_sleep at 0x7f227be84f28> (4, True) 0
put it on the q
no change in state (4, True) (4, True)
sensing q:  1
learning:  (4, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (4, False) 1
put it on the q
no change in state (4, False) (4, False)
sensing q:  1
learning:  (4, False) <function wakeup at 0x7f227be6a598> (2, False) 1
put it on the q
no change in state (2, False) (2, False)
sensing q:  1
learning:  (2, False) <function wakeup at 0x7f227be6a598> (0, True) -10
put it on the q
no change in state (0, True) (0, True)
sensing q:  1
learning:  (0, True) <function go_to_sleep at 0x7f227be84f28> (1, True) 0
put it on the q
no change in state (1, True) (1, True)
sensing q:  1
learning:  (1, True) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
no change in state (3, True) (3, True)
sensing q:  1
learning:  (3, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (4, False) 1
put it on the q
no change in state (4, False) (4, False)
sensing q:  1
learning:  (4, False) <function wakeup at 0x7f227be6a598> (3, False) 1
put it on the q
learning:  (3, False) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
learning:  (3, True) <function wakeup at 0x7f227be6a598> (3, False) 0
put it on the q
learning:  (3, False) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
no change in state (3, True) (3, True)
sensing q:  1
learning:  (3, True) <function go_to_sleep at 0x7f227be84f28> (4, True) 0
put it on the q
no change in state (4, True) (4, True)
sensing q:  1
learning:  (4, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (4, False) 1
put it on the q
no change in state (4, False) (4, False)
sensing q:  1
learning:  (4, False) <function wakeup at 0x7f227be6a598> (2, False) 1
put it on the q
learning:  (2, False) <function go_to_sleep at 0x7f227be84f28> (2, True) 0
put it on the q
learning:  (2, True) <function wakeup at 0x7f227be6a598> (2, False) 0
put it on the q
learning:  (2, False) <function go_to_sleep at 0x7f227be84f28> (2, True) 0
put it on the q
no change in state (2, True) (2, True)
sensing q:  1
learning:  (2, True) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
no change in state (3, True) (3, True)
sensing q:  1
learning:  (3, True) <function go_to_sleep at 0x7f227be84f28> (4, True) 0
put it on the q
no change in state (4, True) (4, True)
sensing q:  1
learning:  (4, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (3, False) 1
put it on the q
learning:  (3, False) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
no change in state (3, True) (3, True)
sensing q:  1
learning:  (3, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (4, False) 1
put it on the q
no change in state (4, False) (4, False)
sensing q:  1
learning:  (4, False) <function wakeup at 0x7f227be6a598> (3, False) 1
put it on the q
learning:  (3, False) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
no change in state (3, True) (3, True)
sensing q:  1
learning:  (3, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (4, False) 1
put it on the q
no change in state (4, False) (4, False)
sensing q:  1
learning:  (4, False) <function wakeup at 0x7f227be6a598> (3, False) 1
put it on the q
learning:  (3, False) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
learning:  (3, True) <function wakeup at 0x7f227be6a598> (3, False) 0
put it on the q
learning:  (3, False) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
no change in state (3, True) (3, True)
sensing q:  1
learning:  (3, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (4, False) 1
put it on the q
no change in state (4, False) (4, False)
sensing q:  1
learning:  (4, False) <function wakeup at 0x7f227be6a598> (3, False) 1
put it on the q
learning:  (3, False) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
no change in state (3, True) (3, True)
sensing q:  1
learning:  (3, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (4, False) 1
put it on the q
no change in state (4, False) (4, False)
sensing q:  1
learning:  (4, False) <function wakeup at 0x7f227be6a598> (3, False) 1
put it on the q
learning:  (3, False) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
no change in state (3, True) (3, True)
sensing q:  1
learning:  (3, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (4, False) 1
put it on the q
no change in state (4, False) (4, False)
sensing q:  1
learning:  (4, False) <function wakeup at 0x7f227be6a598> (3, False) 1
put it on the q
learning:  (3, False) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
no change in state (3, True) (3, True)
sensing q:  1
learning:  (3, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (4, False) 1
put it on the q
no change in state (4, False) (4, False)
sensing q:  1
learning:  (4, False) <function wakeup at 0x7f227be6a598> (2, False) 1
put it on the q
learning:  (2, False) <function go_to_sleep at 0x7f227be84f28> (2, True) 0
put it on the q
no change in state (2, True) (2, True)
sensing q:  1
learning:  (2, True) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
no change in state (3, True) (3, True)
sensing q:  1
learning:  (3, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (4, False) 1
put it on the q
no change in state (4, False) (4, False)
sensing q:  1
learning:  (4, False) <function wakeup at 0x7f227be6a598> (3, False) 1
put it on the q
learning:  (3, False) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
no change in state (3, True) (3, True)
sensing q:  1
learning:  (3, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (4, False) 1
put it on the q
no change in state (4, False) (4, False)
sensing q:  1
learning:  (4, False) <function wakeup at 0x7f227be6a598> (2, False) 1
put it on the q
learning:  (2, False) <function go_to_sleep at 0x7f227be84f28> (2, True) 0
put it on the q
no change in state (2, True) (2, True)
sensing q:  1
learning:  (2, True) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
no change in state (3, True) (3, True)
sensing q:  1
learning:  (3, True) <function go_to_sleep at 0x7f227be84f28> (4, True) 0
put it on the q
no change in state (4, True) (4, True)
sensing q:  1
learning:  (4, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (3, False) 1
put it on the q
learning:  (3, False) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
no change in state (3, True) (3, True)
sensing q:  1
learning:  (3, True) <function go_to_sleep at 0x7f227be84f28> (4, True) 0
put it on the q
no change in state (4, True) (4, True)
sensing q:  1
learning:  (4, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (3, False) 1
put it on the q
learning:  (3, False) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
no change in state (3, True) (3, True)
sensing q:  1
learning:  (3, True) <function go_to_sleep at 0x7f227be84f28> (4, True) 0
put it on the q
no change in state (4, True) (4, True)
sensing q:  1
learning:  (4, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (3, False) 1
put it on the q
learning:  (3, False) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
no change in state (3, True) (3, True)
sensing q:  1
learning:  (3, True) <function go_to_sleep at 0x7f227be84f28> (4, True) 0
put it on the q
no change in state (4, True) (4, True)
sensing q:  1
learning:  (4, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (3, False) 1
put it on the q
learning:  (3, False) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
no change in state (3, True) (3, True)
sensing q:  1
learning:  (3, True) <function go_to_sleep at 0x7f227be84f28> (4, True) 0
put it on the q
no change in state (4, True) (4, True)
sensing q:  1
learning:  (4, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (3, False) 1
put it on the q
learning:  (3, False) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
no change in state (3, True) (3, True)
sensing q:  1
learning:  (3, True) <function go_to_sleep at 0x7f227be84f28> (4, True) 0
put it on the q
no change in state (4, True) (4, True)
sensing q:  1
learning:  (4, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (3, False) 1
put it on the q
learning:  (3, False) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
no change in state (3, True) (3, True)
sensing q:  1
learning:  (3, True) <function go_to_sleep at 0x7f227be84f28> (4, True) 0
put it on the q
no change in state (4, True) (4, True)
sensing q:  1
learning:  (4, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (3, False) 1
put it on the q
learning:  (3, False) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
no change in state (3, True) (3, True)
sensing q:  1
learning:  (3, True) <function go_to_sleep at 0x7f227be84f28> (4, True) 0
put it on the q
no change in state (4, True) (4, True)
sensing q:  1
learning:  (4, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (3, False) 1
put it on the q
learning:  (3, False) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
no change in state (3, True) (3, True)
sensing q:  1
learning:  (3, True) <function go_to_sleep at 0x7f227be84f28> (4, True) 0
put it on the q
no change in state (4, True) (4, True)
sensing q:  1
learning:  (4, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (3, False) 1
put it on the q
learning:  (3, False) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
no change in state (3, True) (3, True)
sensing q:  1
learning:  (3, True) <function go_to_sleep at 0x7f227be84f28> (4, True) 0
put it on the q
no change in state (4, True) (4, True)
sensing q:  1
learning:  (4, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (3, False) 1
put it on the q
learning:  (3, False) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
no change in state (3, True) (3, True)
sensing q:  1
learning:  (3, True) <function go_to_sleep at 0x7f227be84f28> (4, True) 0
put it on the q
no change in state (4, True) (4, True)
sensing q:  1
learning:  (4, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (3, False) 1
put it on the q
learning:  (3, False) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
no change in state (3, True) (3, True)
sensing q:  1
learning:  (3, True) <function go_to_sleep at 0x7f227be84f28> (4, True) 0
put it on the q
no change in state (4, True) (4, True)
sensing q:  1
learning:  (4, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (3, False) 1
put it on the q
learning:  (3, False) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
no change in state (3, True) (3, True)
sensing q:  1
learning:  (3, True) <function go_to_sleep at 0x7f227be84f28> (4, True) 0
put it on the q
no change in state (4, True) (4, True)
sensing q:  1
learning:  (4, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (3, False) 1
put it on the q
learning:  (3, False) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
no change in state (3, True) (3, True)
sensing q:  1
learning:  (3, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (4, False) 1
put it on the q
learning:  (4, False) <function go_to_sleep at 0x7f227be84f28> (4, True) 0
put it on the q
no change in state (4, True) (4, True)
sensing q:  1
learning:  (4, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (4, False) 1
put it on the q
no change in state (4, False) (4, False)
sensing q:  1
learning:  (4, False) <function wakeup at 0x7f227be6a598> (3, False) 1
put it on the q
learning:  (3, False) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
no change in state (3, True) (3, True)
sensing q:  1
learning:  (3, True) <function go_to_sleep at 0x7f227be84f28> (4, True) 0
put it on the q
no change in state (4, True) (4, True)
sensing q:  1
learning:  (4, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)
sensing q:  1
learning:  (5, False) <function wakeup at 0x7f227be6a598> (3, False) 1
put it on the q
learning:  (3, False) <function go_to_sleep at 0x7f227be84f28> (3, True) 0
put it on the q
no change in state (3, True) (3, True)
sensing q:  1
learning:  (3, True) <function go_to_sleep at 0x7f227be84f28> (4, True) 0
put it on the q
no change in state (4, True) (4, True)
sensing q: 
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-3-39ad8895081a> in <module>()
    110         loop.stop()
    111 loop.call_later(100, loop_stopper)
--> 112 loop.run_until_complete(asyncio.wait(tasks))
    113 loop.close()

/usr/lib/python3.4/asyncio/base_events.py in run_until_complete(self, future)
    312         future.remove_done_callback(_run_until_complete_cb)
    313         if not future.done():
--> 314             raise RuntimeError('Event loop stopped before Future completed.')
    315 
    316         return future.result()

RuntimeError: Event loop stopped before Future completed.
 1
learning:  (4, True) <function go_to_sleep at 0x7f227be84f28> (5, False) 0
put it on the q
no change in state (5, False) (5, False)

In [3]:
agent.learner.q


Out[3]:
{((0, False), 'go_to_sleep'): -10,
 ((0, False), 'wakeup'): -9.68902408056793,
 ((0, True), 'go_to_sleep'): 0.7693803507144094,
 ((1, False), 'go_to_sleep'): 2.7547503673120106,
 ((1, False), 'wakeup'): -9.938252092910037,
 ((1, True), 'go_to_sleep'): 2.26926505804937,
 ((1, True), 'wakeup'): 0.0397319657275938,
 ((2, False), 'go_to_sleep'): 2.9805596202904554,
 ((2, False), 'wakeup'): -12.360390668223692,
 ((2, True), 'go_to_sleep'): 2.403710403766903,
 ((2, True), 'wakeup'): 1.2829517442732277,
 ((3, False), 'go_to_sleep'): 1.7243976956351732,
 ((3, False), 'wakeup'): 3.505835058957417,
 ((3, True), 'go_to_sleep'): 0.0,
 ((3, True), 'wakeup'): 2.9952764775634613,
 ((4, False), 'wakeup'): 4.070598505566764,
 ((4, True), 'go_to_sleep'): 2.9219004733851985,
 ((4, True), 'wakeup'): 0,
 ((5, False), 'go_to_sleep'): 1.393029057730107,
 ((5, False), 'wakeup'): 4.38480404222528,
 ((5, True), 'go_to_sleep'): 2.1572802738717933}

In [ ]:


In [3]:


In [3]:


In [37]:


In [36]:


In [36]:


In [ ]: