+
    ,i                         ^ RI t ^ RIt^ RIHt ^RIHt ^RIHtH	t	H
t
 ]P                  ! ]4      P                  t ! R R4      tRRRRR	RR
R/tR t ! R R4      t ! R R4      tR# )    N)eigh)Options)MaxEvalErrorTargetSuccessFeasibleSuccessc                      a  ] tR t^t o RtR t]R 4       t]R 4       t]R 4       t	]	P                  R 4       t	]R 4       t]P                  R 4       tR	 tR
tV tR# )Interpolationz
Interpolation set.

This class stores a base point around which the models are expanded and the
interpolation points. The coordinates of the interpolation points are
relative to the base point.
c                   V\         P                  ,          V n        R\        P                  ! VP
                  P                  VP
                  P                  ,
          4      ,          pV\         P                  ,          V8  de   W2\         P                  P                  &   \        P                  ! V\         P                  ,          V.4      V\         P                  P                  &   \        P                  ! VP                  4      V n        V P                  VP
                  P                  RV\         P                  ,          ,          ,           8*  pVP
                  P                  V,          V P                  V&   VP
                  P                  RV\         P                  ,          ,          ,           V P                  8  V P                  VP
                  P                  V\         P                  ,          ,           8*  ,          p\        P                  ! VP
                  P                  V,          V\         P                  ,          ,           VP
                  P                  V,          4      V P                  V&   V P                  VP
                  P                  RV\         P                  ,          ,          ,
          8  pVP
                  P                  V,          V P                  V&   V P                  VP
                  P                  RV\         P                  ,          ,          ,
          8  VP
                  P                  V\         P                  ,          ,
          V P                  8*  ,          p\        P                   ! VP
                  P                  V,          V\         P                  ,          ,
          VP
                  P                  V,          4      V P                  V&   \        P"                  ! VP$                  V\         P&                  ,          34      V n        \+        ^V\         P&                  ,          4       EFy  pWP$                  8:  du   Wh^,
          ,          '       d1   V\         P                  ,          ) V P,                  V^,
          V3&   KY  V\         P                  ,          V P,                  V^,
          V3&   K  V^VP$                  ,          8:  Ed   WHVP$                  ,
          ^,
          ,          '       dH   RV\         P                  ,          ,          V P,                  WP$                  ,
          ^,
          V3&   EK  WhVP$                  ,
          ^,
          ,          '       dH   RV\         P                  ,          ,          V P,                  WP$                  ,
          ^,
          V3&   EK{  V\         P                  ,          ) V P,                  WP$                  ,
          ^,
          V3&   EK  WP$                  ,
          ^,
          VP$                  ,          p	V^V	,           VP$                  ,          ,
          ^,
          p
W,           VP$                  ,          pV P,                  W^,           3,          V P,                  W3&   V P,                  W^,           3,          V P,                  W3&   EK|  	  R# )z
Initialize the interpolation set.

Parameters
----------
pb : `cobyqa.problem.Problem`
    Problem to be solved.
options : dict
    Options of the solver.
      ?       @Ng       )r   DEBUG_debugnpminboundsxuxlRHOBEGvalueRHOENDcopyx0_x_basex_baseminimummaximumzerosnNPT_xptrangexpt)selfpboptions
max_radiusvery_close_xl_idxclose_xl_idxvery_close_xu_idxclose_xu_idxkspreadk1k2s   &&&         :/usr/lib/python3/dist-packages/scipy/_lib/cobyqa/models.py__init__Interpolation.__init__   s7    gmm,266")),,"=>>
7>>"Z/,6GNN((),.FFGNN+-GGNN(() wwruu~KK299<<#0G*GGG 	 *,6G)H%&IILL3!8884;;F[[BIILL77>>+BBBD %'JJIILL&)@@IILL&%
L!
 KK299<<#0G*GGG 	 *,6G)H%&KK")),,ww~~/F)FFFYY\\GGNN33t{{BD %'JJIILL&)@@IILL&%
L! HHbddGGKK$89:	q''++./ADDy$U++*1'..*A)ADHHQUAX&)0)@DHHQUAX&a"$$h$X\2203ggnn6M0MDHHQX\1_-&244x!|4404ww~~7N0NDHHQX\1_-181H0HDHHQX\1_-dd(Q,244/!f*,,q0kRTT)"&((2Av:"6"&((2Av:"6% 0    c                <    V P                   P                  ^ ,          # zD
Number of variables.

Returns
-------
int
    Number of variables.
r"   shaper#   s   &r/   r   Interpolation.n\        xx~~a  r2   c                <    V P                   P                  ^,          # zZ
Number of interpolation points.

Returns
-------
int
    Number of interpolation points.
r5   r7   s   &r/   nptInterpolation.npth   r9   r2   c                    V P                   # )zb
Interpolation points.

Returns
-------
`numpy.ndarray`, shape (n, npt)
    Interpolation points.
)r    r7   s   &r/   r"   Interpolation.xptt   s     yyr2   c                    V P                   '       d/   VP                  V P                  V P                  38X  g   Q R4       hWn        R# )zz
Set the interpolation points.

Parameters
----------
xpt : `numpy.ndarray`, shape (n, npt)
    New interpolation points.
z The shape of `xpt` is not valid.N)r   r6   r   r<   r    )r#   r"   s   &&r/   r"   r?      sG     ;;;99!  2 22  	r2   c                    V P                   # )z
Base point around which the models are expanded.

Returns
-------
`numpy.ndarray`, shape (n,)
    Base point around which the models are expanded.
)r   r7   s   &r/   r   Interpolation.x_base   s     ||r2   c                |    V P                   '       d$   VP                  V P                  38X  g   Q R4       hWn        R# )z
Set the base point around which the models are expanded.

Parameters
----------
x_base : `numpy.ndarray`, shape (n,)
    New base point around which the models are expanded.
z#The shape of `x_base` is not valid.N)r   r6   r   r   )r#   r   s   &&r/   r   rB      s>     ;;;<<$  545  r2   c                    V P                   '       d)   ^ Tu;8:  d   V P                  8  g   Q R4       h Q R4       hV P                  V P                  RV3,          ,           # )z
Get the `k`-th interpolation point.

The return point is relative to the origin.

Parameters
----------
k : int
    Index of the interpolation point.

