+
    ,i,                         R t ^ RIt^ RIt^ RIt^ RIt^RIHtH	t	H
t
HtHt ^ RIHt ^ RIHt . tR t ! R R4      tR	R ltR# )
zTrust-region optimization.N)_check_unknown_options_status_messageOptimizeResult_prepare_scalar_function_call_callback_maybe_halt)HessianUpdateStrategy)
FD_METHODSc                 6   a aa ^ .oS f   SR3# VV V3R lpSV3# )    Nc                 x   < S^ ;;,          ^,          uu&   S! \         P                  ! V 4      .VS,           O5!  # )r
   )npcopy)xwrapper_argsargsfunctionncallss   &*=/usr/lib/python3/dist-packages/scipy/optimize/_trustregion.pyfunction_wrapper(_wrap_function.<locals>.function_wrapper   s-    q	Q	
;lT&9;;     )r   r   r   r   s   ff @r   _wrap_functionr      s/     SFt|<
 ###r   c                      a  ] tR t^t o RtRR ltR t]R 4       t]R 4       t	]R 4       t
R t]R	 4       tR
 tR tRtV tR# )BaseQuadraticSubproblema9  
Base/abstract class defining the quadratic model for trust-region
minimization. Child classes must implement the ``solve`` method.

Values of the objective function, Jacobian and Hessian (if provided) at
the current iterate ``x`` are evaluated on demand and then stored as
attributes ``fun``, ``jac``, ``hess``.
Nc                    Wn         R V n        R V n        R V n        R V n        R V n        R V n        W n        W0n        W@n	        WPn
        R # N)_x_f_g_h_g_mag_cauchy_point_newton_point_fun_jac_hess_hessp)selfr   funjachesshessps   &&&&&&r   __init__ BaseQuadraticSubproblem.__init__(   sG    !!		
r   c                    V P                   \        P                  ! V P                  V4      ,           R \        P                  ! WP	                  V4      4      ,          ,           # )g      ?)r)   r   dotr*   r,   r(   ps   &&r   __call__ BaseQuadraticSubproblem.__call__5   s;    xx"&&1--bffQ

16N0NNNr   c                v    V P                   f!   V P                  V P                  4      V n         V P                   # )z1Value of objective function at current iteration.)r   r$   r   r(   s   &r   r)   BaseQuadraticSubproblem.fun8   *     77?ii(DGwwr   c                v    V P                   f!   V P                  V P                  4      V n         V P                   # )z=Value of Jacobian of objective function at current iteration.)r   r%   r   r6   s   &r   r*   BaseQuadraticSubproblem.jac?   r8   r   c                v    V P                   f!   V P                  V P                  4      V n         V P                   # )z<Value of Hessian of objective function at current iteration.)r    r&   r   r6   s   &r   r+   BaseQuadraticSubproblem.hessF   s*     77?jj)DGwwr   c                    V P                   e   V P                  V P                  V4      # \        P                  ! V P                  V4      # r   )r'   r   r   r0   r+   r1   s   &&r   r,   BaseQuadraticSubproblem.hesspM   s6    ;;";;tww**66$))Q''r   c                    V P                   f/   \        P                  P                  V P                  4      V n         V P                   # )zAMagnitude of jacobian of objective function at current iteration.)r!   scipylinalgnormr*   r6   s   &r   jac_magBaseQuadraticSubproblem.jac_magS   s2     ;;,,++DHH5DK{{r   c                   \         P                  ! W"4      p^\         P                  ! W4      ,          p\         P                  ! W4      V^,          ,
          p\        P                  ! WU,          ^V,          V,          ,
          4      pV\        P                  ! Wu4      ,           pV) ^V,          ,          p	RV,          V,          p
\        W.4      # )z
Solve the scalar quadratic equation ``||z + t d|| == trust_radius``.
This is like a line-sphere intersection.
Return the two values of t, sorted from low to high.
)r   r0   mathsqrtcopysignsorted)r(   zdtrust_radiusabcsqrt_discriminantauxtatbs   &&&&       r   get_boundaries_intersections4BaseQuadraticSubproblem.get_boundaries_intersectionsZ   s     FF1LqFF1L<?* IIacAaCEk2 $-- 155TQqS\TCZrhr   c                    \        R 4      h)z9The solve method should be implemented by the child class)NotImplementedError)r(   rM   s   &&r   solveBaseQuadraticSubproblem.solveq   s    ! #4 5 	5r   )r"   r   r$   r   r!   r    r&   r'   r%   r#   r   )NN)__name__
__module____qualname____firstlineno____doc__r-   r3   propertyr)   r*   r+   r,   rC   rU   rY   __static_attributes____classdictcell__)__classdict__s   @r   r   r      sy     O      (   .5 5r   r   c                  a$ \        V4       Vf   \        R4      hVf   Vf   \        R4      hVf   \        R4      h^ T	u;8:  d   R8  g   M \        R4      hV^ 8:  d   \        R4      hV^ 8:  d   \        R4      hWx8  d   \        R	4      h\        P                  ! V4      P                  4       p\        WW4VVR
7      o$S$P                  p S$P                  p\        V4      '       d   S$P                  pMG\        V4      '       d   M5V\        9   g   \        V\        4      '       d
   RpV$3R lpM\        R4      h\        WR4      w  ppVf   \        V4      ^,          p^ pTpTpV'       d   V.pV! VWWE4      p^ pVP                   V
8  Ed3    VP#                  V4      w  ppT! T4      pTT,           pT! TYYE4      pTP                  TP                  ,
          pTP                  T,
          pT^ 8:  d   ^pMTT,          p T R8  d   TR,          pM"T R8  d   T'       d   \)        ^T,          T4      pT T	8  d   TpTpT'       d&   XP+                  \        P,                  ! T4      4       T^,          p\/        TTP                  R7      p!\1        TT!4      '       d   M!TP                   T
8  d   ^ pMTT8  g   EKA  ^p \2        R,          \2        R,          RR3p"V'       d   V^ 8X  d   \5        V"V,          4       M$\6        P8                  ! V"V,          \:        ^R7       \5        RVP                  R 24       \5        RVR 24       \5        RS$P<                  R 24       \5        RS$P>                  R 24       \5        RS$P@                  V^ ,          ,           R 24       \/        VV^ 8H  VVP                  VPB                  S$P<                  S$P>                  S$P@                  V^ ,          ,           VV"V,          R7
      p#Ve   VP                  V#R&   V'       d   XV#R&   V##   \        P$                  P&                   d    ^p EK  i ; i)a  
Minimization of scalar function of one or more variables using a
trust-region algorithm.

Options for the trust-region algorithm are:
    initial_trust_radius : float
        Initial trust radius.
    max_trust_radius : float
        Never propose steps that are longer than this value.
    eta : float
        Trust region related acceptance stringency for proposed steps.
    gtol : float
        Gradient norm must be less than `gtol`
        before successful termination.
    maxiter : int
        Maximum number of iterations to perform.
    disp : bool
        If True, print convergence message.
    inexact : bool
        Accuracy to solve subproblems. If True requires less nonlinear
        iterations, but more vector products. Only effective for method
        trust-krylov.
    workers : int, map-like callable, optional
        A map-like callable, such as `multiprocessing.Pool.map` for evaluating
        any numerical differentiation in parallel.
        This evaluation is carried out as ``workers(fun, iterable)``.
        Only for 'trust-krylov', 'trust-ncg'.

        .. versionadded:: 1.16.0

This function is called by the `minimize` function.
It is not supposed to be called directly.
Nz7Jacobian is currently required for trust-region methodsz_Either the Hessian or the Hessian-vector product is currently required for trust-region methodszBA subproblem solving strategy is required for trust-region methodsg      ?zinvalid acceptance stringencyz%the max trust radius must be positivez)the initial trust radius must be positivez?the initial trust radius must be less than the max trust radius)r*   r+   r   workersc                 D   < SP                  V 4      P                  V4      # r   )r+   r0   )r   r2   r   sfs   &&*r   r,   %_minimize_trust_region.<locals>.hessp   s    771:>>!$$r   g      ?)r   r)   successmaxiterz:A bad approximation caused failure to predict improvement.z3A linalg error occurred, such as a non-psd Hessian.)
stacklevelz!         Current function value: fz         Iterations: rL   z         Function evaluations: z         Gradient evaluations: z         Hessian evaluations: )
r   ri   statusr)   r*   nfevnjevnhevnitmessager+   allvecs)"r   
ValueError	Exceptionr   asarrayflattenr   r)   gradcallabler+   r   
isinstancer   r   lenrC   rY   rA   LinAlgErrorminappendr   r   r   r   printwarningswarnRuntimeWarningrn   ngevrp   r*   )%r)   x0r   r*   r+   r,   
subprobleminitial_trust_radiusmax_trust_radiusetagtolrj   disp
return_allcallbackinexactre   unknown_optionsnhesspwarnflagrM   r   rs   mkr2   hits_boundarypredicted_value
x_proposed
m_proposedactual_reductionpredicted_reductionrhointermediate_resultstatus_messagesresultrg   s%   &&&&&&&&&&&&&&&&&,                  @r   _minimize_trust_regionr   v   s'   N ?+
{ # $ 	$| J K 	K 0 1 	1OtO7881?@@q DEE/ , - 	- 
B			!B 
"S$
B &&C
''C~~ww	% 	
*

41F G G 	%  J K 	K #5/MFE b'#+ H (L
A#1c,A	A ))t
	 ww|4A} A$ U

CdB
 55:>>1eeo5!#H!44 :D L4ZMq~/?@L 9AA NN2771:&	Q,qaee<$X/BCC 99tH <H I&I&HA	O q=/(+,MM/(3^PQR1!%%;<%aU+,/{;</{;<.rww/B1.EFGa(a- !155rwwRWW!#6!9!4!$3H$=?F
 v#yM] yy$$ 	H	s   P( (!QQ)r   NNNNg      ?g     @@g333333?g-C6?NFFNTN)r_   rG   r   numpyr   scipy.linalgr@   	_optimizer   r   r   r   r   'scipy.optimize._hessian_update_strategyr   (scipy.optimize._differentiable_functionsr   __all__r   r   r   r   r   r   <module>r      sD         3 3 J ?
$U5 U5pHr   