Hi all,
am I allowed to change the limits of the following integral:
integral ( Zk ) dk from i/2 to infinity + i/2, where i is an imaginary number. Function Z is also complex. Can I just integrate it over 0 to infinity??
thank you,
K
Another guess..my guess is that K is referring to a violation of the (unnecessary) Feller condition, but we'll see ...
# SHGO.py
# DJD
# minimize f(x) = abs(x1-2) + abs(x2-2), x = (x1,x2)
#
# g(x) = x1 - x2^2 >= 0 parabola
# h(x) = x1^2 + x2^2 -1 = 0 circle
#
# Global minimum = (sqrt(2)/2, sqrt(2)/2)
#
# Also eggholder function
from scipy.optimize import minimize_scalar, minimize, shgo, brute, fmin
import math
import numpy as np
#Constrained methods
print("constrained optimisation")
fun = lambda x: math.fabs(x[0] - 2) + math.fabs(x[1] - 2)
#choice 1
cons1 = {'type': 'ineq', 'fun': lambda x: x[0] - pow(x[1],2)}
cons2 = {'type': 'eq', 'fun': lambda x: pow(x[0],2) + pow(x[1],2) - 1.0 }
cons = [cons1, cons2]
# SLSQP method
x0 = [2,0]
bnds = [(0,None), (0,None)]
v = minimize(fun,x0, method='SLSQP', bounds = bnds, constraints = cons)
print(v)
#print(fun(v[0], v[1]))
# SHGO (Simplicial Homology Global Optimisation)
result = shgo(fun, bounds = bnds, constraints = cons, sampling_method ='simplicial')
print("global minimum ", result.x)
print("success? ", result.success)
print(result.fun)
print("local minima ", result.xl)
print("values at local minima ", result.funl)
# Several local minima
def eggholder(xc):
x = xc[0]; y = xc[1]
return (-(y+ 47.0)*np.sin(np.sqrt(abs(0.5*x + y+47.0)))
- x*np.sin(np.sqrt(abs(x- (y+47.0))))
)
bnds = [(-512,512), (-512,512)]
#choice 1 (ineq always g(x) >= 0)
cons1 = {'type': 'ineq', 'fun': lambda x: x + 1}
cons2 = {'type': 'ineq', 'fun': lambda x: 3.0 - x}
cons = [cons1, cons2]
# SHGO method
#result = shgo(fun, bounds = bnds, constraints = cons, sampling_method ='sobol')
result = shgo(eggholder, bounds = bnds, n = 64, sampling_method ='sobol')
print("global minimum ", result.x)
print("success? ", result.success)
print(result.fun)
print("local minima ", result.xl)
print("values at local minima ", result.funl)
import quadpy
import numpy
val, err = quadpy.quad(lambda x: numpy.exp(1j * x), 0, 1)
print(val)
# correctly gives (0.8414709848078964+0.4596976941318605j)