Returns
-------
`numpy.ndarray`, shape (n,)
    `k`-th interpolation point.
zThe index `k` is not valid.NNN)r   r<   r   r"   )r#   r+   s   &&r/   pointInterpolation.point   sQ      ;;;$DHH$C&CC$C&CC${{TXXad^++r2   )r   r   r    N)__name__
__module____qualname____firstlineno____doc__r0   propertyr   r<   r"   setterr   rF   __static_attributes____classdictcell____classdict__s   @r/   r	   r	      s     D7L 	! 	! 	! 	! 	 	 	ZZ   	 	 ]] , ,r2   r	   r"   aright_scalingr   c                f   \         R,          eY   \        P                  ! V P                  \         R,          4      '       d'   \         R,          \         R,          \         R,          3# \        P                  ! \        P
                  P                  V P                  ^ R7      \        R7      pV P                  V,          pVP                  w  r4\        P                  ! WC,           ^,           WC,           ^,           34      pRVP                  V,          R	,          ,          VRV1RV13&   R
VRV1V3&   VP                  VRV1V^,           R13&   R
WTRV13&   W%V^,           R1RV13&   \        P                  ! WC,           ^,           4      pR
VR	,          ,          VRV% VR	,          Wd&   WV^,           R% \        VRR7      w  rx\        P                  ! V P                  4      \         R&   \        P                  ! V4      \         R&   \        P                  ! V4      \         R&   Wx3\         R&   WVWx33# )aa  
Build the left-hand side matrix of the interpolation system. The
matrix below stores W * diag(right_scaling),
where W is the theoretical matrix of the interpolation system. The
right scaling matrices is chosen to keep the elements in
the matrix well-balanced.

Parameters
----------
interpolation : `cobyqa.models.Interpolation`
    Interpolation set.
r"   NrS   rT   r   )axisinitialr   r         ?F)check_finite)_cacher   array_equalr"   maxlinalgnormEPSr6   r   Temptyr   r   )	interpolationscale	xpt_scaler   r<   rS   rT   
eig_valueseig_vectorss	   &        r/   build_systemrh      s   " e} R^^6%=& & c{F?3VF^CCFF299>>-"3"3!><cJE!!E)I__FA
#'A+sw{+,A9;;2s::AdsdDSDjMAdsdCiL!AdsdC!GHnA4C4iL!cAghn HHSWq[)Ms
*M$3M##'("159JGGM--.F5M''!*F3K ggm4F? .F6Nj666r2   c                      a  ] tR t^t o RtR tR t]R 4       t]R 4       t	R t
R tR tR	 tR
 tR t]R 4       t]R 4       tRtV tR# )	Quadratica  
Quadratic model.

This class stores the Hessian matrix of the quadratic model using the
implicit/explicit representation designed by Powell for NEWUOA [1]_.

References
----------
.. [1] M. J. D. Powell. The NEWUOA software for unconstrained optimization
   without derivatives. In G. Di Pillo and M. Roma, editors, *Large-Scale
   Nonlinear Optimization*, volume 83 of Nonconvex Optim. Appl., pages
   255--297. Springer, Boston, MA, USA, 2006. `doi:10.1007/0-387-30065-1_16
   <https://doi.org/10.1007/0-387-30065-1_16>`_.
c                   W0n         V P                   '       d$   VP                  VP                  38X  g   Q R4       hVP                  VP                  ^,           8  d!   \	        RVP                  ^,            R24      hV P                  VV4      w  V n        V n        V n        p\        P                  ! V P                  V P                  34      V n        R# )a  
Initialize the quadratic model.

Parameters
----------
interpolation : `cobyqa.models.Interpolation`
    Interpolation set.
values : `numpy.ndarray`, shape (npt,)
    Values of the interpolated function at the interpolation points.
debug : bool
    Whether to make debugging tests during the execution.

Raises
------
`numpy.linalg.LinAlgError`
    If the interpolation system is ill-defined.
#The shape of `values` is not valid.z4The number of interpolation points must be at least .N)r   r6   r<   r   
ValueError
_get_model_const_grad_i_hessr   r   _e_hess)r#   rc   valuesdebug_s   &&&& r/   r0   Quadratic.__init__  s    $ ;;;<<!!$  545  }22F ??Q&'q*  48??4
0TZq xx 01r2   c                   V P                   '       d$   VP                  V P                  38X  g   Q R4       hWP                  ,
          pV P                  V P
                  V,          ,           RV P                  VP                  P                  V,          R,          ,          W0P                  ,          V,          ,           ,          ,           # )a!  
Evaluate the quadratic model at a given point.

Parameters
----------
x : `numpy.ndarray`, shape (n,)
    Point at which the quadratic model is evaluated.
interpolation : `cobyqa.models.Interpolation`
    Interpolation set.

Returns
-------
float
    Value of the quadratic model at `x`.
The shape of `x` is not valid.r   r   )
r   r6   r   r   rp   rq   rr   r"   ra   rs   r#   xrc   x_diffs   &&& r/   __call__Quadratic.__call__(  s      ;;;77tvvi'I)II')))KKjj6!" 1 1 3 3f <DD<<'&01	
r2   c                .    V P                   P                  # r4   )rq   sizer7   s   &r/   r   Quadratic.nE  s     zzr2   c                .    V P                   P                  # )z
Number of interpolation points used to define the quadratic model.

Returns
-------
int
    Number of interpolation points used to define the quadratic model.
)rr   r   r7   s   &r/   r<   Quadratic.nptQ  s     ||   r2   c                    V P                   '       d$   VP                  V P                  38X  g   Q R4       hWP                  ,
          pV P                  V P                  W24      ,           # )aZ  
Evaluate the gradient of the quadratic model at a given point.

Parameters
----------
x : `numpy.ndarray`, shape (n,)
    Point at which the gradient of the quadratic model is evaluated.
interpolation : `cobyqa.models.Interpolation`
    Interpolation set.

Returns
-------
`numpy.ndarray`, shape (n,)
    Gradient of the quadratic model at `x`.
ry   )r   r6   r   r   rq   	hess_prodrz   s   &&& r/   gradQuadratic.grad]  sQ      ;;;77tvvi'I)II')))zzDNN6AAAr2   c                    V P                   VP                  V P                  R\        P                  3,          VP                  P
                  ,          ,          ,           # )z
