Created
December 15, 2015 15:05
-
-
Save robinvanemden/23f350c275a7f687e6f0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
def getobs( x, max = 5, err=0 ): | |
if (err==0): | |
obsr = -1*pow((x-max),2) | |
else: | |
obsr = -1*pow((x-max),2) + np.random.normal(0,err,1) | |
return obsr; | |
max = 5 # Set maximum | |
stream = 3000 # Length of stream | |
inttime = 100 # Integration time | |
amplitude = 1.4 # Amlitude LIF | |
learnrate = .004 # Learnrate | |
omega = (2*np.pi)/inttime # Omega | |
x0 = 1.0 # Startvalue | |
p_return = 0.80 # Chance that returns | |
variance = 1 # variance in observations | |
values = np.zeros((inttime,3)) | |
values.fill(np.nan) | |
x = 0.0 | |
t = 0.0 | |
y = 0.0 | |
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 | |
print(x0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment