[SciPy-user] optimize.fmin_bfgs only returning a scalar for xopt?
David Warde-Farley
dwf@cs.toronto....
Thu Apr 3 15:18:28 CDT 2008
On 3-Apr-08, at 3:30 PM, Nils Wagner wrote:
> Can you provide us with your example code ?
Sure. Here I'm just attempting to fit a logistic regression model.
def lr_probs(coeffs, data, target):
bias = coeffs[0]
coeffs = coeffs[1:]
eta = bias + N.sum(coeffs * data, axis=1)
probs = 1 / (1 + N.exp(-eta))
return probs
def lr_nloglik(coeffs, data, target, decay=0):
probs = lr_probs(coeffs, data, target)
bias = coeffs[0]
coeffs = coeffs[1:]
L = N.sum(target * probs)
if decay:
L = L - decay * (bias**2 + N.sum(coeffs**2))
return -L
def lr_fit(data, target, decay=None):
#initial = S.randn(data.shape[1] + 1) * 0.01
initial = N.zeros(data.shape[1] + 1)
beta, lik, fcalls, gcalls = opt.fmin_bfgs(lr_nloglik, initial,
None, args=(data,target,decay))
More information about the SciPy-user
mailing list