Evaluate the Hessian matrix of the quadratic model.

Parameters
----------
interpolation : `cobyqa.models.Interpolation`
    Interpolation set.

Returns
-------
`numpy.ndarray`, shape (n, n)
    Hessian matrix of the quadratic model.
rE   )rs   r"   rr   r   newaxisra   )r#   rc   s   &&r/   hessQuadratic.hessr  sG     ||m//LLBJJ'-*;*;*=*==
 
 	
r2   c                   V P                   '       d$   VP                  V P                  38X  g   Q R4       hV P                  V,          VP                  V P
                  VP                  P                  V,          ,          ,          ,           # )a  
Evaluate the right product of the Hessian matrix of the quadratic model
with a given vector.

Parameters
----------
v : `numpy.ndarray`, shape (n,)
    Vector with which the Hessian matrix of the quadratic model is
    multiplied from the right.
interpolation : `cobyqa.models.Interpolation`
    Interpolation set.

Returns
-------
`numpy.ndarray`, shape (n,)
    Right product of the Hessian matrix of the quadratic model with
    `v`.
The shape of `v` is not valid.)r   r6   r   rs   r"   rr   ra   r#   vrc   s   &&&r/   r   Quadratic.hess_prod  sk    & ;;;77tvvi'I)II'||a-"3"3LLM--//!34#
 
 	
r2   c                   V P                   '       d$   VP                  V P                  38X  g   Q R4       hWP                  ,          V,          V P                  VP
                  P                  V,          R,          ,          ,           # )a\  
Evaluate the curvature of the quadratic model along a given direction.

Parameters
----------
v : `numpy.ndarray`, shape (n,)
    Direction along which the curvature of the quadratic model is
    evaluated.
interpolation : `cobyqa.models.Interpolation`
    Interpolation set.

Returns
-------
float
    Curvature of the quadratic model along `v`.
r   r   )r   r6   r   rs   rr   r"   ra   r   s   &&&r/   curvQuadratic.curv  sf    " ;;;77tvvi'I)II'q llm//11A5#==>	
r2   c                n   V P                   '       do   ^ Tu;8:  d   V P                  8  g   Q R4       h Q R4       hVP                  V P                  38X  g   Q R4       hVP                  V P                  38X  g   Q R4       hV ;P                  V P
                  V,          \        P                  ! W34      ,          ,          un        RV P
                  V&   V P                  VV4      w  rVrxV ;P                  V,          un	        V ;P                  V,          un
        V ;P
                  V,          un        V# )a  
Update the quadratic model.

This method applies the derivative-free symmetric Broyden update to the
quadratic model. The `knew`-th interpolation point must be updated
before calling this method.

Parameters
----------
interpolation : `cobyqa.models.Interpolation`
    Updated interpolation set.
k_new : int
    Index of the updated interpolation point.
dir_old : `numpy.ndarray`, shape (n,)
    Value of ``interpolation.xpt[:, k_new]`` before the update.
values_diff : `numpy.ndarray`, shape (npt,)
    Differences between the values of the interpolated nonlinear
    function and the previous quadratic model at the updated
    interpolation points.

Raises
------
`numpy.linalg.LinAlgError`
    If the interpolation system is ill-defined.
The index `k_new` is not valid.z$The shape of `dir_old` is not valid.z(The shape of `values_diff` is not valid.        )r   r<   r6   r   rs   rr   r   outerro   rp   rq   )	r#   rc   k_newdir_oldvalues_diffconstr   i_hessill_conditioneds	   &&&&&    r/   updateQuadratic.update  s   4 ;;;((K*KK(K*KK(==%  656  $$)  :9:  	U+bhhw.HHH!U 040
,V 	u

d
r2   c                   V P                   '       d$   VP                  V P                  38X  g   Q R4       hV ! W!4      V n        V P	                  W!4      V n        W!P                  ,
          p\        P                  ! VVP                  RVR\        P                  3,          ,          ,
          V P                  ,          4      pV ;P                  WDP                  ,           ,          un        R# )a  
Shift the point around which the quadratic model is defined.

Parameters
----------
interpolation : `cobyqa.models.Interpolation`
    Previous interpolation set.
new_x_base : `numpy.ndarray`, shape (n,)
    Point that will replace ``interpolation.x_base``.
'The shape of `new_x_base` is not valid.r   rE   N)r   r6   r   rp   r   rq   r   r   r   r"   r   rr   rs   ra   )r#   rc   
new_x_baseshiftr   s   &&&  r/   shift_x_baseQuadratic.shift_x_base  s     ;;;##(  989  :5YYz9
111uQ

]';!;;t||K
 	))r2   c                \   V P                   P                  w  r#VP                  ^8X  d&   VP                  ^ ,          W2,           ^,           8X  g   Q R4       h\        V 4      w  rEpWR\        P
                  3,          ,          p\        P                  ! \        P                  ! V4      4      '       d1   \        P                  ! \        P                  ! V4      4      '       g    \        P                  P                  R4      hVw  r\        P                  ! V4      \        8  p
