L iddlZddlZddlmZddlmZddlmZm Z m Z eje jZGddZdddddZd ZGd d ZGd d Zy)N)eigh)Options) MaxEvalError TargetSuccessFeasibleSuccessceZdZdZdZedZedZedZejdZedZ e jdZ d Z y ) 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" |tj|_dtj|j j |j jz z}|tj|kDr`||tjj<tj|tj|g|tjj<tj|j|_ |j|j jd|tjzzk}|j j||j|<|j jd|tjzz|jk|j|j j|tjzkz}tj|j j||tjz|j j ||j|<|j|j j d|tjzz k\}|j j ||j|<|j|j j d|tjzz k|j j |tjz |jkz}tj |j j ||tjz |j j||j|<tj"|j$|tj&f|_t+d|tj&D]}||j$krU||dz r'|tj |j,|dz |f<B|tj|j,|dz |f<h|d|j$zkr|||j$z dz r6d|tjz|j,||j$z dz |f<|||j$z dz r7d|tjz|j,||j$z dz |f<|tj |j,||j$z dz |f<F||j$z dz |j$z} |d| z|j$zz dz } | | z|j$z} |j,| | dzf|j,| |f<|j,| | dzf|j,| |f<y)z Initialize the interpolation set. Parameters ---------- pb : `cobyqa.problem.Problem` Problem to be solved. options : dict Options of the solver. ?r@gN)rDEBUG_debugnpminboundsxuxlRHOBEGvalueRHOENDcopyx0_x_basex_baseminimummaximumzerosnNPT_xptrangexpt) selfpboptions max_radiusvery_close_xl_idx close_xl_idxvery_close_xu_idx close_xu_idxkspreadk1k2s ^/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/scipy/_lib/cobyqa/models.py__init__zInterpolation.__init__sOgmm, 266")),,"=>> 7>> "Z /,6GGNN(( ),.FFGNN+-GGNN(( )wwruu~ KK299<<#0G*GG G *,6G)H %& IILL3!88 84;; F [[BIILL77>>+BB BD %'JJ IILL &)@ @ IILL &%  L! KK299<<#0G*GG G *,6G)H %& KK")),,ww~~/F)FF F YY\\GGNN3 3t{{ BD %'JJ IILL &)@ @ IILL &%  L! HHbddGGKK$89: q''++./ 7ABDDy$QU+*1'..*A)ADHHQUAX&)0)@DHHQUAX&a"$$h$QX\203ggnn6M0MDHHQX\1_-&q244x!|404ww~~7N0NDHHQX\1_-181H0HDHHQX\1_-bdd(Q,244/!f*,,q06kRTT)"&((2rAv:"6Q"&((2rAv:"6Q% 7c4|jjdS)t Number of variables. Returns ------- int Number of variables. rr$shaper%s r1r zInterpolation.n\xx~~a  r3c4|jjdS) Number of interpolation points. Returns ------- int Number of interpolation points. rr6r8s r1nptzInterpolation.npthr9r3c|jS)z Interpolation points. Returns ------- `numpy.ndarray`, shape (n, npt) Interpolation points. )r"r8s r1r$zInterpolation.xpttsyyr3c|jr,|j|j|jfk(sJd||_y)z Set the interpolation points. Parameters ---------- xpt : `numpy.ndarray`, shape (n, npt) New interpolation points. z The shape of `xpt` is not valid.N)rr7r r<r")r%r$s r1r$zInterpolation.xptsG ;;99! 22 2 r3c|jS)z Base point around which the models are expanded. Returns ------- `numpy.ndarray`, shape (n,) Base point around which the models are expanded. )rr8s r1rzInterpolation.x_bases||r3cl|jr!|j|jfk(sJd||_y)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)rr7r r)r%rs r1rzInterpolation.x_bases> ;;<<$ 54 5 r3c|jr$d|cxkr|jksJdJd|j|jdd|fzS)a< 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. rzThe index `k` is not valid.N)rr<rr$)r%r-s r1pointzInterpolation.pointsO ;;$DHH$ C&C C$ C&C C${{TXXad^++r3N) __name__ __module__ __qualname____doc__r2propertyr r<r$setterrrBr3r1r r sD7L ! ! ! !   ZZ    ]]  ,r3r )r$a right_scalingrctdAtj|jtdrtdtdtdfStjtj j |jdt}|j|z }|j\}}tj||zd z||zd zf}d |j|zd zz|d|d|f<d |d||f<|j|d||d zdf<d ||d|f<|||d zdd|f<tj||zd z}d |d zz |d||d z||<|||d zdt|d \}}tj|jtd<tj|td<tj|td<||ftd<||||ffS)a 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$NrJrKrr)axisinitialrr r?F) check_finite)_cacher array_equalr$maxlinalgnormEPSr7rTemptyrr) interpolationscale xpt_scaler r<rJrK eig_values eig_vectorss r1 build_systemr_s"e} R^^6%=&c{F?3VF^CC FF299>>-"3"3!>`_. c||_|jr!|j|jfk(sJd|j|jdzkrt d|jdzd|j ||\|_|_|_}tj|j|jf|_ y)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.rz4The number of interpolation points must be at least .N) rr7r<r ValueError _get_model_const_grad_i_hessrr_e_hess)r%rZvaluesdebug_s r1r2zQuadratic.__init__s$ ;;<<!!$ 54 5   }2 2F ??Q&'q* 48??  4 0 TZqxx 01 r3c2|jr!|j|jfk(sJd||jz }|j|j |zzd|j |jj|zdzz||jz|zzzzS)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) rr7r rrgrhrir$rXrjr%xrZx_diffs r1__call__zQuadratic.__call__(s ;;77tvvi' I)I I']))) KKjj6! " 1 1 3 3f <DD4<<'&01  r3c.|jjS)r5)rhsizer8s r1r z Quadratic.nEszzr3c.|jjS)z Number of interpolation points used to define the quadratic model. Returns ------- int Number of interpolation points used to define the quadratic model. )rirur8s r1r<z Quadratic.nptQs||   r3c|jr!|j|jfk(sJd||jz }|j|j ||zS)a 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`. ro)rr7r rrh hess_prodrps r1gradzQuadratic.grad]sS ;;77tvvi' I)I I'])))zzDNN6=AAAr3c|j|j|jddtjf|jj zzzS)a; 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. N)rjr$rirnewaxisrX)r%rZs r1hesszQuadratic.hessrsG||m// LLBJJ '-*;*;*=*= =   r3c|jr!|j|jfk(sJd|j|z|j|j |jj |zzzzS)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.)rr7r rjr$rirXr%vrZs r1rxzQuadratic.hess_prodsi& ;;77tvvi' I)I I'||a-"3"3 LLM--//!3 4#   r3c|jr!|j|jfk(sJd||jz|z|j|j j |zdzzzS)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)rr7r rjrir$rXrs r1curvzQuadratic.curvsf" ;;77tvvi' I)I I'  q llm//11A5#== > r3c&|jrfd|cxkr|jksJdJd|j|jfk(sJd|j|jfk(sJd|xj|j |t j||zz c_d|j |<|j||\}}}}|xj|z c_ |xj|z c_ |xj |z c_|S)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. rThe index `k_new` is not valid.z$The shape of `dir_old` is not valid.z(The shape of `values_diff` is not valid.) rr<r7r rjrirouterrfrgrh) r%rZk_newdir_old values_diffconstryi_hessill_conditioneds r1updatezQuadratic.updates4 ;;(( K*K K( K*K K(==% 65 6$$) :9 :  U+bhhw.HHH ! U04  0 ,tV_ u  d   r3c|jr!|j|jfk(sJd||||_|j |||_||j z }tj||jd|ddtjfzz |jz}|xj||jzz c_ y)aB 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 N)rr7r rgryrhrrrr$r{rirjrX)r%rZ new_x_baseshiftrs r1 shift_x_basezQuadratic.shift_x_bases ;;##( 98 9:}5 YYz=9 ]111    uQ ]';!; ;t|| K  )) r3c|jj\}}|jdk(r|jd||zdzk(sJdt|\}}}||ddtj fz}t j t j|r(t j t j|stjjd|\}} t j|tkD} | dd| f} d|| z } t j | d} | | j|z| ddtj fzz} | |ddtj fz| fS)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. r rrz The shape of `rhs` is not valid.Nz(The interpolation system is ill-defined.rP) r$r7ndimr_rr{allisfiniterU LinAlgErrorabsrWrX)rZrhsr r<rJrKeig rhs_scaledr]r^large_eig_valuesinv_eig_valuesrleft_scaled_solutionss r1 solve_systemszQuadratic.solve_systemssZ0""((3 HHMciilcAgk9 . - . 9!-] ;=#=BJJ77 r{{1~&266"++j2I+J))'':  #& K66*-3!!%5"56 z*:;;66"2A66 + ]]Z '>!RZZ-+H H!  "M!RZZ-$@ @   r3c L|j|jfk(sJd|jj\}}tj |t j |t j|dzggj\}}||df||dzddf|d|df|fS)a 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. rcrrN) r7r<r$rarrblockrrX)rZrkr r<rqrs r1rfzQuadratic._get_modelBs4||      1 0 1 ""((3&44  HHQ a  ?ay!C!GHaK.!DSD!G*oEEr3N)rCrDrErFr2rsrGr r<ryr|rxrrr staticmethodrrfrIr3r1raras  2D :   ! !B* $ 2 02h*0> > @(F(Fr3rac:eZdZdZdZedZedZedZedZ edZ edZ ed Z ed Z d Zd Zd ZdZdZdZd#dZd#dZd#dZd#dZd#dZd#dZd#dZd#dZd#dZd#dZdZdZd#dZ dZ!d#d Z"d#d!Z#d"Z$y)$Modelsz6 Models for a nonlinear optimization problem. c |tj|_t|||_|j j d}|||\}}}tj|tjtj|_ tj|tj|jftj|_ tj|tj|jftj|_t|tjD]}||tj k\rt"|dk(r6||j$|<||j&|ddf<||j(|ddf<nW|j j |}|||\|j$|<|j&|ddf<|j(|ddf<|j*rh|j-|j j ||j&|ddf|j(|ddf|tj.krt0|j||tj2ksK|j-|j j ||j&|ddf|j(|ddf|tj.kst4t7|j |j|tj|_tj:|j<t6|_tj:|j@t6|_!t|j<D]H} t7|j |j&dd| f|tj|j>| <Jt|j@D]H} t7|j |j(dd| f|tj|jB| <J|jr|jEyy)aE 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. rN)dtype)#rrrr _interpolationrZrBrfullr!nan_fun_valru_cub_val_ceq_valr#MAX_EVALrfun_valcub_valceq_valis_feasibilitymaxcvFEASIBILITY_TOLrTARGETrra_funrYm_nonlinear_ub_cubm_nonlinear_eq_ceq_check_interpolation_conditions) r%r&r'penaltyx_evalfun_initcub_initceq_initr-is r1r2zModels.__init__ssx6gmm, +B8##))!,')&'':$(H 4bff= !5x}} ErvvN !5x}} ErvvN ww{{+,& $AGG,,--""Av"* Q%- QT"%- QT"++11!4JLKG Qad!3T\\!Q$5G!!HH&&,,Q/LLA&LLA& 7223 4&%  a GGNN$;;HH&&,,Q/LLA&LLA& 7223 4$#M& $R    MM GMM "  HHT00 B HHT00 B t**+ A$"" QT" &DIIaL  t**+ A$"" QT" &DIIaL  ;;  0 0 2 r3c.|jjS)z~ Dimension of the problem. Returns ------- int Dimension of the problem. )rZr r8s r1r zModels.ns!!###r3c.|jjS)r;)rZr<r8s r1r<z Models.npts!!%%%r3c4|jjdS)z Number of nonlinear inequality constraints. Returns ------- int Number of nonlinear inequality constraints. r)rr7r8s r1rzModels.m_nonlinear_ub||!!!$$r3c4|jjdS)z Number of nonlinear equality constraints. Returns ------- int Number of nonlinear equality constraints. r)rr7r8s r1rzModels.m_nonlinear_eqrr3c|jS)z Interpolation set. Returns ------- `cobyqa.models.Interpolation` Interpolation set. )rr8s r1rZzModels.interpolations"""r3c|jS)z Values of the objective function at the interpolation points. Returns ------- `numpy.ndarray`, shape (npt,) Values of the objective function at the interpolation points. )rr8s r1rzModels.fun_vals}}r3c|jS)a1 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. )rr8s r1rzModels.cub_val}}r3c|jS)a- 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. )rr8s r1rzModels.ceq_val,rr3c|jr!|j|jfk(sJd|j||jS)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`. ro)rr7r rrZr%rqs r1funz Models.fun:s@ ;;77tvvi' I)I I'yyD..//r3c|jr!|j|jfk(sJd|jj ||j S)a 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`. ro)rr7r rryrZrs r1fun_gradzModels.fun_gradNsD ;;77tvvi' I)I I'yy~~a!3!344r3cL|jj|jS)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. )rr|rZr8s r1fun_hesszModels.fun_hessbsyy~~d0011r3c|jr!|j|jfk(sJd|jj ||j S)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~)rr7r rrxrZr%rs r1 fun_hess_prodzModels.fun_hess_prodnsF" ;;77tvvi' I)I I'yy""1d&8&899r3c|jr!|j|jfk(sJd|jj ||j S)a 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~)rr7r rrrZrs r1fun_curvzModels.fun_curvsD" ;;77tvvi' I)I I'yy~~a!3!344r3c|jr!|j|jfk(sJdt|j|j |j}|j ||jS)ap 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. ro)rr7r rarZrry)r%rqmodels r1 fun_alt_gradzModels.fun_alt_grads\, ;;77tvvi' I)I I'$,,dllDKKHzz!T//00r3Nc 2|jrD|j|jfk(sJd|!|j|jfk(sJdt j |j |Dcgc]}|||jc}Scc}w)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. ro!The shape of `mask` is not valid.)rr7r rrarray_get_cubrZr%rqmaskrs r1cubz Models.cubs& ;;77tvvi' I)I I'<4::##2$ 32 3xx7;}}T7J KeU1d(( ) K  K3Bc ^|jrD|j|jfk(sJd|!|j|jfk(sJdt j |j |Dcgc]}|j||j c}d|jfScc}w)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. ror) rr7r rrreshaperryrZrs r1cub_gradzModels.cub_grad& ;;77tvvi' I)I I'<4::##2$ 32 3zz--- /ZZ4-- . / L   /3#B*c0|jr#|!|j|jfk(sJdtj|j |Dcgc]}|j |jc}d|j|jfScc}w)a 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. rr) rr7rrrrr|rZr r%rrs r1cub_hesszModels.cub_hess ;;<4::##2$ 32 3zz9=t9L MUZZ** + M    M"Bc ^|jrD|j|jfk(sJd|!|j|jfk(sJdt j |j |Dcgc]}|j||j c}d|jfScc}w)a 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~rr) rr7r rrrrrxrZr%rrrs r1 cub_hess_prodzModels.cub_hess_prod& ;;77tvvi' I)I I'<4::##2$ 32 3zz"]]40 4#5#56 L    rc D|jrD|j|jfk(sJd|!|j|jfk(sJdt j |j |Dcgc]}|j||j c}Scc}w)az 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) rr7r rrrrrrZrs r1cub_curvzModels.cub_curv&& ;;77tvvi' I)I I'<4::##2$ 32 3xx--- /ZZ4-- . /   /3#Bc 2|jrD|j|jfk(sJd|!|j|jfk(sJdt j |j |Dcgc]}|||jc}Scc}w)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. ror)rr7r rrr_get_ceqrZrs r1ceqz Models.ceqCs$ ;;77tvvi' I)I I'<4::##2$ 32 3xx7;}}T7J KeU1d(( ) K  Krc ^|jrD|j|jfk(sJd|!|j|jfk(sJdt j |j |Dcgc]}|j||j c}d|jfScc}w)aZ 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. rorr) rr7r rrrrryrZrs r1ceq_gradzModels.ceq_grad^rrc0|jr#|!|j|jfk(sJdtj|j |Dcgc]}|j |jc}d|j|jfScc}w)a 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. rr) rr7rrrrr|rZr rs r1ceq_hesszModels.ceq_hess|rrc ^|jrD|j|jfk(sJd|!|j|jfk(sJdt j |j |Dcgc]}|j||j c}d|jfScc}w)a 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~rr) rr7r rrrrrxrZrs r1 ceq_hess_prodzModels.ceq_hess_prodrrc D|jrD|j|jfk(sJd|!|j|jfk(sJdt j |j |Dcgc]}|j||j c}Scc}w)at 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) rr7r rrrrrrZrs r1ceq_curvzModels.ceq_curvrrct|j|j|j|_t |j D]A}t|j|jdd|f|j|j|<Ct |jD]A}t|j|jdd|f|j|j|<C|jr|jyy)a9 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. N) rarZrrrr#rrrrrrr)r%rs r1 reset_modelszModels.reset_modelssd00$,, L t**+ A$"" QT" DIIaL  t**+ A$"" QT" DIIaL  ;;  0 0 2 r3c |jrd|cxkr|jksJdJd|j|jfk(sJdt |t sJd|j|j fk(sJd|j|jfk(sJdtj|j}tj|jj}tj|jj}||j|z ||<||j|z ||ddf<||j|z ||ddf<||j|<||j|ddf<||j|ddf<tj |j"j$dd|f} ||j"j&z |j"j$dd|f<|j(j+|j"|| |} t-|j D]8} | xs2|j.| j+|j"|| |dd| f} :t-|jD]8} | xs2|j0| j+|j"|| |dd| f} :|jr|j3| S)a 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. rr"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.N)rr<r7r isinstancefloatrrrrrrrrrrrrZr$rrrr#rrr) r%rx_newrrrfun_diffcub_diffceq_diffrrrs r1update_interpolationzModels.update_interpolations8 ;;(( K*K K( K*K K(;;466)+ 54 5+gu- 32 3-==##% 65 6==##% 65 6 88DHH%88DLL../88DLL../!DHHUO3$txx6$txx6& U!( UAX!( UAX''$,,00E:;+043E3E3L3L+Lq%x())**         t**+ A-11D1D""A 2O t**+ A-11D1D""A 2O  ;;  0 0 2r3cf|jrG|j|jfk(sJd|$d|cxkr|jksJdJd||jj z }t j|j|jzdzdf}d|jjj|zdzz|d|jdf<d||jdf<|||jdzddf<tj|j|d}d||zdzz|dddf|dddfzz }|t j|j|jzdz|j}t jtj|j|d}|d|jdf} nat j|j|jzdzd| }tj|j|d|df}||df} ||z| dzzS) 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. rNrrrr rrP)rr7r r<rZrrrYr$rXrareyediag) r%rrrnew_col inv_new_colbeta coord_vecalphataus r1 determinantszModels.determinants@sIH ;;;;466)+ 54 5+ e!6dhh!6 10 16!6 10 16**111((DHHtvv-1156t))--//%7C??  $(( A "! $)1 q !--d.@.@'J1M eem++gadmk!Q$>O.OO =txx$&&014dhh?IGG''&&E jj!m,Ctxx$&&014a%@I++""  Qh E eQh'Ct|c3h&&r3c~|jr!|j|jfk(sJd|jj |j ||j D]}|j |j | |jD]}|j |j | ||j jz }|j xj|z c_|j xj|ddtjfzc_ |tjr|jyy)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. rN)rr7r rrrZrrrr$rr{rrr)r%rr'rrs r1rzModels.shift_x_bases ;;##( 98 9 t11:>YY ?E   t11: > ?YY ?E   t11: > ?T//666 !!U*! %2:: "66 7== !  0 0 2 "r3c<| |jS|j|S)ao 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. )rr%rs r1rzModels._get_cub!Ltyy=diio=r3c<| |jS|j|S)ak 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. )rrs r1rzModels._get_ceqrr3c d}d}d}t|jD]1}tj|tj|j |j j||j|z g}tjtj|j|j j||j|ddfz |}tjtj|j|j j||j|ddfz |}4dtjtzt|j|jz}||tjtj|jdzkDrt!j"dt$d||tjtj|jdzkDrt!j"dt$d||tjtj|jdzkDrt!j"d t$dyy) zM Check the interpolation conditions of all quadratic models. rNrNg$@rPzJThe interpolation conditions for the objective function are not satisfied.r zVThe interpolation conditions for the inequality constraint function are not satisfied.zTThe interpolation conditions for the equality constraint function are not satisfied.)r#r<rrTrrrZrBrrrrrsqrtrWr warningswarnRuntimeWarning)r% error_fun error_cub error_ceqr-tols r1rz&Models._check_interpolation_conditionss   txx AFF!3!3!9!9!!<= QOIHHT//55a89DLLA > 1r3r)rnumpyr scipy.linalgrsettingsrutilsrrrfinforepsrWr rRr_rarrIr3r1r)sl??bhhuor,r,jD4 F.7buFuFp KKr3