Scipy XX
Scipy XX
Scipy XX
return betta ~ 3¢xt07*cxt01+19*K001-19, 25exfo}2 + xf1]*2 - 1) In (19): sol a (p> sox otf, (0.5, 0.5)) hitps/Ipeople.duke.edul~cce' 4/eta-663-20°6/'3_ Optimization htm 3, the fixed point is unstable, even chaotic, but we would never know that just from the plot above.(0710572022, 10:53 Using optimization routines from scipy and slatsmodels — Computational Stasis in Python outti9}: array(t 1.11694147, 0.829524221) yy In (201: fsolve(f, (0.5, 0.5)) “pb ur{20}: array({ 1.11694147, 0.829524221) ap We can also give the jacobian In (211: def jects)
return c-6*xt01, 17, c0.5#xto1, 2*x01101 In [22]: sol = root(f, (0.5, 0.5), Jac=jac) “> sol.x, sol. fun our(22}: (array({ 1.11696147, 0.829524221), [> array(t -4.233835500-12, -3.31612515e-121)) Check that values found are really roots In {23}: np.allclose(f(sol.x), 0) “bp out{23}: True “Pp Starting from other initial conditions, different roots may be found In [24]: sol = root(f, (1 4 ff> sex 129) out(24): array({ 0.778013%4, -0.92123498)) “p In [25]: np.allelose(f(sol.x), 0) «bp ut{25}: True «bp \We will assume that our optimization problem is to minimize some univariate or multivariate function f (2). This is without loss of generality, since to find the maximum, we can simply minime — f(r). We will also assume that we are dealing with multivariate or real-valued smooth functions - non-smooth or discrete functions (eg. integer-valued) are outside the scope. ofthis course To find the minimum of a function, we first need to be able to express the function as a mathemtical exoresssion. For example, in lesst squares regression, the function that we are optimizing is of the form ys — f(2i,0) for some parameter(s) 8. To choose an appropirate optimization algorihtm, we should at least answr these two questions if possible: 1. Is the function convex? 2. Are there any constraints that the solution must meet? Finally, we need to realize that optimization mehthods are nearly always designed to find local optima. For convex problems, there is only one minimum and so this is not a problem. However, if there are multiple local minima, often heuristics such as multiple random starts must be adopted to find a “good” enouhg solution. Is the function convex? hitps/Ipeople.duke.edul~cce' 4/eta-663-20°6/'3_ Optimization htm(0710572022, 10:53 Using optimization routines from scipy and slatsmodels — Computational Stasis in Python Convex functions are very nice because they have a single global minimum, and there are very efficient algorithms for solving large convex systems. Intuitively, a function is convex if every chord joining two points on the function lies above the function. More formally, a function is convex if : nowrap Sta + (1 #6) < tf(a) + (1-1) (6) forsome : math : 't'betweenand! — thisisshowninthe figurebelow. Tn (26): def f(x)