V	RV
3,          p	RW,          ,          p\        P                  ! V
^ 4      ( pV	V	P                  V,          VR\        P
                  3,          ,          ,          pWR\        P
                  3,          ,          V3# )a  
Solve the interpolation systems.

Parameters
----------
interpolation : `cobyqa.models.Interpolation`
    Interpolation set.
rhs : `numpy.ndarray`, shape (npt + n + 1, m)
    Right-hand side vectors of the ``m`` interpolation systems.

Returns
-------
`numpy.ndarray`, shape (npt + n + 1, m)
    Solutions of the interpolation systems.
`numpy.ndarray`, shape (m, )
    Whether the interpolation systems are ill-conditioned.

Raises
------
`numpy.linalg.LinAlgError`
    If the interpolation systems are ill-defined.
z The shape of `rhs` is not valid.rE   z(The interpolation system is ill-defined.rY   )r"   r6   ndimrh   r   r   allisfiniter^   LinAlgErrorabsr`   ra   )rc   rhsr   r<   rS   rT   eig
rhs_scaledrf   rg   large_eig_valuesinv_eig_valuesr   left_scaled_solutionss   &&            r/   solve_systemsQuadratic.solve_systems  sQ   0 ""((HHMciilcgk9	.-	.9 !-] ;# BJJ77
r{{1~&&266"++j2I+J+J))'': 
 #&
66*-3!!%5"56z;;66"2A66 +]]Z'>!RZZ-+HH!
 "!RZZ-$@@
 	
r2   c           
     t   VP                   V P                  38X  g   Q R4       hV P                  P                   w  r#\        P	                  V \
        P                  ! V\
        P                  ! V^,           4      ..4      P                  4      w  rEWC^ 3,          WC^,           R1^ 3,          VRV1^ 3,          V3# )a3  
Solve the interpolation system.

Parameters
----------
interpolation : `cobyqa.models.Interpolation`
    Interpolation set.
values : `numpy.ndarray`, shape (npt,)
    Values of the interpolated function at the interpolation points.

Returns
-------
float
    Constant term of the quadratic model.
`numpy.ndarray`, shape (n,)
    Gradient of the quadratic model at ``interpolation.x_base``.
`numpy.ndarray`, shape (npt,)
    Implicit Hessian matrix of the quadratic model.

Raises
------
`numpy.linalg.LinAlgError`
    If the interpolation system is ill-defined.
rl   N)	r6   r<   r"   rj   r   r   blockr   ra   )rc   rt   r   r<   r{   r   s   &&    r/   ro   Quadratic._get_modelB  s    4 || 
 
 	10	1 
 ""((&44HH Q a

 ay!!GHaK.!DSD!G*oEEr2   )rp   r   rs   rq   rr   N)rH   rI   rJ   rK   rL   r0   r}   rM   r   r<   r   r   r   r   r   r   staticmethodr   ro   rO   rP   rQ   s   @r/   rj   rj      s      2D
: 	 	 	! 	!B*
$
2
02h*0 >
 >
@ (F (Fr2   rj   c                   h  a  ] tR tRt o RtR t]R 4       t]R 4       t]R 4       t	]R 4       t
]R 4       t]R	 4       t]R
 4       t]R 4       tR tR tR tR tR tR tR%R ltR%R ltR%R ltR%R ltR%R ltR%R ltR%R ltR%R ltR%R ltR%R ltR tR t R%R lt!R  t"R%R! lt#R%R" lt$R# t%R$t&V t'R# )&Modelsin  z.
