I want to define a function :
And I want to find minimum with respect to (a,b) for points :
x = np.array([.2, .5, .8, .9, 1.3, 1.7, 2.1, 2.7])
y = f(x) + np.random.randn(len(x))
Using function : optimize.fmin_cg (you can find documentation here : https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.fmin_cg.html)
My work so far
I managed to define a compute_error() function :
def compute_error(a,b):
k=[0]*len(x)
for i in range(0,len(x)):
k[i]=(y[i]-(a*x[i]+b))**2
return sum(k)
And I tried to minimize it using this optimize function, however I met some problems.
x_0=np.array((0,0)) #start optimization from point (0,0)
minimum = optimize.fmin_cg(compute_error,x_0)
TypeError: compute_error() missing 1 required positional argument: 'b'
