Python dual- variable search algorithm -
I have an algorithm that:
- takes two inputs (x, y) , Where x and y are two 'lambda' variables in two independent pauson distribution ().
- Calculate the matrix product of two pauson vectors
/ P>
import math, random (zodiac), zodiac (lower_quadrant), zodiac (diagonal)] def poinson (m, n): p = math In XP (-M) R = [P] category I (1, n): P * = M / Float (I) RApment (P) Returns in RDR Range (N): For i (NA) Imitation (MX, My, N): R = [0.0] in Category (N): Range (3)] PX, PI = (Poison (MX, N), Poison (Mary, N)): i & gt ; J: k = 0 alif i
Now I need to solve for X and Y I specifically cut output of the following solver function:
def solution (p, n, generation, decay, tolerance): def rms_error (x, y): Return (zodiac (zip (x, y)]) / float (lane (x)) ** 0.5 def calcerer (x, y, n, target): 2 for x * (xy) * * x, estimate = Simulation (X, Y, N) returns Rms_error (target, estimate ) Err = calc_error (math.exp (q [0]), math.exp (q [1]), n, p) err range for best, besterr = q, i (generations) In: Best RR & LT tolerance: break = q = list (bestq) if random.random () <0.5: J = 1 other: J = 1 FAC = ((generations-I + 1) / float (generations )) ** Decay C [J] + = Random.Guos (0, 1) * ACC FL = Calc_Areer (Math.exp (q [0]), math.exp (q [1]), n, p) if Error & lt; besterr, besterr = q, err # print (i, bestq, besterr) q, err = [math.exp (q)] for q in bestq, best rr return (i, q, err)
which works, but A larger number tries to give a much more optimized response:
if __name__ == "__ main__": p, n = [0.5, 0.2, 0.3], 10 Q, mistake Print = i, err =
Pre>
and:
justin @justin-thinkpad-x220: ~ / work / $ python help.py [0.5, 0.2, 0.3] [0.5000246335218251, 0.20006624338256798, 0.29990837191131686] (99 9, 6.680 993630511076-05) Justin @ Justin-Thinkpad-X120: ~ / work / $
I CS Pram I am not happy and feel that I am completely missing the search literature here. Can someone recommend such a better way to search for variables in 2-D space like this?
Thanks
You can use the library to resolve it: P <=> Import Mathematics, random def poison (m, n): p = math.exp (-m) r = [p] i in category (1, n): p * = m / Float (i) r.append (p) returns R def emulation (MX, Mary, N): R = [0.0 I in range (3)] PX, PI = (Possession (MX, N), Poison (Mary, N )) For range (n): range for j (n): if i & gt; J: k = 0 alif i
output:
done . Current function value: 0.000000 Change: 67 function evaluation: 125 [0.49999812501285623, 0.20000418001288445, 0.2999969464616799]
Comments
Post a Comment