0
$\begingroup$

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 crumby since I pared it down a bit for the question.

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]
$\endgroup$
  • $\begingroup$ What is the function that you are optimizing? $\endgroup$ – nicoguaro Apr 15 '15 at 18:19
1
$\begingroup$

It looks to me like the log_like function you're providing optimizes to infinity. That would trigger this specific error.

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.