L i%JdZddlZddlZddlmZmZgZddZ GddeZ y) z"Dog-leg trust-region optimization.N)_minimize_trust_regionBaseQuadraticSubproblemc t| tdt|s tdt||f|||td|S)a  Minimization of scalar function of one or more variables using the dog-leg trust-region algorithm. Options ------- initial_trust_radius : float Initial trust-region radius. max_trust_radius : float Maximum value of the trust-region radius. No steps that are longer than this value will be proposed. eta : float Trust region related acceptance stringency for proposed steps. gtol : float Gradient norm must be less than `gtol` before successful termination. z,Jacobian is required for dogleg minimizationz+Hessian is required for dogleg minimization)argsjachess subproblem) ValueErrorcallablerDoglegSubproblem)funx0rrr trust_region_optionss h/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/scipy/optimize/_trustregion_dogleg.py_minimize_doglegr sO( {GHH D>FGG !#r :#D-= :$8 ::c"eZdZdZdZdZdZy)r z0Quadratic subproblem solved by the dogleg methodc|jS|j}|j|}tj||tj||z |z|_|jS)zV The Cauchy point is minimal along the direction of steepest descent. ) _cauchy_pointrhesspnpdot)selfgBgs r cauchy_pointzDoglegSubproblem.cauchy_point)s[    %AAB#%66!Q<"&&B-#?!@1!DD !!!rc|j]|j}|j}tjj |}tjj || |_|jS)zS The Newton point is a global minimum of the approximate function. ) _newton_pointrr scipylinalg cho_factor cho_solve)rrBcho_infos r newton_pointzDoglegSubproblem.newton_point3s^    %A A||..q1H"',,"8"81"E!ED !!!rcJ|j}tjj||krd}||fS|j }tjj|}||k\r|||z z}d}||fS|j |||z |\}}||||z zz}d}||fS)a Minimize a function using the dog-leg trust-region algorithm. This algorithm requires function values and first and second derivatives. It also performs a costly Hessian decomposition for most iterations, and the Hessian is required to be positive definite. Parameters ---------- trust_radius : float We are allowed to wander only this far away from the origin. Returns ------- p : ndarray The proposed step. hits_boundary : bool True if the proposed step is on the boundary of the trust region. Notes ----- The Hessian is required to be positive definite. References ---------- .. [1] Jorge Nocedal and Stephen Wright, Numerical Optimization, second edition, Springer-Verlag, 2006, page 73. FT)r&r r!normrget_boundaries_intersections) r trust_radiusp_best hits_boundaryp_up_u_norm p_boundary_tbs rsolvezDoglegSubproblem.solve>sD""$ <<  V $| 3!M=( (!<<$$S) | # x 78J M}, ,11#v|2>@22#..  =((rN)__name__ __module__ __qualname____doc__rr&r2rrr r &s:" "<)rr )r7NN) r6numpyr scipy.linalgr _trustregionrr__all__rr r7rrr<s*(K ::T).T)r