def partD(x): out = [0]*len(x) h = 10**-6 f = fkt(x) for i in range(len(x)): tmp = x tmp[i] = tmp[i] + h out[i] = (fkt(tmp) - f) / h return out
def partD(vector, radi): out = [0]*len(vector) h = 10**-6 f = fkt(vector, radi) for i in range(len(vector)): tmp = vector tmp[i] = tmp[i] + h out[i] = (fkt(tmp, radi) - f) / h return out
def calcSupremum(radi): fkt_input = [] for i in range(len(radi)): front = radi[:i+1] fkt_input.append(2*sum(front)) # double radius fkt_input.append(0) print 'vec', radi, fkt_input return fkt(fkt_input, radi)
def searchVectorStep(x, r, b): pdf = partD(x, r) n = [-pdf[i] for i in range(len(x))] n.append(1) normN = norm(n) if(normN == 1): normN = normN + 0.001 n[-1] = normN ** 2 - 1 r = ((b - fkt(x, r)) * normN ** 2) / (1 - normN ** 2) d = n / (normN ** 2) return x + r * d[:len(x)]
def searchVectorStep(coords, radi, b): pdf = partD(coords, radi) n = [-pdf[i] for i in range(len(coords))] n.append(1) normN = norm(n) if(normN == 1): normN = normN + 0.001 n[-1] = normN ** 2 - 1 radi = ((b - fkt(coords, radi)) * normN ** 2) / (1 - normN ** 2) d = n / (normN ** 2) return coords + radi * d[:len(coords)]