Skip to content

Instantly share code, notes, and snippets.

View robinvanemden's full-sized avatar
🌳
⏩ ⏩

Robin van Emden robinvanemden

🌳
⏩ ⏩
View GitHub Profile
# -*- coding: utf-8 -*-
#from IPython import get_ipython
#get_ipython().magic('reset -sf')
import sys,random
import ujson as json
import asyncio,aiohttp,pymongo
import numpy as np
import numpy as np
def matrixpush(m, row):
if not np.all(np.isfinite(values[:,0])):
i = np.count_nonzero(np.logical_not(np.isnan(values[:,0])))
m[i,] = row
else:
m = np.vstack([m,row])
m = m[1:,]
return(m)
for t in range(0,stream):
x = x0 + amplitude*np.cos(omega * t)
y = amplitude*np.cos(omega * t)*getobs(x,5,variance)
values = matrixpush(values, np.array([t,x,y]))
if np.all(np.isfinite(values[:,0])):
x0 = x0 + learnrate * sum( values[:,2] ) / inttime
<strong>Eyewitness</strong>
Three suspects have been lined up by the police, and two witnesses are asked how certain they are of seeing each of the suspects at the crime-scene. Which subject would might have been at the crime scene, according to you?
<style type="text/css">
.table {
width: 100%;
border: 1px solid #C0C0C0;
border-collapse: collapse;
padding: 5px;
}
.table th {
@robinvanemden
robinvanemden / lif.py
Created January 2, 2016 13:47
Implementation of the Lock in Feedback algorithm in the Python Tornado based StreamingBandit web server
# Implementation of Lock in Feedback.
# -*- coding: utf-8 -*-
from libs.base import *
import numpy as np
import json
class Lif:
def __init__(self, theta, x0=1.0, A=1.4, T=100, gamma=.004, omega=0.8, lifversion=2):
self._set_parameters(x0, A, T, gamma, omega, lifversion)
# -*- coding: utf-8 -*-
import libs.lif as lf
key = "question"
value = self.context['question']
theta = self.get_theta(all_float=False, key=key, value=value)
Lif = lf.Lif(theta, x0=self.context['x0'], A=1.4 , T=100, gamma=.004, omega=.8, lifversion=2)
suggestion = Lif.suggest()
# -*- coding: utf-8 -*-
import libs.lif as lf
key = "question"
value = self.context['question']
theta = self.get_theta(all_float=False, key=key, value=value)
Lif = lf.Lif(theta, x0=self.context['x0'], A=1.4 , T=100, gamma=.004, omega=.8, lifversion=2)
Lif.update(self.action["t"],self.action["x"], self.reward)
self.set_theta(Lif, key=key, value=value)
import sys,random
import json
import asyncio,aiohttp,pymongo,time
import numpy as np
import matplotlib.pyplot as plt
MONGO_IP = "78.46.212.194"
MONGO_PORT = 27017
SB_BASE_URL = "https://strm.mnds.org:8080"
/**
*
* Qualtrics_barebones_question_for_lif.js
* Javascript code to integrate Streamingbandit & Qualtrics.
* Sends an receives JSON to and from StreamingBandit server
*
**/
/* --- insert as <script> into look and feel ---*/
# -*- coding: utf-8 -*-
#==============================================================================
# Reset IPython - may delete the following when not making use of Spyder IDE
from IPython import get_ipython
get_ipython().magic('reset -sf')
#==============================================================================