Scipy fmin警告说明

时间:2015-03-10 21:23:36

标签: python numpy scipy mathematical-optimization

Desired error not necessarily achieved due to precision loss”在scipy_fmin方法的上下文中意味着什么?我似乎无法在任何地方找到解释。

这是我的代码:

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

因为我把它减了一点,所以代码有点偏。

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]

0 个答案:

没有答案