I am trying to minimize the following function using scipy.optimize :

whose gradient is this:

(For those interested, this is the likelihood function of the Bradley-Terry-Luce model for pairwise comparisons. Very closely related to logistic regression.)
It is quite clear that adding a constant to all parameters does not change the value of the function. Therefore, I give \ theta_1 = 0. Here is the implementation of the object functions and the gradient in python (here theta here is x ):
def objective(x): x = np.insert(x, 0, 0.0) tiles = np.tile(x, (len(x), 1)) combs = tiles.T - tiles exps = np.dstack((zeros, combs)) return np.sum(cijs * scipy.misc.logsumexp(exps, axis=2)) def gradient(x): zeros = np.zeros(cijs.shape) x = np.insert(x, 0, 0.0) tiles = np.tile(x, (len(x), 1)) combs = tiles - tiles.T one = 1.0 / (np.exp(combs) + 1) two = 1.0 / (np.exp(combs.T) + 1) mat = (cijs * one) + (cijs.T * two) grad = np.sum(mat, axis=0) return grad[1:]
Here is an example of what cijs might look cijs :
[[ 0 5 1 4 6] [ 4 0 2 2 0] [ 6 4 0 9 3] [ 6 8 3 0 5] [10 7 11 4 0]]
This is the code that I executed to do the minimization:
x0 = numpy.random.random(nb_items - 1) # Let try one algorithm... xopt1 = scipy.optimize.fmin_bfgs(objective, x0, fprime=gradient, disp=True) # And another one... xopt2 = scipy.optimize.fmin_cg(objective, x0, fprime=gradient, disp=True)
However, in the first iteration, it always fails:
Warning: Desired error not necessarily achieved due to precision loss. Current function value: 73.290610 Iterations: 0 Function evaluations: 38 Gradient evaluations: 27
I cannot understand why he is failing. The error is displayed due to this line: https://github.com/scipy/scipy/blob/master/scipy/optimize/optimize.py#L853
So this “search in the Wolfe line” seems unsuccessful, but I don’t know how to get from here ... Any help is appreciated!