0

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]
ali_m
  • 71,714
  • 23
  • 223
  • 298
H X
  • 43
  • 1
  • 7
  • 1
    This is a duplicate of [this question](http://scicomp.stackexchange.com/questions/2004/scipy-optimize-fmin-bfgs-desired-error-not-necessarily-achieved-due-to-precisi). Tried to flag it as duplicate but it failed (because at another Stack Exchange site?) – GertVdE Mar 10 '15 at 22:02
  • another possible duplicate: http://stackoverflow.com/q/24767191/1461210 – ali_m Mar 10 '15 at 22:22
  • That is a [generic status message](https://github.com/scipy/scipy/blob/c567b61d89fa3e433408d720e724cdf257ea8e71/scipy/optimize/optimize.py#L42-L49) that can be returned by many different optimizers for many different reasons. You need to show us some code if you want a definitive answer. – ali_m Mar 10 '15 at 22:26
  • Will add some code once I can get to my computer! Thank you! – H X Mar 11 '15 at 02:12
  • Better migrate to scicomp.stackexchange.com – GertVdE Mar 11 '15 at 06:49
  • @GertVdE I think this question is a better fit for SO - it's about a specific software implementation of a solver, rather than a generic question about optimization. – ali_m Mar 11 '15 at 10:38
  • @ali_m thanks for the edit! looks a lot nicer! (still kinda new to stack overflow) – H X Mar 11 '15 at 17:34

0 Answers0