Models for a nonlinear optimization problem.
c                P	   V\         P                  ,          V n        \        W4      V n        V P
                  P                  ^ 4      pV! WC4      w  rVp\        P                  ! V\         P                  ,          \        P                  4      V n        \        P                  ! V\         P                  ,          VP                  3\        P                  4      V n        \        P                  ! V\         P                  ,          VP                  3\        P                  4      V n        \        V\         P                  ,          4       EF  pW\         P                   ,          8  d   \"        hV^ 8X  d0   WPP$                  V&   W`P&                  VR3&   WpP(                  VR3&   MSV P
                  P                  V4      pV! VV4      w  V P$                  V&   V P&                  VR3&   V P(                  VR3&   VP*                  '       ds   VP-                  V P
                  P                  V4      V P&                  VR3,          V P(                  VR3,          4      V\         P.                  ,          8:  d   \0        hV P                  V,          V\         P2                  ,          8:  g   EKb  VP-                  V P
                  P                  V4      V P&                  VR3,          V P(                  VR3,          4      V\         P.                  ,          8:  g   EK  \4        h	  \7        V P
                  V P                  V\         P                  ,          4      V n        \        P:                  ! V P<                  \6        R7      V n        \        P:                  ! V P@                  \6        R7      V n!        \        V P<                  4       FO  p	\7        V P
                  V P&                  RV	3,          V\         P                  ,          4      V P>                  V	&   KQ  	  \        V P@                  4       FO  p	\7        V P
                  V P(                  RV	3,          V\         P                  ,          4      V PB                  V	&   KQ  	  V P                  '       d   V PE                  4        R# R# )a  
Initialize the models.

Parameters
----------
pb : `cobyqa.problem.Problem`
    Problem to be solved.
options : dict
    Options of the solver.
penalty : float
    Penalty parameter used to select the point in the filter to forward
    to the callback function.

Raises
------
`cobyqa.utils.MaxEvalError`
    If the maximum number of evaluations is reached.
`cobyqa.utils.TargetSuccess`
    If a nearly feasible point has been found with an objective
    function value below the target.
`cobyqa.utils.FeasibleSuccess`
    If a feasible point has been found for a feasibility problem.
`numpy.linalg.LinAlgError`
    If the interpolation system is ill-defined.
rE   )dtypeN)#r   r   r   r	   _interpolationrc   rF   r   fullr   nan_fun_valr   _cub_val_ceq_valr!   MAX_EVALr   fun_valcub_valceq_valis_feasibilitymaxcvFEASIBILITY_TOLr   TARGETr   rj   _funrb   m_nonlinear_ub_cubm_nonlinear_eq_ceq_check_interpolation_conditions)
r#   r$   r%   penaltyx_evalfun_initcub_initceq_initr+   is
   &&&&      r/   r0   Models.__init__s  s`   6 gmm,+B8 ##))!,')&':$H 4bff=!5x}} ErvvN!5x}} ErvvNww{{+,AG,,--""Av"*Q%-QT"%-QT"++11!4JLKGQad!3T\\!Q$5G !!!HH&&,,Q/LLA&LLA&
 72234 &%
 a GGNN$;;HH&&,,Q/LLA&LLA&
 72234 $#M -R MMGMM"
	
 HHT00	B	HHT00	B	t**+A$""QT"&DIIaL , t**+A$""QT"&DIIaL , ;;;002 r2   c                .    V P                   P                  # )zN
Dimension of the problem.

Returns
-------
int
    Dimension of the problem.
)rc   r   r7   s   &r/   r   Models.n  s     !!###r2   c                .    V P                   P                  # r;   )rc   r<   r7   s   &r/   r<   
Models.npt  s     !!%%%r2   c                <    V P                   P                  ^,          # )zr
Number of nonlinear inequality constraints.

Returns
-------
int
    Number of nonlinear inequality constraints.
)r   r6   r7   s   &r/   r   Models.m_nonlinear_ub       ||!!!$$r2   c                <    V P                   P                  ^,          # )zn
Number of nonlinear equality constraints.

Returns
-------
int
    Number of nonlinear equality constraints.
)r   r6   r7   s   &r/   r   Models.m_nonlinear_eq  r   r2   c                    V P                   # )zZ
Interpolation set.

Returns
-------
`cobyqa.models.Interpolation`
    Interpolation set.
)r   r7   s   &r/   rc   Models.interpolation  s     """r2   c                    V P                   # )z
Values of the objective function at the interpolation points.

Returns
-------
`numpy.ndarray`, shape (npt,)
    Values of the objective function at the interpolation points.
)r   r7   s   &r/   r   Models.fun_val  s     }}r2   c                    V P                   # )z
Values of the nonlinear inequality constraint functions at the
interpolation points.

Returns
-------
`numpy.ndarray`, shape (npt, m_nonlinear_ub)
    Values of the nonlinear inequality constraint functions at the
    interpolation points.
)r   r7   s   &r/   r   Models.cub_val       }}r2   c                    V P                   # )z
Values of the nonlinear equality constraint functions at the
interpolation points.

Returns
-------
`numpy.ndarray`, shape (npt, m_nonlinear_eq)
    Values of the nonlinear equality constraint functions at the
    interpolation points.
)r   r7   s   &r/   r   Models.ceq_val,  r   r2   c                    V P                   '       d$   VP                  V P                  38X  g   Q R4       hV P                  WP                  4      # )a-  
Evaluate the quadratic model of the objective function at a given
point.

Parameters
----------
x : `numpy.ndarray`, shape (n,)
    Point at which to evaluate the quadratic model of the objective
    function.

Returns
-------
float
    Value of the quadratic model of the objective function at `x`.
ry   )r   r6   r   r   rc   r#   r{   s   &&r/   fun
Models.fun:  s@      ;;;77tvvi'I)II'yy..//r2   c                    V P                   '       d$   VP                  V P                  38X  g   Q R4       hV P                  P	                  WP
                  4      # )af  
Evaluate the gradient of the quadratic model of the objective function
at a given point.

Parameters
----------
x : `numpy.ndarray`, shape (n,)
    Point at which to evaluate the gradient of the quadratic model of
    the objective function.

Returns
-------
`numpy.ndarray`, shape (n,)
    Gradient of the quadratic model of the objective function at `x`.
ry   )r   r6   r   r   r   rc   r   s   &&r/   fun_gradModels.fun_gradN  sD      ;;;77tvvi'I)II'yy~~a!3!344r2   c                L    V P                   P                  V P                  4      # )z
Evaluate the Hessian matrix of the quadratic model of the objective
function.

Returns
-------
`numpy.ndarray`, shape (n, n)
    Hessian matrix of the quadratic model of the objective function.
)r   r   rc   r7   s   &r/   fun_hessModels.fun_hessb  s     yy~~d0011r2   c                    V P                   '       d$   VP                  V P                  38X  g   Q R4       hV P                  P	                  WP
                  4      # )a  
Evaluate the right product of the Hessian matrix of the quadratic model
of the objective function with a given vector.

Parameters
----------
v : `numpy.ndarray`, shape (n,)
    Vector with which the Hessian matrix of the quadratic model of the
    objective function is multiplied from the right.

Returns
-------
`numpy.ndarray`, shape (n,)
    Right product of the Hessian matrix of the quadratic model of the
    objective function with `v`.
r   )r   r6   r   r   r   rc   r#   r   s   &&r/   fun_hess_prodModels.fun_hess_prodn  sF    " ;;;77tvvi'I)II'yy""1&8&899r2   c                    V P                   '       d$   VP                  V P                  38X  g   Q R4       hV P                  P	                  WP
                  4      # )ai  
Evaluate the curvature of the quadratic model of the objective function
along a given direction.

Parameters
----------
v : `numpy.ndarray`, shape (n,)
    Direction along which the curvature of the quadratic model of the
    objective function is evaluated.

Returns
-------
float
    Curvature of the quadratic model of the objective function along
    `v`.
r   )r   r6   r   r   r   rc   r   s   &&r/   fun_curvModels.fun_curv  sD    " ;;;77tvvi'I)II'yy~~a!3!344r2   c                    V P                   '       d$   VP                  V P                  38X  g   Q R4       h\        V P                  V P
                  V P                   4      pVP                  WP                  4      # )a  
Evaluate the gradient of the alternative quadratic model of the
objective function at a given point.

Parameters
----------
x : `numpy.ndarray`, shape (n,)
    Point at which to evaluate the gradient of the alternative
    quadratic model of the objective function.

Returns
-------
`numpy.ndarray`, shape (n,)
    Gradient of the alternative quadratic model of the objective
    function at `x`.

Raises
------
`numpy.linalg.LinAlgError`
    If the interpolation system is ill-defined.
ry   )r   r6   r   rj   rc   r   r   )r#   r{   models   && r/   fun_alt_gradModels.fun_alt_grad  s\    , ;;;77tvvi'I)II'$,,dllDKKHzz!//00r2   Nc           	     L   V P                   '       dK   VP                  V P                  38X  g   Q R4       hVe$   VP                  V P                  38X  g   Q R4       h\        P
                  ! V P                  V4       Uu. uF  q3! WP                  4      NK  	  up4      # u upi )a  
Evaluate the quadratic models of the nonlinear inequality functions at
a given point.

Parameters
----------
x : `numpy.ndarray`, shape (n,)
    Point at which to evaluate the quadratic models of the nonlinear
    inequality functions.
mask : `numpy.ndarray`, shape (m_nonlinear_ub,), optional
    Mask of the quadratic models to consider.

Returns
-------
`numpy.ndarray`
    Values of the quadratic model of the nonlinear inequality
    functions.
ry   !The shape of `mask` is not valid.)r   r6   r   r   r   array_get_cubrc   r#   r{   maskr   s   &&& r/   cub
Models.cub  s    & ;;;77tvvi'I)II'<4::##2 $ 323  xx7;}}T7JK7JeU1(()7JK
 	
K    B!c           	     z   V P                   '       dK   VP                  V P                  38X  g   Q R4       hVe$   VP                  V P                  38X  g   Q R4       h\        P
                  ! V P                  V4       Uu. uF  pVP                  WP                  4      NK   	  upRV P                  34      # u upi )a  
Evaluate the gradients of the quadratic models of the nonlinear
inequality functions at a given point.

Parameters
----------
x : `numpy.ndarray`, shape (n,)
    Point at which to evaluate the gradients of the quadratic models of
    the nonlinear inequality functions.
mask : `numpy.ndarray`, shape (m_nonlinear_eq,), optional
    Mask of the quadratic models to consider.

Returns
-------
`numpy.ndarray`
    Gradients of the quadratic model of the nonlinear inequality
    functions.
ry   r   )	r   r6   r   r   r   reshaper  r   rc   r  s   &&& r/   cub_gradModels.cub_grad      & ;;;77tvvi'I)II'<4::##2 $ 323  zz---/- ZZ--.-/L
 	
/    $B8c                H   V P                   '       d(   Ve$   VP                  V P                  38X  g   Q R4       h\        P                  ! V P                  V4       Uu. uF  q"P                  V P                  4      NK  	  upRV P                  V P                  34      # u upi )aV  
Evaluate the Hessian matrices of the quadratic models of the nonlinear
inequality functions.

Parameters
----------
mask : `numpy.ndarray`, shape (m_nonlinear_ub,), optional
    Mask of the quadratic models to consider.

Returns
-------
`numpy.ndarray`
    Hessian matrices of the quadratic models of the nonlinear
    inequality functions.
r   r  )	r   r6   r   r   r	  r  r   rc   r   r#   r  r   s   && r/   cub_hessModels.cub_hess        ;;;<4::##2 $ 323  zz9=t9LM9LZZ**+9LM 
 	
M   #Bc           	     z   V P                   '       dK   VP                  V P                  38X  g   Q R4       hVe$   VP                  V P                  38X  g   Q R4       h\        P
                  ! V P                  V4       Uu. uF  pVP                  WP                  4      NK   	  upRV P                  34      # u upi )aJ  
Evaluate the right product of the Hessian matrices of the quadratic
models of the nonlinear inequality functions with a given vector.

Parameters
----------
v : `numpy.ndarray`, shape (n,)
    Vector with which the Hessian matrices of the quadratic models of
    the nonlinear inequality functions are multiplied from the right.
mask : `numpy.ndarray`, shape (m_nonlinear_ub,), optional
    Mask of the quadratic models to consider.

Returns
-------
`numpy.ndarray`
    Right products of the Hessian matrices of the quadratic models of
    the nonlinear inequality functions with `v`.
r   r   r  )	r   r6   r   r   r   r	  r  r   rc   r#   r   r  r   s   &&& r/   cub_hess_prodModels.cub_hess_prod      & ;;;77tvvi'I)II'<4::##2 $ 323  zz "]]400E #5#560 L
 	
r  c           	     `   V P                   '       dK   VP                  V P                  38X  g   Q R4       hVe$   VP                  V P                  38X  g   Q R4       h\        P
                  ! V P                  V4       Uu. uF  pVP                  WP                  4      NK   	  up4      # u upi )a  
Evaluate the curvature of the quadratic models of the nonlinear
inequality functions along a given direction.

Parameters
----------
v : `numpy.ndarray`, shape (n,)
    Direction along which the curvature of the quadratic models of the
    nonlinear inequality functions is evaluated.
mask : `numpy.ndarray`, shape (m_nonlinear_ub,), optional
    Mask of the quadratic models to consider.

Returns
-------
`numpy.ndarray`
    Curvature of the quadratic models of the nonlinear inequality
    functions along `v`.
r   r   )	r   r6   r   r   r   r   r  r   rc   r  s   &&& r/   cub_curvModels.cub_curv&      & ;;;77tvvi'I)II'<4::##2 $ 323  xx---/- ZZ--.-/
 	
/    $B+c           	     L   V P                   '       dK   VP                  V P                  38X  g   Q R4       hVe$   VP                  V P                  38X  g   Q R4       h\        P
                  ! V P                  V4       Uu. uF  q3! WP                  4      NK  	  up4      # u upi )a  
Evaluate the quadratic models of the nonlinear equality functions at a
given point.

Parameters
----------
x : `numpy.ndarray`, shape (n,)
    Point at which to evaluate the quadratic models of the nonlinear
    equality functions.
mask : `numpy.ndarray`, shape (m_nonlinear_eq,), optional
    Mask of the quadratic models to consider.

Returns
-------
`numpy.ndarray`
    Values of the quadratic model of the nonlinear equality functions.
ry   r   )r   r6   r   r   r   r   _get_ceqrc   r  s   &&& r/   ceq
Models.ceqC  s    $ ;;;77tvvi'I)II'<4::##2 $ 323  xx7;}}T7JK7JeU1(()7JK
 	
