Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When using scipy.optimize.fmin_bfgs I got TypeError: f() missing 1 required positional argument:

I'm trying to calculate minima of the six-hump camelback function using scipy.optimize.fmin_bfgs() function. Here is my code:

import numpy as np
import matplotlib.pyplot as plt
from scipy import optimize

def f(x,y):
    return (4 - 2.1*x**2 + x**4/3)*x**2 + x*y + (4*y**2 - 4)*y**2

x0 = [0,0]

optimize.fmin_bfgs(f, x0)

Output:

TypeError: f() missing 1 required positional argument: 'y'

I guess there is something wrong with the way I pass x0?

like image 542
mihagazvoda Avatar asked Aug 05 '16 13:08

mihagazvoda


1 Answers

Per this page there should be one array argument to f: http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.minimize.html

Do instead:

def f(x):
    return (4 - 2.1*x[0]**2 + x[0]**4/3)*x[0]**2 + x[0]*x[1] + (4*x[1]**2 - 4)*x[1]**2

x0 = [0,0]
optimize.fmin_bfgs(f,x0)
like image 112
mechanical_meat Avatar answered Oct 23 '22 06:10

mechanical_meat