What does "Desired error not necessarily achieved due to precision loss
" mean in the context of the scipy_fmin
methods? I can't seem to find an explanation anywhere.
Here is my code:
import math
import numpy
import random
import scipy.optimize as opt
import matplotlib.pyplot as plt
from numpy import array
from numpy import dot
from random import randint
from numpy import matrix
import sys
ns = []
st = []
lam_funtrix = []
time_steps = 1000
delta_t = 0.1
mu = -0.7
def gen_st():
global st
st = []
for i in range(0, time_steps):
st.append(random.normalvariate(0,1) * math.sqrt(delta_t))
def f(val):
return math.exp(val)
def get_lam(t):
rate = mu
return pow(delta_t, -1) * f(rate)
def white_noise():
global ns
for i in range(0, time_steps):
lam = get_lam(i) * delta_t
spike_at_bin = numpy.random.poisson(lam)
ns.append(spike_at_bin)
def gen_lam_log(i, mu):
rate = mu
return pow(delta_t, -1) * f(rate)
def gen_lam_fun(mu):
global lam_funtrix
lam_funtrix = []
for i in range(0, time_steps):
lam_funtrix.append(gen_lam_log(i, mu))
def log_like(t):
mu = t
gen_lam_fun(mu)
sum = 0
for i in range(0,time_steps):
val = lam_funtrix[i]
sum = sum - ((ns[i] * math.log(val*delta_t)) - (val*delta_t))
return sum
def der_mu():
sum = 0.0
for i in range(0, time_steps):
sum -= (ns[i] - lam_funtrix[i] * delta_t)
return sum
def first_der(t):
mu = t
gen_lam_fun(mu)
dm = der_mu()
return dm
gen_st()
white_noise()
init_guess = array([0])
vals = opt.fmin_cg(log_like, init_guess, fprime=first_der)
print vals
The code is a little off since I pared it down a bit.
Warning: Desired error not necessarily achieved due to precision loss.
Current function value: 822.835581
Iterations: 1
Function evaluations: 18
Gradient evaluations: 6
[-0.7943019]