Kr  c           	     z   V P                   '       dK   VP                  V P                  38X  g   Q R4       hVe$   VP                  V P                  38X  g   Q R4       h\        P
                  ! V P                  V4       Uu. uF  pVP                  WP                  4      NK   	  upRV P                  34      # u upi )a  
Evaluate the gradients of the quadratic models of the nonlinear
equality functions at a given point.

Parameters
----------
x : `numpy.ndarray`, shape (n,)
    Point at which to evaluate the gradients of the quadratic models of
    the nonlinear equality functions.
mask : `numpy.ndarray`, shape (m_nonlinear_eq,), optional
    Mask of the quadratic models to consider.

Returns
-------
`numpy.ndarray`
    Gradients of the quadratic model of the nonlinear equality
    functions.
ry   r   r  )	r   r6   r   r   r   r	  r  r   rc   r  s   &&& r/   ceq_gradModels.ceq_grad^  r  r  c                H   V P                   '       d(   Ve$   VP                  V P                  38X  g   Q R4       h\        P                  ! V P                  V4       Uu. uF  q"P                  V P                  4      NK  	  upRV P                  V P                  34      # u upi )aR  
Evaluate the Hessian matrices of the quadratic models of the nonlinear
equality functions.

Parameters
----------
mask : `numpy.ndarray`, shape (m_nonlinear_eq,), optional
    Mask of the quadratic models to consider.

Returns
-------
`numpy.ndarray`
    Hessian matrices of the quadratic models of the nonlinear equality
    functions.
