L irddlZddlZddlmZmZddlmZmZm Z m Z m Z m Z GddZ dZGddZy) N)assert_allcloseassert_array_almost_equal) fmin_cobylaminimizeBoundsNonlinearConstraintLinearConstraintOptimizeResultcBeZdZdZdZdZdZdZdZdZ dZ d Z y ) TestCobylactjddg|_tjddg|_ddddd|_y) Ng888@g7l 'V?gUUUUUU?rgư>d)disprhobegtolmaxiter)npsqrtx0mathsolutionoptsselfs f/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/scipy/optimize/tests/test_cobyla.py setup_methodzTestCobyla.setup_method sA77?+\:?3U; !D #% c6|ddzt|ddzzS)Nrr)absrxs rfunzTestCobyla.funs!tQwQqTA%%rc*|ddz|ddzzdz S)Nrr rr#s rcon1zTestCobyla.con1s"tQw1q 2%%rc&|j| SN)r)r#s rcon2zTestCobyla.con2s ! }rc t|j|j|j|jgdddd}t ||j dy)Nrh㈵>r)rrhoendmaxfunr-C6?atol)rr%rr)r,rrr#s r test_simplezTestCobyla.test_simples@ $''DIItyy+A!#Ca 94==t4rcGdd}Gdd}|}|}t|jdtjd|jdf}t |j |jd|||j }t |j |jd|||j }t|j|jd |jsJ|j|jd ksJ||jd ksJ||j |j |jdzksJ|t!|j|j"dd|jsJ|j|j |j k(sJ|j|jk(sJ|j|jk(sJ|j$|j$k(sJdy)NceZdZdZdZy)1TestCobyla.test_minimize_simple..Callbackc d|_d|_yNrn_callslast_xrs r__init__z:TestCobyla.test_minimize_simple..Callback.__init__&s  " rc<|xjdz c_||_yNrr:r#s r__call__z:TestCobyla.test_minimize_simple..Callback.__call__*s !  rN__name__ __module__ __qualname__r=r@r(rrCallbackr7%s  # rrEceZdZdZdZy):TestCobyla.test_minimize_simple..CallbackNewSyntaxcd|_yr9)r;rs rr=zCTestCobyla.test_minimize_simple..CallbackNewSyntax.__init__/s   rcRt|tsJ|xjdz c_yr?) isinstancer r;)rintermediate_results rr@zCTestCobyla.test_minimize_simple..CallbackNewSyntax.__call__2s!!"5~FFF ! rNrAr(rrCallbackNewSyntaxrG.s  ! "rrLrineqtyper%cobyla)method constraintscallbackoptionsr1r2r.FMbP?zGLast design vector sent to the callback is not equal to returned value.)decimalerr_msgzGCallback is not called the same amount of times for old and new syntax.)rr)rinfr,rr%rrrr$rsuccessmessagemaxcvnfevrr<r;)rrErLrScallback_new_syntaxconssolsol_news rtest_minimize_simplezTestCobyla.test_minimize_simple$s   " ":/1$DIIq"&&9 24txxt ($))=488TWWX4 3TYYHt}}48{{'CKK'{yy4$$xx"}!c!}ww$--0477<<7! EE OO$  //ww'++%%%yyGMM)))xx7<<'''#6#>#>> V U V>rcddddddf}tddgd|dd i }|jd kDsJ|jsJtd dgd|dd i }|jd kDsJ|jrJy)NrMc d|z S)Nr(r$s rz?TestCobyla.test_minimize_constraint_violation..V !a%rrNc |dz S)NrWr(rgs rrhz?TestCobyla.test_minimize_constraint_violation..Wrirc|Sr+r(rgs rrhz?TestCobyla.test_minimize_constraint_violation..XrrrPcatolg333333?rQrRrTg?c|Sr+r(rgs rrhz?TestCobyla.test_minimize_constraint_violation..\rlrg?)rr]r[)rr`ras r"test_minimize_constraint_violationz-TestCobyla.test_minimize_constraint_violationSs 88:{QCd '~/yy3{{{{QCd '~/yy3;;;rcd}tddgdd|i}|jdk(sJ|jsJ|j|ksJy)Nc |dzSNr r(rgs rrhz*TestCobyla.test_f_target..cs ArirPf_target)rQrTr)rstatusr[r%)rruras r test_f_targetzTestCobyla.test_f_targetasO~uX *H57zzQ{{{ww("""rctddgdd}t|j|jd||j}dt j dz dz t j ddz dz g}t|j|d |jsJ|j|jd ksJ||jd ksJ||j|j|d zksJ|y) Ng?rPrnrfr!rr1r2g:0yE>rrV) r rr%rrrrrr$r[r\r]r^)rrRrars r test_minimize_linear_constraintsz+TestCobyla.test_minimize_linear_constraintsis&Sz3<  HH GG#II  ^q(2771:>Q*>?xd3{{'CKK'{yy4$$xx3##ww(+d227C72rN) rBrCrDrr%r)r,r4rcrprwrzr(rrr r s1%&&5 -V^ #8rr c$ d fd}d}d}tjddg} ||g}ddg}d }t ||d }t||d t ||d }t |dd |Dcgc]}d|d } }t || d }t|j |d |j sJ|jt|j|d d|d} t || d }t|jdd ycc}w)Nc0|ddz dz|ddz dzzS)Nrrr g@r(rgs rr%z$test_vector_constraints..fun}s%!q1}!s Q..rc|dz Sr?r()r$r%s rfminz%test_vector_constraints..fmins1vzrc tjgdgdgdg}tjtt|Dcgc]%}||df|dz||df|dzz||dfz'c}Scc}w)N)rr )r)rr r rrr )rarrayrangelen)r$ais rcons1z&test_vector_constraints..cons1s HHj+z: ;xx*/A-9%&1a41Q4!AqD'AaD.81a4!9: :9s*A5c|Sr+r(rgs rcons2z&test_vector_constraints..cons2srr rgffffff?g333333?g?r.)r/r1r2rrMrN)rRr) rrrrrr$r[r\r%) r~rrr cons_listxsolfsolrar`rRr%s @rtest_vector_constraintsrzs/:  1a& BeU#I :D D c2y 6CCD) c2tD 1CCHad+>GGTF40GKG 3  >CCEE4d+ ;;# #;CGGT-!$/K 3  >CCGGQT*Hs6 D ceZdZdZdZy) TestBoundscd}gd}gd}t||Dcgc] \}}||f }}}t|gdd|}gd}|jsJt|j|d ycc}}w) Nc2tj|dzSrtrsumrgs rfz TestBounds.test_basic..f66!Q$< r)rNrN)rrNNr)rr r!rfrWrPrrQbounds)rrrrrrVr2)ziprr[rr$) rrlbubrbrresrefs r test_basiczTestBounds.test_basicsl ' +%(R[1TQ1a&11q_XfM&{{{s. 2sA(cd}ttj tj gtjtjg}t|ddgd|}|jsJt |j ddtdtj gtjtjg}t|ddgd|}|jsJt |j ddgdy) Nc2tj|dzSrtrrgs rrz$TestBounds.test_unbounded..frrrr rPrrrVr2)rrrZrr[rr$)rrrrs rtest_unboundedzTestBounds.test_unboundeds "&&266'*RVVRVV,<=qaVHVD{{{qt,RVVG rvvrvv&67qaVHVD{{{1vD1rN)rBrCrDrrr(rrrrs / 2rr)rnumpyr numpy.testingrrscipy.optimizerrrrr r r rrr(rrrs5 D k8k8\'+T22r