r   r  )	r   r6   r   r   r	  r  r   rc   r   r  s   && r/   ceq_hessModels.ceq_hess|  r  r  c           	     z   V P                   '       dK   VP                  V P                  38X  g   Q R4       hVe$   VP                  V P                  38X  g   Q R4       h\        P
                  ! V P                  V4       Uu. uF  pVP                  WP                  4      NK   	  upRV P                  34      # u upi )aD  
Evaluate the right product of the Hessian matrices of the quadratic
models of the nonlinear equality functions with a given vector.

Parameters
----------
v : `numpy.ndarray`, shape (n,)
    Vector with which the Hessian matrices of the quadratic models of
    the nonlinear equality functions are multiplied from the right.
mask : `numpy.ndarray`, shape (m_nonlinear_eq,), optional
    Mask of the quadratic models to consider.

Returns
-------
`numpy.ndarray`
    Right products of the Hessian matrices of the quadratic models of
    the nonlinear equality functions with `v`.
r   r   r  )	r   r6   r   r   r   r	  r  r   rc   r  s   &&& r/   ceq_hess_prodModels.ceq_hess_prod  r  r  c           	     `   V P                   '       dK   VP                  V P                  38X  g   Q R4       hVe$   VP                  V P                  38X  g   Q R4       h\        P
                  ! V P                  V4       Uu. uF  pVP                  WP                  4      NK   	  up4      # u upi )a  
Evaluate the curvature of the quadratic models of the nonlinear
equality functions along a given direction.

Parameters
----------
v : `numpy.ndarray`, shape (n,)
    Direction along which the curvature of the quadratic models of the
    nonlinear equality functions is evaluated.
mask : `numpy.ndarray`, shape (m_nonlinear_eq,), optional
    Mask of the quadratic models to consider.

Returns
-------
`numpy.ndarray`
    Curvature of the quadratic models of the nonlinear equality
    functions along `v`.
r   r   )	r   r6   r   r   r   r   r  r   rc   r  s   &&& r/   ceq_curvModels.ceq_curv  r  r  c                "   \        V P                  V P                  V P                  4      V n        \        V P                  4       FD  p\        V P                  V P                  RV3,          V P                  4      V P                  V&   KF  	  \        V P                  4       FD  p\        V P                  V P                  RV3,          V P                  4      V P                  V&   KF  	  V P                  '       d   V P                  4        R# R# )z
Set the quadratic models of the objective function, nonlinear
inequality constraints, and nonlinear equality constraints to the
alternative quadratic models.

Raises
------
`numpy.linalg.LinAlgError`
    If the interpolation system is ill-defined.
rE   N)rj   rc   r   r   r   r!   r   r   r   r   r   r   r   )r#   r   s   & r/   reset_modelsModels.reset_models  s     d00$,,L	t**+A$""QT"DIIaL , t**+A$""QT"DIIaL , ;;;002 r2   c           	     D   V P                   '       d   ^ Tu;8:  d   V P                  8  g   Q R4       h Q R4       hVP                  V P                  38X  g   Q R4       h\	        V\
        4      '       g   Q R4       hVP                  V P                  38X  g   Q R4       hVP                  V P                  38X  g   Q R4       h\        P                  ! V P                  4      p\        P                  ! V P                  P                  4      p\        P                  ! V P                  P                  4      pW0P                  V4      ,
          Wa&   W@P                  V4      ,
          WqR3&   WPP                  V4      ,
          WR3&   W0P                  V&   W@P                  VR3&   WPP                  VR3&   \        P                   ! V P"                  P$                  RV3,          4      p	W P"                  P&                  ,
          V P"                  P$                  RV3&   V P(                  P+                  V P"                  VV	V4      p
\-        V P                  4       FE  pT
;'       g9    V P.                  V,          P+                  V P"                  VV	VRV3,          4      p
KG  	  \-        V P                  4       FE  pT
;'       g9    V P0                  V,          P+                  V P"                  VV	VRV3,          4      p
KG  	  V P                   '       d   V P3                  4        V
# )aG  
Update the interpolation set.

This method updates the interpolation set by replacing the `knew`-th
interpolation point with `xnew`. It also updates the function values
and the quadratic models.

Parameters
----------
k_new : int
    Index of the updated interpolation point.
x_new : `numpy.ndarray`, shape (n,)
    New interpolation point. Its value is interpreted as relative to
    the origin, not the base point.
fun_val : float
    Value of the objective function at `x_new`.
    Objective function value at `x_new`.
cub_val : `numpy.ndarray`, shape (m_nonlinear_ub,)
    Values of the nonlinear inequality constraints at `x_new`.
ceq_val : `numpy.ndarray`, shape (m_nonlinear_eq,)
    Values of the nonlinear equality constraints at `x_new`.

Raises
------
`numpy.linalg.LinAlgError`
    If the interpolation system is ill-defined.
r   "The shape of `x_new` is not valid.z The function value is not valid.z$The shape of `cub_val` is not valid.z$The shape of `ceq_val` is not valid.rE   )r   r<   r6   r   
isinstancefloatr   r   r   r   r   r   r   r  r   r   r   rc   r"   r   r   r   r!   r   r   r   )r#   r   x_newr   r   r   fun_diffcub_diffceq_diffr   r   r   s   &&&&&&      r/   update_interpolationModels.update_interpolation  s   8 ;;;((K*KK(K*KK(;;466)+ 545+gu-- 323-==##%  656  ==##%  656 
 88DHH%88DLL../88DLL../!HHUO3$xx6$xx6 &U!(UAX!(UAX ''$,,00E:;+03E3E3L3L+Lq%x( ))**	
 t**+A-  11D1D""A	2O , t**+A-  11D1D""A	2O , ;;;002r2   c                L   V P                   '       dQ   VP                  V P                  38X  g   Q R4       hVe*   ^ Tu;8:  d   V P                  8  g    Q R4       h Q R4       hWP                  P
                  ,
          p\        P                  ! V P                  V P                  ,           ^,           ^34      pRV P                  P                  P                  V,          R,          ,          VRV P                  1^ 3&   RW@P                  ^ 3&   W4V P                  ^,           R1^ 3&   \        P                  V P                  V4      ^ ,          pRW3,          R,          ,          VR,          VR,          ,          ,
          pVf   \        P                  ! V P                  V P                  ,           ^,           V P                  4      p\        P                  ! \        P                  V P                  V4      ^ ,          4      pVRV P                  1^ 3,          p	Mu\        P                  ! V P                  V P                  ,           ^,           ^V) 4      p\        P                  V P                  V4      ^ ,          V^ 3,          pWR^ 3,          p	W,          V	R,          ,           # )a  
Compute the normalized determinants of the new interpolation systems.

Parameters
----------
x_new : `numpy.ndarray`, shape (n,)
    New interpolation point. Its value is interpreted as relative to
    the origin, not the base point.
k_new : int, optional
    Index of the updated interpolation point. If `k_new` is not
    specified, all the possible determinants are computed.

Returns
-------
{float, `numpy.ndarray`, shape (npt,)}
    Determinant(s) of the new interpolation system.

Raises
------
`numpy.linalg.LinAlgError`
    If the interpolation system is ill-defined.

Notes
-----
The determinants are normalized by the determinant of the current
interpolation system. For stability reasons, the calculations are done
using the formula (2.12) in [1]_.

References
----------
.. [1] M. J. D. Powell. On updating the inverse of a KKT matrix.
   Technical Report DAMTP 2004/NA01, Department of Applied Mathematics
   and Theoretical Physics, University of Cambridge, Cambridge, UK,
   2004.
r2  Nr   r   r   rY   )rE   r   )r   r6   r   r<   rc   r   r   rb   r"   ra   rj   r   eyediag)
r#   r5  r   r   new_colinv_new_colbeta	coord_vecalphataus
   &&&       r/   determinantsModels.determinants@  s7   H ;;;;;466)+ 545+ e!6dhh!61016!61016 **111((DHHtvv-1156t))--//%7C?? 	
$((
A"!$)1q !--d.@.@'J1Mem++gdmk$>O.OO =txx$&&014dhh?IGG''&& E jj!m,Ctxx$&&014a%@I++"" 	
 QhE Qh'C|c3h&&r2   c                   V P                   '       d$   VP                  V P                  38X  g   Q R4       hV P                  P	                  V P
                  V4       V P                   F  pVP	                  V P
                  V4       K!  	  V P                   F  pVP	                  V P
                  V4       K!  	  WP
                  P                  ,
          pV P
                  ;P                  V,          un        V P
                  ;P                  VR\        P                  3,          ,          un	        V\        P                  ,          '       d   V P                  4        R# R# )z
Shift the base point without changing the interpolation set.

Parameters
----------
new_x_base : `numpy.ndarray`, shape (n,)
    New base point.
options : dict
    Options of the solver.
r   rE   N)r   r6   r   r   r   rc   r   r   r   r"   r   r   r   r   r   )r#   r   r%   r   r   s   &&&  r/   r   Models.shift_x_base  s    ;;;##(  989 
 			t11:>YYEt11:> YYEt11:>  //666!!U*!%2::"667==!!002 "r2   c                H    Vf   V P                   # V P                   V,          # )a  
Get the quadratic models of the nonlinear inequality constraints.

Parameters
----------
mask : `numpy.ndarray`, shape (m_nonlinear_ub,), optional
    Mask of the quadratic models to return.

Returns
-------
`numpy.ndarray`
    Quadratic models of the nonlinear inequality constraints.
)r   r#   r  s   &&r/   r  Models._get_cub       !Ltyy=diio=r2   c                H    Vf   V P                   # V P                   V,          # )a  
Get the quadratic models of the nonlinear equality constraints.

Parameters
----------
mask : `numpy.ndarray`, shape (m_nonlinear_eq,), optional
    Mask of the quadratic models to return.

Returns
-------
`numpy.ndarray`
    Quadratic models of the nonlinear equality constraints.
)r   rI  s   &&r/   r  Models._get_ceq  rK  r2   c                   RpRpRp\        V P                  4       EFL  p\        P                  ! V\        P                  ! V P                  V P                  P                  V4      4      V P                  V,          ,
          4      .4      p\        P                  ! \        P                  ! V P                  V P                  P                  V4      4      V P                  VR3,          ,
          4      VR7      p\        P                  ! \        P                  ! V P                  V P                  P                  V4      4      V P                  VR3,          ,
          4      VR7      pEKO  	  R\        P                  ! \        4      ,          \        V P                  V P                  4      ,          pW\        P                  ! \        P                  ! V P                  4      RR7      ,          8  d   \         P"                  ! R\$        ^4       W%\        P                  ! \        P                  ! V P                  4      RR7      ,          8  d   \         P"                  ! R\$        ^4       W5\        P                  ! \        P                  ! V P                  4      RR7      ,          8  d   \         P"                  ! R\$        ^4       R	# R	# )
z=
Check the interpolation conditions of all quadratic models.
r   rE   rW   g      $@rY   zJThe interpolation conditions for the objective function are not satisfied.zVThe interpolation conditions for the inequality constraint function are not satisfied.zTThe interpolation conditions for the equality constraint function are not satisfied.N)r!   r<   r   r]   r   r   rc   rF   r   r  r   r   r   sqrtr`   r   warningswarnRuntimeWarning)r#   	error_fun	error_cub	error_ceqr+   tols   &     r/   r   &Models._check_interpolation_conditions  s    			txxAFF!3!3!9!9!!<=QOI HHT//55a89DLLA<NN "	I HHT//55a89DLLA<NN "	I !* RWWS\!C$99RVVBFF4<<$8#FFFMM!	 RVVBFF4<<$8#FFFMM.	 RVVBFF4<<$8#FFFMM.	 Gr2   )r   r   r   r   r   r   r   r   )N)(rH   rI   rJ   rK   rL   r0   rM   r   r<   r   r   rc   r   r   r   r   r   r   r   r   r   r  r
  r  r  r  r   r#  r&  r)  r,  r/  r9  rD  r   r  r  r   rO   rP   rQ   s   @r/   r   r   n  s/    a3F 	$ 	$ 	& 	& 	% 	% 	% 	% 	# 	# 	 	    0(5(
2:*5*16
8
<
2
@
:
6
<
2
@
:36QfH'T3<> > 1 1r2   r   )rP  numpyr   scipy.linalgr   settingsr   utilsr   r   r   finfor4  epsr`   r	   r[   rh   rj   r    r2   r/   <module>r_     sr        ? ? 	hhuor, r,j sD/4	F.7buF uFpK Kr2   