_add_newdocs.py 235 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850
  1. # Docstrings for generated ufuncs
  2. #
  3. # The syntax is designed to look like the function add_newdoc is being
  4. # called from numpy.lib, but in this file add_newdoc puts the
  5. # docstrings in a dictionary. This dictionary is used in
  6. # _generate_pyx.py to generate the docstrings for the ufuncs in
  7. # scipy.special at the C level when the ufuncs are created at compile
  8. # time.
  9. docdict: dict[str, str] = {}
  10. def get(name):
  11. return docdict.get(name)
  12. def add_newdoc(name, doc):
  13. docdict[name] = doc
  14. add_newdoc("_sf_error_test_function",
  15. """
  16. Private function; do not use.
  17. """)
  18. add_newdoc("_cosine_cdf",
  19. """
  20. _cosine_cdf(x)
  21. Cumulative distribution function (CDF) of the cosine distribution::
  22. { 0, x < -pi
  23. cdf(x) = { (pi + x + sin(x))/(2*pi), -pi <= x <= pi
  24. { 1, x > pi
  25. Parameters
  26. ----------
  27. x : array_like
  28. `x` must contain real numbers.
  29. Returns
  30. -------
  31. scalar or ndarray
  32. The cosine distribution CDF evaluated at `x`.
  33. """)
  34. add_newdoc("_cosine_invcdf",
  35. """
  36. _cosine_invcdf(p)
  37. Inverse of the cumulative distribution function (CDF) of the cosine
  38. distribution.
  39. The CDF of the cosine distribution is::
  40. cdf(x) = (pi + x + sin(x))/(2*pi)
  41. This function computes the inverse of cdf(x).
  42. Parameters
  43. ----------
  44. p : array_like
  45. `p` must contain real numbers in the interval ``0 <= p <= 1``.
  46. `nan` is returned for values of `p` outside the interval [0, 1].
  47. Returns
  48. -------
  49. scalar or ndarray
  50. The inverse of the cosine distribution CDF evaluated at `p`.
  51. """)
  52. add_newdoc("_ellip_harm",
  53. """
  54. Internal function, use `ellip_harm` instead.
  55. """)
  56. add_newdoc("_ellip_norm",
  57. """
  58. Internal function, use `ellip_norm` instead.
  59. """)
  60. add_newdoc("wrightomega",
  61. r"""
  62. wrightomega(z, out=None)
  63. Wright Omega function.
  64. Defined as the solution to
  65. .. math::
  66. \omega + \log(\omega) = z
  67. where :math:`\log` is the principal branch of the complex logarithm.
  68. Parameters
  69. ----------
  70. z : array_like
  71. Points at which to evaluate the Wright Omega function
  72. out : ndarray, optional
  73. Optional output array for the function values
  74. Returns
  75. -------
  76. omega : scalar or ndarray
  77. Values of the Wright Omega function
  78. See Also
  79. --------
  80. lambertw : The Lambert W function
  81. Notes
  82. -----
  83. .. versionadded:: 0.19.0
  84. The function can also be defined as
  85. .. math::
  86. \omega(z) = W_{K(z)}(e^z)
  87. where :math:`K(z) = \lceil (\Im(z) - \pi)/(2\pi) \rceil` is the
  88. unwinding number and :math:`W` is the Lambert W function.
  89. The implementation here is taken from [1]_.
  90. References
  91. ----------
  92. .. [1] Lawrence, Corless, and Jeffrey, "Algorithm 917: Complex
  93. Double-Precision Evaluation of the Wright :math:`\omega`
  94. Function." ACM Transactions on Mathematical Software,
  95. 2012. :doi:`10.1145/2168773.2168779`.
  96. Examples
  97. --------
  98. >>> import numpy as np
  99. >>> from scipy.special import wrightomega, lambertw
  100. >>> wrightomega([-2, -1, 0, 1, 2])
  101. array([0.12002824, 0.27846454, 0.56714329, 1. , 1.5571456 ])
  102. Complex input:
  103. >>> wrightomega(3 + 5j)
  104. (1.5804428632097158+3.8213626783287937j)
  105. Verify that ``wrightomega(z)`` satisfies ``w + log(w) = z``:
  106. >>> w = -5 + 4j
  107. >>> wrightomega(w + np.log(w))
  108. (-5+4j)
  109. Verify the connection to ``lambertw``:
  110. >>> z = 0.5 + 3j
  111. >>> wrightomega(z)
  112. (0.0966015889280649+1.4937828458191993j)
  113. >>> lambertw(np.exp(z))
  114. (0.09660158892806493+1.4937828458191993j)
  115. >>> z = 0.5 + 4j
  116. >>> wrightomega(z)
  117. (-0.3362123489037213+2.282986001579032j)
  118. >>> lambertw(np.exp(z), k=1)
  119. (-0.33621234890372115+2.282986001579032j)
  120. """)
  121. add_newdoc("agm",
  122. """
  123. agm(a, b, out=None)
  124. Compute the arithmetic-geometric mean of `a` and `b`.
  125. Start with a_0 = a and b_0 = b and iteratively compute::
  126. a_{n+1} = (a_n + b_n)/2
  127. b_{n+1} = sqrt(a_n*b_n)
  128. a_n and b_n converge to the same limit as n increases; their common
  129. limit is agm(a, b).
  130. Parameters
  131. ----------
  132. a, b : array_like
  133. Real values only. If the values are both negative, the result
  134. is negative. If one value is negative and the other is positive,
  135. `nan` is returned.
  136. out : ndarray, optional
  137. Optional output array for the function values
  138. Returns
  139. -------
  140. scalar or ndarray
  141. The arithmetic-geometric mean of `a` and `b`.
  142. Examples
  143. --------
  144. >>> import numpy as np
  145. >>> from scipy.special import agm
  146. >>> a, b = 24.0, 6.0
  147. >>> agm(a, b)
  148. 13.458171481725614
  149. Compare that result to the iteration:
  150. >>> while a != b:
  151. ... a, b = (a + b)/2, np.sqrt(a*b)
  152. ... print("a = %19.16f b=%19.16f" % (a, b))
  153. ...
  154. a = 15.0000000000000000 b=12.0000000000000000
  155. a = 13.5000000000000000 b=13.4164078649987388
  156. a = 13.4582039324993694 b=13.4581390309909850
  157. a = 13.4581714817451772 b=13.4581714817060547
  158. a = 13.4581714817256159 b=13.4581714817256159
  159. When array-like arguments are given, broadcasting applies:
  160. >>> a = np.array([[1.5], [3], [6]]) # a has shape (3, 1).
  161. >>> b = np.array([6, 12, 24, 48]) # b has shape (4,).
  162. >>> agm(a, b)
  163. array([[ 3.36454287, 5.42363427, 9.05798751, 15.53650756],
  164. [ 4.37037309, 6.72908574, 10.84726853, 18.11597502],
  165. [ 6. , 8.74074619, 13.45817148, 21.69453707]])
  166. """)
  167. add_newdoc("bdtr",
  168. r"""
  169. bdtr(k, n, p, out=None)
  170. Binomial distribution cumulative distribution function.
  171. Sum of the terms 0 through `floor(k)` of the Binomial probability density.
  172. .. math::
  173. \mathrm{bdtr}(k, n, p) =
  174. \sum_{j=0}^{\lfloor k \rfloor} {{n}\choose{j}} p^j (1-p)^{n-j}
  175. Parameters
  176. ----------
  177. k : array_like
  178. Number of successes (double), rounded down to the nearest integer.
  179. n : array_like
  180. Number of events (int).
  181. p : array_like
  182. Probability of success in a single event (float).
  183. out : ndarray, optional
  184. Optional output array for the function values
  185. Returns
  186. -------
  187. y : scalar or ndarray
  188. Probability of `floor(k)` or fewer successes in `n` independent events with
  189. success probabilities of `p`.
  190. Notes
  191. -----
  192. The terms are not summed directly; instead the regularized incomplete beta
  193. function is employed, according to the formula,
  194. .. math::
  195. \mathrm{bdtr}(k, n, p) =
  196. I_{1 - p}(n - \lfloor k \rfloor, \lfloor k \rfloor + 1).
  197. Wrapper for the Cephes [1]_ routine `bdtr`.
  198. References
  199. ----------
  200. .. [1] Cephes Mathematical Functions Library,
  201. http://www.netlib.org/cephes/
  202. """)
  203. add_newdoc("bdtrc",
  204. r"""
  205. bdtrc(k, n, p, out=None)
  206. Binomial distribution survival function.
  207. Sum of the terms `floor(k) + 1` through `n` of the binomial probability
  208. density,
  209. .. math::
  210. \mathrm{bdtrc}(k, n, p) =
  211. \sum_{j=\lfloor k \rfloor +1}^n {{n}\choose{j}} p^j (1-p)^{n-j}
  212. Parameters
  213. ----------
  214. k : array_like
  215. Number of successes (double), rounded down to nearest integer.
  216. n : array_like
  217. Number of events (int)
  218. p : array_like
  219. Probability of success in a single event.
  220. out : ndarray, optional
  221. Optional output array for the function values
  222. Returns
  223. -------
  224. y : scalar or ndarray
  225. Probability of `floor(k) + 1` or more successes in `n` independent
  226. events with success probabilities of `p`.
  227. See Also
  228. --------
  229. bdtr
  230. betainc
  231. Notes
  232. -----
  233. The terms are not summed directly; instead the regularized incomplete beta
  234. function is employed, according to the formula,
  235. .. math::
  236. \mathrm{bdtrc}(k, n, p) = I_{p}(\lfloor k \rfloor + 1, n - \lfloor k \rfloor).
  237. Wrapper for the Cephes [1]_ routine `bdtrc`.
  238. References
  239. ----------
  240. .. [1] Cephes Mathematical Functions Library,
  241. http://www.netlib.org/cephes/
  242. """)
  243. add_newdoc("bdtri",
  244. r"""
  245. bdtri(k, n, y, out=None)
  246. Inverse function to `bdtr` with respect to `p`.
  247. Finds the event probability `p` such that the sum of the terms 0 through
  248. `k` of the binomial probability density is equal to the given cumulative
  249. probability `y`.
  250. Parameters
  251. ----------
  252. k : array_like
  253. Number of successes (float), rounded down to the nearest integer.
  254. n : array_like
  255. Number of events (float)
  256. y : array_like
  257. Cumulative probability (probability of `k` or fewer successes in `n`
  258. events).
  259. out : ndarray, optional
  260. Optional output array for the function values
  261. Returns
  262. -------
  263. p : scalar or ndarray
  264. The event probability such that `bdtr(\lfloor k \rfloor, n, p) = y`.
  265. See Also
  266. --------
  267. bdtr
  268. betaincinv
  269. Notes
  270. -----
  271. The computation is carried out using the inverse beta integral function
  272. and the relation,::
  273. 1 - p = betaincinv(n - k, k + 1, y).
  274. Wrapper for the Cephes [1]_ routine `bdtri`.
  275. References
  276. ----------
  277. .. [1] Cephes Mathematical Functions Library,
  278. http://www.netlib.org/cephes/
  279. """)
  280. add_newdoc("bdtrik",
  281. """
  282. bdtrik(y, n, p, out=None)
  283. Inverse function to `bdtr` with respect to `k`.
  284. Finds the number of successes `k` such that the sum of the terms 0 through
  285. `k` of the Binomial probability density for `n` events with probability
  286. `p` is equal to the given cumulative probability `y`.
  287. Parameters
  288. ----------
  289. y : array_like
  290. Cumulative probability (probability of `k` or fewer successes in `n`
  291. events).
  292. n : array_like
  293. Number of events (float).
  294. p : array_like
  295. Success probability (float).
  296. out : ndarray, optional
  297. Optional output array for the function values
  298. Returns
  299. -------
  300. k : scalar or ndarray
  301. The number of successes `k` such that `bdtr(k, n, p) = y`.
  302. See Also
  303. --------
  304. bdtr
  305. Notes
  306. -----
  307. Formula 26.5.24 of [1]_ (or equivalently [2]_) is used to reduce the binomial
  308. distribution to the cumulative incomplete beta distribution.
  309. Computation of `k` involves a search for a value that produces the desired
  310. value of `y`. The search relies on the monotonicity of `y` with `k`.
  311. Wrapper for the CDFLIB [3]_ Fortran routine `cdfbin`.
  312. References
  313. ----------
  314. .. [1] Milton Abramowitz and Irene A. Stegun, eds.
  315. Handbook of Mathematical Functions with Formulas,
  316. Graphs, and Mathematical Tables. New York: Dover, 1972.
  317. .. [2] NIST Digital Library of Mathematical Functions
  318. https://dlmf.nist.gov/8.17.5#E5
  319. .. [3] Barry Brown, James Lovato, and Kathy Russell,
  320. CDFLIB: Library of Fortran Routines for Cumulative Distribution
  321. Functions, Inverses, and Other Parameters.
  322. """)
  323. add_newdoc("bdtrin",
  324. """
  325. bdtrin(k, y, p, out=None)
  326. Inverse function to `bdtr` with respect to `n`.
  327. Finds the number of events `n` such that the sum of the terms 0 through
  328. `k` of the Binomial probability density for events with probability `p` is
  329. equal to the given cumulative probability `y`.
  330. Parameters
  331. ----------
  332. k : array_like
  333. Number of successes (float).
  334. y : array_like
  335. Cumulative probability (probability of `k` or fewer successes in `n`
  336. events).
  337. p : array_like
  338. Success probability (float).
  339. out : ndarray, optional
  340. Optional output array for the function values
  341. Returns
  342. -------
  343. n : scalar or ndarray
  344. The number of events `n` such that `bdtr(k, n, p) = y`.
  345. See Also
  346. --------
  347. bdtr
  348. Notes
  349. -----
  350. Formula 26.5.24 of [1]_ (or equivalently [2]_) is used to reduce the binomial
  351. distribution to the cumulative incomplete beta distribution.
  352. Computation of `n` involves a search for a value that produces the desired
  353. value of `y`. The search relies on the monotonicity of `y` with `n`.
  354. Wrapper for the CDFLIB [3]_ Fortran routine `cdfbin`.
  355. References
  356. ----------
  357. .. [1] Milton Abramowitz and Irene A. Stegun, eds.
  358. Handbook of Mathematical Functions with Formulas,
  359. Graphs, and Mathematical Tables. New York: Dover, 1972.
  360. .. [2] NIST Digital Library of Mathematical Functions
  361. https://dlmf.nist.gov/8.17.5#E5
  362. .. [3] Barry Brown, James Lovato, and Kathy Russell,
  363. CDFLIB: Library of Fortran Routines for Cumulative Distribution
  364. Functions, Inverses, and Other Parameters.
  365. """)
  366. add_newdoc("btdtria",
  367. r"""
  368. btdtria(p, b, x, out=None)
  369. Inverse of `betainc` with respect to `a`.
  370. This is the inverse of the beta cumulative distribution function, `betainc`,
  371. considered as a function of `a`, returning the value of `a` for which
  372. `betainc(a, b, x) = p`, or
  373. .. math::
  374. p = \int_0^x \frac{\Gamma(a + b)}{\Gamma(a)\Gamma(b)} t^{a-1} (1-t)^{b-1}\,dt
  375. Parameters
  376. ----------
  377. p : array_like
  378. Cumulative probability, in [0, 1].
  379. b : array_like
  380. Shape parameter (`b` > 0).
  381. x : array_like
  382. The quantile, in [0, 1].
  383. out : ndarray, optional
  384. Optional output array for the function values
  385. Returns
  386. -------
  387. a : scalar or ndarray
  388. The value of the shape parameter `a` such that `betainc(a, b, x) = p`.
  389. See Also
  390. --------
  391. betainc : Regularized incomplete beta function
  392. betaincinv : Inverse of the regularized incomplete beta function
  393. btdtrib : Inverse of the beta cumulative distribution function, with respect to `b`.
  394. Notes
  395. -----
  396. This function wraps the ``ibeta_inva`` routine from the
  397. Boost Math C++ library [1]_.
  398. References
  399. ----------
  400. .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
  401. Examples
  402. --------
  403. >>> import scipy.special as sc
  404. This function is the inverse of `betainc` for fixed
  405. values of :math:`b` and :math:`x`.
  406. >>> a, b, x = 1.2, 3.1, 0.2
  407. >>> y = sc.betainc(a, b, x)
  408. >>> sc.btdtria(y, b, x)
  409. 1.2
  410. """)
  411. add_newdoc("btdtrib",
  412. r"""
  413. btdtria(a, p, x, out=None)
  414. Inverse of `betainc` with respect to `b`.
  415. This is the inverse of the beta cumulative distribution function, `betainc`,
  416. considered as a function of `b`, returning the value of `b` for which
  417. `betainc(a, b, x) = p`, or
  418. .. math::
  419. p = \int_0^x \frac{\Gamma(a + b)}{\Gamma(a)\Gamma(b)} t^{a-1} (1-t)^{b-1}\,dt
  420. Parameters
  421. ----------
  422. a : array_like
  423. Shape parameter (`a` > 0).
  424. p : array_like
  425. Cumulative probability, in [0, 1].
  426. x : array_like
  427. The quantile, in [0, 1].
  428. out : ndarray, optional
  429. Optional output array for the function values
  430. Returns
  431. -------
  432. b : scalar or ndarray
  433. The value of the shape parameter `b` such that `betainc(a, b, x) = p`.
  434. See Also
  435. --------
  436. betainc : Regularized incomplete beta function
  437. betaincinv : Inverse of the regularized incomplete beta function with
  438. respect to `x`.
  439. btdtria : Inverse of the beta cumulative distribution function, with respect to `a`.
  440. Notes
  441. -----
  442. Wrapper for the `ibeta_invb` routine from the Boost Math C++ library [1]_.
  443. References
  444. ----------
  445. .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
  446. Examples
  447. --------
  448. >>> import scipy.special as sc
  449. >>> a, b, x = 1.2, 3.1, 0.2
  450. >>> y = sc.betainc(a, b, x)
  451. `btdtrib` is the inverse of `betainc` for fixed values of :math:`a` and
  452. :math:`x`:
  453. >>> sc.btdtrib(a, y, x)
  454. 3.1
  455. """)
  456. add_newdoc(
  457. "betainc",
  458. r"""
  459. betainc(a, b, x, out=None)
  460. Regularized incomplete beta function.
  461. Computes the regularized incomplete beta function, defined as [1]_:
  462. .. math::
  463. I_x(a, b) = \frac{\Gamma(a+b)}{\Gamma(a)\Gamma(b)} \int_0^x
  464. t^{a-1}(1-t)^{b-1}dt,
  465. for :math:`0 \leq x \leq 1`.
  466. This function is the cumulative distribution function for the beta
  467. distribution; its range is [0, 1].
  468. Parameters
  469. ----------
  470. a, b : array_like
  471. Positive, real-valued parameters
  472. x : array_like
  473. Real-valued such that :math:`0 \leq x \leq 1`,
  474. the upper limit of integration
  475. out : ndarray, optional
  476. Optional output array for the function values
  477. Returns
  478. -------
  479. scalar or ndarray
  480. Value of the regularized incomplete beta function
  481. See Also
  482. --------
  483. beta : beta function
  484. betaincinv : inverse of the regularized incomplete beta function
  485. betaincc : complement of the regularized incomplete beta function
  486. scipy.stats.beta : beta distribution
  487. Notes
  488. -----
  489. The term *regularized* in the name of this function refers to the
  490. scaling of the function by the gamma function terms shown in the
  491. formula. When not qualified as *regularized*, the name *incomplete
  492. beta function* often refers to just the integral expression,
  493. without the gamma terms. One can use the function `beta` from
  494. `scipy.special` to get this "nonregularized" incomplete beta
  495. function by multiplying the result of ``betainc(a, b, x)`` by
  496. ``beta(a, b)``.
  497. ``betainc(a, b, x)`` is treated as a two parameter family of functions
  498. of a single variable `x`, rather than as a function of three variables.
  499. This impacts only the limiting cases ``a = 0``, ``b = 0``, ``a = inf``,
  500. ``b = inf``.
  501. In general
  502. .. math::
  503. \lim_{(a, b) \rightarrow (a_0, b_0)} \mathrm{betainc}(a, b, x)
  504. is treated as a pointwise limit in ``x``. Thus for example,
  505. ``betainc(0, b, 0)`` equals ``0`` for ``b > 0``, although it would be
  506. indeterminate when considering the simultaneous limit ``(a, x) -> (0+, 0+)``.
  507. This function wraps the ``ibeta`` routine from the
  508. Boost Math C++ library [2]_.
  509. References
  510. ----------
  511. .. [1] NIST Digital Library of Mathematical Functions
  512. https://dlmf.nist.gov/8.17
  513. .. [2] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
  514. Examples
  515. --------
  516. Let :math:`B(a, b)` be the `beta` function.
  517. >>> import scipy.special as sc
  518. The coefficient in terms of `gamma` is equal to
  519. :math:`1/B(a, b)`. Also, when :math:`x=1`
  520. the integral is equal to :math:`B(a, b)`.
  521. Therefore, :math:`I_{x=1}(a, b) = 1` for any :math:`a, b`.
  522. >>> sc.betainc(0.2, 3.5, 1.0)
  523. 1.0
  524. It satisfies
  525. :math:`I_x(a, b) = x^a F(a, 1-b, a+1, x)/ (aB(a, b))`,
  526. where :math:`F` is the hypergeometric function `hyp2f1`:
  527. >>> a, b, x = 1.4, 3.1, 0.5
  528. >>> x**a * sc.hyp2f1(a, 1 - b, a + 1, x)/(a * sc.beta(a, b))
  529. 0.8148904036225295
  530. >>> sc.betainc(a, b, x)
  531. 0.8148904036225296
  532. This functions satisfies the relationship
  533. :math:`I_x(a, b) = 1 - I_{1-x}(b, a)`:
  534. >>> sc.betainc(2.2, 3.1, 0.4)
  535. 0.49339638807619446
  536. >>> 1 - sc.betainc(3.1, 2.2, 1 - 0.4)
  537. 0.49339638807619446
  538. """)
  539. add_newdoc(
  540. "betaincc",
  541. r"""
  542. betaincc(a, b, x, out=None)
  543. Complement of the regularized incomplete beta function.
  544. Computes the complement of the regularized incomplete beta function,
  545. defined as [1]_:
  546. .. math::
  547. \bar{I}_x(a, b) = 1 - I_x(a, b)
  548. = 1 - \frac{\Gamma(a+b)}{\Gamma(a)\Gamma(b)} \int_0^x
  549. t^{a-1}(1-t)^{b-1}dt,
  550. for :math:`0 \leq x \leq 1`.
  551. Parameters
  552. ----------
  553. a, b : array_like
  554. Positive, real-valued parameters
  555. x : array_like
  556. Real-valued such that :math:`0 \leq x \leq 1`,
  557. the upper limit of integration
  558. out : ndarray, optional
  559. Optional output array for the function values
  560. Returns
  561. -------
  562. scalar or ndarray
  563. Value of the regularized incomplete beta function
  564. See Also
  565. --------
  566. betainc : regularized incomplete beta function
  567. betaincinv : inverse of the regularized incomplete beta function
  568. betainccinv :
  569. inverse of the complement of the regularized incomplete beta function
  570. beta : beta function
  571. scipy.stats.beta : beta distribution
  572. Notes
  573. -----
  574. .. versionadded:: 1.11.0
  575. Like `betainc`, ``betaincc(a, b, x)`` is treated as a two parameter
  576. family of functions of a single variable `x`, rather than as a function of
  577. three variables. See the `betainc` docstring for more info on how this
  578. impacts limiting cases.
  579. This function wraps the ``ibetac`` routine from the
  580. Boost Math C++ library [2]_.
  581. References
  582. ----------
  583. .. [1] NIST Digital Library of Mathematical Functions
  584. https://dlmf.nist.gov/8.17
  585. .. [2] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
  586. Examples
  587. --------
  588. >>> from scipy.special import betaincc, betainc
  589. The naive calculation ``1 - betainc(a, b, x)`` loses precision when
  590. the values of ``betainc(a, b, x)`` are close to 1:
  591. >>> 1 - betainc(0.5, 8, [0.9, 0.99, 0.999])
  592. array([2.0574632e-09, 0.0000000e+00, 0.0000000e+00])
  593. By using ``betaincc``, we get the correct values:
  594. >>> betaincc(0.5, 8, [0.9, 0.99, 0.999])
  595. array([2.05746321e-09, 1.97259354e-17, 1.96467954e-25])
  596. """)
  597. add_newdoc(
  598. "betaincinv",
  599. r"""
  600. betaincinv(a, b, y, out=None)
  601. Inverse of the regularized incomplete beta function.
  602. Computes :math:`x` such that:
  603. .. math::
  604. y = I_x(a, b) = \frac{\Gamma(a+b)}{\Gamma(a)\Gamma(b)}
  605. \int_0^x t^{a-1}(1-t)^{b-1}dt,
  606. where :math:`I_x` is the normalized incomplete beta function `betainc`
  607. and :math:`\Gamma` is the `gamma` function [1]_.
  608. Parameters
  609. ----------
  610. a, b : array_like
  611. Positive, real-valued parameters
  612. y : array_like
  613. Real-valued input
  614. out : ndarray, optional
  615. Optional output array for function values
  616. Returns
  617. -------
  618. scalar or ndarray
  619. Value of the inverse of the regularized incomplete beta function
  620. See Also
  621. --------
  622. betainc : regularized incomplete beta function
  623. gamma : gamma function
  624. Notes
  625. -----
  626. This function wraps the ``ibeta_inv`` routine from the
  627. Boost Math C++ library [2]_.
  628. References
  629. ----------
  630. .. [1] NIST Digital Library of Mathematical Functions
  631. https://dlmf.nist.gov/8.17
  632. .. [2] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
  633. Examples
  634. --------
  635. >>> import scipy.special as sc
  636. This function is the inverse of `betainc` for fixed
  637. values of :math:`a` and :math:`b`.
  638. >>> a, b = 1.2, 3.1
  639. >>> y = sc.betainc(a, b, 0.2)
  640. >>> sc.betaincinv(a, b, y)
  641. 0.2
  642. >>>
  643. >>> a, b = 7.5, 0.4
  644. >>> x = sc.betaincinv(a, b, 0.5)
  645. >>> sc.betainc(a, b, x)
  646. 0.5
  647. """)
  648. add_newdoc(
  649. "betainccinv",
  650. r"""
  651. betainccinv(a, b, y, out=None)
  652. Inverse of the complemented regularized incomplete beta function.
  653. Computes :math:`x` such that:
  654. .. math::
  655. y = 1 - I_x(a, b) = 1 - \frac{\Gamma(a+b)}{\Gamma(a)\Gamma(b)}
  656. \int_0^x t^{a-1}(1-t)^{b-1}dt,
  657. where :math:`I_x` is the normalized incomplete beta function `betainc`
  658. and :math:`\Gamma` is the `gamma` function [1]_.
  659. Parameters
  660. ----------
  661. a, b : array_like
  662. Positive, real-valued parameters
  663. y : array_like
  664. Real-valued input
  665. out : ndarray, optional
  666. Optional output array for function values
  667. Returns
  668. -------
  669. scalar or ndarray
  670. Value of the inverse of the regularized incomplete beta function
  671. See Also
  672. --------
  673. betainc : regularized incomplete beta function
  674. betaincc : complement of the regularized incomplete beta function
  675. Notes
  676. -----
  677. .. versionadded:: 1.11.0
  678. This function wraps the ``ibetac_inv`` routine from the
  679. Boost Math C++ library [2]_.
  680. References
  681. ----------
  682. .. [1] NIST Digital Library of Mathematical Functions
  683. https://dlmf.nist.gov/8.17
  684. .. [2] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
  685. Examples
  686. --------
  687. >>> from scipy.special import betainccinv, betaincc
  688. This function is the inverse of `betaincc` for fixed
  689. values of :math:`a` and :math:`b`.
  690. >>> a, b = 1.2, 3.1
  691. >>> y = betaincc(a, b, 0.2)
  692. >>> betainccinv(a, b, y)
  693. 0.2
  694. >>> a, b = 7, 2.5
  695. >>> x = betainccinv(a, b, 0.875)
  696. >>> betaincc(a, b, x)
  697. 0.875
  698. """)
  699. add_newdoc("boxcox",
  700. """
  701. boxcox(x, lmbda, out=None)
  702. Compute the Box-Cox transformation.
  703. The Box-Cox transformation is::
  704. y = (x**lmbda - 1) / lmbda if lmbda != 0
  705. log(x) if lmbda == 0
  706. Returns `nan` if ``x < 0``.
  707. Returns `-inf` if ``x == 0`` and ``lmbda < 0``.
  708. Parameters
  709. ----------
  710. x : array_like
  711. Data to be transformed.
  712. lmbda : array_like
  713. Power parameter of the Box-Cox transform.
  714. out : ndarray, optional
  715. Optional output array for the function values
  716. Returns
  717. -------
  718. y : scalar or ndarray
  719. Transformed data.
  720. Notes
  721. -----
  722. .. versionadded:: 0.14.0
  723. Examples
  724. --------
  725. >>> from scipy.special import boxcox
  726. >>> boxcox([1, 4, 10], 2.5)
  727. array([ 0. , 12.4 , 126.09110641])
  728. >>> boxcox(2, [0, 1, 2])
  729. array([ 0.69314718, 1. , 1.5 ])
  730. """)
  731. add_newdoc("boxcox1p",
  732. """
  733. boxcox1p(x, lmbda, out=None)
  734. Compute the Box-Cox transformation of 1 + `x`.
  735. The Box-Cox transformation computed by `boxcox1p` is::
  736. y = ((1+x)**lmbda - 1) / lmbda if lmbda != 0
  737. log(1+x) if lmbda == 0
  738. Returns `nan` if ``x < -1``.
  739. Returns `-inf` if ``x == -1`` and ``lmbda < 0``.
  740. Parameters
  741. ----------
  742. x : array_like
  743. Data to be transformed.
  744. lmbda : array_like
  745. Power parameter of the Box-Cox transform.
  746. out : ndarray, optional
  747. Optional output array for the function values
  748. Returns
  749. -------
  750. y : scalar or ndarray
  751. Transformed data.
  752. Notes
  753. -----
  754. .. versionadded:: 0.14.0
  755. Examples
  756. --------
  757. >>> from scipy.special import boxcox1p
  758. >>> boxcox1p(1e-4, [0, 0.5, 1])
  759. array([ 9.99950003e-05, 9.99975001e-05, 1.00000000e-04])
  760. >>> boxcox1p([0.01, 0.1], 0.25)
  761. array([ 0.00996272, 0.09645476])
  762. """)
  763. add_newdoc("inv_boxcox",
  764. """
  765. inv_boxcox(y, lmbda, out=None)
  766. Compute the inverse of the Box-Cox transformation.
  767. Find ``x`` such that::
  768. y = (x**lmbda - 1) / lmbda if lmbda != 0
  769. log(x) if lmbda == 0
  770. Parameters
  771. ----------
  772. y : array_like
  773. Data to be transformed.
  774. lmbda : array_like
  775. Power parameter of the Box-Cox transform.
  776. out : ndarray, optional
  777. Optional output array for the function values
  778. Returns
  779. -------
  780. x : scalar or ndarray
  781. Transformed data.
  782. Notes
  783. -----
  784. .. versionadded:: 0.16.0
  785. Examples
  786. --------
  787. >>> from scipy.special import boxcox, inv_boxcox
  788. >>> y = boxcox([1, 4, 10], 2.5)
  789. >>> inv_boxcox(y, 2.5)
  790. array([1., 4., 10.])
  791. """)
  792. add_newdoc("inv_boxcox1p",
  793. """
  794. inv_boxcox1p(y, lmbda, out=None)
  795. Compute the inverse of the Box-Cox transformation.
  796. Find ``x`` such that::
  797. y = ((1+x)**lmbda - 1) / lmbda if lmbda != 0
  798. log(1+x) if lmbda == 0
  799. Parameters
  800. ----------
  801. y : array_like
  802. Data to be transformed.
  803. lmbda : array_like
  804. Power parameter of the Box-Cox transform.
  805. out : ndarray, optional
  806. Optional output array for the function values
  807. Returns
  808. -------
  809. x : scalar or ndarray
  810. Transformed data.
  811. Notes
  812. -----
  813. .. versionadded:: 0.16.0
  814. Examples
  815. --------
  816. >>> from scipy.special import boxcox1p, inv_boxcox1p
  817. >>> y = boxcox1p([1, 4, 10], 2.5)
  818. >>> inv_boxcox1p(y, 2.5)
  819. array([1., 4., 10.])
  820. """)
  821. add_newdoc("chdtr",
  822. r"""
  823. chdtr(v, x, out=None)
  824. Chi square cumulative distribution function.
  825. Returns the area under the left tail (from 0 to `x`) of the Chi
  826. square probability density function with `v` degrees of freedom:
  827. .. math::
  828. \frac{1}{2^{v/2} \Gamma(v/2)} \int_0^x t^{v/2 - 1} e^{-t/2} dt
  829. Here :math:`\Gamma` is the Gamma function; see `gamma`. This
  830. integral can be expressed in terms of the regularized lower
  831. incomplete gamma function `gammainc` as
  832. ``gammainc(v / 2, x / 2)``. [1]_
  833. Parameters
  834. ----------
  835. v : array_like
  836. Degrees of freedom.
  837. x : array_like
  838. Upper bound of the integral.
  839. out : ndarray, optional
  840. Optional output array for the function results.
  841. Returns
  842. -------
  843. scalar or ndarray
  844. Values of the cumulative distribution function.
  845. See Also
  846. --------
  847. chdtrc, chdtri, chdtriv, gammainc
  848. References
  849. ----------
  850. .. [1] Chi-Square distribution,
  851. https://www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm
  852. Examples
  853. --------
  854. >>> import numpy as np
  855. >>> import scipy.special as sc
  856. It can be expressed in terms of the regularized lower incomplete
  857. gamma function.
  858. >>> v = 1
  859. >>> x = np.arange(4)
  860. >>> sc.chdtr(v, x)
  861. array([0. , 0.68268949, 0.84270079, 0.91673548])
  862. >>> sc.gammainc(v / 2, x / 2)
  863. array([0. , 0.68268949, 0.84270079, 0.91673548])
  864. """)
  865. add_newdoc("chdtrc",
  866. r"""
  867. chdtrc(v, x, out=None)
  868. Chi square survival function.
  869. Returns the area under the right hand tail (from `x` to infinity)
  870. of the Chi square probability density function with `v` degrees of
  871. freedom:
  872. .. math::
  873. \frac{1}{2^{v/2} \Gamma(v/2)} \int_x^\infty t^{v/2 - 1} e^{-t/2} dt
  874. Here :math:`\Gamma` is the Gamma function; see `gamma`. This
  875. integral can be expressed in terms of the regularized upper
  876. incomplete gamma function `gammaincc` as
  877. ``gammaincc(v / 2, x / 2)``. [1]_
  878. Parameters
  879. ----------
  880. v : array_like
  881. Degrees of freedom.
  882. x : array_like
  883. Lower bound of the integral.
  884. out : ndarray, optional
  885. Optional output array for the function results.
  886. Returns
  887. -------
  888. scalar or ndarray
  889. Values of the survival function.
  890. See Also
  891. --------
  892. chdtr, chdtri, chdtriv, gammaincc
  893. References
  894. ----------
  895. .. [1] Chi-Square distribution,
  896. https://www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm
  897. Examples
  898. --------
  899. >>> import numpy as np
  900. >>> import scipy.special as sc
  901. It can be expressed in terms of the regularized upper incomplete
  902. gamma function.
  903. >>> v = 1
  904. >>> x = np.arange(4)
  905. >>> sc.chdtrc(v, x)
  906. array([1. , 0.31731051, 0.15729921, 0.08326452])
  907. >>> sc.gammaincc(v / 2, x / 2)
  908. array([1. , 0.31731051, 0.15729921, 0.08326452])
  909. """)
  910. add_newdoc("chdtri",
  911. """
  912. chdtri(v, p, out=None)
  913. Inverse to `chdtrc` with respect to `x`.
  914. Returns `x` such that ``chdtrc(v, x) == p``.
  915. Parameters
  916. ----------
  917. v : array_like
  918. Degrees of freedom.
  919. p : array_like
  920. Probability.
  921. out : ndarray, optional
  922. Optional output array for the function results.
  923. Returns
  924. -------
  925. x : scalar or ndarray
  926. Value so that the probability a Chi square random variable
  927. with `v` degrees of freedom is greater than `x` equals `p`.
  928. See Also
  929. --------
  930. chdtrc, chdtr, chdtriv
  931. References
  932. ----------
  933. .. [1] Chi-Square distribution,
  934. https://www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm
  935. Examples
  936. --------
  937. >>> import scipy.special as sc
  938. It inverts `chdtrc`.
  939. >>> v, p = 1, 0.3
  940. >>> sc.chdtrc(v, sc.chdtri(v, p))
  941. 0.3
  942. >>> x = 1
  943. >>> sc.chdtri(v, sc.chdtrc(v, x))
  944. 1.0
  945. """)
  946. add_newdoc("chdtriv",
  947. """
  948. chdtriv(p, x, out=None)
  949. Inverse to `chdtr` with respect to `v`.
  950. Returns `v` such that ``chdtr(v, x) == p``.
  951. Parameters
  952. ----------
  953. p : array_like
  954. Probability that the Chi square random variable is less than
  955. or equal to `x`.
  956. x : array_like
  957. Nonnegative input.
  958. out : ndarray, optional
  959. Optional output array for the function results.
  960. Returns
  961. -------
  962. scalar or ndarray
  963. Degrees of freedom.
  964. See Also
  965. --------
  966. chdtr, chdtrc, chdtri
  967. Notes
  968. -----
  969. This function wraps routines from the Boost Math C++ library [1]_.
  970. References
  971. ----------
  972. .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
  973. .. [2] Chi-Square distribution,
  974. https://www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm
  975. Examples
  976. --------
  977. >>> import scipy.special as sc
  978. It inverts `chdtr`.
  979. >>> p, x = 0.5, 1
  980. >>> sc.chdtr(sc.chdtriv(p, x), x)
  981. 0.5000000000000003
  982. >>> v = 1
  983. >>> sc.chdtriv(sc.chdtr(v, x), v)
  984. 1.0
  985. """)
  986. add_newdoc("chndtr",
  987. r"""
  988. chndtr(x, df, nc, out=None)
  989. Non-central chi square cumulative distribution function
  990. The cumulative distribution function is given by:
  991. .. math::
  992. P(\chi^{\prime 2} \vert \nu, \lambda) =\sum_{j=0}^{\infty}
  993. e^{-\lambda /2}
  994. \frac{(\lambda /2)^j}{j!} P(\chi^{\prime 2} \vert \nu + 2j),
  995. where :math:`\nu > 0` is the degrees of freedom (``df``) and
  996. :math:`\lambda \geq 0` is the non-centrality parameter (``nc``).
  997. Parameters
  998. ----------
  999. x : array_like
  1000. Upper bound of the integral; must satisfy ``x >= 0``
  1001. df : array_like
  1002. Degrees of freedom; must satisfy ``df > 0``
  1003. nc : array_like
  1004. Non-centrality parameter; must satisfy ``nc >= 0``
  1005. out : ndarray, optional
  1006. Optional output array for the function results
  1007. Returns
  1008. -------
  1009. x : scalar or ndarray
  1010. Value of the non-central chi square cumulative distribution function.
  1011. See Also
  1012. --------
  1013. chndtrix: Noncentral Chi Squared distribution quantile
  1014. chndtridf: Inverse of `chndtr` with respect to `df`
  1015. chndtrinc: Inverse of `chndtr` with respect to `nc`
  1016. scipy.stats.ncx2: Non-central chi-squared distribution
  1017. Notes
  1018. -----
  1019. The noncentral chi squared distribution is also available in
  1020. `scipy.stats.ncx2`. ``scipy.stats.ncx2.cdf`` is equivalent to `chndtr`.
  1021. This function wraps routines from the Boost Math C++ library [1]_.
  1022. References
  1023. ----------
  1024. .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
  1025. Examples
  1026. --------
  1027. >>> import numpy as np
  1028. >>> import scipy.special as sc
  1029. Compute the noncentral chi squared distribution CDF at one point.
  1030. >>> x = 4.0
  1031. >>> df = 1.0
  1032. >>> nc = 5.0
  1033. >>> sc.chndtr(x, df, nc)
  1034. 0.40667858759710945
  1035. Plot the noncentral chi squared distribution CDF for different parameters.
  1036. >>> import matplotlib.pyplot as plt
  1037. >>> x = np.linspace(0, 40, 1000)
  1038. >>> plt.plot(x, sc.chndtr(x, 1, 5), label=r"$df=1,\ nc=5$")
  1039. >>> plt.plot(x, sc.chndtr(x, 5, 10), label=r"$df=5,\ nc=10$")
  1040. >>> plt.legend()
  1041. >>> plt.show()
  1042. """)
  1043. add_newdoc("chndtrix",
  1044. """
  1045. chndtrix(p, df, nc, out=None)
  1046. Inverse to `chndtr` vs `x`
  1047. Calculated using a search to find a value for `x` that produces the
  1048. desired value of `p`.
  1049. Parameters
  1050. ----------
  1051. p : array_like
  1052. Probability; must satisfy ``0 <= p < 1``
  1053. df : array_like
  1054. Degrees of freedom; must satisfy ``df > 0``
  1055. nc : array_like
  1056. Non-centrality parameter; must satisfy ``nc >= 0``
  1057. out : ndarray, optional
  1058. Optional output array for the function results
  1059. Returns
  1060. -------
  1061. x : scalar or ndarray
  1062. Value so that the probability a non-central Chi square random variable
  1063. with `df` degrees of freedom and non-centrality, `nc`, is greater than
  1064. `x` equals `p`.
  1065. See Also
  1066. --------
  1067. chndtr : Noncentral chi-squared distribution CDF
  1068. chndtridf : inverse of `chndtr` with respect to `cdf`
  1069. chndtrinc : inverse of `chndtr` with respect to `nc`
  1070. scipy.stats.ncx2 : Non-central chi-squared distribution
  1071. Notes
  1072. -----
  1073. The noncentral chi squared distribution is also available in
  1074. `scipy.stats.ncx2`. ``scipy.stats.ncx2.ppf`` is equivalent to `chndtrix`.
  1075. This function wraps routines from the Boost Math C++ library [1]_.
  1076. References
  1077. ----------
  1078. .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
  1079. Examples
  1080. --------
  1081. >>> from scipy.special import chndtrix, chndtr
  1082. Compute the noncentral chi squared distribution CDF at one point.
  1083. >>> x, df, nc = 3, 5, 10
  1084. >>> p = chndtr(x, df, nc)
  1085. `chndtrix` is the inverse of `chndtr` with respect to `x`:
  1086. >>> chndtrix(p, df, nc)
  1087. 3.0
  1088. """)
  1089. add_newdoc("chndtridf",
  1090. """
  1091. chndtridf(x, p, nc, out=None)
  1092. Inverse to `chndtr` vs `df`
  1093. Calculated using a search to find a value for `df` that produces the
  1094. desired value of `p`.
  1095. Parameters
  1096. ----------
  1097. x : array_like
  1098. Upper bound of the integral; must satisfy ``x >= 0``
  1099. p : array_like
  1100. Probability; must satisfy ``0 <= p < 1``
  1101. nc : array_like
  1102. Non-centrality parameter; must satisfy ``nc >= 0``
  1103. out : ndarray, optional
  1104. Optional output array for the function results
  1105. Returns
  1106. -------
  1107. df : scalar or ndarray
  1108. Degrees of freedom
  1109. See Also
  1110. --------
  1111. chndtr : Noncentral chi-squared distribution CDF
  1112. chndtrix : inverse of `chndtr` with respect to `x`
  1113. chndtrinc : inverse of `chndtr` with respect to `nc`
  1114. scipy.stats.ncx2 : Non-central chi-squared distribution
  1115. Notes
  1116. -----
  1117. The noncentral chi squared distribution is also available in
  1118. `scipy.stats.ncx2`.
  1119. This function wraps routines from the Boost Math C++ library [1]_.
  1120. References
  1121. ----------
  1122. .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
  1123. Examples
  1124. --------
  1125. >>> from scipy.special import chndtridf, chndtr
  1126. Compute the noncentral chi squared distribution CDF at one point.
  1127. >>> x, df, nc = 3, 5, 10
  1128. >>> p = chndtr(x, df, nc)
  1129. `chndtridf` is the inverse of `chndtr` with respect to `df`:
  1130. >>> chndtridf(x, p, nc)
  1131. 5.0
  1132. """)
  1133. add_newdoc("chndtrinc",
  1134. """
  1135. chndtrinc(x, df, p, out=None)
  1136. Inverse to `chndtr` vs `nc`
  1137. Calculated using a search to find a value for `df` that produces the
  1138. desired value of `p`.
  1139. Parameters
  1140. ----------
  1141. x : array_like
  1142. Upper bound of the integral; must satisfy ``x >= 0``
  1143. df : array_like
  1144. Degrees of freedom; must satisfy ``df > 0``
  1145. p : array_like
  1146. Probability; must satisfy ``0 <= p < 1``
  1147. out : ndarray, optional
  1148. Optional output array for the function results
  1149. Returns
  1150. -------
  1151. nc : scalar or ndarray
  1152. Non-centrality
  1153. See Also
  1154. --------
  1155. chndtr : Noncentral chi-squared distribution CDF
  1156. chndtridf : inverse of `chndtr` with respect to `df`
  1157. chndtrinc : inverse of `chndtr` with respect to `nc`
  1158. scipy.stats.ncx2 : Non-central chi-squared distribution
  1159. Notes
  1160. -----
  1161. The noncentral chi squared distribution is also available in
  1162. `scipy.stats.ncx2`.
  1163. This function wraps routines from the Boost Math C++ library [1]_.
  1164. References
  1165. ----------
  1166. .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
  1167. Examples
  1168. --------
  1169. >>> from scipy.special import chndtrinc, chndtr
  1170. Compute the noncentral chi squared distribution CDF at one point.
  1171. >>> x, df, nc = 3, 5, 10
  1172. >>> p = chndtr(x, df, nc)
  1173. `chndtrinc` is the inverse of `chndtr` with respect to `nc`:
  1174. >>> chndtrinc(x, df, p)
  1175. 10.0
  1176. """)
  1177. add_newdoc(
  1178. "elliprc",
  1179. r"""
  1180. elliprc(x, y, out=None)
  1181. Degenerate symmetric elliptic integral.
  1182. The function RC is defined as [1]_
  1183. .. math::
  1184. R_{\mathrm{C}}(x, y) =
  1185. \frac{1}{2} \int_0^{+\infty} (t + x)^{-1/2} (t + y)^{-1} dt
  1186. = R_{\mathrm{F}}(x, y, y)
  1187. Parameters
  1188. ----------
  1189. x, y : array_like
  1190. Real or complex input parameters. `x` can be any number in the
  1191. complex plane cut along the negative real axis. `y` must be non-zero.
  1192. out : ndarray, optional
  1193. Optional output array for the function values
  1194. Returns
  1195. -------
  1196. R : scalar or ndarray
  1197. Value of the integral. If `y` is real and negative, the Cauchy
  1198. principal value is returned. If both of `x` and `y` are real, the
  1199. return value is real. Otherwise, the return value is complex.
  1200. See Also
  1201. --------
  1202. elliprf : Completely-symmetric elliptic integral of the first kind.
  1203. elliprd : Symmetric elliptic integral of the second kind.
  1204. elliprg : Completely-symmetric elliptic integral of the second kind.
  1205. elliprj : Symmetric elliptic integral of the third kind.
  1206. Notes
  1207. -----
  1208. RC is a degenerate case of the symmetric integral RF: ``elliprc(x, y) ==
  1209. elliprf(x, y, y)``. It is an elementary function rather than an elliptic
  1210. integral.
  1211. The code implements Carlson's algorithm based on the duplication theorems
  1212. and series expansion up to the 7th order. [2]_
  1213. .. versionadded:: 1.8.0
  1214. References
  1215. ----------
  1216. .. [1] B. C. Carlson, ed., Chapter 19 in "Digital Library of Mathematical
  1217. Functions," NIST, US Dept. of Commerce.
  1218. https://dlmf.nist.gov/19.16.E6
  1219. .. [2] B. C. Carlson, "Numerical computation of real or complex elliptic
  1220. integrals," Numer. Algorithm, vol. 10, no. 1, pp. 13-26, 1995.
  1221. https://arxiv.org/abs/math/9409227
  1222. https://doi.org/10.1007/BF02198293
  1223. Examples
  1224. --------
  1225. Basic homogeneity property:
  1226. >>> import numpy as np
  1227. >>> from scipy.special import elliprc
  1228. >>> x = 1.2 + 3.4j
  1229. >>> y = 5.
  1230. >>> scale = 0.3 + 0.4j
  1231. >>> elliprc(scale*x, scale*y)
  1232. (0.5484493976710874-0.4169557678995833j)
  1233. >>> elliprc(x, y)/np.sqrt(scale)
  1234. (0.5484493976710874-0.41695576789958333j)
  1235. When the two arguments coincide, the integral is particularly
  1236. simple:
  1237. >>> x = 1.2 + 3.4j
  1238. >>> elliprc(x, x)
  1239. (0.4299173120614631-0.3041729818745595j)
  1240. >>> 1/np.sqrt(x)
  1241. (0.4299173120614631-0.30417298187455954j)
  1242. Another simple case: the first argument vanishes:
  1243. >>> y = 1.2 + 3.4j
  1244. >>> elliprc(0, y)
  1245. (0.6753125346116815-0.47779380263880866j)
  1246. >>> np.pi/2/np.sqrt(y)
  1247. (0.6753125346116815-0.4777938026388088j)
  1248. When `x` and `y` are both positive, we can express
  1249. :math:`R_C(x,y)` in terms of more elementary functions. For the
  1250. case :math:`0 \le x < y`,
  1251. >>> x = 3.2
  1252. >>> y = 6.
  1253. >>> elliprc(x, y)
  1254. 0.44942991498453444
  1255. >>> np.arctan(np.sqrt((y-x)/x))/np.sqrt(y-x)
  1256. 0.44942991498453433
  1257. And for the case :math:`0 \le y < x`,
  1258. >>> x = 6.
  1259. >>> y = 3.2
  1260. >>> elliprc(x,y)
  1261. 0.4989837501576147
  1262. >>> np.log((np.sqrt(x)+np.sqrt(x-y))/np.sqrt(y))/np.sqrt(x-y)
  1263. 0.49898375015761476
  1264. """)
  1265. add_newdoc(
  1266. "elliprd",
  1267. r"""
  1268. elliprd(x, y, z, out=None)
  1269. Symmetric elliptic integral of the second kind.
  1270. The function RD is defined as [1]_
  1271. .. math::
  1272. R_{\mathrm{D}}(x, y, z) =
  1273. \frac{3}{2} \int_0^{+\infty} [(t + x) (t + y)]^{-1/2} (t + z)^{-3/2}
  1274. dt
  1275. Parameters
  1276. ----------
  1277. x, y, z : array_like
  1278. Real or complex input parameters. `x` or `y` can be any number in the
  1279. complex plane cut along the negative real axis, but at most one of them
  1280. can be zero, while `z` must be non-zero.
  1281. out : ndarray, optional
  1282. Optional output array for the function values
  1283. Returns
  1284. -------
  1285. R : scalar or ndarray
  1286. Value of the integral. If all of `x`, `y`, and `z` are real, the
  1287. return value is real. Otherwise, the return value is complex.
  1288. See Also
  1289. --------
  1290. elliprc : Degenerate symmetric elliptic integral.
  1291. elliprf : Completely-symmetric elliptic integral of the first kind.
  1292. elliprg : Completely-symmetric elliptic integral of the second kind.
  1293. elliprj : Symmetric elliptic integral of the third kind.
  1294. Notes
  1295. -----
  1296. RD is a degenerate case of the elliptic integral RJ: ``elliprd(x, y, z) ==
  1297. elliprj(x, y, z, z)``.
  1298. The code implements Carlson's algorithm based on the duplication theorems
  1299. and series expansion up to the 7th order. [2]_
  1300. .. versionadded:: 1.8.0
  1301. References
  1302. ----------
  1303. .. [1] B. C. Carlson, ed., Chapter 19 in "Digital Library of Mathematical
  1304. Functions," NIST, US Dept. of Commerce.
  1305. https://dlmf.nist.gov/19.16.E5
  1306. .. [2] B. C. Carlson, "Numerical computation of real or complex elliptic
  1307. integrals," Numer. Algorithm, vol. 10, no. 1, pp. 13-26, 1995.
  1308. https://arxiv.org/abs/math/9409227
  1309. https://doi.org/10.1007/BF02198293
  1310. Examples
  1311. --------
  1312. Basic homogeneity property:
  1313. >>> import numpy as np
  1314. >>> from scipy.special import elliprd
  1315. >>> x = 1.2 + 3.4j
  1316. >>> y = 5.
  1317. >>> z = 6.
  1318. >>> scale = 0.3 + 0.4j
  1319. >>> elliprd(scale*x, scale*y, scale*z)
  1320. (-0.03703043835680379-0.24500934665683802j)
  1321. >>> elliprd(x, y, z)*np.power(scale, -1.5)
  1322. (-0.0370304383568038-0.24500934665683805j)
  1323. All three arguments coincide:
  1324. >>> x = 1.2 + 3.4j
  1325. >>> elliprd(x, x, x)
  1326. (-0.03986825876151896-0.14051741840449586j)
  1327. >>> np.power(x, -1.5)
  1328. (-0.03986825876151894-0.14051741840449583j)
  1329. The so-called "second lemniscate constant":
  1330. >>> elliprd(0, 2, 1)/3
  1331. 0.5990701173677961
  1332. >>> from scipy.special import gamma
  1333. >>> gamma(0.75)**2/np.sqrt(2*np.pi)
  1334. 0.5990701173677959
  1335. """)
  1336. add_newdoc(
  1337. "elliprf",
  1338. r"""
  1339. elliprf(x, y, z, out=None)
  1340. Completely-symmetric elliptic integral of the first kind.
  1341. The function RF is defined as [1]_
  1342. .. math::
  1343. R_{\mathrm{F}}(x, y, z) =
  1344. \frac{1}{2} \int_0^{+\infty} [(t + x) (t + y) (t + z)]^{-1/2} dt
  1345. Parameters
  1346. ----------
  1347. x, y, z : array_like
  1348. Real or complex input parameters. `x`, `y`, or `z` can be any number in
  1349. the complex plane cut along the negative real axis, but at most one of
  1350. them can be zero.
  1351. out : ndarray, optional
  1352. Optional output array for the function values
  1353. Returns
  1354. -------
  1355. R : scalar or ndarray
  1356. Value of the integral. If all of `x`, `y`, and `z` are real, the return
  1357. value is real. Otherwise, the return value is complex.
  1358. See Also
  1359. --------
  1360. elliprc : Degenerate symmetric integral.
  1361. elliprd : Symmetric elliptic integral of the second kind.
  1362. elliprg : Completely-symmetric elliptic integral of the second kind.
  1363. elliprj : Symmetric elliptic integral of the third kind.
  1364. Notes
  1365. -----
  1366. The code implements Carlson's algorithm based on the duplication theorems
  1367. and series expansion up to the 7th order (cf.:
  1368. https://dlmf.nist.gov/19.36.i) and the AGM algorithm for the complete
  1369. integral. [2]_
  1370. .. versionadded:: 1.8.0
  1371. References
  1372. ----------
  1373. .. [1] B. C. Carlson, ed., Chapter 19 in "Digital Library of Mathematical
  1374. Functions," NIST, US Dept. of Commerce.
  1375. https://dlmf.nist.gov/19.16.E1
  1376. .. [2] B. C. Carlson, "Numerical computation of real or complex elliptic
  1377. integrals," Numer. Algorithm, vol. 10, no. 1, pp. 13-26, 1995.
  1378. https://arxiv.org/abs/math/9409227
  1379. https://doi.org/10.1007/BF02198293
  1380. Examples
  1381. --------
  1382. Basic homogeneity property:
  1383. >>> import numpy as np
  1384. >>> from scipy.special import elliprf
  1385. >>> x = 1.2 + 3.4j
  1386. >>> y = 5.
  1387. >>> z = 6.
  1388. >>> scale = 0.3 + 0.4j
  1389. >>> elliprf(scale*x, scale*y, scale*z)
  1390. (0.5328051227278146-0.4008623567957094j)
  1391. >>> elliprf(x, y, z)/np.sqrt(scale)
  1392. (0.5328051227278147-0.4008623567957095j)
  1393. All three arguments coincide:
  1394. >>> x = 1.2 + 3.4j
  1395. >>> elliprf(x, x, x)
  1396. (0.42991731206146316-0.30417298187455954j)
  1397. >>> 1/np.sqrt(x)
  1398. (0.4299173120614631-0.30417298187455954j)
  1399. The so-called "first lemniscate constant":
  1400. >>> elliprf(0, 1, 2)
  1401. 1.3110287771460598
  1402. >>> from scipy.special import gamma
  1403. >>> gamma(0.25)**2/(4*np.sqrt(2*np.pi))
  1404. 1.3110287771460598
  1405. """)
  1406. add_newdoc(
  1407. "elliprg",
  1408. r"""
  1409. elliprg(x, y, z, out=None)
  1410. Completely-symmetric elliptic integral of the second kind.
  1411. The function RG is defined as [1]_
  1412. .. math::
  1413. R_{\mathrm{G}}(x, y, z) =
  1414. \frac{1}{4} \int_0^{+\infty} [(t + x) (t + y) (t + z)]^{-1/2}
  1415. \left(\frac{x}{t + x} + \frac{y}{t + y} + \frac{z}{t + z}\right) t
  1416. dt
  1417. Parameters
  1418. ----------
  1419. x, y, z : array_like
  1420. Real or complex input parameters. `x`, `y`, or `z` can be any number in
  1421. the complex plane cut along the negative real axis.
  1422. out : ndarray, optional
  1423. Optional output array for the function values
  1424. Returns
  1425. -------
  1426. R : scalar or ndarray
  1427. Value of the integral. If all of `x`, `y`, and `z` are real, the return
  1428. value is real. Otherwise, the return value is complex.
  1429. See Also
  1430. --------
  1431. elliprc : Degenerate symmetric integral.
  1432. elliprd : Symmetric elliptic integral of the second kind.
  1433. elliprf : Completely-symmetric elliptic integral of the first kind.
  1434. elliprj : Symmetric elliptic integral of the third kind.
  1435. Notes
  1436. -----
  1437. The implementation uses the relation [1]_
  1438. .. math::
  1439. 2 R_{\mathrm{G}}(x, y, z) =
  1440. z R_{\mathrm{F}}(x, y, z) -
  1441. \frac{1}{3} (x - z) (y - z) R_{\mathrm{D}}(x, y, z) +
  1442. \sqrt{\frac{x y}{z}}
  1443. and the symmetry of `x`, `y`, `z` when at least one non-zero parameter can
  1444. be chosen as the pivot. When one of the arguments is close to zero, the AGM
  1445. method is applied instead. Other special cases are computed following Ref.
  1446. [2]_
  1447. .. versionadded:: 1.8.0
  1448. References
  1449. ----------
  1450. .. [1] B. C. Carlson, "Numerical computation of real or complex elliptic
  1451. integrals," Numer. Algorithm, vol. 10, no. 1, pp. 13-26, 1995.
  1452. https://arxiv.org/abs/math/9409227
  1453. https://doi.org/10.1007/BF02198293
  1454. .. [2] B. C. Carlson, ed., Chapter 19 in "Digital Library of Mathematical
  1455. Functions," NIST, US Dept. of Commerce.
  1456. https://dlmf.nist.gov/19.16.E1
  1457. https://dlmf.nist.gov/19.20.ii
  1458. Examples
  1459. --------
  1460. Basic homogeneity property:
  1461. >>> import numpy as np
  1462. >>> from scipy.special import elliprg
  1463. >>> x = 1.2 + 3.4j
  1464. >>> y = 5.
  1465. >>> z = 6.
  1466. >>> scale = 0.3 + 0.4j
  1467. >>> elliprg(scale*x, scale*y, scale*z)
  1468. (1.195936862005246+0.8470988320464167j)
  1469. >>> elliprg(x, y, z)*np.sqrt(scale)
  1470. (1.195936862005246+0.8470988320464165j)
  1471. Simplifications:
  1472. >>> elliprg(0, y, y)
  1473. 1.756203682760182
  1474. >>> 0.25*np.pi*np.sqrt(y)
  1475. 1.7562036827601817
  1476. >>> elliprg(0, 0, z)
  1477. 1.224744871391589
  1478. >>> 0.5*np.sqrt(z)
  1479. 1.224744871391589
  1480. The surface area of a triaxial ellipsoid with semiaxes ``a``, ``b``, and
  1481. ``c`` is given by
  1482. .. math::
  1483. S = 4 \pi a b c R_{\mathrm{G}}(1 / a^2, 1 / b^2, 1 / c^2).
  1484. >>> def ellipsoid_area(a, b, c):
  1485. ... r = 4.0 * np.pi * a * b * c
  1486. ... return r * elliprg(1.0 / (a * a), 1.0 / (b * b), 1.0 / (c * c))
  1487. >>> print(ellipsoid_area(1, 3, 5))
  1488. 108.62688289491807
  1489. """)
  1490. add_newdoc(
  1491. "elliprj",
  1492. r"""
  1493. elliprj(x, y, z, p, out=None)
  1494. Symmetric elliptic integral of the third kind.
  1495. The function RJ is defined as [1]_
  1496. .. math::
  1497. R_{\mathrm{J}}(x, y, z, p) =
  1498. \frac{3}{2} \int_0^{+\infty} [(t + x) (t + y) (t + z)]^{-1/2}
  1499. (t + p)^{-1} dt
  1500. .. warning::
  1501. This function should be considered experimental when the inputs are
  1502. unbalanced. Check correctness with another independent implementation.
  1503. Parameters
  1504. ----------
  1505. x, y, z, p : array_like
  1506. Real or complex input parameters. `x`, `y`, or `z` are numbers in
  1507. the complex plane cut along the negative real axis (subject to further
  1508. constraints, see Notes), and at most one of them can be zero. `p` must
  1509. be non-zero.
  1510. out : ndarray, optional
  1511. Optional output array for the function values
  1512. Returns
  1513. -------
  1514. R : scalar or ndarray
  1515. Value of the integral. If all of `x`, `y`, `z`, and `p` are real, the
  1516. return value is real. Otherwise, the return value is complex.
  1517. If `p` is real and negative, while `x`, `y`, and `z` are real,
  1518. non-negative, and at most one of them is zero, the Cauchy principal
  1519. value is returned. [1]_ [2]_
  1520. See Also
  1521. --------
  1522. elliprc : Degenerate symmetric integral.
  1523. elliprd : Symmetric elliptic integral of the second kind.
  1524. elliprf : Completely-symmetric elliptic integral of the first kind.
  1525. elliprg : Completely-symmetric elliptic integral of the second kind.
  1526. Notes
  1527. -----
  1528. The code implements Carlson's algorithm based on the duplication theorems
  1529. and series expansion up to the 7th order. [3]_ The algorithm is slightly
  1530. different from its earlier incarnation as it appears in [1]_, in that the
  1531. call to `elliprc` (or ``atan``/``atanh``, see [4]_) is no longer needed in
  1532. the inner loop. Asymptotic approximations are used where arguments differ
  1533. widely in the order of magnitude. [5]_
  1534. The input values are subject to certain sufficient but not necessary
  1535. constraints when input arguments are complex. Notably, ``x``, ``y``, and
  1536. ``z`` must have non-negative real parts, unless two of them are
  1537. non-negative and complex-conjugates to each other while the other is a real
  1538. non-negative number. [1]_ If the inputs do not satisfy the sufficient
  1539. condition described in Ref. [1]_ they are rejected outright with the output
  1540. set to NaN.
  1541. In the case where one of ``x``, ``y``, and ``z`` is equal to ``p``, the
  1542. function ``elliprd`` should be preferred because of its less restrictive
  1543. domain.
  1544. .. versionadded:: 1.8.0
  1545. References
  1546. ----------
  1547. .. [1] B. C. Carlson, "Numerical computation of real or complex elliptic
  1548. integrals," Numer. Algorithm, vol. 10, no. 1, pp. 13-26, 1995.
  1549. https://arxiv.org/abs/math/9409227
  1550. https://doi.org/10.1007/BF02198293
  1551. .. [2] B. C. Carlson, ed., Chapter 19 in "Digital Library of Mathematical
  1552. Functions," NIST, US Dept. of Commerce.
  1553. https://dlmf.nist.gov/19.20.iii
  1554. .. [3] B. C. Carlson, J. FitzSimmons, "Reduction Theorems for Elliptic
  1555. Integrands with the Square Root of Two Quadratic Factors," J.
  1556. Comput. Appl. Math., vol. 118, nos. 1-2, pp. 71-85, 2000.
  1557. https://doi.org/10.1016/S0377-0427(00)00282-X
  1558. .. [4] F. Johansson, "Numerical Evaluation of Elliptic Functions, Elliptic
  1559. Integrals and Modular Forms," in J. Blumlein, C. Schneider, P.
  1560. Paule, eds., "Elliptic Integrals, Elliptic Functions and Modular
  1561. Forms in Quantum Field Theory," pp. 269-293, 2019 (Cham,
  1562. Switzerland: Springer Nature Switzerland)
  1563. https://arxiv.org/abs/1806.06725
  1564. https://doi.org/10.1007/978-3-030-04480-0
  1565. .. [5] B. C. Carlson, J. L. Gustafson, "Asymptotic Approximations for
  1566. Symmetric Elliptic Integrals," SIAM J. Math. Anls., vol. 25, no. 2,
  1567. pp. 288-303, 1994.
  1568. https://arxiv.org/abs/math/9310223
  1569. https://doi.org/10.1137/S0036141092228477
  1570. Examples
  1571. --------
  1572. Basic homogeneity property:
  1573. >>> import numpy as np
  1574. >>> from scipy.special import elliprj
  1575. >>> x = 1.2 + 3.4j
  1576. >>> y = 5.
  1577. >>> z = 6.
  1578. >>> p = 7.
  1579. >>> scale = 0.3 - 0.4j
  1580. >>> elliprj(scale*x, scale*y, scale*z, scale*p)
  1581. (0.10834905565679157+0.19694950747103812j)
  1582. >>> elliprj(x, y, z, p)*np.power(scale, -1.5)
  1583. (0.10834905565679556+0.19694950747103854j)
  1584. Reduction to simpler elliptic integral:
  1585. >>> elliprj(x, y, z, z)
  1586. (0.08288462362195129-0.028376809745123258j)
  1587. >>> from scipy.special import elliprd
  1588. >>> elliprd(x, y, z)
  1589. (0.08288462362195136-0.028376809745123296j)
  1590. All arguments coincide:
  1591. >>> elliprj(x, x, x, x)
  1592. (-0.03986825876151896-0.14051741840449586j)
  1593. >>> np.power(x, -1.5)
  1594. (-0.03986825876151894-0.14051741840449583j)
  1595. """)
  1596. add_newdoc("entr",
  1597. r"""
  1598. entr(x, out=None)
  1599. Elementwise function for computing entropy.
  1600. .. math:: \text{entr}(x) = \begin{cases} - x \log(x) & x > 0 \\ 0 & x = 0
  1601. \\ -\infty & \text{otherwise} \end{cases}
  1602. Parameters
  1603. ----------
  1604. x : ndarray
  1605. Input array.
  1606. out : ndarray, optional
  1607. Optional output array for the function values
  1608. Returns
  1609. -------
  1610. res : scalar or ndarray
  1611. The value of the elementwise entropy function at the given points `x`.
  1612. See Also
  1613. --------
  1614. kl_div, rel_entr, scipy.stats.entropy
  1615. Notes
  1616. -----
  1617. .. versionadded:: 0.15.0
  1618. This function is concave.
  1619. The origin of this function is in convex programming; see [1]_.
  1620. Given a probability distribution :math:`p_1, \ldots, p_n`,
  1621. the definition of entropy in the context of *information theory* is
  1622. .. math::
  1623. \sum_{i = 1}^n \mathrm{entr}(p_i).
  1624. To compute the latter quantity, use `scipy.stats.entropy`.
  1625. References
  1626. ----------
  1627. .. [1] Boyd, Stephen and Lieven Vandenberghe. *Convex optimization*.
  1628. Cambridge University Press, 2004.
  1629. :doi:`https://doi.org/10.1017/CBO9780511804441`
  1630. """)
  1631. add_newdoc(
  1632. "erfinv",
  1633. """
  1634. erfinv(y, out=None)
  1635. Inverse of the error function.
  1636. Computes the inverse of the error function.
  1637. In the complex domain, there is no unique complex number w satisfying
  1638. erf(w)=z. This indicates a true inverse function would be multivalued.
  1639. When the domain restricts to the real, -1 < x < 1, there is a unique real
  1640. number satisfying erf(erfinv(x)) = x.
  1641. Parameters
  1642. ----------
  1643. y : ndarray
  1644. Argument at which to evaluate. Domain: [-1, 1]
  1645. out : ndarray, optional
  1646. Optional output array for the function values
  1647. Returns
  1648. -------
  1649. erfinv : scalar or ndarray
  1650. The inverse of erf of y, element-wise
  1651. See Also
  1652. --------
  1653. erf : Error function of a complex argument
  1654. erfc : Complementary error function, ``1 - erf(x)``
  1655. erfcinv : Inverse of the complementary error function
  1656. Notes
  1657. -----
  1658. This function wraps the ``erf_inv`` routine from the
  1659. Boost Math C++ library [1]_.
  1660. References
  1661. ----------
  1662. .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
  1663. Examples
  1664. --------
  1665. >>> import numpy as np
  1666. >>> import matplotlib.pyplot as plt
  1667. >>> from scipy.special import erfinv, erf
  1668. >>> erfinv(0.5)
  1669. 0.4769362762044699
  1670. >>> y = np.linspace(-1.0, 1.0, num=9)
  1671. >>> x = erfinv(y)
  1672. >>> x
  1673. array([ -inf, -0.81341985, -0.47693628, -0.22531206, 0. ,
  1674. 0.22531206, 0.47693628, 0.81341985, inf])
  1675. Verify that ``erf(erfinv(y))`` is ``y``.
  1676. >>> erf(x)
  1677. array([-1. , -0.75, -0.5 , -0.25, 0. , 0.25, 0.5 , 0.75, 1. ])
  1678. Plot the function:
  1679. >>> y = np.linspace(-1, 1, 200)
  1680. >>> fig, ax = plt.subplots()
  1681. >>> ax.plot(y, erfinv(y))
  1682. >>> ax.grid(True)
  1683. >>> ax.set_xlabel('y')
  1684. >>> ax.set_title('erfinv(y)')
  1685. >>> plt.show()
  1686. """)
  1687. add_newdoc(
  1688. "erfcinv",
  1689. """
  1690. erfcinv(y, out=None)
  1691. Inverse of the complementary error function.
  1692. Computes the inverse of the complementary error function.
  1693. In the complex domain, there is no unique complex number w satisfying
  1694. erfc(w)=z. This indicates a true inverse function would be multivalued.
  1695. When the domain restricts to the real, 0 < x < 2, there is a unique real
  1696. number satisfying erfc(erfcinv(x)) = erfcinv(erfc(x)).
  1697. It is related to inverse of the error function by erfcinv(1-x) = erfinv(x)
  1698. Parameters
  1699. ----------
  1700. y : ndarray
  1701. Argument at which to evaluate. Domain: [0, 2]
  1702. out : ndarray, optional
  1703. Optional output array for the function values
  1704. Returns
  1705. -------
  1706. erfcinv : scalar or ndarray
  1707. The inverse of erfc of y, element-wise
  1708. See Also
  1709. --------
  1710. erf : Error function of a complex argument
  1711. erfc : Complementary error function, ``1 - erf(x)``
  1712. erfinv : Inverse of the error function
  1713. Examples
  1714. --------
  1715. >>> import numpy as np
  1716. >>> import matplotlib.pyplot as plt
  1717. >>> from scipy.special import erfcinv
  1718. >>> erfcinv(0.5)
  1719. 0.4769362762044699
  1720. >>> y = np.linspace(0.0, 2.0, num=11)
  1721. >>> erfcinv(y)
  1722. array([ inf, 0.9061938 , 0.59511608, 0.37080716, 0.17914345,
  1723. -0. , -0.17914345, -0.37080716, -0.59511608, -0.9061938 ,
  1724. -inf])
  1725. Plot the function:
  1726. >>> y = np.linspace(0, 2, 200)
  1727. >>> fig, ax = plt.subplots()
  1728. >>> ax.plot(y, erfcinv(y))
  1729. >>> ax.grid(True)
  1730. >>> ax.set_xlabel('y')
  1731. >>> ax.set_title('erfcinv(y)')
  1732. >>> plt.show()
  1733. """)
  1734. add_newdoc("eval_jacobi",
  1735. r"""
  1736. eval_jacobi(n, alpha, beta, x, out=None)
  1737. Evaluate Jacobi polynomial at a point.
  1738. The Jacobi polynomials can be defined via the Gauss hypergeometric
  1739. function :math:`{}_2F_1` as
  1740. .. math::
  1741. P_n^{(\alpha, \beta)}(x) = \frac{(\alpha + 1)_n}{\Gamma(n + 1)}
  1742. {}_2F_1(-n, 1 + \alpha + \beta + n; \alpha + 1; (1 - z)/2)
  1743. where :math:`(\cdot)_n` is the Pochhammer symbol; see `poch`. When
  1744. :math:`n` is an integer the result is a polynomial of degree
  1745. :math:`n`. See 22.5.42 in [AS]_ or [DLMF]_ for details.
  1746. Parameters
  1747. ----------
  1748. n : array_like
  1749. Degree of the polynomial. If not an integer the result is
  1750. determined via the relation to the Gauss hypergeometric
  1751. function.
  1752. alpha : array_like
  1753. Parameter
  1754. beta : array_like
  1755. Parameter
  1756. x : array_like
  1757. Points at which to evaluate the polynomial
  1758. out : ndarray, optional
  1759. Optional output array for the function values
  1760. Returns
  1761. -------
  1762. P : scalar or ndarray
  1763. Values of the Jacobi polynomial
  1764. See Also
  1765. --------
  1766. roots_jacobi : roots and quadrature weights of Jacobi polynomials
  1767. jacobi : Jacobi polynomial object
  1768. hyp2f1 : Gauss hypergeometric function
  1769. References
  1770. ----------
  1771. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  1772. Handbook of Mathematical Functions with Formulas,
  1773. Graphs, and Mathematical Tables. New York: Dover, 1972.
  1774. .. [DLMF] NIST Digital Library of Mathematical Functions,
  1775. https://dlmf.nist.gov/18.5.E7
  1776. """)
  1777. add_newdoc("eval_sh_jacobi",
  1778. r"""
  1779. eval_sh_jacobi(n, p, q, x, out=None)
  1780. Evaluate shifted Jacobi polynomial at a point.
  1781. Defined by
  1782. .. math::
  1783. G_n^{(p, q)}(x)
  1784. = \binom{2n + p - 1}{n}^{-1} P_n^{(p - q, q - 1)}(2x - 1),
  1785. where :math:`P_n^{(\cdot, \cdot)}` is the n-th Jacobi polynomial.
  1786. See 22.5.2 in [AS]_ (or equivalently [DLMF]_) for details.
  1787. Parameters
  1788. ----------
  1789. n : int
  1790. Degree of the polynomial. If not an integer, the result is
  1791. determined via the relation to `binom` and `eval_jacobi`.
  1792. p : float
  1793. Parameter
  1794. q : float
  1795. Parameter
  1796. out : ndarray, optional
  1797. Optional output array for the function values
  1798. Returns
  1799. -------
  1800. G : scalar or ndarray
  1801. Values of the shifted Jacobi polynomial.
  1802. See Also
  1803. --------
  1804. roots_sh_jacobi : roots and quadrature weights of shifted Jacobi
  1805. polynomials
  1806. sh_jacobi : shifted Jacobi polynomial object
  1807. eval_jacobi : evaluate Jacobi polynomials
  1808. References
  1809. ----------
  1810. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  1811. Handbook of Mathematical Functions with Formulas,
  1812. Graphs, and Mathematical Tables. New York: Dover, 1972.
  1813. .. [DLMF] NIST Digital Library of Mathematical Functions,
  1814. https://dlmf.nist.gov/18.1.E2
  1815. """)
  1816. add_newdoc("eval_gegenbauer",
  1817. r"""
  1818. eval_gegenbauer(n, alpha, x, out=None)
  1819. Evaluate Gegenbauer polynomial at a point.
  1820. The Gegenbauer polynomials can be defined via the Gauss
  1821. hypergeometric function :math:`{}_2F_1` as
  1822. .. math::
  1823. C_n^{(\alpha)} = \frac{(2\alpha)_n}{\Gamma(n + 1)}
  1824. {}_2F_1(-n, 2\alpha + n; \alpha + 1/2; (1 - z)/2).
  1825. When :math:`n` is an integer the result is a polynomial of degree
  1826. :math:`n`. See 22.5.46 in [AS]_ (or equivalently [DLMF]_) for details.
  1827. Parameters
  1828. ----------
  1829. n : array_like
  1830. Degree of the polynomial. If not an integer, the result is
  1831. determined via the relation to the Gauss hypergeometric
  1832. function.
  1833. alpha : array_like
  1834. Parameter
  1835. x : array_like
  1836. Points at which to evaluate the Gegenbauer polynomial
  1837. out : ndarray, optional
  1838. Optional output array for the function values
  1839. Returns
  1840. -------
  1841. C : scalar or ndarray
  1842. Values of the Gegenbauer polynomial
  1843. See Also
  1844. --------
  1845. roots_gegenbauer : roots and quadrature weights of Gegenbauer
  1846. polynomials
  1847. gegenbauer : Gegenbauer polynomial object
  1848. hyp2f1 : Gauss hypergeometric function
  1849. References
  1850. ----------
  1851. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  1852. Handbook of Mathematical Functions with Formulas,
  1853. Graphs, and Mathematical Tables. New York: Dover, 1972.
  1854. .. [DLMF] NIST Digital Library of Mathematical Functions,
  1855. https://dlmf.nist.gov/18.5.E9
  1856. """)
  1857. add_newdoc("eval_chebyt",
  1858. r"""
  1859. eval_chebyt(n, x, out=None)
  1860. Evaluate Chebyshev polynomial of the first kind at a point.
  1861. The Chebyshev polynomials of the first kind can be defined via the
  1862. Gauss hypergeometric function :math:`{}_2F_1` as
  1863. .. math::
  1864. T_n(x) = {}_2F_1(n, -n; 1/2; (1 - x)/2).
  1865. When :math:`n` is an integer the result is a polynomial of degree
  1866. :math:`n`. See 22.5.47 in [AS]_ (or equivalently [DLMF]_) for details.
  1867. Parameters
  1868. ----------
  1869. n : array_like
  1870. Degree of the polynomial. If not an integer, the result is
  1871. determined via the relation to the Gauss hypergeometric
  1872. function.
  1873. x : array_like
  1874. Points at which to evaluate the Chebyshev polynomial
  1875. out : ndarray, optional
  1876. Optional output array for the function values
  1877. Returns
  1878. -------
  1879. T : scalar or ndarray
  1880. Values of the Chebyshev polynomial
  1881. See Also
  1882. --------
  1883. roots_chebyt : roots and quadrature weights of Chebyshev
  1884. polynomials of the first kind
  1885. chebyu : Chebychev polynomial object
  1886. eval_chebyu : evaluate Chebyshev polynomials of the second kind
  1887. hyp2f1 : Gauss hypergeometric function
  1888. numpy.polynomial.chebyshev.Chebyshev : Chebyshev series
  1889. Notes
  1890. -----
  1891. This routine is numerically stable for `x` in ``[-1, 1]`` at least
  1892. up to order ``10000``.
  1893. References
  1894. ----------
  1895. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  1896. Handbook of Mathematical Functions with Formulas,
  1897. Graphs, and Mathematical Tables. New York: Dover, 1972.
  1898. .. [DLMF] NIST Digital Library of Mathematical Functions,
  1899. https://dlmf.nist.gov/18.5.E11_2
  1900. """)
  1901. add_newdoc("eval_chebyu",
  1902. r"""
  1903. eval_chebyu(n, x, out=None)
  1904. Evaluate Chebyshev polynomial of the second kind at a point.
  1905. The Chebyshev polynomials of the second kind can be defined via
  1906. the Gauss hypergeometric function :math:`{}_2F_1` as
  1907. .. math::
  1908. U_n(x) = (n + 1) {}_2F_1(-n, n + 2; 3/2; (1 - x)/2).
  1909. When :math:`n` is an integer the result is a polynomial of degree
  1910. :math:`n`. See 22.5.48 in [AS]_ (or equivalently [DLMF]_) for details.
  1911. Parameters
  1912. ----------
  1913. n : array_like
  1914. Degree of the polynomial. If not an integer, the result is
  1915. determined via the relation to the Gauss hypergeometric
  1916. function.
  1917. x : array_like
  1918. Points at which to evaluate the Chebyshev polynomial
  1919. out : ndarray, optional
  1920. Optional output array for the function values
  1921. Returns
  1922. -------
  1923. U : scalar or ndarray
  1924. Values of the Chebyshev polynomial
  1925. See Also
  1926. --------
  1927. roots_chebyu : roots and quadrature weights of Chebyshev
  1928. polynomials of the second kind
  1929. chebyu : Chebyshev polynomial object
  1930. eval_chebyt : evaluate Chebyshev polynomials of the first kind
  1931. hyp2f1 : Gauss hypergeometric function
  1932. References
  1933. ----------
  1934. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  1935. Handbook of Mathematical Functions with Formulas,
  1936. Graphs, and Mathematical Tables. New York: Dover, 1972.
  1937. .. [DLMF] NIST Digital Library of Mathematical Functions,
  1938. https://dlmf.nist.gov/18.5.E11_4
  1939. """)
  1940. add_newdoc("eval_chebys",
  1941. r"""
  1942. eval_chebys(n, x, out=None)
  1943. Evaluate Chebyshev polynomial of the second kind on [-2, 2] at a
  1944. point.
  1945. These polynomials are defined as
  1946. .. math::
  1947. S_n(x) = U_n(x/2)
  1948. where :math:`U_n` is a Chebyshev polynomial of the second kind.
  1949. See 22.5.13 in [AS]_ (or equivalently [DLMF]_) for details.
  1950. Parameters
  1951. ----------
  1952. n : array_like
  1953. Degree of the polynomial. If not an integer, the result is
  1954. determined via the relation to `eval_chebyu`.
  1955. x : array_like
  1956. Points at which to evaluate the Chebyshev polynomial
  1957. out : ndarray, optional
  1958. Optional output array for the function values
  1959. Returns
  1960. -------
  1961. S : scalar or ndarray
  1962. Values of the Chebyshev polynomial
  1963. See Also
  1964. --------
  1965. roots_chebys : roots and quadrature weights of Chebyshev
  1966. polynomials of the second kind on [-2, 2]
  1967. chebys : Chebyshev polynomial object
  1968. eval_chebyu : evaluate Chebyshev polynomials of the second kind
  1969. References
  1970. ----------
  1971. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  1972. Handbook of Mathematical Functions with Formulas,
  1973. Graphs, and Mathematical Tables. New York: Dover, 1972.
  1974. .. [DLMF] NIST Digital Library of Mathematical Functions,
  1975. https://dlmf.nist.gov/18.1.E3
  1976. Examples
  1977. --------
  1978. >>> import numpy as np
  1979. >>> import scipy.special as sc
  1980. They are a scaled version of the Chebyshev polynomials of the
  1981. second kind.
  1982. >>> x = np.linspace(-2, 2, 6)
  1983. >>> sc.eval_chebys(3, x)
  1984. array([-4. , 0.672, 0.736, -0.736, -0.672, 4. ])
  1985. >>> sc.eval_chebyu(3, x / 2)
  1986. array([-4. , 0.672, 0.736, -0.736, -0.672, 4. ])
  1987. """)
  1988. add_newdoc("eval_chebyc",
  1989. r"""
  1990. eval_chebyc(n, x, out=None)
  1991. Evaluate Chebyshev polynomial of the first kind on [-2, 2] at a
  1992. point.
  1993. These polynomials are defined as
  1994. .. math::
  1995. C_n(x) = 2 T_n(x/2)
  1996. where :math:`T_n` is a Chebyshev polynomial of the first kind. See
  1997. 22.5.11 in [AS]_ (or equivalently [DLMF]_) for details.
  1998. Parameters
  1999. ----------
  2000. n : array_like
  2001. Degree of the polynomial. If not an integer, the result is
  2002. determined via the relation to `eval_chebyt`.
  2003. x : array_like
  2004. Points at which to evaluate the Chebyshev polynomial
  2005. out : ndarray, optional
  2006. Optional output array for the function values
  2007. Returns
  2008. -------
  2009. C : scalar or ndarray
  2010. Values of the Chebyshev polynomial
  2011. See Also
  2012. --------
  2013. roots_chebyc : roots and quadrature weights of Chebyshev
  2014. polynomials of the first kind on [-2, 2]
  2015. chebyc : Chebyshev polynomial object
  2016. numpy.polynomial.chebyshev.Chebyshev : Chebyshev series
  2017. eval_chebyt : evaluate Chebycshev polynomials of the first kind
  2018. References
  2019. ----------
  2020. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  2021. Handbook of Mathematical Functions with Formulas,
  2022. Graphs, and Mathematical Tables. New York: Dover, 1972.
  2023. .. [DLMF] NIST Digital Library of Mathematical Functions,
  2024. https://dlmf.nist.gov/18.1.E3
  2025. Examples
  2026. --------
  2027. >>> import numpy as np
  2028. >>> import scipy.special as sc
  2029. They are a scaled version of the Chebyshev polynomials of the
  2030. first kind.
  2031. >>> x = np.linspace(-2, 2, 6)
  2032. >>> sc.eval_chebyc(3, x)
  2033. array([-2. , 1.872, 1.136, -1.136, -1.872, 2. ])
  2034. >>> 2 * sc.eval_chebyt(3, x / 2)
  2035. array([-2. , 1.872, 1.136, -1.136, -1.872, 2. ])
  2036. """)
  2037. add_newdoc("eval_sh_chebyt",
  2038. r"""
  2039. eval_sh_chebyt(n, x, out=None)
  2040. Evaluate shifted Chebyshev polynomial of the first kind at a
  2041. point.
  2042. These polynomials are defined as
  2043. .. math::
  2044. T_n^*(x) = T_n(2x - 1)
  2045. where :math:`T_n` is a Chebyshev polynomial of the first kind. See
  2046. 22.5.14 in [AS]_ (or equivalently [DLMF]_) for details.
  2047. Parameters
  2048. ----------
  2049. n : array_like
  2050. Degree of the polynomial. If not an integer, the result is
  2051. determined via the relation to `eval_chebyt`.
  2052. x : array_like
  2053. Points at which to evaluate the shifted Chebyshev polynomial
  2054. out : ndarray, optional
  2055. Optional output array for the function values
  2056. Returns
  2057. -------
  2058. T : scalar or ndarray
  2059. Values of the shifted Chebyshev polynomial
  2060. See Also
  2061. --------
  2062. roots_sh_chebyt : roots and quadrature weights of shifted
  2063. Chebyshev polynomials of the first kind
  2064. sh_chebyt : shifted Chebyshev polynomial object
  2065. eval_chebyt : evaluate Chebyshev polynomials of the first kind
  2066. numpy.polynomial.chebyshev.Chebyshev : Chebyshev series
  2067. References
  2068. ----------
  2069. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  2070. Handbook of Mathematical Functions with Formulas,
  2071. Graphs, and Mathematical Tables. New York: Dover, 1972.
  2072. .. [DLMF] NIST Digital Library of Mathematical Functions,
  2073. https://dlmf.nist.gov/18.7.E7
  2074. """)
  2075. add_newdoc("eval_sh_chebyu",
  2076. r"""
  2077. eval_sh_chebyu(n, x, out=None)
  2078. Evaluate shifted Chebyshev polynomial of the second kind at a
  2079. point.
  2080. These polynomials are defined as
  2081. .. math::
  2082. U_n^*(x) = U_n(2x - 1)
  2083. where :math:`U_n` is a Chebyshev polynomial of the first kind. See
  2084. 22.5.15 in [AS]_ (or equivalently [DLMF]_) for details.
  2085. Parameters
  2086. ----------
  2087. n : array_like
  2088. Degree of the polynomial. If not an integer, the result is
  2089. determined via the relation to `eval_chebyu`.
  2090. x : array_like
  2091. Points at which to evaluate the shifted Chebyshev polynomial
  2092. out : ndarray, optional
  2093. Optional output array for the function values
  2094. Returns
  2095. -------
  2096. U : scalar or ndarray
  2097. Values of the shifted Chebyshev polynomial
  2098. See Also
  2099. --------
  2100. roots_sh_chebyu : roots and quadrature weights of shifted
  2101. Chebychev polynomials of the second kind
  2102. sh_chebyu : shifted Chebyshev polynomial object
  2103. eval_chebyu : evaluate Chebyshev polynomials of the second kind
  2104. References
  2105. ----------
  2106. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  2107. Handbook of Mathematical Functions with Formulas,
  2108. Graphs, and Mathematical Tables. New York: Dover, 1972.
  2109. .. [DLMF] NIST Digital Library of Mathematical Functions,
  2110. https://dlmf.nist.gov/18.7.E8
  2111. """)
  2112. add_newdoc("eval_legendre",
  2113. r"""
  2114. eval_legendre(n, x, out=None)
  2115. Evaluate Legendre polynomial at a point.
  2116. The Legendre polynomials can be defined via the Gauss
  2117. hypergeometric function :math:`{}_2F_1` as
  2118. .. math::
  2119. P_n(x) = {}_2F_1(-n, n + 1; 1; (1 - x)/2).
  2120. When :math:`n` is an integer the result is a polynomial of degree
  2121. :math:`n`. See 22.5.49 in [AS]_ (or equivalently [DLMF]_) for details.
  2122. Parameters
  2123. ----------
  2124. n : array_like
  2125. Degree of the polynomial. If not an integer, the result is
  2126. determined via the relation to the Gauss hypergeometric
  2127. function.
  2128. x : array_like
  2129. Points at which to evaluate the Legendre polynomial
  2130. out : ndarray, optional
  2131. Optional output array for the function values
  2132. Returns
  2133. -------
  2134. P : scalar or ndarray
  2135. Values of the Legendre polynomial
  2136. See Also
  2137. --------
  2138. roots_legendre : roots and quadrature weights of Legendre
  2139. polynomials
  2140. legendre : Legendre polynomial object
  2141. hyp2f1 : Gauss hypergeometric function
  2142. numpy.polynomial.legendre.Legendre : Legendre series
  2143. References
  2144. ----------
  2145. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  2146. Handbook of Mathematical Functions with Formulas,
  2147. Graphs, and Mathematical Tables. New York: Dover, 1972.
  2148. .. [DLMF] NIST Digital Library of Mathematical Functions,
  2149. https://dlmf.nist.gov/15.9.E7
  2150. Examples
  2151. --------
  2152. >>> import numpy as np
  2153. >>> from scipy.special import eval_legendre
  2154. Evaluate the zero-order Legendre polynomial at x = 0
  2155. >>> eval_legendre(0, 0)
  2156. 1.0
  2157. Evaluate the first-order Legendre polynomial between -1 and 1
  2158. >>> X = np.linspace(-1, 1, 5) # Domain of Legendre polynomials
  2159. >>> eval_legendre(1, X)
  2160. array([-1. , -0.5, 0. , 0.5, 1. ])
  2161. Evaluate Legendre polynomials of order 0 through 4 at x = 0
  2162. >>> N = range(0, 5)
  2163. >>> eval_legendre(N, 0)
  2164. array([ 1. , 0. , -0.5 , 0. , 0.375])
  2165. Plot Legendre polynomials of order 0 through 4
  2166. >>> X = np.linspace(-1, 1)
  2167. >>> import matplotlib.pyplot as plt
  2168. >>> for n in range(0, 5):
  2169. ... y = eval_legendre(n, X)
  2170. ... plt.plot(X, y, label=r'$P_{}(x)$'.format(n))
  2171. >>> plt.title("Legendre Polynomials")
  2172. >>> plt.xlabel("x")
  2173. >>> plt.ylabel(r'$P_n(x)$')
  2174. >>> plt.legend(loc='lower right')
  2175. >>> plt.show()
  2176. """)
  2177. add_newdoc("eval_sh_legendre",
  2178. r"""
  2179. eval_sh_legendre(n, x, out=None)
  2180. Evaluate shifted Legendre polynomial at a point.
  2181. These polynomials are defined as
  2182. .. math::
  2183. P_n^*(x) = P_n(2x - 1)
  2184. where :math:`P_n` is a Legendre polynomial. See 2.2.11 in [AS]_
  2185. or [DLMF]_ for details.
  2186. Parameters
  2187. ----------
  2188. n : array_like
  2189. Degree of the polynomial. If not an integer, the value is
  2190. determined via the relation to `eval_legendre`.
  2191. x : array_like
  2192. Points at which to evaluate the shifted Legendre polynomial
  2193. out : ndarray, optional
  2194. Optional output array for the function values
  2195. Returns
  2196. -------
  2197. P : scalar or ndarray
  2198. Values of the shifted Legendre polynomial
  2199. See Also
  2200. --------
  2201. roots_sh_legendre : roots and quadrature weights of shifted
  2202. Legendre polynomials
  2203. sh_legendre : shifted Legendre polynomial object
  2204. eval_legendre : evaluate Legendre polynomials
  2205. numpy.polynomial.legendre.Legendre : Legendre series
  2206. References
  2207. ----------
  2208. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  2209. Handbook of Mathematical Functions with Formulas,
  2210. Graphs, and Mathematical Tables. New York: Dover, 1972.
  2211. .. [DLMF] NIST Digital Library of Mathematical Functions,
  2212. https://dlmf.nist.gov/18.7.E10
  2213. """)
  2214. add_newdoc("eval_genlaguerre",
  2215. r"""
  2216. eval_genlaguerre(n, alpha, x, out=None)
  2217. Evaluate generalized Laguerre polynomial at a point.
  2218. The generalized Laguerre polynomials can be defined via the
  2219. confluent hypergeometric function :math:`{}_1F_1` as
  2220. .. math::
  2221. L_n^{(\alpha)}(x) = \binom{n + \alpha}{n}
  2222. {}_1F_1(-n, \alpha + 1, x).
  2223. When :math:`n` is an integer the result is a polynomial of degree
  2224. :math:`n`. See 22.5.54 in [AS]_ or [DLMF]_ for details. The Laguerre
  2225. polynomials are the special case where :math:`\alpha = 0`.
  2226. Parameters
  2227. ----------
  2228. n : array_like
  2229. Degree of the polynomial. If not an integer, the result is
  2230. determined via the relation to the confluent hypergeometric
  2231. function.
  2232. alpha : array_like
  2233. Parameter; must have ``alpha > -1``
  2234. x : array_like
  2235. Points at which to evaluate the generalized Laguerre
  2236. polynomial
  2237. out : ndarray, optional
  2238. Optional output array for the function values
  2239. Returns
  2240. -------
  2241. L : scalar or ndarray
  2242. Values of the generalized Laguerre polynomial
  2243. See Also
  2244. --------
  2245. roots_genlaguerre : roots and quadrature weights of generalized
  2246. Laguerre polynomials
  2247. genlaguerre : generalized Laguerre polynomial object
  2248. hyp1f1 : confluent hypergeometric function
  2249. eval_laguerre : evaluate Laguerre polynomials
  2250. References
  2251. ----------
  2252. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  2253. Handbook of Mathematical Functions with Formulas,
  2254. Graphs, and Mathematical Tables. New York: Dover, 1972.
  2255. .. [DLMF] NIST Digital Library of Mathematical Functions,
  2256. https://dlmf.nist.gov/18.5.E12
  2257. """)
  2258. add_newdoc("eval_laguerre",
  2259. r"""
  2260. eval_laguerre(n, x, out=None)
  2261. Evaluate Laguerre polynomial at a point.
  2262. The Laguerre polynomials can be defined via the confluent
  2263. hypergeometric function :math:`{}_1F_1` as
  2264. .. math::
  2265. L_n(x) = {}_1F_1(-n, 1, x).
  2266. See 22.5.16 and 22.5.54 in [AS]_ (or equivalently [DLMF1]_ and [DLMF2]_)
  2267. for details. When :math:`n` is an integer the result is a polynomial
  2268. of degree :math:`n`.
  2269. Parameters
  2270. ----------
  2271. n : array_like
  2272. Degree of the polynomial. If not an integer the result is
  2273. determined via the relation to the confluent hypergeometric
  2274. function.
  2275. x : array_like
  2276. Points at which to evaluate the Laguerre polynomial
  2277. out : ndarray, optional
  2278. Optional output array for the function values
  2279. Returns
  2280. -------
  2281. L : scalar or ndarray
  2282. Values of the Laguerre polynomial
  2283. See Also
  2284. --------
  2285. roots_laguerre : roots and quadrature weights of Laguerre
  2286. polynomials
  2287. laguerre : Laguerre polynomial object
  2288. numpy.polynomial.laguerre.Laguerre : Laguerre series
  2289. eval_genlaguerre : evaluate generalized Laguerre polynomials
  2290. References
  2291. ----------
  2292. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  2293. Handbook of Mathematical Functions with Formulas,
  2294. Graphs, and Mathematical Tables. New York: Dover, 1972.
  2295. .. [DLMF1] NIST Digital Library of Mathematical Functions,
  2296. https://dlmf.nist.gov/18.1#I1.ix7.p1
  2297. .. [DLMF2] NIST Digital Library of Mathematical Functions,
  2298. https://dlmf.nist.gov/18.5.E12
  2299. """)
  2300. add_newdoc("eval_hermite",
  2301. r"""
  2302. eval_hermite(n, x, out=None)
  2303. Evaluate physicist's Hermite polynomial at a point.
  2304. Defined by
  2305. .. math::
  2306. H_n(x) = (-1)^n e^{x^2} \frac{d^n}{dx^n} e^{-x^2};
  2307. :math:`H_n` is a polynomial of degree :math:`n`. See 22.11.7 in
  2308. [AS]_ or [DLMF]_ for details.
  2309. Parameters
  2310. ----------
  2311. n : array_like
  2312. Degree of the polynomial
  2313. x : array_like
  2314. Points at which to evaluate the Hermite polynomial
  2315. out : ndarray, optional
  2316. Optional output array for the function values
  2317. Returns
  2318. -------
  2319. H : scalar or ndarray
  2320. Values of the Hermite polynomial
  2321. See Also
  2322. --------
  2323. roots_hermite : roots and quadrature weights of physicist's
  2324. Hermite polynomials
  2325. hermite : physicist's Hermite polynomial object
  2326. numpy.polynomial.hermite.Hermite : Physicist's Hermite series
  2327. eval_hermitenorm : evaluate Probabilist's Hermite polynomials
  2328. References
  2329. ----------
  2330. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  2331. Handbook of Mathematical Functions with Formulas,
  2332. Graphs, and Mathematical Tables. New York: Dover, 1972.
  2333. .. [DLMF] NIST Digital Library of Mathematical Functions,
  2334. https://dlmf.nist.gov/18.5.T1
  2335. """)
  2336. add_newdoc("eval_hermitenorm",
  2337. r"""
  2338. eval_hermitenorm(n, x, out=None)
  2339. Evaluate probabilist's (normalized) Hermite polynomial at a
  2340. point.
  2341. Defined by
  2342. .. math::
  2343. He_n(x) = (-1)^n e^{x^2/2} \frac{d^n}{dx^n} e^{-x^2/2};
  2344. :math:`He_n` is a polynomial of degree :math:`n`. See 22.11.8 in
  2345. [AS]_ or [DLMF]_ for details.
  2346. Parameters
  2347. ----------
  2348. n : array_like
  2349. Degree of the polynomial
  2350. x : array_like
  2351. Points at which to evaluate the Hermite polynomial
  2352. out : ndarray, optional
  2353. Optional output array for the function values
  2354. Returns
  2355. -------
  2356. He : scalar or ndarray
  2357. Values of the Hermite polynomial
  2358. See Also
  2359. --------
  2360. roots_hermitenorm : roots and quadrature weights of probabilist's
  2361. Hermite polynomials
  2362. hermitenorm : probabilist's Hermite polynomial object
  2363. numpy.polynomial.hermite_e.HermiteE : Probabilist's Hermite series
  2364. eval_hermite : evaluate physicist's Hermite polynomials
  2365. References
  2366. ----------
  2367. .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
  2368. Handbook of Mathematical Functions with Formulas,
  2369. Graphs, and Mathematical Tables. New York: Dover, 1972.
  2370. .. [DLMF] NIST Digital Library of Mathematical Functions,
  2371. https://dlmf.nist.gov/18.5.T1
  2372. """)
  2373. add_newdoc("expn",
  2374. r"""
  2375. expn(n, x, out=None)
  2376. Generalized exponential integral En.
  2377. For integer :math:`n \geq 0` and real :math:`x \geq 0` the
  2378. generalized exponential integral is defined as [DLMF]_
  2379. .. math::
  2380. E_n(x) = x^{n - 1} \int_x^\infty \frac{e^{-t}}{t^n} dt.
  2381. Parameters
  2382. ----------
  2383. n : array_like
  2384. Non-negative integers
  2385. x : array_like
  2386. Real argument
  2387. out : ndarray, optional
  2388. Optional output array for the function results
  2389. Returns
  2390. -------
  2391. scalar or ndarray
  2392. Values of the generalized exponential integral
  2393. See Also
  2394. --------
  2395. exp1 : special case of :math:`E_n` for :math:`n = 1`
  2396. expi : related to :math:`E_n` when :math:`n = 1`
  2397. References
  2398. ----------
  2399. .. [DLMF] Digital Library of Mathematical Functions, 8.19.2
  2400. https://dlmf.nist.gov/8.19#E2
  2401. Examples
  2402. --------
  2403. >>> import numpy as np
  2404. >>> import scipy.special as sc
  2405. Its domain is nonnegative n and x.
  2406. >>> sc.expn(-1, 1.0), sc.expn(1, -1.0)
  2407. (nan, nan)
  2408. It has a pole at ``x = 0`` for ``n = 1, 2``; for larger ``n`` it
  2409. is equal to ``1 / (n - 1)``.
  2410. >>> sc.expn([0, 1, 2, 3, 4], 0)
  2411. array([ inf, inf, 1. , 0.5 , 0.33333333])
  2412. For n equal to 0 it reduces to ``exp(-x) / x``.
  2413. >>> x = np.array([1, 2, 3, 4])
  2414. >>> sc.expn(0, x)
  2415. array([0.36787944, 0.06766764, 0.01659569, 0.00457891])
  2416. >>> np.exp(-x) / x
  2417. array([0.36787944, 0.06766764, 0.01659569, 0.00457891])
  2418. For n equal to 1 it reduces to `exp1`.
  2419. >>> sc.expn(1, x)
  2420. array([0.21938393, 0.04890051, 0.01304838, 0.00377935])
  2421. >>> sc.exp1(x)
  2422. array([0.21938393, 0.04890051, 0.01304838, 0.00377935])
  2423. """)
  2424. add_newdoc("fdtr",
  2425. r"""
  2426. fdtr(dfn, dfd, x, out=None)
  2427. F cumulative distribution function.
  2428. Returns the value of the cumulative distribution function of the
  2429. F-distribution, also known as Snedecor's F-distribution or the
  2430. Fisher-Snedecor distribution.
  2431. The F-distribution with parameters :math:`d_n` and :math:`d_d` is the
  2432. distribution of the random variable,
  2433. .. math::
  2434. X = \frac{U_n/d_n}{U_d/d_d},
  2435. where :math:`U_n` and :math:`U_d` are random variables distributed
  2436. :math:`\chi^2`, with :math:`d_n` and :math:`d_d` degrees of freedom,
  2437. respectively.
  2438. Parameters
  2439. ----------
  2440. dfn : array_like
  2441. First parameter (positive float).
  2442. dfd : array_like
  2443. Second parameter (positive float).
  2444. x : array_like
  2445. Argument (nonnegative float).
  2446. out : ndarray, optional
  2447. Optional output array for the function values
  2448. Returns
  2449. -------
  2450. y : scalar or ndarray
  2451. The CDF of the F-distribution with parameters `dfn` and `dfd` at `x`.
  2452. See Also
  2453. --------
  2454. fdtrc : F distribution survival function
  2455. fdtri : F distribution inverse cumulative distribution
  2456. scipy.stats.f : F distribution
  2457. Notes
  2458. -----
  2459. The regularized incomplete beta function is used, according to the
  2460. formula,
  2461. .. math::
  2462. F(d_n, d_d; x) = I_{xd_n/(d_d + xd_n)}(d_n/2, d_d/2).
  2463. Wrapper for a routine from the Boost Math C++ library [1]_. The
  2464. F distribution is also available as `scipy.stats.f`. Calling
  2465. `fdtr` directly can improve performance compared to the ``cdf``
  2466. method of `scipy.stats.f` (see last example below).
  2467. References
  2468. ----------
  2469. .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
  2470. Examples
  2471. --------
  2472. Calculate the function for ``dfn=1`` and ``dfd=2`` at ``x=1``.
  2473. >>> import numpy as np
  2474. >>> from scipy.special import fdtr
  2475. >>> fdtr(1, 2, 1)
  2476. 0.5773502691896258
  2477. Calculate the function at several points by providing a NumPy array for
  2478. `x`.
  2479. >>> x = np.array([0.5, 2., 3.])
  2480. >>> fdtr(1, 2, x)
  2481. array([0.4472136 , 0.70710678, 0.77459667])
  2482. Plot the function for several parameter sets.
  2483. >>> import matplotlib.pyplot as plt
  2484. >>> dfn_parameters = [1, 5, 10, 50]
  2485. >>> dfd_parameters = [1, 1, 2, 3]
  2486. >>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
  2487. >>> parameters_list = list(zip(dfn_parameters, dfd_parameters,
  2488. ... linestyles))
  2489. >>> x = np.linspace(0, 30, 1000)
  2490. >>> fig, ax = plt.subplots()
  2491. >>> for parameter_set in parameters_list:
  2492. ... dfn, dfd, style = parameter_set
  2493. ... fdtr_vals = fdtr(dfn, dfd, x)
  2494. ... ax.plot(x, fdtr_vals, label=rf"$d_n={dfn},\, d_d={dfd}$",
  2495. ... ls=style)
  2496. >>> ax.legend()
  2497. >>> ax.set_xlabel("$x$")
  2498. >>> ax.set_title("F distribution cumulative distribution function")
  2499. >>> plt.show()
  2500. The F distribution is also available as `scipy.stats.f`. Using `fdtr`
  2501. directly can be much faster than calling the ``cdf`` method of
  2502. `scipy.stats.f`, especially for small arrays or individual values.
  2503. To get the same results one must use the following parametrization:
  2504. ``stats.f(dfn, dfd).cdf(x)=fdtr(dfn, dfd, x)``.
  2505. >>> from scipy.stats import f
  2506. >>> dfn, dfd = 1, 2
  2507. >>> x = 1
  2508. >>> fdtr_res = fdtr(dfn, dfd, x) # this will often be faster than below
  2509. >>> f_dist_res = f(dfn, dfd).cdf(x)
  2510. >>> fdtr_res == f_dist_res # test that results are equal
  2511. True
  2512. """)
  2513. add_newdoc("fdtrc",
  2514. r"""
  2515. fdtrc(dfn, dfd, x, out=None)
  2516. F survival function.
  2517. Returns the complemented F-distribution function (the integral of the
  2518. density from `x` to infinity).
  2519. Parameters
  2520. ----------
  2521. dfn : array_like
  2522. First parameter (positive float).
  2523. dfd : array_like
  2524. Second parameter (positive float).
  2525. x : array_like
  2526. Argument (nonnegative float).
  2527. out : ndarray, optional
  2528. Optional output array for the function values
  2529. Returns
  2530. -------
  2531. y : scalar or ndarray
  2532. The complemented F-distribution function with parameters `dfn` and
  2533. `dfd` at `x`.
  2534. See Also
  2535. --------
  2536. fdtr : F distribution cumulative distribution function
  2537. fdtri : F distribution inverse cumulative distribution function
  2538. scipy.stats.f : F distribution
  2539. Notes
  2540. -----
  2541. The regularized incomplete beta function is used, according to the
  2542. formula,
  2543. .. math::
  2544. F(d_n, d_d; x) = I_{d_d/(d_d + xd_n)}(d_d/2, d_n/2).
  2545. Wrapper for a routine from the Boost Math C++ library [1]_. The
  2546. F distribution is also available as `scipy.stats.f`. Calling
  2547. `fdtrc` directly can improve performance compared to the ``sf``
  2548. method of `scipy.stats.f` (see last example below).
  2549. References
  2550. ----------
  2551. .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
  2552. Examples
  2553. --------
  2554. Calculate the function for ``dfn=1`` and ``dfd=2`` at ``x=1``.
  2555. >>> import numpy as np
  2556. >>> from scipy.special import fdtrc
  2557. >>> fdtrc(1, 2, 1)
  2558. 0.42264973081037427
  2559. Calculate the function at several points by providing a NumPy array for
  2560. `x`.
  2561. >>> x = np.array([0.5, 2., 3.])
  2562. >>> fdtrc(1, 2, x)
  2563. array([0.5527864 , 0.29289322, 0.22540333])
  2564. Plot the function for several parameter sets.
  2565. >>> import matplotlib.pyplot as plt
  2566. >>> dfn_parameters = [1, 5, 10, 50]
  2567. >>> dfd_parameters = [1, 1, 2, 3]
  2568. >>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
  2569. >>> parameters_list = list(zip(dfn_parameters, dfd_parameters,
  2570. ... linestyles))
  2571. >>> x = np.linspace(0, 30, 1000)
  2572. >>> fig, ax = plt.subplots()
  2573. >>> for parameter_set in parameters_list:
  2574. ... dfn, dfd, style = parameter_set
  2575. ... fdtrc_vals = fdtrc(dfn, dfd, x)
  2576. ... ax.plot(x, fdtrc_vals, label=rf"$d_n={dfn},\, d_d={dfd}$",
  2577. ... ls=style)
  2578. >>> ax.legend()
  2579. >>> ax.set_xlabel("$x$")
  2580. >>> ax.set_title("F distribution survival function")
  2581. >>> plt.show()
  2582. The F distribution is also available as `scipy.stats.f`. Using `fdtrc`
  2583. directly can be much faster than calling the ``sf`` method of
  2584. `scipy.stats.f`, especially for small arrays or individual values.
  2585. To get the same results one must use the following parametrization:
  2586. ``stats.f(dfn, dfd).sf(x)=fdtrc(dfn, dfd, x)``.
  2587. >>> from scipy.stats import f
  2588. >>> dfn, dfd = 1, 2
  2589. >>> x = 1
  2590. >>> fdtrc_res = fdtrc(dfn, dfd, x) # this will often be faster than below
  2591. >>> f_dist_res = f(dfn, dfd).sf(x)
  2592. >>> f_dist_res == fdtrc_res # test that results are equal
  2593. True
  2594. """)
  2595. add_newdoc("fdtri",
  2596. r"""
  2597. fdtri(dfn, dfd, p, out=None)
  2598. The `p`-th quantile of the F-distribution.
  2599. This function is the inverse of the F-distribution CDF, `fdtr`, returning
  2600. the `x` such that `fdtr(dfn, dfd, x) = p`.
  2601. Parameters
  2602. ----------
  2603. dfn : array_like
  2604. First parameter (positive float).
  2605. dfd : array_like
  2606. Second parameter (positive float).
  2607. p : array_like
  2608. Cumulative probability, in [0, 1].
  2609. out : ndarray, optional
  2610. Optional output array for the function values
  2611. Returns
  2612. -------
  2613. x : scalar or ndarray
  2614. The quantile corresponding to `p`.
  2615. See Also
  2616. --------
  2617. fdtr : F distribution cumulative distribution function
  2618. fdtrc : F distribution survival function
  2619. scipy.stats.f : F distribution
  2620. Notes
  2621. -----
  2622. Wrapper for a routine from the Boost Math C++ library [1]_. The
  2623. F distribution is also available as `scipy.stats.f`. Calling
  2624. `fdtri` directly can improve performance compared to the ``ppf``
  2625. method of `scipy.stats.f` (see last example below).
  2626. References
  2627. ----------
  2628. .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
  2629. Examples
  2630. --------
  2631. `fdtri` represents the inverse of the F distribution CDF which is
  2632. available as `fdtr`. Here, we calculate the CDF for ``df1=1``, ``df2=2``
  2633. at ``x=3``. `fdtri` then returns ``3`` given the same values for `df1`,
  2634. `df2` and the computed CDF value.
  2635. >>> import numpy as np
  2636. >>> from scipy.special import fdtri, fdtr
  2637. >>> df1, df2 = 1, 2
  2638. >>> x = 3
  2639. >>> cdf_value = fdtr(df1, df2, x)
  2640. >>> fdtri(df1, df2, cdf_value)
  2641. 3.000000000000006
  2642. Calculate the function at several points by providing a NumPy array for
  2643. `x`.
  2644. >>> x = np.array([0.1, 0.4, 0.7])
  2645. >>> fdtri(1, 2, x)
  2646. array([0.02020202, 0.38095238, 1.92156863])
  2647. Plot the function for several parameter sets.
  2648. >>> import matplotlib.pyplot as plt
  2649. >>> dfn_parameters = [50, 10, 1, 50]
  2650. >>> dfd_parameters = [0.5, 1, 1, 5]
  2651. >>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
  2652. >>> parameters_list = list(zip(dfn_parameters, dfd_parameters,
  2653. ... linestyles))
  2654. >>> x = np.linspace(0, 1, 1000)
  2655. >>> fig, ax = plt.subplots()
  2656. >>> for parameter_set in parameters_list:
  2657. ... dfn, dfd, style = parameter_set
  2658. ... fdtri_vals = fdtri(dfn, dfd, x)
  2659. ... ax.plot(x, fdtri_vals, label=rf"$d_n={dfn},\, d_d={dfd}$",
  2660. ... ls=style)
  2661. >>> ax.legend()
  2662. >>> ax.set_xlabel("$x$")
  2663. >>> title = "F distribution inverse cumulative distribution function"
  2664. >>> ax.set_title(title)
  2665. >>> ax.set_ylim(0, 30)
  2666. >>> plt.show()
  2667. The F distribution is also available as `scipy.stats.f`. Using `fdtri`
  2668. directly can be much faster than calling the ``ppf`` method of
  2669. `scipy.stats.f`, especially for small arrays or individual values.
  2670. To get the same results one must use the following parametrization:
  2671. ``stats.f(dfn, dfd).ppf(x)=fdtri(dfn, dfd, x)``.
  2672. >>> from scipy.stats import f
  2673. >>> dfn, dfd = 1, 2
  2674. >>> x = 0.7
  2675. >>> fdtri_res = fdtri(dfn, dfd, x) # this will often be faster than below
  2676. >>> f_dist_res = f(dfn, dfd).ppf(x)
  2677. >>> f_dist_res == fdtri_res # test that results are equal
  2678. True
  2679. """)
  2680. add_newdoc("fdtridfd",
  2681. """
  2682. fdtridfd(dfn, p, x, out=None)
  2683. Inverse to `fdtr` vs dfd
  2684. Finds the F density argument dfd such that ``fdtr(dfn, dfd, x) == p``.
  2685. Parameters
  2686. ----------
  2687. dfn : array_like
  2688. First parameter (positive float).
  2689. p : array_like
  2690. Cumulative probability, in [0, 1].
  2691. x : array_like
  2692. Argument (nonnegative float).
  2693. out : ndarray, optional
  2694. Optional output array for the function values
  2695. Returns
  2696. -------
  2697. dfd : scalar or ndarray
  2698. `dfd` such that ``fdtr(dfn, dfd, x) == p``.
  2699. See Also
  2700. --------
  2701. fdtr : F distribution cumulative distribution function
  2702. fdtrc : F distribution survival function
  2703. fdtri : F distribution quantile function
  2704. scipy.stats.f : F distribution
  2705. Examples
  2706. --------
  2707. Compute the F distribution cumulative distribution function for one
  2708. parameter set.
  2709. >>> from scipy.special import fdtridfd, fdtr
  2710. >>> dfn, dfd, x = 10, 5, 2
  2711. >>> cdf_value = fdtr(dfn, dfd, x)
  2712. >>> cdf_value
  2713. 0.7700248806501017
  2714. Verify that `fdtridfd` recovers the original value for `dfd`:
  2715. >>> fdtridfd(dfn, cdf_value, x)
  2716. 5.0
  2717. """)
  2718. '''
  2719. commented out as fdtridfn seems to have bugs and is not in functions.json
  2720. see: https://github.com/scipy/scipy/pull/15622#discussion_r811440983
  2721. add_newdoc(
  2722. "fdtridfn",
  2723. """
  2724. fdtridfn(p, dfd, x, out=None)
  2725. Inverse to `fdtr` vs dfn
  2726. finds the F density argument dfn such that ``fdtr(dfn, dfd, x) == p``.
  2727. Parameters
  2728. ----------
  2729. p : array_like
  2730. Cumulative probability, in [0, 1].
  2731. dfd : array_like
  2732. Second parameter (positive float).
  2733. x : array_like
  2734. Argument (nonnegative float).
  2735. out : ndarray, optional
  2736. Optional output array for the function values
  2737. Returns
  2738. -------
  2739. dfn : scalar or ndarray
  2740. `dfn` such that ``fdtr(dfn, dfd, x) == p``.
  2741. See Also
  2742. --------
  2743. fdtr, fdtrc, fdtri, fdtridfd
  2744. """)
  2745. '''
  2746. add_newdoc("gdtr",
  2747. r"""
  2748. gdtr(a, b, x, out=None)
  2749. Gamma distribution cumulative distribution function.
  2750. Returns the integral from zero to `x` of the gamma probability density
  2751. function,
  2752. .. math::
  2753. F = \int_0^x \frac{a^b}{\Gamma(b)} t^{b-1} e^{-at}\,dt,
  2754. where :math:`\Gamma` is the gamma function.
  2755. Parameters
  2756. ----------
  2757. a : array_like
  2758. The rate parameter of the gamma distribution, sometimes denoted
  2759. :math:`\beta` (float). It is also the reciprocal of the scale
  2760. parameter :math:`\theta`.
  2761. b : array_like
  2762. The shape parameter of the gamma distribution, sometimes denoted
  2763. :math:`\alpha` (float).
  2764. x : array_like
  2765. The quantile (upper limit of integration; float).
  2766. out : ndarray, optional
  2767. Optional output array for the function values
  2768. Returns
  2769. -------
  2770. F : scalar or ndarray
  2771. The CDF of the gamma distribution with parameters `a` and `b`
  2772. evaluated at `x`.
  2773. See Also
  2774. --------
  2775. gdtrc : 1 - CDF of the gamma distribution.
  2776. scipy.stats.gamma: Gamma distribution
  2777. Notes
  2778. -----
  2779. The evaluation is carried out using the relation to the incomplete gamma
  2780. integral (regularized gamma function).
  2781. Wrapper for the Cephes [1]_ routine `gdtr`. Calling `gdtr` directly can
  2782. improve performance compared to the ``cdf`` method of `scipy.stats.gamma`
  2783. (see last example below).
  2784. References
  2785. ----------
  2786. .. [1] Cephes Mathematical Functions Library,
  2787. http://www.netlib.org/cephes/
  2788. Examples
  2789. --------
  2790. Compute the function for ``a=1``, ``b=2`` at ``x=5``.
  2791. >>> import numpy as np
  2792. >>> from scipy.special import gdtr
  2793. >>> import matplotlib.pyplot as plt
  2794. >>> gdtr(1., 2., 5.)
  2795. 0.9595723180054873
  2796. Compute the function for ``a=1`` and ``b=2`` at several points by
  2797. providing a NumPy array for `x`.
  2798. >>> xvalues = np.array([1., 2., 3., 4])
  2799. >>> gdtr(1., 1., xvalues)
  2800. array([0.63212056, 0.86466472, 0.95021293, 0.98168436])
  2801. `gdtr` can evaluate different parameter sets by providing arrays with
  2802. broadcasting compatible shapes for `a`, `b` and `x`. Here we compute the
  2803. function for three different `a` at four positions `x` and ``b=3``,
  2804. resulting in a 3x4 array.
  2805. >>> a = np.array([[0.5], [1.5], [2.5]])
  2806. >>> x = np.array([1., 2., 3., 4])
  2807. >>> a.shape, x.shape
  2808. ((3, 1), (4,))
  2809. >>> gdtr(a, 3., x)
  2810. array([[0.01438768, 0.0803014 , 0.19115317, 0.32332358],
  2811. [0.19115317, 0.57680992, 0.82642193, 0.9380312 ],
  2812. [0.45618688, 0.87534798, 0.97974328, 0.9972306 ]])
  2813. Plot the function for four different parameter sets.
  2814. >>> a_parameters = [0.3, 1, 2, 6]
  2815. >>> b_parameters = [2, 10, 15, 20]
  2816. >>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
  2817. >>> parameters_list = list(zip(a_parameters, b_parameters, linestyles))
  2818. >>> x = np.linspace(0, 30, 1000)
  2819. >>> fig, ax = plt.subplots()
  2820. >>> for parameter_set in parameters_list:
  2821. ... a, b, style = parameter_set
  2822. ... gdtr_vals = gdtr(a, b, x)
  2823. ... ax.plot(x, gdtr_vals, label=fr"$a= {a},\, b={b}$", ls=style)
  2824. >>> ax.legend()
  2825. >>> ax.set_xlabel("$x$")
  2826. >>> ax.set_title("Gamma distribution cumulative distribution function")
  2827. >>> plt.show()
  2828. The gamma distribution is also available as `scipy.stats.gamma`. Using
  2829. `gdtr` directly can be much faster than calling the ``cdf`` method of
  2830. `scipy.stats.gamma`, especially for small arrays or individual values.
  2831. To get the same results one must use the following parametrization:
  2832. ``stats.gamma(b, scale=1/a).cdf(x)=gdtr(a, b, x)``.
  2833. >>> from scipy.stats import gamma
  2834. >>> a = 2.
  2835. >>> b = 3
  2836. >>> x = 1.
  2837. >>> gdtr_result = gdtr(a, b, x) # this will often be faster than below
  2838. >>> gamma_dist_result = gamma(b, scale=1/a).cdf(x)
  2839. >>> gdtr_result == gamma_dist_result # test that results are equal
  2840. True
  2841. """)
  2842. add_newdoc("gdtrc",
  2843. r"""
  2844. gdtrc(a, b, x, out=None)
  2845. Gamma distribution survival function.
  2846. Integral from `x` to infinity of the gamma probability density function,
  2847. .. math::
  2848. F = \int_x^\infty \frac{a^b}{\Gamma(b)} t^{b-1} e^{-at}\,dt,
  2849. where :math:`\Gamma` is the gamma function.
  2850. Parameters
  2851. ----------
  2852. a : array_like
  2853. The rate parameter of the gamma distribution, sometimes denoted
  2854. :math:`\beta` (float). It is also the reciprocal of the scale
  2855. parameter :math:`\theta`.
  2856. b : array_like
  2857. The shape parameter of the gamma distribution, sometimes denoted
  2858. :math:`\alpha` (float).
  2859. x : array_like
  2860. The quantile (lower limit of integration; float).
  2861. out : ndarray, optional
  2862. Optional output array for the function values
  2863. Returns
  2864. -------
  2865. F : scalar or ndarray
  2866. The survival function of the gamma distribution with parameters `a`
  2867. and `b` evaluated at `x`.
  2868. See Also
  2869. --------
  2870. gdtr: Gamma distribution cumulative distribution function
  2871. scipy.stats.gamma: Gamma distribution
  2872. gdtrix
  2873. Notes
  2874. -----
  2875. The evaluation is carried out using the relation to the incomplete gamma
  2876. integral (regularized gamma function).
  2877. Wrapper for the Cephes [1]_ routine `gdtrc`. Calling `gdtrc` directly can
  2878. improve performance compared to the ``sf`` method of `scipy.stats.gamma`
  2879. (see last example below).
  2880. References
  2881. ----------
  2882. .. [1] Cephes Mathematical Functions Library,
  2883. http://www.netlib.org/cephes/
  2884. Examples
  2885. --------
  2886. Compute the function for ``a=1`` and ``b=2`` at ``x=5``.
  2887. >>> import numpy as np
  2888. >>> from scipy.special import gdtrc
  2889. >>> import matplotlib.pyplot as plt
  2890. >>> gdtrc(1., 2., 5.)
  2891. 0.04042768199451279
  2892. Compute the function for ``a=1``, ``b=2`` at several points by providing
  2893. a NumPy array for `x`.
  2894. >>> xvalues = np.array([1., 2., 3., 4])
  2895. >>> gdtrc(1., 1., xvalues)
  2896. array([0.36787944, 0.13533528, 0.04978707, 0.01831564])
  2897. `gdtrc` can evaluate different parameter sets by providing arrays with
  2898. broadcasting compatible shapes for `a`, `b` and `x`. Here we compute the
  2899. function for three different `a` at four positions `x` and ``b=3``,
  2900. resulting in a 3x4 array.
  2901. >>> a = np.array([[0.5], [1.5], [2.5]])
  2902. >>> x = np.array([1., 2., 3., 4])
  2903. >>> a.shape, x.shape
  2904. ((3, 1), (4,))
  2905. >>> gdtrc(a, 3., x)
  2906. array([[0.98561232, 0.9196986 , 0.80884683, 0.67667642],
  2907. [0.80884683, 0.42319008, 0.17357807, 0.0619688 ],
  2908. [0.54381312, 0.12465202, 0.02025672, 0.0027694 ]])
  2909. Plot the function for four different parameter sets.
  2910. >>> a_parameters = [0.3, 1, 2, 6]
  2911. >>> b_parameters = [2, 10, 15, 20]
  2912. >>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
  2913. >>> parameters_list = list(zip(a_parameters, b_parameters, linestyles))
  2914. >>> x = np.linspace(0, 30, 1000)
  2915. >>> fig, ax = plt.subplots()
  2916. >>> for parameter_set in parameters_list:
  2917. ... a, b, style = parameter_set
  2918. ... gdtrc_vals = gdtrc(a, b, x)
  2919. ... ax.plot(x, gdtrc_vals, label=fr"$a= {a},\, b={b}$", ls=style)
  2920. >>> ax.legend()
  2921. >>> ax.set_xlabel("$x$")
  2922. >>> ax.set_title("Gamma distribution survival function")
  2923. >>> plt.show()
  2924. The gamma distribution is also available as `scipy.stats.gamma`.
  2925. Using `gdtrc` directly can be much faster than calling the ``sf`` method
  2926. of `scipy.stats.gamma`, especially for small arrays or individual
  2927. values. To get the same results one must use the following parametrization:
  2928. ``stats.gamma(b, scale=1/a).sf(x)=gdtrc(a, b, x)``.
  2929. >>> from scipy.stats import gamma
  2930. >>> a = 2
  2931. >>> b = 3
  2932. >>> x = 1.
  2933. >>> gdtrc_result = gdtrc(a, b, x) # this will often be faster than below
  2934. >>> gamma_dist_result = gamma(b, scale=1/a).sf(x)
  2935. >>> gdtrc_result == gamma_dist_result # test that results are equal
  2936. True
  2937. """)
  2938. add_newdoc("gdtria",
  2939. """
  2940. gdtria(p, b, x, out=None)
  2941. Inverse of `gdtr` vs a.
  2942. Returns the inverse with respect to the parameter `a` of ``p =
  2943. gdtr(a, b, x)``, the cumulative distribution function of the gamma
  2944. distribution.
  2945. Parameters
  2946. ----------
  2947. p : array_like
  2948. Probability values.
  2949. b : array_like
  2950. `b` parameter values of `gdtr(a, b, x)`. `b` is the "shape" parameter
  2951. of the gamma distribution.
  2952. x : array_like
  2953. Nonnegative real values, from the domain of the gamma distribution.
  2954. out : ndarray, optional
  2955. If a fourth argument is given, it must be a numpy.ndarray whose size
  2956. matches the broadcast result of `a`, `b` and `x`. `out` is then the
  2957. array returned by the function.
  2958. Returns
  2959. -------
  2960. a : scalar or ndarray
  2961. Values of the `a` parameter such that ``p = gdtr(a, b, x)`. ``1/a``
  2962. is the "scale" parameter of the gamma distribution.
  2963. See Also
  2964. --------
  2965. gdtr : CDF of the gamma distribution.
  2966. gdtrib : Inverse with respect to `b` of `gdtr(a, b, x)`.
  2967. gdtrix : Inverse with respect to `x` of `gdtr(a, b, x)`.
  2968. Notes
  2969. -----
  2970. Wrapper for the CDFLIB [1]_ Fortran routine `cdfgam`.
  2971. The cumulative distribution function `p` is computed using a routine by
  2972. DiDinato and Morris [2]_. Computation of `a` involves a search for a value
  2973. that produces the desired value of `p`. The search relies on the
  2974. monotonicity of `p` with `a`.
  2975. References
  2976. ----------
  2977. .. [1] Barry Brown, James Lovato, and Kathy Russell,
  2978. CDFLIB: Library of Fortran Routines for Cumulative Distribution
  2979. Functions, Inverses, and Other Parameters.
  2980. .. [2] DiDinato, A. R. and Morris, A. H.,
  2981. Computation of the incomplete gamma function ratios and their
  2982. inverse. ACM Trans. Math. Softw. 12 (1986), 377-393.
  2983. Examples
  2984. --------
  2985. First evaluate `gdtr`.
  2986. >>> from scipy.special import gdtr, gdtria
  2987. >>> p = gdtr(1.2, 3.4, 5.6)
  2988. >>> print(p)
  2989. 0.94378087442
  2990. Verify the inverse.
  2991. >>> gdtria(p, 3.4, 5.6)
  2992. 1.2
  2993. """)
  2994. add_newdoc("gdtrib",
  2995. """
  2996. gdtrib(a, p, x, out=None)
  2997. Inverse of `gdtr` vs b.
  2998. Returns the inverse with respect to the parameter `b` of ``p =
  2999. gdtr(a, b, x)``, the cumulative distribution function of the gamma
  3000. distribution.
  3001. Parameters
  3002. ----------
  3003. a : array_like
  3004. `a` parameter values of ``gdtr(a, b, x)`. ``1/a`` is the "scale"
  3005. parameter of the gamma distribution.
  3006. p : array_like
  3007. Probability values.
  3008. x : array_like
  3009. Nonnegative real values, from the domain of the gamma distribution.
  3010. out : ndarray, optional
  3011. If a fourth argument is given, it must be a numpy.ndarray whose size
  3012. matches the broadcast result of `a`, `b` and `x`. `out` is then the
  3013. array returned by the function.
  3014. Returns
  3015. -------
  3016. b : scalar or ndarray
  3017. Values of the `b` parameter such that `p = gdtr(a, b, x)`. `b` is
  3018. the "shape" parameter of the gamma distribution.
  3019. See Also
  3020. --------
  3021. gdtr : CDF of the gamma distribution.
  3022. gdtria : Inverse with respect to `a` of `gdtr(a, b, x)`.
  3023. gdtrix : Inverse with respect to `x` of `gdtr(a, b, x)`.
  3024. Notes
  3025. -----
  3026. The cumulative distribution function `p` is computed using the Cephes [1]_
  3027. routines `igam` and `igamc`. Computation of `b` involves a search for a value
  3028. that produces the desired value of `p` using Chandrupatla's bracketing
  3029. root finding algorithm [2]_.
  3030. Note that there are some edge cases where `gdtrib` is extended by taking
  3031. limits where they are uniquely defined. In particular
  3032. ``x == 0`` with ``p > 0`` and ``p == 0`` with ``x > 0``.
  3033. For these edge cases, a numerical result will be returned for
  3034. ``gdtrib(a, p, x)`` even though ``gdtr(a, gdtrib(a, p, x), x)`` is
  3035. undefined.
  3036. References
  3037. ----------
  3038. .. [1] Cephes Mathematical Functions Library,
  3039. http://www.netlib.org/cephes/
  3040. .. [2] Chandrupatla, Tirupathi R.
  3041. "A new hybrid quadratic/bisection algorithm for finding the zero of a
  3042. nonlinear function without using derivatives".
  3043. Advances in Engineering Software, 28(3), 145-149.
  3044. https://doi.org/10.1016/s0965-9978(96)00051-8
  3045. Examples
  3046. --------
  3047. First evaluate `gdtr`.
  3048. >>> from scipy.special import gdtr, gdtrib
  3049. >>> p = gdtr(1.2, 3.4, 5.6)
  3050. >>> print(p)
  3051. 0.94378087442
  3052. Verify the inverse.
  3053. >>> gdtrib(1.2, p, 5.6)
  3054. 3.3999999999999995
  3055. """)
  3056. add_newdoc("gdtrix",
  3057. """
  3058. gdtrix(a, b, p, out=None)
  3059. Inverse of `gdtr` vs x.
  3060. Returns the inverse with respect to the parameter `x` of ``p =
  3061. gdtr(a, b, x)``, the cumulative distribution function of the gamma
  3062. distribution. This is also known as the pth quantile of the
  3063. distribution.
  3064. Parameters
  3065. ----------
  3066. a : array_like
  3067. `a` parameter values of ``gdtr(a, b, x)``. ``1/a`` is the "scale"
  3068. parameter of the gamma distribution.
  3069. b : array_like
  3070. `b` parameter values of ``gdtr(a, b, x)``. `b` is the "shape" parameter
  3071. of the gamma distribution.
  3072. p : array_like
  3073. Probability values.
  3074. out : ndarray, optional
  3075. If a fourth argument is given, it must be a numpy.ndarray whose size
  3076. matches the broadcast result of `a`, `b` and `x`. `out` is then the
  3077. array returned by the function.
  3078. Returns
  3079. -------
  3080. x : scalar or ndarray
  3081. Values of the `x` parameter such that `p = gdtr(a, b, x)`.
  3082. See Also
  3083. --------
  3084. gdtr : CDF of the gamma distribution.
  3085. gdtria : Inverse with respect to `a` of ``gdtr(a, b, x)``.
  3086. gdtrib : Inverse with respect to `b` of ``gdtr(a, b, x)``.
  3087. Notes
  3088. -----
  3089. Wrapper for the CDFLIB [1]_ Fortran routine `cdfgam`.
  3090. The cumulative distribution function `p` is computed using a routine by
  3091. DiDinato and Morris [2]_. Computation of `x` involves a search for a value
  3092. that produces the desired value of `p`. The search relies on the
  3093. monotonicity of `p` with `x`.
  3094. References
  3095. ----------
  3096. .. [1] Barry Brown, James Lovato, and Kathy Russell,
  3097. CDFLIB: Library of Fortran Routines for Cumulative Distribution
  3098. Functions, Inverses, and Other Parameters.
  3099. .. [2] DiDinato, A. R. and Morris, A. H.,
  3100. Computation of the incomplete gamma function ratios and their
  3101. inverse. ACM Trans. Math. Softw. 12 (1986), 377-393.
  3102. Examples
  3103. --------
  3104. First evaluate `gdtr`.
  3105. >>> from scipy.special import gdtr, gdtrix
  3106. >>> p = gdtr(1.2, 3.4, 5.6)
  3107. >>> print(p)
  3108. 0.94378087442
  3109. Verify the inverse.
  3110. >>> gdtrix(1.2, 3.4, p)
  3111. 5.5999999999999996
  3112. """)
  3113. add_newdoc("huber",
  3114. r"""
  3115. huber(delta, r, out=None)
  3116. Huber loss function.
  3117. .. math:: \text{huber}(\delta, r) = \begin{cases} \infty & \delta < 0 \\
  3118. \frac{1}{2}r^2 & 0 \le \delta, | r | \le \delta \\
  3119. \delta ( |r| - \frac{1}{2}\delta ) & \text{otherwise} \end{cases}
  3120. Parameters
  3121. ----------
  3122. delta : ndarray
  3123. Input array, indicating the quadratic vs. linear loss changepoint.
  3124. r : ndarray
  3125. Input array, possibly representing residuals.
  3126. out : ndarray, optional
  3127. Optional output array for the function values
  3128. Returns
  3129. -------
  3130. scalar or ndarray
  3131. The computed Huber loss function values.
  3132. See Also
  3133. --------
  3134. pseudo_huber : smooth approximation of this function
  3135. Notes
  3136. -----
  3137. `huber` is useful as a loss function in robust statistics or machine
  3138. learning to reduce the influence of outliers as compared to the common
  3139. squared error loss, residuals with a magnitude higher than `delta` are
  3140. not squared [1]_.
  3141. Typically, `r` represents residuals, the difference
  3142. between a model prediction and data. Then, for :math:`|r|\leq\delta`,
  3143. `huber` resembles the squared error and for :math:`|r|>\delta` the
  3144. absolute error. This way, the Huber loss often achieves
  3145. a fast convergence in model fitting for small residuals like the squared
  3146. error loss function and still reduces the influence of outliers
  3147. (:math:`|r|>\delta`) like the absolute error loss. As :math:`\delta` is
  3148. the cutoff between squared and absolute error regimes, it has
  3149. to be tuned carefully for each problem. `huber` is also
  3150. convex, making it suitable for gradient based optimization.
  3151. .. versionadded:: 0.15.0
  3152. References
  3153. ----------
  3154. .. [1] Peter Huber. "Robust Estimation of a Location Parameter",
  3155. 1964. Annals of Statistics. 53 (1): 73 - 101.
  3156. Examples
  3157. --------
  3158. Import all necessary modules.
  3159. >>> import numpy as np
  3160. >>> from scipy.special import huber
  3161. >>> import matplotlib.pyplot as plt
  3162. Compute the function for ``delta=1`` at ``r=2``
  3163. >>> huber(1., 2.)
  3164. 1.5
  3165. Compute the function for different `delta` by providing a NumPy array or
  3166. list for `delta`.
  3167. >>> huber([1., 3., 5.], 4.)
  3168. array([3.5, 7.5, 8. ])
  3169. Compute the function at different points by providing a NumPy array or
  3170. list for `r`.
  3171. >>> huber(2., np.array([1., 1.5, 3.]))
  3172. array([0.5 , 1.125, 4. ])
  3173. The function can be calculated for different `delta` and `r` by
  3174. providing arrays for both with compatible shapes for broadcasting.
  3175. >>> r = np.array([1., 2.5, 8., 10.])
  3176. >>> deltas = np.array([[1.], [5.], [9.]])
  3177. >>> print(r.shape, deltas.shape)
  3178. (4,) (3, 1)
  3179. >>> huber(deltas, r)
  3180. array([[ 0.5 , 2. , 7.5 , 9.5 ],
  3181. [ 0.5 , 3.125, 27.5 , 37.5 ],
  3182. [ 0.5 , 3.125, 32. , 49.5 ]])
  3183. Plot the function for different `delta`.
  3184. >>> x = np.linspace(-4, 4, 500)
  3185. >>> deltas = [1, 2, 3]
  3186. >>> linestyles = ["dashed", "dotted", "dashdot"]
  3187. >>> fig, ax = plt.subplots()
  3188. >>> combined_plot_parameters = list(zip(deltas, linestyles))
  3189. >>> for delta, style in combined_plot_parameters:
  3190. ... ax.plot(x, huber(delta, x), label=fr"$\delta={delta}$", ls=style)
  3191. >>> ax.legend(loc="upper center")
  3192. >>> ax.set_xlabel("$x$")
  3193. >>> ax.set_title(r"Huber loss function $h_{\delta}(x)$")
  3194. >>> ax.set_xlim(-4, 4)
  3195. >>> ax.set_ylim(0, 8)
  3196. >>> plt.show()
  3197. """)
  3198. add_newdoc("hyp0f1",
  3199. r"""
  3200. hyp0f1(v, z, out=None)
  3201. Confluent hypergeometric limit function 0F1.
  3202. Parameters
  3203. ----------
  3204. v : array_like
  3205. Real-valued parameter
  3206. z : array_like
  3207. Real- or complex-valued argument
  3208. out : ndarray, optional
  3209. Optional output array for the function results
  3210. Returns
  3211. -------
  3212. scalar or ndarray
  3213. The confluent hypergeometric limit function
  3214. Notes
  3215. -----
  3216. This function is defined as:
  3217. .. math:: _0F_1(v, z) = \sum_{k=0}^{\infty}\frac{z^k}{(v)_k k!}.
  3218. It's also the limit as :math:`q \to \infty` of :math:`_1F_1(q; v; z/q)`,
  3219. and satisfies the differential equation :math:`f''(z) + vf'(z) =
  3220. f(z)`. See [1]_ for more information.
  3221. References
  3222. ----------
  3223. .. [1] Wolfram MathWorld, "Confluent Hypergeometric Limit Function",
  3224. http://mathworld.wolfram.com/ConfluentHypergeometricLimitFunction.html
  3225. Examples
  3226. --------
  3227. >>> import numpy as np
  3228. >>> import scipy.special as sc
  3229. It is one when `z` is zero.
  3230. >>> sc.hyp0f1(1, 0)
  3231. 1.0
  3232. It is the limit of the confluent hypergeometric function as `q`
  3233. goes to infinity.
  3234. >>> q = np.array([1, 10, 100, 1000])
  3235. >>> v = 1
  3236. >>> z = 1
  3237. >>> sc.hyp1f1(q, v, z / q)
  3238. array([2.71828183, 2.31481985, 2.28303778, 2.27992985])
  3239. >>> sc.hyp0f1(v, z)
  3240. 2.2795853023360673
  3241. It is related to Bessel functions.
  3242. >>> n = 1
  3243. >>> x = np.linspace(0, 1, 5)
  3244. >>> sc.jv(n, x)
  3245. array([0. , 0.12402598, 0.24226846, 0.3492436 , 0.44005059])
  3246. >>> (0.5 * x)**n / sc.factorial(n) * sc.hyp0f1(n + 1, -0.25 * x**2)
  3247. array([0. , 0.12402598, 0.24226846, 0.3492436 , 0.44005059])
  3248. """)
  3249. add_newdoc("hyp1f1",
  3250. r"""
  3251. hyp1f1(a, b, x, out=None)
  3252. Confluent hypergeometric function 1F1.
  3253. The confluent hypergeometric function is defined by the series
  3254. .. math::
  3255. {}_1F_1(a; b; x) = \sum_{k = 0}^\infty \frac{(a)_k}{(b)_k k!} x^k.
  3256. See [DLMF]_ for more details. Here :math:`(\cdot)_k` is the
  3257. Pochhammer symbol; see `poch`.
  3258. Parameters
  3259. ----------
  3260. a, b : array_like
  3261. Real parameters
  3262. x : array_like
  3263. Real or complex argument
  3264. out : ndarray, optional
  3265. Optional output array for the function results
  3266. Returns
  3267. -------
  3268. scalar or ndarray
  3269. Values of the confluent hypergeometric function
  3270. See Also
  3271. --------
  3272. hyperu : another confluent hypergeometric function
  3273. hyp0f1 : confluent hypergeometric limit function
  3274. hyp2f1 : Gaussian hypergeometric function
  3275. Notes
  3276. -----
  3277. For real values, this function uses the ``hyp1f1`` routine from the C++ Boost
  3278. library [2]_, for complex values a C translation of the specfun
  3279. Fortran library [3]_.
  3280. References
  3281. ----------
  3282. .. [DLMF] NIST Digital Library of Mathematical Functions
  3283. https://dlmf.nist.gov/13.2#E2
  3284. .. [2] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
  3285. .. [3] Zhang, Jin, "Computation of Special Functions", John Wiley
  3286. and Sons, Inc, 1996.
  3287. Examples
  3288. --------
  3289. >>> import numpy as np
  3290. >>> import scipy.special as sc
  3291. It is one when `x` is zero:
  3292. >>> sc.hyp1f1(0.5, 0.5, 0)
  3293. 1.0
  3294. It is singular when `b` is a nonpositive integer.
  3295. >>> sc.hyp1f1(0.5, -1, 0)
  3296. inf
  3297. It is a polynomial when `a` is a nonpositive integer.
  3298. >>> a, b, x = -1, 0.5, np.array([1.0, 2.0, 3.0, 4.0])
  3299. >>> sc.hyp1f1(a, b, x)
  3300. array([-1., -3., -5., -7.])
  3301. >>> 1 + (a / b) * x
  3302. array([-1., -3., -5., -7.])
  3303. It reduces to the exponential function when ``a = b``.
  3304. >>> sc.hyp1f1(2, 2, [1, 2, 3, 4])
  3305. array([ 2.71828183, 7.3890561 , 20.08553692, 54.59815003])
  3306. >>> np.exp([1, 2, 3, 4])
  3307. array([ 2.71828183, 7.3890561 , 20.08553692, 54.59815003])
  3308. """)
  3309. add_newdoc("hyperu",
  3310. r"""
  3311. hyperu(a, b, x, out=None)
  3312. Confluent hypergeometric function U
  3313. It is defined as the solution to the equation
  3314. .. math::
  3315. x \frac{d^2w}{dx^2} + (b - x) \frac{dw}{dx} - aw = 0
  3316. which satisfies the property
  3317. .. math::
  3318. U(a, b, x) \sim x^{-a}
  3319. as :math:`x \to \infty`. See [DLMF]_ for more details.
  3320. Parameters
  3321. ----------
  3322. a, b : array_like
  3323. Real-valued parameters
  3324. x : array_like
  3325. Real-valued argument
  3326. out : ndarray, optional
  3327. Optional output array for the function values
  3328. Returns
  3329. -------
  3330. scalar or ndarray
  3331. Values of `U`
  3332. References
  3333. ----------
  3334. .. [DLMF] NIST Digital Library of Mathematics Functions
  3335. https://dlmf.nist.gov/13.2#E6
  3336. Examples
  3337. --------
  3338. >>> import numpy as np
  3339. >>> import scipy.special as sc
  3340. It has a branch cut along the negative `x` axis.
  3341. >>> x = np.linspace(-0.1, -10, 5)
  3342. >>> sc.hyperu(1, 1, x)
  3343. array([nan, nan, nan, nan, nan])
  3344. It approaches zero as `x` goes to infinity.
  3345. >>> x = np.array([1, 10, 100])
  3346. >>> sc.hyperu(1, 1, x)
  3347. array([0.59634736, 0.09156333, 0.00990194])
  3348. It satisfies Kummer's transformation.
  3349. >>> a, b, x = 2, 1, 1
  3350. >>> sc.hyperu(a, b, x)
  3351. 0.1926947246463881
  3352. >>> x**(1 - b) * sc.hyperu(a - b + 1, 2 - b, x)
  3353. 0.1926947246463881
  3354. """)
  3355. add_newdoc("_igam_fac",
  3356. """
  3357. Internal function, do not use.
  3358. """)
  3359. add_newdoc("kl_div",
  3360. r"""
  3361. kl_div(x, y, out=None)
  3362. Elementwise function for computing Kullback-Leibler divergence.
  3363. .. math::
  3364. \mathrm{kl\_div}(x, y) =
  3365. \begin{cases}
  3366. x \log(x / y) - x + y & x > 0, y > 0 \\
  3367. y & x = 0, y \ge 0 \\
  3368. \infty & \text{otherwise}
  3369. \end{cases}
  3370. Parameters
  3371. ----------
  3372. x, y : array_like
  3373. Real arguments
  3374. out : ndarray, optional
  3375. Optional output array for the function results
  3376. Returns
  3377. -------
  3378. scalar or ndarray
  3379. Values of the Kullback-Liebler divergence.
  3380. See Also
  3381. --------
  3382. entr, rel_entr, scipy.stats.entropy
  3383. Notes
  3384. -----
  3385. .. versionadded:: 0.15.0
  3386. This function is non-negative and is jointly convex in `x` and `y`.
  3387. The origin of this function is in convex programming; see [1]_ for
  3388. details. This is why the function contains the extra :math:`-x
  3389. + y` terms over what might be expected from the Kullback-Leibler
  3390. divergence. For a version of the function without the extra terms,
  3391. see `rel_entr`.
  3392. References
  3393. ----------
  3394. .. [1] Boyd, Stephen and Lieven Vandenberghe. *Convex optimization*.
  3395. Cambridge University Press, 2004.
  3396. :doi:`https://doi.org/10.1017/CBO9780511804441`
  3397. """)
  3398. add_newdoc("kn",
  3399. r"""
  3400. kn(n, x, out=None)
  3401. Modified Bessel function of the second kind of integer order `n`
  3402. Returns the modified Bessel function of the second kind for integer order
  3403. `n` at real `z`.
  3404. These are also sometimes called functions of the third kind, Basset
  3405. functions, or Macdonald functions.
  3406. Parameters
  3407. ----------
  3408. n : array_like of int
  3409. Order of Bessel functions (floats will truncate with a warning)
  3410. x : array_like of float
  3411. Argument at which to evaluate the Bessel functions
  3412. out : ndarray, optional
  3413. Optional output array for the function results.
  3414. Returns
  3415. -------
  3416. scalar or ndarray
  3417. Value of the Modified Bessel function of the second kind,
  3418. :math:`K_n(x)`.
  3419. See Also
  3420. --------
  3421. kv : Same function, but accepts real order and complex argument
  3422. kvp : Derivative of this function
  3423. Notes
  3424. -----
  3425. Wrapper for AMOS [1]_ routine `zbesk`. For a discussion of the
  3426. algorithm used, see [2]_ and the references therein.
  3427. References
  3428. ----------
  3429. .. [1] Donald E. Amos, "AMOS, A Portable Package for Bessel Functions
  3430. of a Complex Argument and Nonnegative Order",
  3431. http://netlib.org/amos/
  3432. .. [2] Donald E. Amos, "Algorithm 644: A portable package for Bessel
  3433. functions of a complex argument and nonnegative order", ACM
  3434. TOMS Vol. 12 Issue 3, Sept. 1986, p. 265
  3435. Examples
  3436. --------
  3437. Plot the function of several orders for real input:
  3438. >>> import numpy as np
  3439. >>> from scipy.special import kn
  3440. >>> import matplotlib.pyplot as plt
  3441. >>> x = np.linspace(0, 5, 1000)
  3442. >>> for N in range(6):
  3443. ... plt.plot(x, kn(N, x), label='$K_{}(x)$'.format(N))
  3444. >>> plt.ylim(0, 10)
  3445. >>> plt.legend()
  3446. >>> plt.title(r'Modified Bessel function of the second kind $K_n(x)$')
  3447. >>> plt.show()
  3448. Calculate for a single value at multiple orders:
  3449. >>> kn([4, 5, 6], 1)
  3450. array([ 44.23241585, 360.9605896 , 3653.83831186])
  3451. """)
  3452. add_newdoc("kolmogi",
  3453. """
  3454. kolmogi(p, out=None)
  3455. Inverse Survival Function of Kolmogorov distribution
  3456. It is the inverse function to `kolmogorov`.
  3457. Returns y such that ``kolmogorov(y) == p``.
  3458. Parameters
  3459. ----------
  3460. p : float array_like
  3461. Probability
  3462. out : ndarray, optional
  3463. Optional output array for the function results
  3464. Returns
  3465. -------
  3466. scalar or ndarray
  3467. The value(s) of kolmogi(p)
  3468. See Also
  3469. --------
  3470. kolmogorov : The Survival Function for the distribution
  3471. scipy.stats.kstwobign : Provides the functionality as a continuous distribution
  3472. smirnov, smirnovi : Functions for the one-sided distribution
  3473. Notes
  3474. -----
  3475. `kolmogorov` is used by `stats.kstest` in the application of the
  3476. Kolmogorov-Smirnov Goodness of Fit test. For historical reasons this
  3477. function is exposed in `scpy.special`, but the recommended way to achieve
  3478. the most accurate CDF/SF/PDF/PPF/ISF computations is to use the
  3479. `stats.kstwobign` distribution.
  3480. Examples
  3481. --------
  3482. >>> from scipy.special import kolmogi
  3483. >>> kolmogi([0, 0.1, 0.25, 0.5, 0.75, 0.9, 1.0])
  3484. array([ inf, 1.22384787, 1.01918472, 0.82757356, 0.67644769,
  3485. 0.57117327, 0. ])
  3486. """)
  3487. add_newdoc("kolmogorov",
  3488. r"""
  3489. kolmogorov(y, out=None)
  3490. Complementary cumulative distribution (Survival Function) function of
  3491. Kolmogorov distribution.
  3492. Returns the complementary cumulative distribution function of
  3493. Kolmogorov's limiting distribution (``D_n*\sqrt(n)`` as n goes to infinity)
  3494. of a two-sided test for equality between an empirical and a theoretical
  3495. distribution. It is equal to the (limit as n->infinity of the)
  3496. probability that ``sqrt(n) * max absolute deviation > y``.
  3497. Parameters
  3498. ----------
  3499. y : float array_like
  3500. Absolute deviation between the Empirical CDF (ECDF) and the target CDF,
  3501. multiplied by sqrt(n).
  3502. out : ndarray, optional
  3503. Optional output array for the function results
  3504. Returns
  3505. -------
  3506. scalar or ndarray
  3507. The value(s) of kolmogorov(y)
  3508. See Also
  3509. --------
  3510. kolmogi : The Inverse Survival Function for the distribution
  3511. scipy.stats.kstwobign : Provides the functionality as a continuous distribution
  3512. smirnov, smirnovi : Functions for the one-sided distribution
  3513. Notes
  3514. -----
  3515. `kolmogorov` is used by `stats.kstest` in the application of the
  3516. Kolmogorov-Smirnov Goodness of Fit test. For historical reasons this
  3517. function is exposed in `scpy.special`, but the recommended way to achieve
  3518. the most accurate CDF/SF/PDF/PPF/ISF computations is to use the
  3519. `stats.kstwobign` distribution.
  3520. Examples
  3521. --------
  3522. Show the probability of a gap at least as big as 0, 0.5 and 1.0.
  3523. >>> import numpy as np
  3524. >>> from scipy.special import kolmogorov
  3525. >>> from scipy.stats import kstwobign
  3526. >>> kolmogorov([0, 0.5, 1.0])
  3527. array([ 1. , 0.96394524, 0.26999967])
  3528. Compare a sample of size 1000 drawn from a Laplace(0, 1) distribution against
  3529. the target distribution, a Normal(0, 1) distribution.
  3530. >>> from scipy.stats import norm, laplace
  3531. >>> rng = np.random.default_rng()
  3532. >>> n = 1000
  3533. >>> lap01 = laplace(0, 1)
  3534. >>> x = np.sort(lap01.rvs(n, random_state=rng))
  3535. >>> np.mean(x), np.std(x)
  3536. (-0.05841730131499543, 1.3968109101997568)
  3537. Construct the Empirical CDF and the K-S statistic Dn.
  3538. >>> target = norm(0,1) # Normal mean 0, stddev 1
  3539. >>> cdfs = target.cdf(x)
  3540. >>> ecdfs = np.arange(n+1, dtype=float)/n
  3541. >>> gaps = np.column_stack([cdfs - ecdfs[:n], ecdfs[1:] - cdfs])
  3542. >>> Dn = np.max(gaps)
  3543. >>> Kn = np.sqrt(n) * Dn
  3544. >>> print('Dn=%f, sqrt(n)*Dn=%f' % (Dn, Kn))
  3545. Dn=0.043363, sqrt(n)*Dn=1.371265
  3546. >>> print(chr(10).join(['For a sample of size n drawn from a N(0, 1) distribution:',
  3547. ... ' the approximate Kolmogorov probability that sqrt(n)*Dn>=%f is %f' %
  3548. ... (Kn, kolmogorov(Kn)),
  3549. ... ' the approximate Kolmogorov probability that sqrt(n)*Dn<=%f is %f' %
  3550. ... (Kn, kstwobign.cdf(Kn))]))
  3551. For a sample of size n drawn from a N(0, 1) distribution:
  3552. the approximate Kolmogorov probability that sqrt(n)*Dn>=1.371265 is 0.046533
  3553. the approximate Kolmogorov probability that sqrt(n)*Dn<=1.371265 is 0.953467
  3554. Plot the Empirical CDF against the target N(0, 1) CDF.
  3555. >>> import matplotlib.pyplot as plt
  3556. >>> plt.step(np.concatenate([[-3], x]), ecdfs, where='post', label='Empirical CDF')
  3557. >>> x3 = np.linspace(-3, 3, 100)
  3558. >>> plt.plot(x3, target.cdf(x3), label='CDF for N(0, 1)')
  3559. >>> plt.ylim([0, 1]); plt.grid(True); plt.legend();
  3560. >>> # Add vertical lines marking Dn+ and Dn-
  3561. >>> iminus, iplus = np.argmax(gaps, axis=0)
  3562. >>> plt.vlines([x[iminus]], ecdfs[iminus], cdfs[iminus],
  3563. ... color='r', linestyle='dashed', lw=4)
  3564. >>> plt.vlines([x[iplus]], cdfs[iplus], ecdfs[iplus+1],
  3565. ... color='r', linestyle='dashed', lw=4)
  3566. >>> plt.show()
  3567. """)
  3568. add_newdoc("_kolmogc",
  3569. r"""
  3570. Internal function, do not use.
  3571. """)
  3572. add_newdoc("_kolmogci",
  3573. r"""
  3574. Internal function, do not use.
  3575. """)
  3576. add_newdoc("_kolmogp",
  3577. r"""
  3578. Internal function, do not use.
  3579. """)
  3580. add_newdoc("_lanczos_sum_expg_scaled",
  3581. """
  3582. Internal function, do not use.
  3583. """)
  3584. add_newdoc(
  3585. "_landau_pdf",
  3586. """
  3587. _landau_pdf(x, loc, scale)
  3588. Probability density function of the Landau distribution.
  3589. Parameters
  3590. ----------
  3591. x : array_like
  3592. Real-valued argument
  3593. loc : array_like
  3594. Real-valued distribution location
  3595. scale : array_like
  3596. Positive, real-valued distribution scale
  3597. Returns
  3598. -------
  3599. scalar or ndarray
  3600. """)
  3601. add_newdoc(
  3602. "_landau_cdf",
  3603. """
  3604. _landau_cdf(x, loc, scale)
  3605. Cumulative distribution function of the Landau distribution.
  3606. Parameters
  3607. ----------
  3608. x : array_like
  3609. Real-valued argument
  3610. loc : array_like
  3611. Real-valued distribution location
  3612. scale : array_like
  3613. Positive, real-valued distribution scale
  3614. Returns
  3615. -------
  3616. scalar or ndarray
  3617. """)
  3618. add_newdoc(
  3619. "_landau_sf",
  3620. """
  3621. _landau_sf(x, loc, scale)
  3622. Survival function of the Landau distribution.
  3623. Parameters
  3624. ----------
  3625. x : array_like
  3626. Real-valued argument
  3627. loc : array_like
  3628. Real-valued distribution location
  3629. scale : array_like
  3630. Positive, real-valued distribution scale
  3631. Returns
  3632. -------
  3633. scalar or ndarray
  3634. """)
  3635. add_newdoc(
  3636. "_landau_ppf",
  3637. """
  3638. _landau_ppf(p, loc, scale)
  3639. Percent point function of the Landau distribution.
  3640. Parameters
  3641. ----------
  3642. p : array_like
  3643. Real-valued argument between 0 and 1
  3644. loc : array_like
  3645. Real-valued distribution location
  3646. scale : array_like
  3647. Positive, real-valued distribution scale
  3648. Returns
  3649. -------
  3650. scalar or ndarray
  3651. """)
  3652. add_newdoc(
  3653. "_landau_isf",
  3654. """
  3655. _landau_isf(p, loc, scale)
  3656. Inverse survival function of the Landau distribution.
  3657. Parameters
  3658. ----------
  3659. p : array_like
  3660. Real-valued argument between 0 and 1
  3661. loc : array_like
  3662. Real-valued distribution location
  3663. scale : array_like
  3664. Positive, real-valued distribution scale
  3665. Returns
  3666. -------
  3667. scalar or ndarray
  3668. """)
  3669. add_newdoc("_lgam1p",
  3670. """
  3671. Internal function, do not use.
  3672. """)
  3673. add_newdoc("lpmv",
  3674. r"""
  3675. lpmv(m, v, x, out=None)
  3676. Associated Legendre function of integer order and real degree.
  3677. Defined as
  3678. .. math::
  3679. P_v^m = (-1)^m (1 - x^2)^{m/2} \frac{d^m}{dx^m} P_v(x)
  3680. where
  3681. .. math::
  3682. P_v = \sum_{k = 0}^\infty \frac{(-v)_k (v + 1)_k}{(k!)^2}
  3683. \left(\frac{1 - x}{2}\right)^k
  3684. is the Legendre function of the first kind. Here :math:`(\cdot)_k`
  3685. is the Pochhammer symbol; see `poch`.
  3686. Parameters
  3687. ----------
  3688. m : array_like
  3689. Order (int or float). If passed a float not equal to an
  3690. integer the function returns NaN.
  3691. v : array_like
  3692. Degree (float).
  3693. x : array_like
  3694. Argument (float). Must have ``|x| <= 1``.
  3695. out : ndarray, optional
  3696. Optional output array for the function results
  3697. Returns
  3698. -------
  3699. pmv : scalar or ndarray
  3700. Value of the associated Legendre function.
  3701. Notes
  3702. -----
  3703. Note that this implementation includes the Condon-Shortley phase.
  3704. References
  3705. ----------
  3706. .. [1] Zhang, Jin, "Computation of Special Functions", John Wiley
  3707. and Sons, Inc, 1996.
  3708. """)
  3709. add_newdoc("nbdtr",
  3710. r"""
  3711. nbdtr(k, n, p, out=None)
  3712. Negative binomial cumulative distribution function.
  3713. Returns the sum of the terms 0 through `k` of the negative binomial
  3714. distribution probability mass function,
  3715. .. math::
  3716. F = \sum_{j=0}^k {{n + j - 1}\choose{j}} p^n (1 - p)^j.
  3717. In a sequence of Bernoulli trials with individual success probabilities
  3718. `p`, this is the probability that `k` or fewer failures precede the nth
  3719. success.
  3720. Parameters
  3721. ----------
  3722. k : array_like
  3723. The maximum number of allowed failures (nonnegative int).
  3724. n : array_like
  3725. The target number of successes (positive int).
  3726. p : array_like
  3727. Probability of success in a single event (float).
  3728. out : ndarray, optional
  3729. Optional output array for the function results
  3730. Returns
  3731. -------
  3732. F : scalar or ndarray
  3733. The probability of `k` or fewer failures before `n` successes in a
  3734. sequence of events with individual success probability `p`.
  3735. See Also
  3736. --------
  3737. nbdtrc : Negative binomial survival function
  3738. nbdtrik : Negative binomial quantile function
  3739. scipy.stats.nbinom : Negative binomial distribution
  3740. Notes
  3741. -----
  3742. If floating point values are passed for `k` or `n`, they will be truncated
  3743. to integers.
  3744. The terms are not summed directly; instead the regularized incomplete beta
  3745. function is employed, according to the formula,
  3746. .. math::
  3747. \mathrm{nbdtr}(k, n, p) = I_{p}(n, k + 1).
  3748. Wrapper for the Cephes [1]_ routine `nbdtr`.
  3749. The negative binomial distribution is also available as
  3750. `scipy.stats.nbinom`. Using `nbdtr` directly can improve performance
  3751. compared to the ``cdf`` method of `scipy.stats.nbinom` (see last example).
  3752. References
  3753. ----------
  3754. .. [1] Cephes Mathematical Functions Library,
  3755. http://www.netlib.org/cephes/
  3756. Examples
  3757. --------
  3758. Compute the function for ``k=10`` and ``n=5`` at ``p=0.5``.
  3759. >>> import numpy as np
  3760. >>> from scipy.special import nbdtr
  3761. >>> nbdtr(10, 5, 0.5)
  3762. 0.940765380859375
  3763. Compute the function for ``n=10`` and ``p=0.5`` at several points by
  3764. providing a NumPy array or list for `k`.
  3765. >>> nbdtr([5, 10, 15], 10, 0.5)
  3766. array([0.15087891, 0.58809853, 0.88523853])
  3767. Plot the function for four different parameter sets.
  3768. >>> import matplotlib.pyplot as plt
  3769. >>> k = np.arange(130)
  3770. >>> n_parameters = [20, 20, 20, 80]
  3771. >>> p_parameters = [0.2, 0.5, 0.8, 0.5]
  3772. >>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
  3773. >>> parameters_list = list(zip(p_parameters, n_parameters,
  3774. ... linestyles))
  3775. >>> fig, ax = plt.subplots(figsize=(8, 8))
  3776. >>> for parameter_set in parameters_list:
  3777. ... p, n, style = parameter_set
  3778. ... nbdtr_vals = nbdtr(k, n, p)
  3779. ... ax.plot(k, nbdtr_vals, label=rf"$n={n},\, p={p}$",
  3780. ... ls=style)
  3781. >>> ax.legend()
  3782. >>> ax.set_xlabel("$k$")
  3783. >>> ax.set_title("Negative binomial cumulative distribution function")
  3784. >>> plt.show()
  3785. The negative binomial distribution is also available as
  3786. `scipy.stats.nbinom`. Using `nbdtr` directly can be much faster than
  3787. calling the ``cdf`` method of `scipy.stats.nbinom`, especially for small
  3788. arrays or individual values. To get the same results one must use the
  3789. following parametrization: ``nbinom(n, p).cdf(k)=nbdtr(k, n, p)``.
  3790. >>> from scipy.stats import nbinom
  3791. >>> k, n, p = 5, 3, 0.5
  3792. >>> nbdtr_res = nbdtr(k, n, p) # this will often be faster than below
  3793. >>> stats_res = nbinom(n, p).cdf(k)
  3794. >>> stats_res, nbdtr_res # test that results are equal
  3795. (0.85546875, 0.85546875)
  3796. `nbdtr` can evaluate different parameter sets by providing arrays with
  3797. shapes compatible for broadcasting for `k`, `n` and `p`. Here we compute
  3798. the function for three different `k` at four locations `p`, resulting in
  3799. a 3x4 array.
  3800. >>> k = np.array([[5], [10], [15]])
  3801. >>> p = np.array([0.3, 0.5, 0.7, 0.9])
  3802. >>> k.shape, p.shape
  3803. ((3, 1), (4,))
  3804. >>> nbdtr(k, 5, p)
  3805. array([[0.15026833, 0.62304687, 0.95265101, 0.9998531 ],
  3806. [0.48450894, 0.94076538, 0.99932777, 0.99999999],
  3807. [0.76249222, 0.99409103, 0.99999445, 1. ]])
  3808. """)
  3809. add_newdoc("nbdtrc",
  3810. r"""
  3811. nbdtrc(k, n, p, out=None)
  3812. Negative binomial survival function.
  3813. Returns the sum of the terms `k + 1` to infinity of the negative binomial
  3814. distribution probability mass function,
  3815. .. math::
  3816. F = \sum_{j=k + 1}^\infty {{n + j - 1}\choose{j}} p^n (1 - p)^j.
  3817. In a sequence of Bernoulli trials with individual success probabilities
  3818. `p`, this is the probability that more than `k` failures precede the nth
  3819. success.
  3820. Parameters
  3821. ----------
  3822. k : array_like
  3823. The maximum number of allowed failures (nonnegative int).
  3824. n : array_like
  3825. The target number of successes (positive int).
  3826. p : array_like
  3827. Probability of success in a single event (float).
  3828. out : ndarray, optional
  3829. Optional output array for the function results
  3830. Returns
  3831. -------
  3832. F : scalar or ndarray
  3833. The probability of `k + 1` or more failures before `n` successes in a
  3834. sequence of events with individual success probability `p`.
  3835. See Also
  3836. --------
  3837. nbdtr : Negative binomial cumulative distribution function
  3838. nbdtrik : Negative binomial percentile function
  3839. scipy.stats.nbinom : Negative binomial distribution
  3840. Notes
  3841. -----
  3842. If floating point values are passed for `k` or `n`, they will be truncated
  3843. to integers.
  3844. The terms are not summed directly; instead the regularized incomplete beta
  3845. function is employed, according to the formula,
  3846. .. math::
  3847. \mathrm{nbdtrc}(k, n, p) = I_{1 - p}(k + 1, n).
  3848. Wrapper for the Cephes [1]_ routine `nbdtrc`.
  3849. The negative binomial distribution is also available as
  3850. `scipy.stats.nbinom`. Using `nbdtrc` directly can improve performance
  3851. compared to the ``sf`` method of `scipy.stats.nbinom` (see last example).
  3852. References
  3853. ----------
  3854. .. [1] Cephes Mathematical Functions Library,
  3855. http://www.netlib.org/cephes/
  3856. Examples
  3857. --------
  3858. Compute the function for ``k=10`` and ``n=5`` at ``p=0.5``.
  3859. >>> import numpy as np
  3860. >>> from scipy.special import nbdtrc
  3861. >>> nbdtrc(10, 5, 0.5)
  3862. 0.059234619140624986
  3863. Compute the function for ``n=10`` and ``p=0.5`` at several points by
  3864. providing a NumPy array or list for `k`.
  3865. >>> nbdtrc([5, 10, 15], 10, 0.5)
  3866. array([0.84912109, 0.41190147, 0.11476147])
  3867. Plot the function for four different parameter sets.
  3868. >>> import matplotlib.pyplot as plt
  3869. >>> k = np.arange(130)
  3870. >>> n_parameters = [20, 20, 20, 80]
  3871. >>> p_parameters = [0.2, 0.5, 0.8, 0.5]
  3872. >>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
  3873. >>> parameters_list = list(zip(p_parameters, n_parameters,
  3874. ... linestyles))
  3875. >>> fig, ax = plt.subplots(figsize=(8, 8))
  3876. >>> for parameter_set in parameters_list:
  3877. ... p, n, style = parameter_set
  3878. ... nbdtrc_vals = nbdtrc(k, n, p)
  3879. ... ax.plot(k, nbdtrc_vals, label=rf"$n={n},\, p={p}$",
  3880. ... ls=style)
  3881. >>> ax.legend()
  3882. >>> ax.set_xlabel("$k$")
  3883. >>> ax.set_title("Negative binomial distribution survival function")
  3884. >>> plt.show()
  3885. The negative binomial distribution is also available as
  3886. `scipy.stats.nbinom`. Using `nbdtrc` directly can be much faster than
  3887. calling the ``sf`` method of `scipy.stats.nbinom`, especially for small
  3888. arrays or individual values. To get the same results one must use the
  3889. following parametrization: ``nbinom(n, p).sf(k)=nbdtrc(k, n, p)``.
  3890. >>> from scipy.stats import nbinom
  3891. >>> k, n, p = 3, 5, 0.5
  3892. >>> nbdtr_res = nbdtrc(k, n, p) # this will often be faster than below
  3893. >>> stats_res = nbinom(n, p).sf(k)
  3894. >>> stats_res, nbdtr_res # test that results are equal
  3895. (0.6367187499999999, 0.6367187499999999)
  3896. `nbdtrc` can evaluate different parameter sets by providing arrays with
  3897. shapes compatible for broadcasting for `k`, `n` and `p`. Here we compute
  3898. the function for three different `k` at four locations `p`, resulting in
  3899. a 3x4 array.
  3900. >>> k = np.array([[5], [10], [15]])
  3901. >>> p = np.array([0.3, 0.5, 0.7, 0.9])
  3902. >>> k.shape, p.shape
  3903. ((3, 1), (4,))
  3904. >>> nbdtrc(k, 5, p)
  3905. array([[8.49731667e-01, 3.76953125e-01, 4.73489874e-02, 1.46902600e-04],
  3906. [5.15491059e-01, 5.92346191e-02, 6.72234070e-04, 9.29610100e-09],
  3907. [2.37507779e-01, 5.90896606e-03, 5.55025308e-06, 3.26346760e-13]])
  3908. """)
  3909. add_newdoc(
  3910. "nbdtri",
  3911. r"""
  3912. nbdtri(k, n, y, out=None)
  3913. Returns the inverse with respect to the parameter `p` of
  3914. ``y = nbdtr(k, n, p)``, the negative binomial cumulative distribution
  3915. function.
  3916. Parameters
  3917. ----------
  3918. k : array_like
  3919. The maximum number of allowed failures (nonnegative int).
  3920. n : array_like
  3921. The target number of successes (positive int).
  3922. y : array_like
  3923. The probability of `k` or fewer failures before `n` successes (float).
  3924. out : ndarray, optional
  3925. Optional output array for the function results
  3926. Returns
  3927. -------
  3928. p : scalar or ndarray
  3929. Probability of success in a single event (float) such that
  3930. `nbdtr(k, n, p) = y`.
  3931. See Also
  3932. --------
  3933. nbdtr : Cumulative distribution function of the negative binomial.
  3934. nbdtrc : Negative binomial survival function.
  3935. scipy.stats.nbinom : negative binomial distribution.
  3936. nbdtrik : Inverse with respect to `k` of `nbdtr(k, n, p)`.
  3937. nbdtrin : Inverse with respect to `n` of `nbdtr(k, n, p)`.
  3938. scipy.stats.nbinom : Negative binomial distribution
  3939. Notes
  3940. -----
  3941. Wrapper for the Cephes [1]_ routine `nbdtri`.
  3942. The negative binomial distribution is also available as
  3943. `scipy.stats.nbinom`. Using `nbdtri` directly can improve performance
  3944. compared to the ``ppf`` method of `scipy.stats.nbinom`.
  3945. References
  3946. ----------
  3947. .. [1] Cephes Mathematical Functions Library,
  3948. http://www.netlib.org/cephes/
  3949. Examples
  3950. --------
  3951. `nbdtri` is the inverse of `nbdtr` with respect to `p`.
  3952. Up to floating point errors the following holds:
  3953. ``nbdtri(k, n, nbdtr(k, n, p))=p``.
  3954. >>> import numpy as np
  3955. >>> from scipy.special import nbdtri, nbdtr
  3956. >>> k, n, y = 5, 10, 0.2
  3957. >>> cdf_val = nbdtr(k, n, y)
  3958. >>> nbdtri(k, n, cdf_val)
  3959. 0.20000000000000004
  3960. Compute the function for ``k=10`` and ``n=5`` at several points by
  3961. providing a NumPy array or list for `y`.
  3962. >>> y = np.array([0.1, 0.4, 0.8])
  3963. >>> nbdtri(3, 5, y)
  3964. array([0.34462319, 0.51653095, 0.69677416])
  3965. Plot the function for three different parameter sets.
  3966. >>> import matplotlib.pyplot as plt
  3967. >>> n_parameters = [5, 20, 30, 30]
  3968. >>> k_parameters = [20, 20, 60, 80]
  3969. >>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
  3970. >>> parameters_list = list(zip(n_parameters, k_parameters, linestyles))
  3971. >>> cdf_vals = np.linspace(0, 1, 1000)
  3972. >>> fig, ax = plt.subplots(figsize=(8, 8))
  3973. >>> for parameter_set in parameters_list:
  3974. ... n, k, style = parameter_set
  3975. ... nbdtri_vals = nbdtri(k, n, cdf_vals)
  3976. ... ax.plot(cdf_vals, nbdtri_vals, label=rf"$k={k},\ n={n}$",
  3977. ... ls=style)
  3978. >>> ax.legend()
  3979. >>> ax.set_ylabel("$p$")
  3980. >>> ax.set_xlabel("$CDF$")
  3981. >>> title = "nbdtri: inverse of negative binomial CDF with respect to $p$"
  3982. >>> ax.set_title(title)
  3983. >>> plt.show()
  3984. `nbdtri` can evaluate different parameter sets by providing arrays with
  3985. shapes compatible for broadcasting for `k`, `n` and `p`. Here we compute
  3986. the function for three different `k` at four locations `p`, resulting in
  3987. a 3x4 array.
  3988. >>> k = np.array([[5], [10], [15]])
  3989. >>> y = np.array([0.3, 0.5, 0.7, 0.9])
  3990. >>> k.shape, y.shape
  3991. ((3, 1), (4,))
  3992. >>> nbdtri(k, 5, y)
  3993. array([[0.37258157, 0.45169416, 0.53249956, 0.64578407],
  3994. [0.24588501, 0.30451981, 0.36778453, 0.46397088],
  3995. [0.18362101, 0.22966758, 0.28054743, 0.36066188]])
  3996. """)
  3997. add_newdoc("nbdtrik",
  3998. r"""
  3999. nbdtrik(y, n, p, out=None)
  4000. Negative binomial percentile function.
  4001. Returns the inverse with respect to the parameter `k` of
  4002. ``y = nbdtr(k, n, p)``, the negative binomial cumulative distribution
  4003. function.
  4004. Parameters
  4005. ----------
  4006. y : array_like
  4007. The probability of `k` or fewer failures before `n` successes (float).
  4008. n : array_like
  4009. The target number of successes (positive int).
  4010. p : array_like
  4011. Probability of success in a single event (float).
  4012. out : ndarray, optional
  4013. Optional output array for the function results
  4014. Returns
  4015. -------
  4016. k : scalar or ndarray
  4017. The maximum number of allowed failures such that `nbdtr(k, n, p) = y`.
  4018. See Also
  4019. --------
  4020. nbdtr : Cumulative distribution function of the negative binomial.
  4021. nbdtrc : Survival function of the negative binomial.
  4022. nbdtri : Inverse with respect to `p` of `nbdtr(k, n, p)`.
  4023. nbdtrin : Inverse with respect to `n` of `nbdtr(k, n, p)`.
  4024. scipy.stats.nbinom : Negative binomial distribution
  4025. Notes
  4026. -----
  4027. Wrapper for the CDFLIB [1]_ Fortran routine `cdfnbn`.
  4028. Formula 26.5.26 of [2]_ or [3]_,
  4029. .. math::
  4030. \sum_{j=k + 1}^\infty {{n + j - 1}
  4031. \choose{j}} p^n (1 - p)^j = I_{1 - p}(k + 1, n),
  4032. is used to reduce calculation of the cumulative distribution function to
  4033. that of a regularized incomplete beta :math:`I`.
  4034. Computation of `k` involves a search for a value that produces the desired
  4035. value of `y`. The search relies on the monotonicity of `y` with `k`.
  4036. References
  4037. ----------
  4038. .. [1] Barry Brown, James Lovato, and Kathy Russell,
  4039. CDFLIB: Library of Fortran Routines for Cumulative Distribution
  4040. Functions, Inverses, and Other Parameters.
  4041. .. [2] Milton Abramowitz and Irene A. Stegun, eds.
  4042. Handbook of Mathematical Functions with Formulas,
  4043. Graphs, and Mathematical Tables. New York: Dover, 1972.
  4044. .. [3] NIST Digital Library of Mathematical Functions
  4045. https://dlmf.nist.gov/8.17.E24
  4046. Examples
  4047. --------
  4048. Compute the negative binomial cumulative distribution function for an
  4049. exemplary parameter set.
  4050. >>> import numpy as np
  4051. >>> from scipy.special import nbdtr, nbdtrik
  4052. >>> k, n, p = 5, 2, 0.5
  4053. >>> cdf_value = nbdtr(k, n, p)
  4054. >>> cdf_value
  4055. 0.9375
  4056. Verify that `nbdtrik` recovers the original value for `k`.
  4057. >>> nbdtrik(cdf_value, n, p)
  4058. 5.0
  4059. Plot the function for different parameter sets.
  4060. >>> import matplotlib.pyplot as plt
  4061. >>> p_parameters = [0.2, 0.5, 0.7, 0.5]
  4062. >>> n_parameters = [30, 30, 30, 80]
  4063. >>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
  4064. >>> parameters_list = list(zip(p_parameters, n_parameters, linestyles))
  4065. >>> cdf_vals = np.linspace(0, 1, 1000)
  4066. >>> fig, ax = plt.subplots(figsize=(8, 8))
  4067. >>> for parameter_set in parameters_list:
  4068. ... p, n, style = parameter_set
  4069. ... nbdtrik_vals = nbdtrik(cdf_vals, n, p)
  4070. ... ax.plot(cdf_vals, nbdtrik_vals, label=rf"$n={n},\ p={p}$",
  4071. ... ls=style)
  4072. >>> ax.legend()
  4073. >>> ax.set_ylabel("$k$")
  4074. >>> ax.set_xlabel("$CDF$")
  4075. >>> ax.set_title("Negative binomial percentile function")
  4076. >>> plt.show()
  4077. The negative binomial distribution is also available as
  4078. `scipy.stats.nbinom`. The percentile function method ``ppf``
  4079. returns the result of `nbdtrik` rounded up to integers:
  4080. >>> from scipy.stats import nbinom
  4081. >>> q, n, p = 0.6, 5, 0.5
  4082. >>> nbinom.ppf(q, n, p), nbdtrik(q, n, p)
  4083. (5.0, 4.800428460273882)
  4084. """)
  4085. add_newdoc("nbdtrin",
  4086. r"""
  4087. nbdtrin(k, y, p, out=None)
  4088. Inverse of `nbdtr` vs `n`.
  4089. Returns the inverse with respect to the parameter `n` of
  4090. ``y = nbdtr(k, n, p)``, the negative binomial cumulative distribution
  4091. function.
  4092. Parameters
  4093. ----------
  4094. k : array_like
  4095. The maximum number of allowed failures (nonnegative int).
  4096. y : array_like
  4097. The probability of `k` or fewer failures before `n` successes (float).
  4098. p : array_like
  4099. Probability of success in a single event (float).
  4100. out : ndarray, optional
  4101. Optional output array for the function results
  4102. Returns
  4103. -------
  4104. n : scalar or ndarray
  4105. The number of successes `n` such that `nbdtr(k, n, p) = y`.
  4106. See Also
  4107. --------
  4108. nbdtr : Cumulative distribution function of the negative binomial.
  4109. nbdtri : Inverse with respect to `p` of `nbdtr(k, n, p)`.
  4110. nbdtrik : Inverse with respect to `k` of `nbdtr(k, n, p)`.
  4111. Notes
  4112. -----
  4113. Wrapper for the CDFLIB [1]_ Fortran routine `cdfnbn`.
  4114. Formula 26.5.26 of [2]_ or [3]_,
  4115. .. math::
  4116. \sum_{j=k + 1}^\infty {{n + j - 1}
  4117. \choose{j}} p^n (1 - p)^j = I_{1 - p}(k + 1, n),
  4118. is used to reduce calculation of the cumulative distribution function to
  4119. that of a regularized incomplete beta :math:`I`.
  4120. Computation of `n` involves a search for a value that produces the desired
  4121. value of `y`. The search relies on the monotonicity of `y` with `n`.
  4122. References
  4123. ----------
  4124. .. [1] Barry Brown, James Lovato, and Kathy Russell,
  4125. CDFLIB: Library of Fortran Routines for Cumulative Distribution
  4126. Functions, Inverses, and Other Parameters.
  4127. .. [2] Milton Abramowitz and Irene A. Stegun, eds.
  4128. Handbook of Mathematical Functions with Formulas,
  4129. Graphs, and Mathematical Tables. New York: Dover, 1972.
  4130. .. [3] NIST Digital Library of Mathematical Functions
  4131. https://dlmf.nist.gov/8.17.E24
  4132. Examples
  4133. --------
  4134. Compute the negative binomial cumulative distribution function for an
  4135. exemplary parameter set.
  4136. >>> from scipy.special import nbdtr, nbdtrin
  4137. >>> k, n, p = 5, 2, 0.5
  4138. >>> cdf_value = nbdtr(k, n, p)
  4139. >>> cdf_value
  4140. 0.9375
  4141. Verify that `nbdtrin` recovers the original value for `n` up to floating
  4142. point accuracy.
  4143. >>> nbdtrin(k, cdf_value, p)
  4144. 1.999999999998137
  4145. """)
  4146. add_newdoc("ncfdtr",
  4147. r"""
  4148. ncfdtr(dfn, dfd, nc, f, out=None)
  4149. Cumulative distribution function of the non-central F distribution.
  4150. The non-central F describes the distribution of,
  4151. .. math::
  4152. Z = \frac{X/d_n}{Y/d_d}
  4153. where :math:`X` and :math:`Y` are independently distributed, with
  4154. :math:`X` distributed non-central :math:`\chi^2` with noncentrality
  4155. parameter `nc` and :math:`d_n` degrees of freedom, and :math:`Y`
  4156. distributed :math:`\chi^2` with :math:`d_d` degrees of freedom.
  4157. Parameters
  4158. ----------
  4159. dfn : array_like
  4160. Degrees of freedom of the numerator sum of squares. Range (0, inf).
  4161. dfd : array_like
  4162. Degrees of freedom of the denominator sum of squares. Range (0, inf).
  4163. nc : array_like
  4164. Noncentrality parameter. Range [0, inf).
  4165. f : array_like
  4166. Quantiles, i.e. the upper limit of integration.
  4167. out : ndarray, optional
  4168. Optional output array for the function results
  4169. Returns
  4170. -------
  4171. cdf : scalar or ndarray
  4172. The calculated CDF. If all inputs are scalar, the return will be a
  4173. float. Otherwise it will be an array.
  4174. See Also
  4175. --------
  4176. ncfdtri : Quantile function; inverse of `ncfdtr` with respect to `f`.
  4177. ncfdtridfd : Inverse of `ncfdtr` with respect to `dfd`.
  4178. ncfdtridfn : Inverse of `ncfdtr` with respect to `dfn`.
  4179. ncfdtrinc : Inverse of `ncfdtr` with respect to `nc`.
  4180. scipy.stats.ncf : Non-central F distribution.
  4181. Notes
  4182. -----
  4183. This function calculates the CDF of the non-central f distribution using
  4184. the Boost Math C++ library [1]_.
  4185. The cumulative distribution function is computed using Formula 26.6.20 of
  4186. [2]_:
  4187. .. math::
  4188. F(d_n, d_d, n_c, f) = \sum_{j=0}^\infty e^{-n_c/2}
  4189. \frac{(n_c/2)^j}{j!} I_{x}(\frac{d_n}{2} + j, \frac{d_d}{2}),
  4190. where :math:`I` is the regularized incomplete beta function, and
  4191. :math:`x = f d_n/(f d_n + d_d)`.
  4192. Note that argument order of `ncfdtr` is different from that of the
  4193. similar ``cdf`` method of `scipy.stats.ncf`: `f` is the last
  4194. parameter of `ncfdtr` but the first parameter of ``scipy.stats.ncf.cdf``.
  4195. References
  4196. ----------
  4197. .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
  4198. .. [2] Milton Abramowitz and Irene A. Stegun, eds.
  4199. Handbook of Mathematical Functions with Formulas,
  4200. Graphs, and Mathematical Tables. New York: Dover, 1972.
  4201. Examples
  4202. --------
  4203. >>> import numpy as np
  4204. >>> from scipy import special
  4205. >>> from scipy import stats
  4206. >>> import matplotlib.pyplot as plt
  4207. Plot the CDF of the non-central F distribution, for nc=0. Compare with the
  4208. F-distribution from scipy.stats:
  4209. >>> x = np.linspace(-1, 8, num=500)
  4210. >>> dfn = 3
  4211. >>> dfd = 2
  4212. >>> ncf_stats = stats.f.cdf(x, dfn, dfd)
  4213. >>> ncf_special = special.ncfdtr(dfn, dfd, 0, x)
  4214. >>> fig = plt.figure()
  4215. >>> ax = fig.add_subplot(111)
  4216. >>> ax.plot(x, ncf_stats, 'b-', lw=3)
  4217. >>> ax.plot(x, ncf_special, 'r-')
  4218. >>> plt.show()
  4219. """)
  4220. add_newdoc("ncfdtri",
  4221. """
  4222. ncfdtri(dfn, dfd, nc, p, out=None)
  4223. Inverse with respect to `f` of the CDF of the non-central F distribution.
  4224. See `ncfdtr` for more details.
  4225. Parameters
  4226. ----------
  4227. dfn : array_like
  4228. Degrees of freedom of the numerator sum of squares. Range (0, inf).
  4229. dfd : array_like
  4230. Degrees of freedom of the denominator sum of squares. Range (0, inf).
  4231. nc : array_like
  4232. Noncentrality parameter. Range [0, inf).
  4233. p : array_like
  4234. Value of the cumulative distribution function. Must be in the
  4235. range [0, 1].
  4236. out : ndarray, optional
  4237. Optional output array for the function results
  4238. Returns
  4239. -------
  4240. f : scalar or ndarray
  4241. Quantiles, i.e., the upper limit of integration.
  4242. See Also
  4243. --------
  4244. ncfdtr : CDF of the non-central F distribution.
  4245. ncfdtridfd : Inverse of `ncfdtr` with respect to `dfd`.
  4246. ncfdtridfn : Inverse of `ncfdtr` with respect to `dfn`.
  4247. ncfdtrinc : Inverse of `ncfdtr` with respect to `nc`.
  4248. scipy.stats.ncf : Non-central F distribution.
  4249. Notes
  4250. -----
  4251. This function calculates the Quantile of the non-central f distribution
  4252. using the Boost Math C++ library [1]_.
  4253. Note that argument order of `ncfdtri` is different from that of the
  4254. similar ``ppf`` method of `scipy.stats.ncf`. `p` is the last parameter
  4255. of `ncfdtri` but the first parameter of ``scipy.stats.ncf.ppf``.
  4256. References
  4257. ----------
  4258. .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
  4259. Examples
  4260. --------
  4261. >>> from scipy.special import ncfdtr, ncfdtri
  4262. Compute the CDF for several values of `f`:
  4263. >>> f = [0.5, 1, 1.5]
  4264. >>> p = ncfdtr(2, 3, 1.5, f)
  4265. >>> p
  4266. array([ 0.20782291, 0.36107392, 0.47345752])
  4267. Compute the inverse. We recover the values of `f`, as expected:
  4268. >>> ncfdtri(2, 3, 1.5, p)
  4269. array([ 0.5, 1. , 1.5])
  4270. """)
  4271. add_newdoc("ncfdtridfd",
  4272. """
  4273. ncfdtridfd(dfn, p, nc, f, out=None)
  4274. Calculate degrees of freedom (denominator) for the noncentral F-distribution.
  4275. This is the inverse with respect to `dfd` of `ncfdtr`.
  4276. See `ncfdtr` for more details.
  4277. Parameters
  4278. ----------
  4279. dfn : array_like
  4280. Degrees of freedom of the numerator sum of squares. Range (0, inf).
  4281. p : array_like
  4282. Value of the cumulative distribution function. Must be in the
  4283. range [0, 1].
  4284. nc : array_like
  4285. Noncentrality parameter. Should be in range (0, 1e4).
  4286. f : array_like
  4287. Quantiles, i.e., the upper limit of integration.
  4288. out : ndarray, optional
  4289. Optional output array for the function results
  4290. Returns
  4291. -------
  4292. dfd : scalar or ndarray
  4293. Degrees of freedom of the denominator sum of squares.
  4294. See Also
  4295. --------
  4296. ncfdtr : CDF of the non-central F distribution.
  4297. ncfdtri : Quantile function; inverse of `ncfdtr` with respect to `f`.
  4298. ncfdtridfn : Inverse of `ncfdtr` with respect to `dfn`.
  4299. ncfdtrinc : Inverse of `ncfdtr` with respect to `nc`.
  4300. Notes
  4301. -----
  4302. The value of the cumulative noncentral F distribution is not necessarily
  4303. monotone in either degrees of freedom. There thus may be two values that
  4304. provide a given CDF value. This routine assumes monotonicity and will
  4305. find an arbitrary one of the two values.
  4306. Examples
  4307. --------
  4308. >>> from scipy.special import ncfdtr, ncfdtridfd
  4309. Compute the CDF for several values of `dfd`:
  4310. >>> dfd = [1, 2, 3]
  4311. >>> p = ncfdtr(2, dfd, 0.25, 15)
  4312. >>> p
  4313. array([ 0.8097138 , 0.93020416, 0.96787852])
  4314. Compute the inverse. We recover the values of `dfd`, as expected:
  4315. >>> ncfdtridfd(2, p, 0.25, 15)
  4316. array([ 1., 2., 3.])
  4317. """)
  4318. add_newdoc("ncfdtridfn",
  4319. """
  4320. ncfdtridfn(p, dfd, nc, f, out=None)
  4321. Calculate degrees of freedom (numerator) for the noncentral F-distribution.
  4322. This is the inverse with respect to `dfn` of `ncfdtr`.
  4323. See `ncfdtr` for more details.
  4324. Parameters
  4325. ----------
  4326. p : array_like
  4327. Value of the cumulative distribution function. Must be in the
  4328. range [0, 1].
  4329. dfd : array_like
  4330. Degrees of freedom of the denominator sum of squares. Range (0, inf).
  4331. nc : array_like
  4332. Noncentrality parameter. Should be in range (0, 1e4).
  4333. f : float
  4334. Quantiles, i.e., the upper limit of integration.
  4335. out : ndarray, optional
  4336. Optional output array for the function results
  4337. Returns
  4338. -------
  4339. dfn : scalar or ndarray
  4340. Degrees of freedom of the numerator sum of squares.
  4341. See Also
  4342. --------
  4343. ncfdtr : CDF of the non-central F distribution.
  4344. ncfdtri : Quantile function; inverse of `ncfdtr` with respect to `f`.
  4345. ncfdtridfd : Inverse of `ncfdtr` with respect to `dfd`.
  4346. ncfdtrinc : Inverse of `ncfdtr` with respect to `nc`.
  4347. Notes
  4348. -----
  4349. The value of the cumulative noncentral F distribution is not necessarily
  4350. monotone in either degrees of freedom. There thus may be two values that
  4351. provide a given CDF value. This routine assumes monotonicity and will
  4352. find an arbitrary one of the two values.
  4353. Examples
  4354. --------
  4355. >>> from scipy.special import ncfdtr, ncfdtridfn
  4356. Compute the CDF for several values of `dfn`:
  4357. >>> dfn = [1, 2, 3]
  4358. >>> p = ncfdtr(dfn, 2, 0.25, 15)
  4359. >>> p
  4360. array([ 0.92562363, 0.93020416, 0.93188394])
  4361. Compute the inverse. We recover the values of `dfn`, as expected:
  4362. >>> ncfdtridfn(p, 2, 0.25, 15)
  4363. array([ 1., 2., 3.])
  4364. """)
  4365. add_newdoc("ncfdtrinc",
  4366. """
  4367. ncfdtrinc(dfn, dfd, p, f, out=None)
  4368. Calculate non-centrality parameter for non-central F distribution.
  4369. This is the inverse with respect to `nc` of `ncfdtr`.
  4370. See `ncfdtr` for more details.
  4371. Parameters
  4372. ----------
  4373. dfn : array_like
  4374. Degrees of freedom of the numerator sum of squares. Range (0, inf).
  4375. dfd : array_like
  4376. Degrees of freedom of the denominator sum of squares. Range (0, inf).
  4377. p : array_like
  4378. Value of the cumulative distribution function. Must be in the
  4379. range [0, 1].
  4380. f : array_like
  4381. Quantiles, i.e., the upper limit of integration.
  4382. out : ndarray, optional
  4383. Optional output array for the function results
  4384. Returns
  4385. -------
  4386. nc : scalar or ndarray
  4387. Noncentrality parameter.
  4388. See Also
  4389. --------
  4390. ncfdtr : CDF of the non-central F distribution.
  4391. ncfdtri : Quantile function; inverse of `ncfdtr` with respect to `f`.
  4392. ncfdtridfd : Inverse of `ncfdtr` with respect to `dfd`.
  4393. ncfdtridfn : Inverse of `ncfdtr` with respect to `dfn`.
  4394. Examples
  4395. --------
  4396. >>> from scipy.special import ncfdtr, ncfdtrinc
  4397. Compute the CDF for several values of `nc`:
  4398. >>> nc = [0.5, 1.5, 2.0]
  4399. >>> p = ncfdtr(2, 3, nc, 15)
  4400. >>> p
  4401. array([ 0.96309246, 0.94327955, 0.93304098])
  4402. Compute the inverse. We recover the values of `nc`, as expected:
  4403. >>> ncfdtrinc(2, 3, p, 15)
  4404. array([ 0.5, 1.5, 2. ])
  4405. """)
  4406. add_newdoc("nctdtr",
  4407. """
  4408. nctdtr(df, nc, t, out=None)
  4409. Cumulative distribution function of the non-central `t` distribution.
  4410. Parameters
  4411. ----------
  4412. df : array_like
  4413. Degrees of freedom of the distribution. Should be in range (0, inf).
  4414. nc : array_like
  4415. Noncentrality parameter.
  4416. t : array_like
  4417. Quantiles, i.e., the upper limit of integration.
  4418. out : ndarray, optional
  4419. Optional output array for the function results
  4420. Returns
  4421. -------
  4422. cdf : scalar or ndarray
  4423. The calculated CDF. If all inputs are scalar, the return will be a
  4424. float. Otherwise, it will be an array.
  4425. See Also
  4426. --------
  4427. nctdtrit : Inverse CDF (iCDF) of the non-central t distribution.
  4428. nctdtridf : Calculate degrees of freedom, given CDF and iCDF values.
  4429. nctdtrinc : Calculate non-centrality parameter, given CDF iCDF values.
  4430. Notes
  4431. -----
  4432. This function calculates the CDF of the non-central t distribution using
  4433. the Boost Math C++ library [1]_.
  4434. Note that the argument order of `nctdtr` is different from that of the
  4435. similar ``cdf`` method of `scipy.stats.nct`: `t` is the last
  4436. parameter of `nctdtr` but the first parameter of ``scipy.stats.nct.cdf``.
  4437. References
  4438. ----------
  4439. .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
  4440. Examples
  4441. --------
  4442. >>> import numpy as np
  4443. >>> from scipy import special
  4444. >>> from scipy import stats
  4445. >>> import matplotlib.pyplot as plt
  4446. Plot the CDF of the non-central t distribution, for nc=0. Compare with the
  4447. t-distribution from scipy.stats:
  4448. >>> x = np.linspace(-5, 5, num=500)
  4449. >>> df = 3
  4450. >>> nct_stats = stats.t.cdf(x, df)
  4451. >>> nct_special = special.nctdtr(df, 0, x)
  4452. >>> fig = plt.figure()
  4453. >>> ax = fig.add_subplot(111)
  4454. >>> ax.plot(x, nct_stats, 'b-', lw=3)
  4455. >>> ax.plot(x, nct_special, 'r-')
  4456. >>> plt.show()
  4457. """)
  4458. add_newdoc("nctdtridf",
  4459. """
  4460. nctdtridf(p, nc, t, out=None)
  4461. Calculate degrees of freedom for non-central t distribution.
  4462. See `nctdtr` for more details.
  4463. Parameters
  4464. ----------
  4465. p : array_like
  4466. CDF values, in range (0, 1].
  4467. nc : array_like
  4468. Noncentrality parameter. Should be in range (-1e6, 1e6).
  4469. t : array_like
  4470. Quantiles, i.e., the upper limit of integration.
  4471. out : ndarray, optional
  4472. Optional output array for the function results
  4473. Returns
  4474. -------
  4475. df : scalar or ndarray
  4476. The degrees of freedom. If all inputs are scalar, the return will be a
  4477. float. Otherwise, it will be an array.
  4478. See Also
  4479. --------
  4480. nctdtr : CDF of the non-central `t` distribution.
  4481. nctdtrit : Inverse CDF (iCDF) of the non-central t distribution.
  4482. nctdtrinc : Calculate non-centrality parameter, given CDF iCDF values.
  4483. Examples
  4484. --------
  4485. >>> from scipy.special import nctdtr, nctdtridf
  4486. Compute the CDF for several values of `df`:
  4487. >>> df = [1, 2, 3]
  4488. >>> p = nctdtr(df, 0.25, 1)
  4489. >>> p
  4490. array([0.67491974, 0.716464 , 0.73349456])
  4491. Compute the inverse. We recover the values of `df`, as expected:
  4492. >>> nctdtridf(p, 0.25, 1)
  4493. array([1., 2., 3.])
  4494. """)
  4495. add_newdoc("nctdtrinc",
  4496. """
  4497. nctdtrinc(df, p, t, out=None)
  4498. Calculate non-centrality parameter for non-central t distribution.
  4499. See `nctdtr` for more details.
  4500. Parameters
  4501. ----------
  4502. df : array_like
  4503. Degrees of freedom of the distribution. Should be in range (0, inf).
  4504. p : array_like
  4505. CDF values, in range (0, 1].
  4506. t : array_like
  4507. Quantiles, i.e., the upper limit of integration.
  4508. out : ndarray, optional
  4509. Optional output array for the function results
  4510. Returns
  4511. -------
  4512. nc : scalar or ndarray
  4513. Noncentrality parameter
  4514. See Also
  4515. --------
  4516. nctdtr : CDF of the non-central `t` distribution.
  4517. nctdtrit : Inverse CDF (iCDF) of the non-central t distribution.
  4518. nctdtridf : Calculate degrees of freedom, given CDF and iCDF values.
  4519. Examples
  4520. --------
  4521. >>> from scipy.special import nctdtr, nctdtrinc
  4522. Compute the CDF for several values of `nc`:
  4523. >>> nc = [0.5, 1.5, 2.5]
  4524. >>> p = nctdtr(3, nc, 1.5)
  4525. >>> p
  4526. array([0.77569497, 0.45524533, 0.1668691 ])
  4527. Compute the inverse. We recover the values of `nc`, as expected:
  4528. >>> nctdtrinc(3, p, 1.5)
  4529. array([0.5, 1.5, 2.5])
  4530. """)
  4531. add_newdoc("nctdtrit",
  4532. """
  4533. nctdtrit(df, nc, p, out=None)
  4534. Inverse cumulative distribution function of the non-central t distribution.
  4535. See `nctdtr` for more details.
  4536. Parameters
  4537. ----------
  4538. df : array_like
  4539. Degrees of freedom of the distribution. Should be in range (0, inf).
  4540. nc : array_like
  4541. Noncentrality parameter.
  4542. p : array_like
  4543. CDF values, in range (0, 1].
  4544. out : ndarray, optional
  4545. Optional output array for the function results
  4546. Returns
  4547. -------
  4548. t : scalar or ndarray
  4549. Quantiles
  4550. See Also
  4551. --------
  4552. nctdtr : CDF of the non-central `t` distribution.
  4553. nctdtridf : Calculate degrees of freedom, given CDF and iCDF values.
  4554. nctdtrinc : Calculate non-centrality parameter, given CDF iCDF values.
  4555. Notes
  4556. -----
  4557. This function calculates the quantile of the non-central t distribution using
  4558. the Boost Math C++ library [1]_.
  4559. Note that the argument order of `nctdtrit` is different from that of the
  4560. similar ``ppf`` method of `scipy.stats.nct`: `t` is the last
  4561. parameter of `nctdtrit` but the first parameter of ``scipy.stats.nct.ppf``.
  4562. References
  4563. ----------
  4564. .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
  4565. Examples
  4566. --------
  4567. >>> from scipy.special import nctdtr, nctdtrit
  4568. Compute the CDF for several values of `t`:
  4569. >>> t = [0.5, 1, 1.5]
  4570. >>> p = nctdtr(3, 1, t)
  4571. >>> p
  4572. array([0.29811049, 0.46922687, 0.6257559 ])
  4573. Compute the inverse. We recover the values of `t`, as expected:
  4574. >>> nctdtrit(3, 1, p)
  4575. array([0.5, 1. , 1.5])
  4576. """)
  4577. add_newdoc("nrdtrimn",
  4578. """
  4579. nrdtrimn(p, std, x, out=None)
  4580. Calculate mean of normal distribution given other params.
  4581. Parameters
  4582. ----------
  4583. p : array_like
  4584. CDF values, in range (0, 1].
  4585. std : array_like
  4586. Standard deviation.
  4587. x : array_like
  4588. Quantiles, i.e. the upper limit of integration.
  4589. out : ndarray, optional
  4590. Optional output array for the function results
  4591. Returns
  4592. -------
  4593. mn : scalar or ndarray
  4594. The mean of the normal distribution.
  4595. See Also
  4596. --------
  4597. scipy.stats.norm : Normal distribution
  4598. ndtr : Standard normal cumulative probability distribution
  4599. ndtri : Inverse of standard normal CDF with respect to quantile
  4600. nrdtrisd : Inverse of normal distribution CDF with respect to
  4601. standard deviation
  4602. Examples
  4603. --------
  4604. `nrdtrimn` can be used to recover the mean of a normal distribution
  4605. if we know the CDF value `p` for a given quantile `x` and the
  4606. standard deviation `std`. First, we calculate
  4607. the normal distribution CDF for an exemplary parameter set.
  4608. >>> from scipy.stats import norm
  4609. >>> mean = 3.
  4610. >>> std = 2.
  4611. >>> x = 6.
  4612. >>> p = norm.cdf(x, loc=mean, scale=std)
  4613. >>> p
  4614. 0.9331927987311419
  4615. Verify that `nrdtrimn` returns the original value for `mean`.
  4616. >>> from scipy.special import nrdtrimn
  4617. >>> nrdtrimn(p, std, x)
  4618. 3.0000000000000004
  4619. """)
  4620. add_newdoc("nrdtrisd",
  4621. """
  4622. nrdtrisd(mn, p, x, out=None)
  4623. Calculate standard deviation of normal distribution given other params.
  4624. Parameters
  4625. ----------
  4626. mn : scalar or ndarray
  4627. The mean of the normal distribution.
  4628. p : array_like
  4629. CDF values, in range (0, 1].
  4630. x : array_like
  4631. Quantiles, i.e. the upper limit of integration.
  4632. out : ndarray, optional
  4633. Optional output array for the function results
  4634. Returns
  4635. -------
  4636. std : scalar or ndarray
  4637. Standard deviation.
  4638. See Also
  4639. --------
  4640. scipy.stats.norm : Normal distribution
  4641. ndtr : Standard normal cumulative probability distribution
  4642. ndtri : Inverse of standard normal CDF with respect to quantile
  4643. nrdtrimn : Inverse of normal distribution CDF with respect to
  4644. mean
  4645. Examples
  4646. --------
  4647. `nrdtrisd` can be used to recover the standard deviation of a normal
  4648. distribution if we know the CDF value `p` for a given quantile `x` and
  4649. the mean `mn`. First, we calculate the normal distribution CDF for an
  4650. exemplary parameter set.
  4651. >>> from scipy.stats import norm
  4652. >>> mean = 3.
  4653. >>> std = 2.
  4654. >>> x = 6.
  4655. >>> p = norm.cdf(x, loc=mean, scale=std)
  4656. >>> p
  4657. 0.9331927987311419
  4658. Verify that `nrdtrisd` returns the original value for `std`.
  4659. >>> from scipy.special import nrdtrisd
  4660. >>> nrdtrisd(mean, p, x)
  4661. 2.0000000000000004
  4662. """)
  4663. add_newdoc("ndtri",
  4664. """
  4665. ndtri(y, out=None)
  4666. Inverse of `ndtr` vs x
  4667. Returns the argument x for which the area under the standard normal
  4668. probability density function (integrated from minus infinity to `x`)
  4669. is equal to y.
  4670. Parameters
  4671. ----------
  4672. p : array_like
  4673. Probability
  4674. out : ndarray, optional
  4675. Optional output array for the function results
  4676. Returns
  4677. -------
  4678. x : scalar or ndarray
  4679. Value of x such that ``ndtr(x) == p``.
  4680. See Also
  4681. --------
  4682. ndtr : Standard normal cumulative probability distribution
  4683. ndtri_exp : Inverse of log_ndtr
  4684. Examples
  4685. --------
  4686. `ndtri` is the percentile function of the standard normal distribution.
  4687. This means it returns the inverse of the cumulative density `ndtr`. First,
  4688. let us compute a cumulative density value.
  4689. >>> import numpy as np
  4690. >>> from scipy.special import ndtri, ndtr
  4691. >>> cdf_val = ndtr(2)
  4692. >>> cdf_val
  4693. 0.9772498680518208
  4694. Verify that `ndtri` yields the original value for `x` up to floating point
  4695. errors.
  4696. >>> ndtri(cdf_val)
  4697. 2.0000000000000004
  4698. Plot the function. For that purpose, we provide a NumPy array as argument.
  4699. >>> import matplotlib.pyplot as plt
  4700. >>> x = np.linspace(0.01, 1, 200)
  4701. >>> fig, ax = plt.subplots()
  4702. >>> ax.plot(x, ndtri(x))
  4703. >>> ax.set_title("Standard normal percentile function")
  4704. >>> plt.show()
  4705. """)
  4706. add_newdoc("pdtr",
  4707. r"""
  4708. pdtr(k, m, out=None)
  4709. Poisson cumulative distribution function.
  4710. Defined as the probability that a Poisson-distributed random
  4711. variable with event rate :math:`m` is less than or equal to
  4712. :math:`k`. More concretely, this works out to be [1]_
  4713. .. math::
  4714. \exp(-m) \sum_{j = 0}^{\lfloor{k}\rfloor} \frac{m^j}{j!}.
  4715. Parameters
  4716. ----------
  4717. k : array_like
  4718. Number of occurrences (nonnegative, real)
  4719. m : array_like
  4720. Shape parameter (nonnegative, real)
  4721. out : ndarray, optional
  4722. Optional output array for the function results
  4723. Returns
  4724. -------
  4725. scalar or ndarray
  4726. Values of the Poisson cumulative distribution function
  4727. See Also
  4728. --------
  4729. pdtrc : Poisson survival function
  4730. pdtrik : inverse of `pdtr` with respect to `k`
  4731. pdtri : inverse of `pdtr` with respect to `m`
  4732. References
  4733. ----------
  4734. .. [1] https://en.wikipedia.org/wiki/Poisson_distribution
  4735. Examples
  4736. --------
  4737. >>> import numpy as np
  4738. >>> import scipy.special as sc
  4739. It is a cumulative distribution function, so it converges to 1
  4740. monotonically as `k` goes to infinity.
  4741. >>> sc.pdtr([1, 10, 100, np.inf], 1)
  4742. array([0.73575888, 0.99999999, 1. , 1. ])
  4743. It is discontinuous at integers and constant between integers.
  4744. >>> sc.pdtr([1, 1.5, 1.9, 2], 1)
  4745. array([0.73575888, 0.73575888, 0.73575888, 0.9196986 ])
  4746. """)
  4747. add_newdoc("pdtrc",
  4748. """
  4749. pdtrc(k, m, out=None)
  4750. Poisson survival function
  4751. Returns the sum of the terms from k+1 to infinity of the Poisson
  4752. distribution: sum(exp(-m) * m**j / j!, j=k+1..inf) = gammainc(
  4753. k+1, m). Arguments must both be non-negative doubles.
  4754. Parameters
  4755. ----------
  4756. k : array_like
  4757. Number of occurrences (nonnegative, real)
  4758. m : array_like
  4759. Shape parameter (nonnegative, real)
  4760. out : ndarray, optional
  4761. Optional output array for the function results
  4762. Returns
  4763. -------
  4764. scalar or ndarray
  4765. Values of the Poisson survival function
  4766. See Also
  4767. --------
  4768. pdtr : Poisson cumulative distribution function
  4769. pdtrik : inverse of `pdtr` with respect to `k`
  4770. pdtri : inverse of `pdtr` with respect to `m`
  4771. Examples
  4772. --------
  4773. >>> import numpy as np
  4774. >>> import scipy.special as sc
  4775. It is a survival function, so it decreases to 0
  4776. monotonically as `k` goes to infinity.
  4777. >>> k = np.array([1, 10, 100, np.inf])
  4778. >>> sc.pdtrc(k, 1)
  4779. array([2.64241118e-001, 1.00477664e-008, 3.94147589e-161, 0.00000000e+000])
  4780. It can be expressed in terms of the lower incomplete gamma
  4781. function `gammainc`.
  4782. >>> sc.gammainc(k + 1, 1)
  4783. array([2.64241118e-001, 1.00477664e-008, 3.94147589e-161, 0.00000000e+000])
  4784. """)
  4785. add_newdoc("pdtri",
  4786. """
  4787. pdtri(k, y, out=None)
  4788. Inverse to `pdtr` vs m
  4789. Returns the Poisson variable `m` such that the sum from 0 to `k` of
  4790. the Poisson density is equal to the given probability `y`:
  4791. calculated by ``gammaincinv(k + 1, y)``. `k` must be a nonnegative
  4792. integer and `y` between 0 and 1.
  4793. Parameters
  4794. ----------
  4795. k : array_like
  4796. Number of occurrences (nonnegative, real)
  4797. y : array_like
  4798. Probability
  4799. out : ndarray, optional
  4800. Optional output array for the function results
  4801. Returns
  4802. -------
  4803. scalar or ndarray
  4804. Values of the shape parameter `m` such that ``pdtr(k, m) = p``
  4805. See Also
  4806. --------
  4807. pdtr : Poisson cumulative distribution function
  4808. pdtrc : Poisson survival function
  4809. pdtrik : inverse of `pdtr` with respect to `k`
  4810. Examples
  4811. --------
  4812. >>> import scipy.special as sc
  4813. Compute the CDF for several values of `m`:
  4814. >>> m = [0.5, 1, 1.5]
  4815. >>> p = sc.pdtr(1, m)
  4816. >>> p
  4817. array([0.90979599, 0.73575888, 0.5578254 ])
  4818. Compute the inverse. We recover the values of `m`, as expected:
  4819. >>> sc.pdtri(1, p)
  4820. array([0.5, 1. , 1.5])
  4821. """)
  4822. add_newdoc("pdtrik",
  4823. """
  4824. pdtrik(p, m, out=None)
  4825. Inverse to `pdtr` vs `k`.
  4826. Parameters
  4827. ----------
  4828. p : array_like
  4829. Probability
  4830. m : array_like
  4831. Shape parameter (nonnegative, real)
  4832. out : ndarray, optional
  4833. Optional output array for the function results
  4834. Returns
  4835. -------
  4836. scalar or ndarray
  4837. The number of occurrences `k` such that ``pdtr(k, m) = p``
  4838. Notes
  4839. -----
  4840. This function relies on the ``gamma_q_inva`` function from the Boost
  4841. Math C++ library [1]_.
  4842. References
  4843. ----------
  4844. .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
  4845. See Also
  4846. --------
  4847. pdtr : Poisson cumulative distribution function
  4848. pdtrc : Poisson survival function
  4849. pdtri : inverse of `pdtr` with respect to `m`
  4850. Examples
  4851. --------
  4852. >>> import scipy.special as sc
  4853. Compute the CDF for several values of `k`:
  4854. >>> k = [1, 2, 3]
  4855. >>> p = sc.pdtr(k, 2)
  4856. >>> p
  4857. array([0.40600585, 0.67667642, 0.85712346])
  4858. Compute the inverse. We recover the values of `k`, as expected:
  4859. >>> sc.pdtrik(p, 2)
  4860. array([1., 2., 3.])
  4861. """)
  4862. add_newdoc("poch",
  4863. r"""
  4864. poch(z, m, out=None)
  4865. Pochhammer symbol.
  4866. The Pochhammer symbol (rising factorial) is defined as
  4867. .. math::
  4868. (z)_m = \frac{\Gamma(z + m)}{\Gamma(z)}
  4869. For positive integer `m` it reads
  4870. .. math::
  4871. (z)_m = z (z + 1) ... (z + m - 1)
  4872. See [DLMF]_ for more details.
  4873. Parameters
  4874. ----------
  4875. z, m : array_like
  4876. Real-valued arguments.
  4877. out : ndarray, optional
  4878. Optional output array for the function results
  4879. Returns
  4880. -------
  4881. scalar or ndarray
  4882. The value of the function.
  4883. References
  4884. ----------
  4885. .. [DLMF] Nist, Digital Library of Mathematical Functions
  4886. https://dlmf.nist.gov/5.2#iii
  4887. Examples
  4888. --------
  4889. >>> import scipy.special as sc
  4890. It is 1 when m is 0.
  4891. >>> sc.poch([1, 2, 3, 4], 0)
  4892. array([1., 1., 1., 1.])
  4893. For z equal to 1 it reduces to the factorial function.
  4894. >>> sc.poch(1, 5)
  4895. 120.0
  4896. >>> 1 * 2 * 3 * 4 * 5
  4897. 120
  4898. It can be expressed in terms of the gamma function.
  4899. >>> z, m = 3.7, 2.1
  4900. >>> sc.poch(z, m)
  4901. 20.529581933776953
  4902. >>> sc.gamma(z + m) / sc.gamma(z)
  4903. 20.52958193377696
  4904. """)
  4905. add_newdoc("powm1", """
  4906. powm1(x, y, out=None)
  4907. Computes ``x**y - 1``.
  4908. This function is useful when `y` is near 0, or when `x` is near 1.
  4909. The function is implemented for real types only (unlike ``numpy.power``,
  4910. which accepts complex inputs).
  4911. Parameters
  4912. ----------
  4913. x : array_like
  4914. The base. Must be a real type (i.e. integer or float, not complex).
  4915. y : array_like
  4916. The exponent. Must be a real type (i.e. integer or float, not complex).
  4917. Returns
  4918. -------
  4919. array_like
  4920. Result of the calculation
  4921. Notes
  4922. -----
  4923. .. versionadded:: 1.10.0
  4924. The underlying code is implemented for single precision and double
  4925. precision floats only. Unlike `numpy.power`, integer inputs to
  4926. `powm1` are converted to floating point, and complex inputs are
  4927. not accepted.
  4928. Note the following edge cases:
  4929. * ``powm1(x, 0)`` returns 0 for any ``x``, including 0, ``inf``
  4930. and ``nan``.
  4931. * ``powm1(1, y)`` returns 0 for any ``y``, including ``nan``
  4932. and ``inf``.
  4933. This function wraps the ``powm1`` routine from the
  4934. Boost Math C++ library [1]_.
  4935. References
  4936. ----------
  4937. .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
  4938. Examples
  4939. --------
  4940. >>> import numpy as np
  4941. >>> from scipy.special import powm1
  4942. >>> x = np.array([1.2, 10.0, 0.9999999975])
  4943. >>> y = np.array([1e-9, 1e-11, 0.1875])
  4944. >>> powm1(x, y)
  4945. array([ 1.82321557e-10, 2.30258509e-11, -4.68749998e-10])
  4946. It can be verified that the relative errors in those results
  4947. are less than 2.5e-16.
  4948. Compare that to the result of ``x**y - 1``, where the
  4949. relative errors are all larger than 8e-8:
  4950. >>> x**y - 1
  4951. array([ 1.82321491e-10, 2.30258035e-11, -4.68750039e-10])
  4952. """)
  4953. add_newdoc("pseudo_huber",
  4954. r"""
  4955. pseudo_huber(delta, r, out=None)
  4956. Pseudo-Huber loss function.
  4957. .. math:: \mathrm{pseudo\_huber}(\delta, r) =
  4958. \delta^2 \left( \sqrt{ 1 + \left( \frac{r}{\delta} \right)^2 } - 1 \right)
  4959. Parameters
  4960. ----------
  4961. delta : array_like
  4962. Input array, indicating the soft quadratic vs. linear loss changepoint.
  4963. r : array_like
  4964. Input array, possibly representing residuals.
  4965. out : ndarray, optional
  4966. Optional output array for the function results
  4967. Returns
  4968. -------
  4969. res : scalar or ndarray
  4970. The computed Pseudo-Huber loss function values.
  4971. See Also
  4972. --------
  4973. huber: Similar function which this function approximates
  4974. Notes
  4975. -----
  4976. Like `huber`, `pseudo_huber` often serves as a robust loss function
  4977. in statistics or machine learning to reduce the influence of outliers.
  4978. Unlike `huber`, `pseudo_huber` is smooth.
  4979. Typically, `r` represents residuals, the difference
  4980. between a model prediction and data. Then, for :math:`|r|\leq\delta`,
  4981. `pseudo_huber` resembles the squared error and for :math:`|r|>\delta` the
  4982. absolute error. This way, the Pseudo-Huber loss often achieves
  4983. a fast convergence in model fitting for small residuals like the squared
  4984. error loss function and still reduces the influence of outliers
  4985. (:math:`|r|>\delta`) like the absolute error loss. As :math:`\delta` is
  4986. the cutoff between squared and absolute error regimes, it has
  4987. to be tuned carefully for each problem. `pseudo_huber` is also
  4988. convex, making it suitable for gradient based optimization. [1]_ [2]_
  4989. .. versionadded:: 0.15.0
  4990. References
  4991. ----------
  4992. .. [1] Hartley, Zisserman, "Multiple View Geometry in Computer Vision".
  4993. 2003. Cambridge University Press. p. 619
  4994. .. [2] Charbonnier et al. "Deterministic edge-preserving regularization
  4995. in computed imaging". 1997. IEEE Trans. Image Processing.
  4996. 6 (2): 298 - 311.
  4997. Examples
  4998. --------
  4999. Import all necessary modules.
  5000. >>> import numpy as np
  5001. >>> from scipy.special import pseudo_huber, huber
  5002. >>> import matplotlib.pyplot as plt
  5003. Calculate the function for ``delta=1`` at ``r=2``.
  5004. >>> pseudo_huber(1., 2.)
  5005. 1.2360679774997898
  5006. Calculate the function at ``r=2`` for different `delta` by providing
  5007. a list or NumPy array for `delta`.
  5008. >>> pseudo_huber([1., 2., 4.], 3.)
  5009. array([2.16227766, 3.21110255, 4. ])
  5010. Calculate the function for ``delta=1`` at several points by providing
  5011. a list or NumPy array for `r`.
  5012. >>> pseudo_huber(2., np.array([1., 1.5, 3., 4.]))
  5013. array([0.47213595, 1. , 3.21110255, 4.94427191])
  5014. The function can be calculated for different `delta` and `r` by
  5015. providing arrays for both with compatible shapes for broadcasting.
  5016. >>> r = np.array([1., 2.5, 8., 10.])
  5017. >>> deltas = np.array([[1.], [5.], [9.]])
  5018. >>> print(r.shape, deltas.shape)
  5019. (4,) (3, 1)
  5020. >>> pseudo_huber(deltas, r)
  5021. array([[ 0.41421356, 1.6925824 , 7.06225775, 9.04987562],
  5022. [ 0.49509757, 2.95084972, 22.16990566, 30.90169944],
  5023. [ 0.49846624, 3.06693762, 27.37435121, 40.08261642]])
  5024. Plot the function for different `delta`.
  5025. >>> x = np.linspace(-4, 4, 500)
  5026. >>> deltas = [1, 2, 3]
  5027. >>> linestyles = ["dashed", "dotted", "dashdot"]
  5028. >>> fig, ax = plt.subplots()
  5029. >>> combined_plot_parameters = list(zip(deltas, linestyles))
  5030. >>> for delta, style in combined_plot_parameters:
  5031. ... ax.plot(x, pseudo_huber(delta, x), label=rf"$\delta={delta}$",
  5032. ... ls=style)
  5033. >>> ax.legend(loc="upper center")
  5034. >>> ax.set_xlabel("$x$")
  5035. >>> ax.set_title(r"Pseudo-Huber loss function $h_{\delta}(x)$")
  5036. >>> ax.set_xlim(-4, 4)
  5037. >>> ax.set_ylim(0, 8)
  5038. >>> plt.show()
  5039. Finally, illustrate the difference between `huber` and `pseudo_huber` by
  5040. plotting them and their gradients with respect to `r`. The plot shows
  5041. that `pseudo_huber` is continuously differentiable while `huber` is not
  5042. at the points :math:`\pm\delta`.
  5043. >>> def huber_grad(delta, x):
  5044. ... grad = np.copy(x)
  5045. ... linear_area = np.argwhere(np.abs(x) > delta)
  5046. ... grad[linear_area]=delta*np.sign(x[linear_area])
  5047. ... return grad
  5048. >>> def pseudo_huber_grad(delta, x):
  5049. ... return x* (1+(x/delta)**2)**(-0.5)
  5050. >>> x=np.linspace(-3, 3, 500)
  5051. >>> delta = 1.
  5052. >>> fig, ax = plt.subplots(figsize=(7, 7))
  5053. >>> ax.plot(x, huber(delta, x), label="Huber", ls="dashed")
  5054. >>> ax.plot(x, huber_grad(delta, x), label="Huber Gradient", ls="dashdot")
  5055. >>> ax.plot(x, pseudo_huber(delta, x), label="Pseudo-Huber", ls="dotted")
  5056. >>> ax.plot(x, pseudo_huber_grad(delta, x), label="Pseudo-Huber Gradient",
  5057. ... ls="solid")
  5058. >>> ax.legend(loc="upper center")
  5059. >>> plt.show()
  5060. """)
  5061. add_newdoc("rel_entr",
  5062. r"""
  5063. rel_entr(x, y, out=None)
  5064. Elementwise function for computing relative entropy.
  5065. .. math::
  5066. \mathrm{rel\_entr}(x, y) =
  5067. \begin{cases}
  5068. x \log(x / y) & x > 0, y > 0 \\
  5069. 0 & x = 0, y \ge 0 \\
  5070. \infty & \text{otherwise}
  5071. \end{cases}
  5072. Parameters
  5073. ----------
  5074. x, y : array_like
  5075. Input arrays
  5076. out : ndarray, optional
  5077. Optional output array for the function results
  5078. Returns
  5079. -------
  5080. scalar or ndarray
  5081. Relative entropy of the inputs
  5082. See Also
  5083. --------
  5084. entr, kl_div, scipy.stats.entropy
  5085. Notes
  5086. -----
  5087. .. versionadded:: 0.15.0
  5088. This function is jointly convex in x and y.
  5089. The origin of this function is in convex programming; see
  5090. [1]_. Given two discrete probability distributions :math:`p_1,
  5091. \ldots, p_n` and :math:`q_1, \ldots, q_n`, the definition of relative
  5092. entropy in the context of *information theory* is
  5093. .. math::
  5094. \sum_{i = 1}^n \mathrm{rel\_entr}(p_i, q_i).
  5095. To compute the latter quantity, use `scipy.stats.entropy`.
  5096. See [2]_ for details.
  5097. References
  5098. ----------
  5099. .. [1] Boyd, Stephen and Lieven Vandenberghe. *Convex optimization*.
  5100. Cambridge University Press, 2004.
  5101. :doi:`https://doi.org/10.1017/CBO9780511804441`
  5102. .. [2] Kullback-Leibler divergence,
  5103. https://en.wikipedia.org/wiki/Kullback%E2%80%93Leibler_divergence
  5104. """)
  5105. add_newdoc("round",
  5106. """
  5107. round(x, out=None)
  5108. Round to the nearest integer.
  5109. Returns the nearest integer to `x`. If `x` ends in 0.5 exactly,
  5110. the nearest even integer is chosen.
  5111. Parameters
  5112. ----------
  5113. x : array_like
  5114. Real valued input.
  5115. out : ndarray, optional
  5116. Optional output array for the function results.
  5117. Returns
  5118. -------
  5119. scalar or ndarray
  5120. The nearest integers to the elements of `x`. The result is of
  5121. floating type, not integer type.
  5122. Examples
  5123. --------
  5124. >>> import scipy.special as sc
  5125. It rounds to even.
  5126. >>> sc.round([0.5, 1.5])
  5127. array([0., 2.])
  5128. """)
  5129. add_newdoc("shichi",
  5130. r"""
  5131. shichi(x, out=None)
  5132. Hyperbolic sine and cosine integrals.
  5133. The hyperbolic sine integral is
  5134. .. math::
  5135. \int_0^x \frac{\sinh{t}}{t}dt
  5136. and the hyperbolic cosine integral is
  5137. .. math::
  5138. \gamma + \log(x) + \int_0^x \frac{\cosh{t} - 1}{t} dt
  5139. where :math:`\gamma` is Euler's constant and :math:`\log` is the
  5140. principal branch of the logarithm [1]_ (see also [2]_).
  5141. Parameters
  5142. ----------
  5143. x : array_like
  5144. Real or complex points at which to compute the hyperbolic sine
  5145. and cosine integrals.
  5146. out : tuple of ndarray, optional
  5147. Optional output arrays for the function results
  5148. Returns
  5149. -------
  5150. si : scalar or ndarray
  5151. Hyperbolic sine integral at ``x``
  5152. ci : scalar or ndarray
  5153. Hyperbolic cosine integral at ``x``
  5154. See Also
  5155. --------
  5156. sici : Sine and cosine integrals.
  5157. exp1 : Exponential integral E1.
  5158. expi : Exponential integral Ei.
  5159. Notes
  5160. -----
  5161. For real arguments with ``x < 0``, ``chi`` is the real part of the
  5162. hyperbolic cosine integral. For such points ``chi(x)`` and ``chi(x
  5163. + 0j)`` differ by a factor of ``1j*pi``.
  5164. For real arguments the function is computed by calling Cephes'
  5165. [3]_ *shichi* routine. For complex arguments the algorithm is based
  5166. on Mpmath's [4]_ *shi* and *chi* routines.
  5167. References
  5168. ----------
  5169. .. [1] Milton Abramowitz and Irene A. Stegun, eds.
  5170. Handbook of Mathematical Functions with Formulas,
  5171. Graphs, and Mathematical Tables. New York: Dover, 1972.
  5172. (See Section 5.2.)
  5173. .. [2] NIST Digital Library of Mathematical Functions
  5174. https://dlmf.nist.gov/6.2.E15 and https://dlmf.nist.gov/6.2.E16
  5175. .. [3] Cephes Mathematical Functions Library,
  5176. http://www.netlib.org/cephes/
  5177. .. [4] Fredrik Johansson and others.
  5178. "mpmath: a Python library for arbitrary-precision floating-point
  5179. arithmetic" (Version 0.19) http://mpmath.org/
  5180. Examples
  5181. --------
  5182. >>> import numpy as np
  5183. >>> import matplotlib.pyplot as plt
  5184. >>> from scipy.special import shichi, sici
  5185. `shichi` accepts real or complex input:
  5186. >>> shichi(0.5)
  5187. (0.5069967498196671, -0.05277684495649357)
  5188. >>> shichi(0.5 + 2.5j)
  5189. ((0.11772029666668238+1.831091777729851j),
  5190. (0.29912435887648825+1.7395351121166562j))
  5191. The hyperbolic sine and cosine integrals Shi(z) and Chi(z) are
  5192. related to the sine and cosine integrals Si(z) and Ci(z) by
  5193. * Shi(z) = -i*Si(i*z)
  5194. * Chi(z) = Ci(-i*z) + i*pi/2
  5195. >>> z = 0.25 + 5j
  5196. >>> shi, chi = shichi(z)
  5197. >>> shi, -1j*sici(1j*z)[0] # Should be the same.
  5198. ((-0.04834719325101729+1.5469354086921228j),
  5199. (-0.04834719325101729+1.5469354086921228j))
  5200. >>> chi, sici(-1j*z)[1] + 1j*np.pi/2 # Should be the same.
  5201. ((-0.19568708973868087+1.556276312103824j),
  5202. (-0.19568708973868087+1.556276312103824j))
  5203. Plot the functions evaluated on the real axis:
  5204. >>> xp = np.geomspace(1e-8, 4.0, 250)
  5205. >>> x = np.concatenate((-xp[::-1], xp))
  5206. >>> shi, chi = shichi(x)
  5207. >>> fig, ax = plt.subplots()
  5208. >>> ax.plot(x, shi, label='Shi(x)')
  5209. >>> ax.plot(x, chi, '--', label='Chi(x)')
  5210. >>> ax.set_xlabel('x')
  5211. >>> ax.set_title('Hyperbolic Sine and Cosine Integrals')
  5212. >>> ax.legend(shadow=True, framealpha=1, loc='lower right')
  5213. >>> ax.grid(True)
  5214. >>> plt.show()
  5215. """)
  5216. add_newdoc("sici",
  5217. r"""
  5218. sici(x, out=None)
  5219. Sine and cosine integrals.
  5220. The sine integral is
  5221. .. math::
  5222. \int_0^x \frac{\sin{t}}{t}dt
  5223. and the cosine integral is
  5224. .. math::
  5225. \gamma + \log(x) + \int_0^x \frac{\cos{t} - 1}{t}dt
  5226. where :math:`\gamma` is Euler's constant and :math:`\log` is the
  5227. principal branch of the logarithm [1]_ (see also [2]_).
  5228. Parameters
  5229. ----------
  5230. x : array_like
  5231. Real or complex points at which to compute the sine and cosine
  5232. integrals.
  5233. out : tuple of ndarray, optional
  5234. Optional output arrays for the function results
  5235. Returns
  5236. -------
  5237. si : scalar or ndarray
  5238. Sine integral at ``x``
  5239. ci : scalar or ndarray
  5240. Cosine integral at ``x``
  5241. See Also
  5242. --------
  5243. shichi : Hyperbolic sine and cosine integrals.
  5244. exp1 : Exponential integral E1.
  5245. expi : Exponential integral Ei.
  5246. Notes
  5247. -----
  5248. For real arguments with ``x < 0``, ``ci`` is the real part of the
  5249. cosine integral. For such points ``ci(x)`` and ``ci(x + 0j)``
  5250. differ by a factor of ``1j*pi``.
  5251. For real arguments the function is computed by calling Cephes'
  5252. [3]_ *sici* routine. For complex arguments the algorithm is based
  5253. on Mpmath's [4]_ *si* and *ci* routines.
  5254. References
  5255. ----------
  5256. .. [1] Milton Abramowitz and Irene A. Stegun, eds.
  5257. Handbook of Mathematical Functions with Formulas,
  5258. Graphs, and Mathematical Tables. New York: Dover, 1972.
  5259. (See Section 5.2.)
  5260. .. [2] NIST Digital Library of Mathematical Functions
  5261. https://dlmf.nist.gov/6.2.E9, https://dlmf.nist.gov/6.2.E12,
  5262. and https://dlmf.nist.gov/6.2.E13
  5263. .. [3] Cephes Mathematical Functions Library,
  5264. http://www.netlib.org/cephes/
  5265. .. [4] Fredrik Johansson and others.
  5266. "mpmath: a Python library for arbitrary-precision floating-point
  5267. arithmetic" (Version 0.19) http://mpmath.org/
  5268. Examples
  5269. --------
  5270. >>> import numpy as np
  5271. >>> import matplotlib.pyplot as plt
  5272. >>> from scipy.special import sici, exp1
  5273. `sici` accepts real or complex input:
  5274. >>> sici(2.5)
  5275. (1.7785201734438267, 0.2858711963653835)
  5276. >>> sici(2.5 + 3j)
  5277. ((4.505735874563953+0.06863305018999577j),
  5278. (0.0793644206906966-2.935510262937543j))
  5279. For z in the right half plane, the sine and cosine integrals are
  5280. related to the exponential integral E1 (implemented in SciPy as
  5281. `scipy.special.exp1`) by
  5282. * Si(z) = (E1(i*z) - E1(-i*z))/2i + pi/2
  5283. * Ci(z) = -(E1(i*z) + E1(-i*z))/2
  5284. See [1]_ (equations 5.2.21 and 5.2.23).
  5285. We can verify these relations:
  5286. >>> z = 2 - 3j
  5287. >>> sici(z)
  5288. ((4.54751388956229-1.3991965806460565j),
  5289. (1.408292501520851+2.9836177420296055j))
  5290. >>> (exp1(1j*z) - exp1(-1j*z))/2j + np.pi/2 # Same as sine integral
  5291. (4.54751388956229-1.3991965806460565j)
  5292. >>> -(exp1(1j*z) + exp1(-1j*z))/2 # Same as cosine integral
  5293. (1.408292501520851+2.9836177420296055j)
  5294. Plot the functions evaluated on the real axis; the dotted horizontal
  5295. lines are at pi/2 and -pi/2:
  5296. >>> x = np.linspace(-16, 16, 150)
  5297. >>> si, ci = sici(x)
  5298. >>> fig, ax = plt.subplots()
  5299. >>> ax.plot(x, si, label='Si(x)')
  5300. >>> ax.plot(x, ci, '--', label='Ci(x)')
  5301. >>> ax.legend(shadow=True, framealpha=1, loc='upper left')
  5302. >>> ax.set_xlabel('x')
  5303. >>> ax.set_title('Sine and Cosine Integrals')
  5304. >>> ax.axhline(np.pi/2, linestyle=':', alpha=0.5, color='k')
  5305. >>> ax.axhline(-np.pi/2, linestyle=':', alpha=0.5, color='k')
  5306. >>> ax.grid(True)
  5307. >>> plt.show()
  5308. """)
  5309. add_newdoc("smirnov",
  5310. r"""
  5311. smirnov(n, d, out=None)
  5312. Kolmogorov-Smirnov complementary cumulative distribution function
  5313. Returns the exact Kolmogorov-Smirnov complementary cumulative
  5314. distribution function,(aka the Survival Function) of Dn+ (or Dn-)
  5315. for a one-sided test of equality between an empirical and a
  5316. theoretical distribution. It is equal to the probability that the
  5317. maximum difference between a theoretical distribution and an empirical
  5318. one based on `n` samples is greater than d.
  5319. Parameters
  5320. ----------
  5321. n : int
  5322. Number of samples
  5323. d : float array_like
  5324. Deviation between the Empirical CDF (ECDF) and the target CDF.
  5325. out : ndarray, optional
  5326. Optional output array for the function results
  5327. Returns
  5328. -------
  5329. scalar or ndarray
  5330. The value(s) of smirnov(n, d), Prob(Dn+ >= d) (Also Prob(Dn- >= d))
  5331. See Also
  5332. --------
  5333. smirnovi : The Inverse Survival Function for the distribution
  5334. scipy.stats.ksone : Provides the functionality as a continuous distribution
  5335. kolmogorov, kolmogi : Functions for the two-sided distribution
  5336. Notes
  5337. -----
  5338. `smirnov` is used by `stats.kstest` in the application of the
  5339. Kolmogorov-Smirnov Goodness of Fit test. For historical reasons this
  5340. function is exposed in `scpy.special`, but the recommended way to achieve
  5341. the most accurate CDF/SF/PDF/PPF/ISF computations is to use the
  5342. `stats.ksone` distribution.
  5343. Examples
  5344. --------
  5345. >>> import numpy as np
  5346. >>> from scipy.special import smirnov
  5347. >>> from scipy.stats import norm
  5348. Show the probability of a gap at least as big as 0, 0.5 and 1.0 for a
  5349. sample of size 5.
  5350. >>> smirnov(5, [0, 0.5, 1.0])
  5351. array([ 1. , 0.056, 0. ])
  5352. Compare a sample of size 5 against N(0, 1), the standard normal
  5353. distribution with mean 0 and standard deviation 1.
  5354. `x` is the sample.
  5355. >>> x = np.array([-1.392, -0.135, 0.114, 0.190, 1.82])
  5356. >>> target = norm(0, 1)
  5357. >>> cdfs = target.cdf(x)
  5358. >>> cdfs
  5359. array([0.0819612 , 0.44630594, 0.5453811 , 0.57534543, 0.9656205 ])
  5360. Construct the empirical CDF and the K-S statistics (Dn+, Dn-, Dn).
  5361. >>> n = len(x)
  5362. >>> ecdfs = np.arange(n+1, dtype=float)/n
  5363. >>> cols = np.column_stack([x, ecdfs[1:], cdfs, cdfs - ecdfs[:n],
  5364. ... ecdfs[1:] - cdfs])
  5365. >>> with np.printoptions(precision=3):
  5366. ... print(cols)
  5367. [[-1.392 0.2 0.082 0.082 0.118]
  5368. [-0.135 0.4 0.446 0.246 -0.046]
  5369. [ 0.114 0.6 0.545 0.145 0.055]
  5370. [ 0.19 0.8 0.575 -0.025 0.225]
  5371. [ 1.82 1. 0.966 0.166 0.034]]
  5372. >>> gaps = cols[:, -2:]
  5373. >>> Dnpm = np.max(gaps, axis=0)
  5374. >>> print(f'Dn-={Dnpm[0]:f}, Dn+={Dnpm[1]:f}')
  5375. Dn-=0.246306, Dn+=0.224655
  5376. >>> probs = smirnov(n, Dnpm)
  5377. >>> print(f'For a sample of size {n} drawn from N(0, 1):',
  5378. ... f' Smirnov n={n}: Prob(Dn- >= {Dnpm[0]:f}) = {probs[0]:.4f}',
  5379. ... f' Smirnov n={n}: Prob(Dn+ >= {Dnpm[1]:f}) = {probs[1]:.4f}',
  5380. ... sep='\n')
  5381. For a sample of size 5 drawn from N(0, 1):
  5382. Smirnov n=5: Prob(Dn- >= 0.246306) = 0.4711
  5383. Smirnov n=5: Prob(Dn+ >= 0.224655) = 0.5245
  5384. Plot the empirical CDF and the standard normal CDF.
  5385. >>> import matplotlib.pyplot as plt
  5386. >>> plt.step(np.concatenate(([-2.5], x, [2.5])),
  5387. ... np.concatenate((ecdfs, [1])),
  5388. ... where='post', label='Empirical CDF')
  5389. >>> xx = np.linspace(-2.5, 2.5, 100)
  5390. >>> plt.plot(xx, target.cdf(xx), '--', label='CDF for N(0, 1)')
  5391. Add vertical lines marking Dn+ and Dn-.
  5392. >>> iminus, iplus = np.argmax(gaps, axis=0)
  5393. >>> plt.vlines([x[iminus]], ecdfs[iminus], cdfs[iminus], color='r',
  5394. ... alpha=0.5, lw=4)
  5395. >>> plt.vlines([x[iplus]], cdfs[iplus], ecdfs[iplus+1], color='m',
  5396. ... alpha=0.5, lw=4)
  5397. >>> plt.grid(True)
  5398. >>> plt.legend(framealpha=1, shadow=True)
  5399. >>> plt.show()
  5400. """)
  5401. add_newdoc("smirnovi",
  5402. """
  5403. smirnovi(n, p, out=None)
  5404. Inverse to `smirnov`
  5405. Returns `d` such that ``smirnov(n, d) == p``, the critical value
  5406. corresponding to `p`.
  5407. Parameters
  5408. ----------
  5409. n : int
  5410. Number of samples
  5411. p : float array_like
  5412. Probability
  5413. out : ndarray, optional
  5414. Optional output array for the function results
  5415. Returns
  5416. -------
  5417. scalar or ndarray
  5418. The value(s) of smirnovi(n, p), the critical values.
  5419. See Also
  5420. --------
  5421. smirnov : The Survival Function (SF) for the distribution
  5422. scipy.stats.ksone : Provides the functionality as a continuous distribution
  5423. kolmogorov, kolmogi : Functions for the two-sided distribution
  5424. scipy.stats.kstwobign : Two-sided Kolmogorov-Smirnov distribution, large n
  5425. Notes
  5426. -----
  5427. `smirnov` is used by `stats.kstest` in the application of the
  5428. Kolmogorov-Smirnov Goodness of Fit test. For historical reasons this
  5429. function is exposed in `scpy.special`, but the recommended way to achieve
  5430. the most accurate CDF/SF/PDF/PPF/ISF computations is to use the
  5431. `stats.ksone` distribution.
  5432. Examples
  5433. --------
  5434. >>> from scipy.special import smirnovi, smirnov
  5435. >>> n = 24
  5436. >>> deviations = [0.1, 0.2, 0.3]
  5437. Use `smirnov` to compute the complementary CDF of the Smirnov
  5438. distribution for the given number of samples and deviations.
  5439. >>> p = smirnov(n, deviations)
  5440. >>> p
  5441. array([0.58105083, 0.12826832, 0.01032231])
  5442. The inverse function ``smirnovi(n, p)`` returns ``deviations``.
  5443. >>> smirnovi(n, p)
  5444. array([0.1, 0.2, 0.3])
  5445. """)
  5446. add_newdoc("_smirnovc",
  5447. """
  5448. _smirnovc(n, d)
  5449. Internal function, do not use.
  5450. """)
  5451. add_newdoc("_smirnovci",
  5452. """
  5453. Internal function, do not use.
  5454. """)
  5455. add_newdoc("_smirnovp",
  5456. """
  5457. _smirnovp(n, p)
  5458. Internal function, do not use.
  5459. """)
  5460. add_newdoc("spence",
  5461. r"""
  5462. spence(z, out=None)
  5463. Spence's function, also known as the dilogarithm.
  5464. It is defined to be
  5465. .. math::
  5466. \int_1^z \frac{\log(t)}{1 - t}dt
  5467. for complex :math:`z`, where the contour of integration is taken
  5468. to avoid the branch cut of the logarithm. Spence's function is
  5469. analytic everywhere except the negative real axis where it has a
  5470. branch cut.
  5471. Parameters
  5472. ----------
  5473. z : array_like
  5474. Points at which to evaluate Spence's function
  5475. out : ndarray, optional
  5476. Optional output array for the function results
  5477. Returns
  5478. -------
  5479. s : scalar or ndarray
  5480. Computed values of Spence's function
  5481. Notes
  5482. -----
  5483. There is a different convention which defines Spence's function by
  5484. the integral
  5485. .. math::
  5486. -\int_0^z \frac{\log(1 - t)}{t}dt;
  5487. this is our ``spence(1 - z)``.
  5488. Examples
  5489. --------
  5490. >>> import numpy as np
  5491. >>> from scipy.special import spence
  5492. >>> import matplotlib.pyplot as plt
  5493. The function is defined for complex inputs:
  5494. >>> spence([1-1j, 1.5+2j, 3j, -10-5j])
  5495. array([-0.20561676+0.91596559j, -0.86766909-1.39560134j,
  5496. -0.59422064-2.49129918j, -1.14044398+6.80075924j])
  5497. For complex inputs on the branch cut, which is the negative real axis,
  5498. the function returns the limit for ``z`` with positive imaginary part.
  5499. For example, in the following, note the sign change of the imaginary
  5500. part of the output for ``z = -2`` and ``z = -2 - 1e-8j``:
  5501. >>> spence([-2 + 1e-8j, -2, -2 - 1e-8j])
  5502. array([2.32018041-3.45139229j, 2.32018042-3.4513923j ,
  5503. 2.32018041+3.45139229j])
  5504. The function returns ``nan`` for real inputs on the branch cut:
  5505. >>> spence(-1.5)
  5506. nan
  5507. Verify some particular values: ``spence(0) = pi**2/6``,
  5508. ``spence(1) = 0`` and ``spence(2) = -pi**2/12``.
  5509. >>> spence([0, 1, 2])
  5510. array([ 1.64493407, 0. , -0.82246703])
  5511. >>> np.pi**2/6, -np.pi**2/12
  5512. (1.6449340668482264, -0.8224670334241132)
  5513. Verify the identity::
  5514. spence(z) + spence(1 - z) = pi**2/6 - log(z)*log(1 - z)
  5515. >>> z = 3 + 4j
  5516. >>> spence(z) + spence(1 - z)
  5517. (-2.6523186143876067+1.8853470951513935j)
  5518. >>> np.pi**2/6 - np.log(z)*np.log(1 - z)
  5519. (-2.652318614387606+1.885347095151394j)
  5520. Plot the function for positive real input.
  5521. >>> fig, ax = plt.subplots()
  5522. >>> x = np.linspace(0, 6, 400)
  5523. >>> ax.plot(x, spence(x))
  5524. >>> ax.grid()
  5525. >>> ax.set_xlabel('x')
  5526. >>> ax.set_title('spence(x)')
  5527. >>> plt.show()
  5528. """)
  5529. add_newdoc(
  5530. "stdtr",
  5531. r"""
  5532. stdtr(df, t, out=None)
  5533. Student t distribution cumulative distribution function
  5534. Returns the integral:
  5535. .. math::
  5536. \frac{\Gamma((df+1)/2)}{\sqrt{\pi df} \Gamma(df/2)}
  5537. \int_{-\infty}^t (1+x^2/df)^{-(df+1)/2}\, dx
  5538. Parameters
  5539. ----------
  5540. df : array_like
  5541. Degrees of freedom
  5542. t : array_like
  5543. Upper bound of the integral
  5544. out : ndarray, optional
  5545. Optional output array for the function results
  5546. Returns
  5547. -------
  5548. scalar or ndarray
  5549. Value of the Student t CDF at t
  5550. See Also
  5551. --------
  5552. stdtridf : inverse of stdtr with respect to `df`
  5553. stdtrit : inverse of stdtr with respect to `t`
  5554. scipy.stats.t : student t distribution
  5555. Notes
  5556. -----
  5557. The student t distribution is also available as `scipy.stats.t`.
  5558. Calling `stdtr` directly can improve performance compared to the
  5559. ``cdf`` method of `scipy.stats.t` (see last example below).
  5560. The function is computed using the Boost Math library [1]_, which
  5561. relies on the incomplete beta function.
  5562. References
  5563. ----------
  5564. .. [1] Boost C++ Libraries, http://www.boost.org/
  5565. Examples
  5566. --------
  5567. Calculate the function for ``df=3`` at ``t=1``.
  5568. >>> import numpy as np
  5569. >>> from scipy.special import stdtr
  5570. >>> import matplotlib.pyplot as plt
  5571. >>> stdtr(3, 1)
  5572. 0.8044988905221148
  5573. Plot the function for three different degrees of freedom.
  5574. >>> x = np.linspace(-10, 10, 1000)
  5575. >>> fig, ax = plt.subplots()
  5576. >>> parameters = [(1, "solid"), (3, "dashed"), (10, "dotted")]
  5577. >>> for (df, linestyle) in parameters:
  5578. ... ax.plot(x, stdtr(df, x), ls=linestyle, label=f"$df={df}$")
  5579. >>> ax.legend()
  5580. >>> ax.set_title("Student t distribution cumulative distribution function")
  5581. >>> plt.show()
  5582. The function can be computed for several degrees of freedom at the same
  5583. time by providing a NumPy array or list for `df`:
  5584. >>> stdtr([1, 2, 3], 1)
  5585. array([0.75 , 0.78867513, 0.80449889])
  5586. It is possible to calculate the function at several points for several
  5587. different degrees of freedom simultaneously by providing arrays for `df`
  5588. and `t` with shapes compatible for broadcasting. Compute `stdtr` at
  5589. 4 points for 3 degrees of freedom resulting in an array of shape 3x4.
  5590. >>> dfs = np.array([[1], [2], [3]])
  5591. >>> t = np.array([2, 4, 6, 8])
  5592. >>> dfs.shape, t.shape
  5593. ((3, 1), (4,))
  5594. >>> stdtr(dfs, t)
  5595. array([[0.85241638, 0.92202087, 0.94743154, 0.96041658],
  5596. [0.90824829, 0.97140452, 0.98666426, 0.99236596],
  5597. [0.93033702, 0.98599577, 0.99536364, 0.99796171]])
  5598. The t distribution is also available as `scipy.stats.t`. Calling `stdtr`
  5599. directly can be much faster than calling the ``cdf`` method of
  5600. `scipy.stats.t`. To get the same results, one must use the following
  5601. parametrization: ``scipy.stats.t(df).cdf(x) = stdtr(df, x)``.
  5602. >>> from scipy.stats import t
  5603. >>> df, x = 3, 1
  5604. >>> stdtr_result = stdtr(df, x) # this can be faster than below
  5605. >>> stats_result = t(df).cdf(x)
  5606. >>> stats_result == stdtr_result # test that results are equal
  5607. True
  5608. """)
  5609. add_newdoc("stdtridf",
  5610. """
  5611. stdtridf(p, t, out=None)
  5612. Inverse of `stdtr` vs df
  5613. Returns the argument df such that stdtr(df, t) is equal to `p`.
  5614. Parameters
  5615. ----------
  5616. p : array_like
  5617. Probability
  5618. t : array_like
  5619. Upper bound of the integral
  5620. out : ndarray, optional
  5621. Optional output array for the function results
  5622. Returns
  5623. -------
  5624. df : scalar or ndarray
  5625. Value of `df` such that ``stdtr(df, t) == p``
  5626. See Also
  5627. --------
  5628. stdtr : Student t CDF
  5629. stdtrit : inverse of stdtr with respect to `t`
  5630. scipy.stats.t : Student t distribution
  5631. Examples
  5632. --------
  5633. Compute the student t cumulative distribution function for one
  5634. parameter set.
  5635. >>> from scipy.special import stdtr, stdtridf
  5636. >>> df, x = 5, 2
  5637. >>> cdf_value = stdtr(df, x)
  5638. >>> cdf_value
  5639. 0.9490302605850709
  5640. Verify that `stdtridf` recovers the original value for `df` given
  5641. the CDF value and `x`.
  5642. >>> stdtridf(cdf_value, x)
  5643. 5.0
  5644. """)
  5645. add_newdoc("stdtrit",
  5646. """
  5647. stdtrit(df, p, out=None)
  5648. The `p`-th quantile of the student t distribution.
  5649. This function is the inverse of the student t distribution cumulative
  5650. distribution function (CDF), returning `t` such that `stdtr(df, t) = p`.
  5651. Returns the argument `t` such that stdtr(df, t) is equal to `p`.
  5652. Parameters
  5653. ----------
  5654. df : array_like
  5655. Degrees of freedom
  5656. p : array_like
  5657. Probability
  5658. out : ndarray, optional
  5659. Optional output array for the function results
  5660. Returns
  5661. -------
  5662. t : scalar or ndarray
  5663. Value of `t` such that ``stdtr(df, t) == p``
  5664. See Also
  5665. --------
  5666. stdtr : Student t CDF
  5667. stdtridf : inverse of stdtr with respect to `df`
  5668. scipy.stats.t : Student t distribution
  5669. Notes
  5670. -----
  5671. The student t distribution is also available as `scipy.stats.t`. Calling
  5672. `stdtrit` directly can improve performance compared to the ``ppf``
  5673. method of `scipy.stats.t` (see last example below).
  5674. The function is computed using the Boost Math library [1]_, which
  5675. relies on the incomplete beta function.
  5676. References
  5677. ----------
  5678. .. [1] Boost C++ Libraries, http://www.boost.org/
  5679. Examples
  5680. --------
  5681. `stdtrit` represents the inverse of the student t distribution CDF which
  5682. is available as `stdtr`. Here, we calculate the CDF for ``df`` at
  5683. ``x=1``. `stdtrit` then returns ``1`` up to floating point errors
  5684. given the same value for `df` and the computed CDF value.
  5685. >>> import numpy as np
  5686. >>> from scipy.special import stdtr, stdtrit
  5687. >>> import matplotlib.pyplot as plt
  5688. >>> df = 3
  5689. >>> x = 1
  5690. >>> cdf_value = stdtr(df, x)
  5691. >>> stdtrit(df, cdf_value)
  5692. 0.9999999994418539
  5693. Plot the function for three different degrees of freedom.
  5694. >>> x = np.linspace(0, 1, 1000)
  5695. >>> parameters = [(1, "solid"), (2, "dashed"), (5, "dotted")]
  5696. >>> fig, ax = plt.subplots()
  5697. >>> for (df, linestyle) in parameters:
  5698. ... ax.plot(x, stdtrit(df, x), ls=linestyle, label=f"$df={df}$")
  5699. >>> ax.legend()
  5700. >>> ax.set_ylim(-10, 10)
  5701. >>> ax.set_title("Student t distribution quantile function")
  5702. >>> plt.show()
  5703. The function can be computed for several degrees of freedom at the same
  5704. time by providing a NumPy array or list for `df`:
  5705. >>> stdtrit([1, 2, 3], 0.7)
  5706. array([0.72654253, 0.6172134 , 0.58438973])
  5707. It is possible to calculate the function at several points for several
  5708. different degrees of freedom simultaneously by providing arrays for `df`
  5709. and `p` with shapes compatible for broadcasting. Compute `stdtrit` at
  5710. 4 points for 3 degrees of freedom resulting in an array of shape 3x4.
  5711. >>> dfs = np.array([[1], [2], [3]])
  5712. >>> p = np.array([0.2, 0.4, 0.7, 0.8])
  5713. >>> dfs.shape, p.shape
  5714. ((3, 1), (4,))
  5715. >>> stdtrit(dfs, p)
  5716. array([[-1.37638192, -0.3249197 , 0.72654253, 1.37638192],
  5717. [-1.06066017, -0.28867513, 0.6172134 , 1.06066017],
  5718. [-0.97847231, -0.27667066, 0.58438973, 0.97847231]])
  5719. The t distribution is also available as `scipy.stats.t`. Calling `stdtrit`
  5720. directly can be much faster than calling the ``ppf`` method of
  5721. `scipy.stats.t`. To get the same results, one must use the following
  5722. parametrization: ``scipy.stats.t(df).ppf(x) = stdtrit(df, x)``.
  5723. >>> from scipy.stats import t
  5724. >>> df, x = 3, 0.5
  5725. >>> stdtrit_result = stdtrit(df, x) # this can be faster than below
  5726. >>> stats_result = t(df).ppf(x)
  5727. >>> stats_result == stdtrit_result # test that results are equal
  5728. True
  5729. """)
  5730. add_newdoc(
  5731. "tklmbda",
  5732. r"""
  5733. tklmbda(x, lmbda, out=None)
  5734. Cumulative distribution function of the Tukey lambda distribution.
  5735. Parameters
  5736. ----------
  5737. x, lmbda : array_like
  5738. Parameters
  5739. out : ndarray, optional
  5740. Optional output array for the function results
  5741. Returns
  5742. -------
  5743. cdf : scalar or ndarray
  5744. Value of the Tukey lambda CDF
  5745. See Also
  5746. --------
  5747. scipy.stats.tukeylambda : Tukey lambda distribution
  5748. Examples
  5749. --------
  5750. >>> import numpy as np
  5751. >>> import matplotlib.pyplot as plt
  5752. >>> from scipy.special import tklmbda, expit
  5753. Compute the cumulative distribution function (CDF) of the Tukey lambda
  5754. distribution at several ``x`` values for `lmbda` = -1.5.
  5755. >>> x = np.linspace(-2, 2, 9)
  5756. >>> x
  5757. array([-2. , -1.5, -1. , -0.5, 0. , 0.5, 1. , 1.5, 2. ])
  5758. >>> tklmbda(x, -1.5)
  5759. array([0.34688734, 0.3786554 , 0.41528805, 0.45629737, 0.5 ,
  5760. 0.54370263, 0.58471195, 0.6213446 , 0.65311266])
  5761. When `lmbda` is 0, the function is the logistic sigmoid function,
  5762. which is implemented in `scipy.special` as `expit`.
  5763. >>> tklmbda(x, 0)
  5764. array([0.11920292, 0.18242552, 0.26894142, 0.37754067, 0.5 ,
  5765. 0.62245933, 0.73105858, 0.81757448, 0.88079708])
  5766. >>> expit(x)
  5767. array([0.11920292, 0.18242552, 0.26894142, 0.37754067, 0.5 ,
  5768. 0.62245933, 0.73105858, 0.81757448, 0.88079708])
  5769. When `lmbda` is 1, the Tukey lambda distribution is uniform on the
  5770. interval [-1, 1], so the CDF increases linearly.
  5771. >>> t = np.linspace(-1, 1, 9)
  5772. >>> tklmbda(t, 1)
  5773. array([0. , 0.125, 0.25 , 0.375, 0.5 , 0.625, 0.75 , 0.875, 1. ])
  5774. In the following, we generate plots for several values of `lmbda`.
  5775. The first figure shows graphs for `lmbda` <= 0.
  5776. >>> styles = ['-', '-.', '--', ':']
  5777. >>> fig, ax = plt.subplots()
  5778. >>> x = np.linspace(-12, 12, 500)
  5779. >>> for k, lmbda in enumerate([-1.0, -0.5, 0.0]):
  5780. ... y = tklmbda(x, lmbda)
  5781. ... ax.plot(x, y, styles[k], label=rf'$\lambda$ = {lmbda:-4.1f}')
  5782. >>> ax.set_title(r'tklmbda(x, $\lambda$)')
  5783. >>> ax.set_label('x')
  5784. >>> ax.legend(framealpha=1, shadow=True)
  5785. >>> ax.grid(True)
  5786. The second figure shows graphs for `lmbda` > 0. The dots in the
  5787. graphs show the bounds of the support of the distribution.
  5788. >>> fig, ax = plt.subplots()
  5789. >>> x = np.linspace(-4.2, 4.2, 500)
  5790. >>> lmbdas = [0.25, 0.5, 1.0, 1.5]
  5791. >>> for k, lmbda in enumerate(lmbdas):
  5792. ... y = tklmbda(x, lmbda)
  5793. ... ax.plot(x, y, styles[k], label=fr'$\lambda$ = {lmbda}')
  5794. >>> ax.set_prop_cycle(None)
  5795. >>> for lmbda in lmbdas:
  5796. ... ax.plot([-1/lmbda, 1/lmbda], [0, 1], '.', ms=8)
  5797. >>> ax.set_title(r'tklmbda(x, $\lambda$)')
  5798. >>> ax.set_xlabel('x')
  5799. >>> ax.legend(framealpha=1, shadow=True)
  5800. >>> ax.grid(True)
  5801. >>> plt.tight_layout()
  5802. >>> plt.show()
  5803. The CDF of the Tukey lambda distribution is also implemented as the
  5804. ``cdf`` method of `scipy.stats.tukeylambda`. In the following,
  5805. ``tukeylambda.cdf(x, -0.5)`` and ``tklmbda(x, -0.5)`` compute the
  5806. same values:
  5807. >>> from scipy.stats import tukeylambda
  5808. >>> x = np.linspace(-2, 2, 9)
  5809. >>> tukeylambda.cdf(x, -0.5)
  5810. array([0.21995157, 0.27093858, 0.33541677, 0.41328161, 0.5 ,
  5811. 0.58671839, 0.66458323, 0.72906142, 0.78004843])
  5812. >>> tklmbda(x, -0.5)
  5813. array([0.21995157, 0.27093858, 0.33541677, 0.41328161, 0.5 ,
  5814. 0.58671839, 0.66458323, 0.72906142, 0.78004843])
  5815. The implementation in ``tukeylambda`` also provides location and scale
  5816. parameters, and other methods such as ``pdf()`` (the probability
  5817. density function) and ``ppf()`` (the inverse of the CDF), so for
  5818. working with the Tukey lambda distribution, ``tukeylambda`` is more
  5819. generally useful. The primary advantage of ``tklmbda`` is that it is
  5820. significantly faster than ``tukeylambda.cdf``.
  5821. """)
  5822. add_newdoc("yn",
  5823. r"""
  5824. yn(n, x, out=None)
  5825. Bessel function of the second kind of integer order and real argument.
  5826. Parameters
  5827. ----------
  5828. n : array_like
  5829. Order (integer).
  5830. x : array_like
  5831. Argument (float).
  5832. out : ndarray, optional
  5833. Optional output array for the function results
  5834. Returns
  5835. -------
  5836. Y : scalar or ndarray
  5837. Value of the Bessel function, :math:`Y_n(x)`.
  5838. See Also
  5839. --------
  5840. yv : For real order and real or complex argument.
  5841. y0: faster implementation of this function for order 0
  5842. y1: faster implementation of this function for order 1
  5843. Notes
  5844. -----
  5845. Wrapper for the Cephes [1]_ routine `yn`.
  5846. The function is evaluated by forward recurrence on `n`, starting with
  5847. values computed by the Cephes routines `y0` and `y1`. If ``n = 0`` or 1,
  5848. the routine for `y0` or `y1` is called directly.
  5849. References
  5850. ----------
  5851. .. [1] Cephes Mathematical Functions Library,
  5852. http://www.netlib.org/cephes/
  5853. Examples
  5854. --------
  5855. Evaluate the function of order 0 at one point.
  5856. >>> from scipy.special import yn
  5857. >>> yn(0, 1.)
  5858. 0.08825696421567697
  5859. Evaluate the function at one point for different orders.
  5860. >>> yn(0, 1.), yn(1, 1.), yn(2, 1.)
  5861. (0.08825696421567697, -0.7812128213002888, -1.6506826068162546)
  5862. The evaluation for different orders can be carried out in one call by
  5863. providing a list or NumPy array as argument for the `v` parameter:
  5864. >>> yn([0, 1, 2], 1.)
  5865. array([ 0.08825696, -0.78121282, -1.65068261])
  5866. Evaluate the function at several points for order 0 by providing an
  5867. array for `z`.
  5868. >>> import numpy as np
  5869. >>> points = np.array([0.5, 3., 8.])
  5870. >>> yn(0, points)
  5871. array([-0.44451873, 0.37685001, 0.22352149])
  5872. If `z` is an array, the order parameter `v` must be broadcastable to
  5873. the correct shape if different orders shall be computed in one call.
  5874. To calculate the orders 0 and 1 for a 1D array:
  5875. >>> orders = np.array([[0], [1]])
  5876. >>> orders.shape
  5877. (2, 1)
  5878. >>> yn(orders, points)
  5879. array([[-0.44451873, 0.37685001, 0.22352149],
  5880. [-1.47147239, 0.32467442, -0.15806046]])
  5881. Plot the functions of order 0 to 3 from 0 to 10.
  5882. >>> import matplotlib.pyplot as plt
  5883. >>> fig, ax = plt.subplots()
  5884. >>> x = np.linspace(0., 10., 1000)
  5885. >>> for i in range(4):
  5886. ... ax.plot(x, yn(i, x), label=f'$Y_{i!r}$')
  5887. >>> ax.set_ylim(-3, 1)
  5888. >>> ax.legend()
  5889. >>> plt.show()
  5890. """)
  5891. add_newdoc("_struve_asymp_large_z",
  5892. """
  5893. _struve_asymp_large_z(v, z, is_h)
  5894. Internal function for testing `struve` & `modstruve`
  5895. Evaluates using asymptotic expansion
  5896. Returns
  5897. -------
  5898. v, err
  5899. """)
  5900. add_newdoc("_struve_power_series",
  5901. """
  5902. _struve_power_series(v, z, is_h)
  5903. Internal function for testing `struve` & `modstruve`
  5904. Evaluates using power series
  5905. Returns
  5906. -------
  5907. v, err
  5908. """)
  5909. add_newdoc("_struve_bessel_series",
  5910. """
  5911. _struve_bessel_series(v, z, is_h)
  5912. Internal function for testing `struve` & `modstruve`
  5913. Evaluates using Bessel function series
  5914. Returns
  5915. -------
  5916. v, err
  5917. """)
  5918. add_newdoc("_spherical_jn",
  5919. """
  5920. Internal function, use `spherical_jn` instead.
  5921. """)
  5922. add_newdoc("_spherical_jn_d",
  5923. """
  5924. Internal function, use `spherical_jn` instead.
  5925. """)
  5926. add_newdoc("_spherical_yn",
  5927. """
  5928. Internal function, use `spherical_yn` instead.
  5929. """)
  5930. add_newdoc("_spherical_yn_d",
  5931. """
  5932. Internal function, use `spherical_yn` instead.
  5933. """)
  5934. add_newdoc("_spherical_in",
  5935. """
  5936. Internal function, use `spherical_in` instead.
  5937. """)
  5938. add_newdoc("_spherical_in_d",
  5939. """
  5940. Internal function, use `spherical_in` instead.
  5941. """)
  5942. add_newdoc("_spherical_kn",
  5943. """
  5944. Internal function, use `spherical_kn` instead.
  5945. """)
  5946. add_newdoc("_spherical_kn_d",
  5947. """
  5948. Internal function, use `spherical_kn` instead.
  5949. """)
  5950. add_newdoc("owens_t",
  5951. """
  5952. owens_t(h, a, out=None)
  5953. Owen's T Function.
  5954. The function T(h, a) gives the probability of the event
  5955. (X > h and 0 < Y < a * X) where X and Y are independent
  5956. standard normal random variables.
  5957. Parameters
  5958. ----------
  5959. h: array_like
  5960. Input value.
  5961. a: array_like
  5962. Input value.
  5963. out : ndarray, optional
  5964. Optional output array for the function results
  5965. Returns
  5966. -------
  5967. t: scalar or ndarray
  5968. Probability of the event (X > h and 0 < Y < a * X),
  5969. where X and Y are independent standard normal random variables.
  5970. References
  5971. ----------
  5972. .. [1] M. Patefield and D. Tandy, "Fast and accurate calculation of
  5973. Owen's T Function", Statistical Software vol. 5, pp. 1-25, 2000.
  5974. Examples
  5975. --------
  5976. >>> from scipy import special
  5977. >>> a = 3.5
  5978. >>> h = 0.78
  5979. >>> special.owens_t(h, a)
  5980. 0.10877216734852274
  5981. """)
  5982. add_newdoc("_factorial",
  5983. """
  5984. Internal function, do not use.
  5985. """)
  5986. add_newdoc("ndtri_exp",
  5987. r"""
  5988. ndtri_exp(y, out=None)
  5989. Inverse of `log_ndtr` vs x. Allows for greater precision than
  5990. `ndtri` composed with `numpy.exp` for very small values of y and for
  5991. y close to 0.
  5992. Parameters
  5993. ----------
  5994. y : array_like of float
  5995. Function argument
  5996. out : ndarray, optional
  5997. Optional output array for the function results
  5998. Returns
  5999. -------
  6000. scalar or ndarray
  6001. Inverse of the log CDF of the standard normal distribution, evaluated
  6002. at y.
  6003. See Also
  6004. --------
  6005. log_ndtr : log of the standard normal cumulative distribution function
  6006. ndtr : standard normal cumulative distribution function
  6007. ndtri : standard normal percentile function
  6008. Examples
  6009. --------
  6010. >>> import numpy as np
  6011. >>> import scipy.special as sc
  6012. `ndtri_exp` agrees with the naive implementation when the latter does
  6013. not suffer from underflow.
  6014. >>> sc.ndtri_exp(-1)
  6015. -0.33747496376420244
  6016. >>> sc.ndtri(np.exp(-1))
  6017. -0.33747496376420244
  6018. For extreme values of y, the naive approach fails
  6019. >>> sc.ndtri(np.exp(-800))
  6020. -inf
  6021. >>> sc.ndtri(np.exp(-1e-20))
  6022. inf
  6023. whereas `ndtri_exp` is still able to compute the result to high precision.
  6024. >>> sc.ndtri_exp(-800)
  6025. -39.88469483825668
  6026. >>> sc.ndtri_exp(-1e-20)
  6027. 9.262340089798409
  6028. """)
  6029. add_newdoc("_stirling2_inexact",
  6030. r"""
  6031. Internal function, do not use.
  6032. """)
  6033. add_newdoc(
  6034. "_beta_pdf",
  6035. r"""
  6036. _beta_pdf(x, a, b)
  6037. Probability density function of beta distribution.
  6038. Parameters
  6039. ----------
  6040. x : array_like
  6041. Real-valued such that :math:`0 \leq x \leq 1`,
  6042. the upper limit of integration
  6043. a, b : array_like
  6044. Positive, real-valued parameters
  6045. Returns
  6046. -------
  6047. scalar or ndarray
  6048. """)
  6049. add_newdoc(
  6050. "_beta_ppf",
  6051. r"""
  6052. _beta_ppf(x, a, b)
  6053. Percent point function of beta distribution.
  6054. Parameters
  6055. ----------
  6056. x : array_like
  6057. Real-valued such that :math:`0 \leq x \leq 1`,
  6058. the upper limit of integration
  6059. a, b : array_like
  6060. Positive, real-valued parameters
  6061. Returns
  6062. -------
  6063. scalar or ndarray
  6064. """)
  6065. add_newdoc(
  6066. "_invgauss_ppf",
  6067. """
  6068. _invgauss_ppf(x, mu)
  6069. Percent point function of inverse gaussian distribution.
  6070. Parameters
  6071. ----------
  6072. x : array_like
  6073. Positive real-valued
  6074. mu : array_like
  6075. Positive, real-valued parameters
  6076. Returns
  6077. -------
  6078. scalar or ndarray
  6079. """)
  6080. add_newdoc(
  6081. "_invgauss_isf",
  6082. """
  6083. _invgauss_isf(x, mu, s)
  6084. Inverse survival function of inverse gaussian distribution.
  6085. Parameters
  6086. ----------
  6087. x : array_like
  6088. Positive real-valued
  6089. mu : array_like
  6090. Positive, real-valued parameters
  6091. s : array_like
  6092. Positive, real-valued parameters
  6093. Returns
  6094. -------
  6095. scalar or ndarray
  6096. """)
  6097. add_newdoc(
  6098. "_cauchy_ppf",
  6099. """
  6100. _cauchy_ppf(p, loc, scale)
  6101. Percent point function (i.e. quantile) of the Cauchy distribution.
  6102. Parameters
  6103. ----------
  6104. p : array_like
  6105. Probabilities
  6106. loc : array_like
  6107. Location parameter of the distribution.
  6108. scale : array_like
  6109. Scale parameter of the distribution.
  6110. Returns
  6111. -------
  6112. scalar or ndarray
  6113. """)
  6114. add_newdoc(
  6115. "_cauchy_isf",
  6116. """
  6117. _cauchy_isf(p, loc, scale)
  6118. Inverse survival function of the Cauchy distribution.
  6119. Parameters
  6120. ----------
  6121. p : array_like
  6122. Probabilities
  6123. loc : array_like
  6124. Location parameter of the distribution.
  6125. scale : array_like
  6126. Scale parameter of the distribution.
  6127. Returns
  6128. -------
  6129. scalar or ndarray
  6130. """)
  6131. add_newdoc(
  6132. "_ncx2_pdf",
  6133. """
  6134. _ncx2_pdf(x, k, l)
  6135. Probability density function of Non-central chi-squared distribution.
  6136. Parameters
  6137. ----------
  6138. x : array_like
  6139. Positive real-valued
  6140. k, l : array_like
  6141. Positive, real-valued parameters
  6142. Returns
  6143. -------
  6144. scalar or ndarray
  6145. """)
  6146. add_newdoc(
  6147. "_ncx2_cdf",
  6148. """
  6149. _ncx2_cdf(x, k, l)
  6150. Cumulative density function of Non-central chi-squared distribution.
  6151. Parameters
  6152. ----------
  6153. x : array_like
  6154. Positive real-valued
  6155. k, l : array_like
  6156. Positive, real-valued parameters
  6157. Returns
  6158. -------
  6159. scalar or ndarray
  6160. """)
  6161. add_newdoc(
  6162. "_ncx2_ppf",
  6163. """
  6164. _ncx2_ppf(x, k, l)
  6165. Percent point function of Non-central chi-squared distribution.
  6166. Parameters
  6167. ----------
  6168. x : array_like
  6169. Positive real-valued
  6170. k, l : array_like
  6171. Positive, real-valued parameters
  6172. Returns
  6173. -------
  6174. scalar or ndarray
  6175. """)
  6176. add_newdoc(
  6177. "_ncx2_sf",
  6178. """
  6179. _ncx2_sf(x, k, l)
  6180. Survival function of Non-central chi-squared distribution.
  6181. Parameters
  6182. ----------
  6183. x : array_like
  6184. Positive real-valued
  6185. k, l : array_like
  6186. Positive, real-valued parameters
  6187. Returns
  6188. -------
  6189. scalar or ndarray
  6190. """)
  6191. add_newdoc(
  6192. "_ncx2_isf",
  6193. """
  6194. _ncx2_isf(x, k, l)
  6195. Inverse survival function of Non-central chi-squared distribution.
  6196. Parameters
  6197. ----------
  6198. x : array_like
  6199. Positive real-valued
  6200. k, l : array_like
  6201. Positive, real-valued parameters
  6202. Returns
  6203. -------
  6204. scalar or ndarray
  6205. """)
  6206. add_newdoc(
  6207. "_ncf_pdf",
  6208. """
  6209. _ncf_pdf(x, v1, v2, l)
  6210. Probability density function of noncentral F-distribution.
  6211. Parameters
  6212. ----------
  6213. x : array_like
  6214. Positive real-valued
  6215. v1, v2, l : array_like
  6216. Positive, real-valued parameters
  6217. Returns
  6218. -------
  6219. scalar or ndarray
  6220. """)
  6221. add_newdoc(
  6222. "_ncf_cdf",
  6223. """
  6224. _ncf_cdf(x, v1, v2, l)
  6225. Cumulative density function of noncentral F-distribution.
  6226. Parameters
  6227. ----------
  6228. x : array_like
  6229. Positive real-valued
  6230. v1, v2, l : array_like
  6231. Positive, real-valued parameters
  6232. Returns
  6233. -------
  6234. scalar or ndarray
  6235. """)
  6236. add_newdoc(
  6237. "_ncf_ppf",
  6238. """
  6239. _ncf_ppf(x, v1, v2, l)
  6240. Percent point function of noncentral F-distribution.
  6241. Parameters
  6242. ----------
  6243. x : array_like
  6244. Positive real-valued
  6245. v1, v2, l : array_like
  6246. Positive, real-valued parameters
  6247. Returns
  6248. -------
  6249. scalar or ndarray
  6250. """)
  6251. add_newdoc(
  6252. "_ncf_sf",
  6253. """
  6254. _ncf_sf(x, v1, v2, l)
  6255. Survival function of noncentral F-distribution.
  6256. Parameters
  6257. ----------
  6258. x : array_like
  6259. Positive real-valued
  6260. v1, v2, l : array_like
  6261. Positive, real-valued parameters
  6262. Returns
  6263. -------
  6264. scalar or ndarray
  6265. """)
  6266. add_newdoc(
  6267. "_ncf_isf",
  6268. """
  6269. _ncf_isf(x, v1, v2, l)
  6270. Inverse survival function of noncentral F-distribution.
  6271. Parameters
  6272. ----------
  6273. x : array_like
  6274. Positive real-valued
  6275. v1, v2, l : array_like
  6276. Positive, real-valued parameters
  6277. Returns
  6278. -------
  6279. scalar or ndarray
  6280. """)
  6281. add_newdoc(
  6282. "_ncf_mean",
  6283. """
  6284. _ncf_mean(v1, v2, l)
  6285. Mean of noncentral F-distribution.
  6286. Parameters
  6287. ----------
  6288. v1, v2, l : array_like
  6289. Positive, real-valued parameters
  6290. Returns
  6291. -------
  6292. scalar or ndarray
  6293. """)
  6294. add_newdoc(
  6295. "_ncf_variance",
  6296. """
  6297. _ncf_variance(v1, v2, l)
  6298. Variance of noncentral F-distribution.
  6299. Parameters
  6300. ----------
  6301. v1, v2, l : array_like
  6302. Positive, real-valued parameters
  6303. Returns
  6304. -------
  6305. scalar or ndarray
  6306. """)
  6307. add_newdoc(
  6308. "_ncf_skewness",
  6309. """
  6310. _ncf_skewness(v1, v2, l)
  6311. Skewness of noncentral F-distribution.
  6312. Parameters
  6313. ----------
  6314. v1, v2, l : array_like
  6315. Positive, real-valued parameters
  6316. Returns
  6317. -------
  6318. scalar or ndarray
  6319. """)
  6320. add_newdoc(
  6321. "_ncf_kurtosis_excess",
  6322. """
  6323. _ncf_kurtosis_excess(v1, v2, l)
  6324. Kurtosis excess of noncentral F-distribution.
  6325. Parameters
  6326. ----------
  6327. v1, v2, l : array_like
  6328. Positive, real-valued parameters
  6329. Returns
  6330. -------
  6331. scalar or ndarray
  6332. """)
  6333. add_newdoc(
  6334. "_nct_cdf",
  6335. """
  6336. _nct_cdf(x, v, l)
  6337. Cumulative density function of noncentral t-distribution.
  6338. Parameters
  6339. ----------
  6340. x : array_like
  6341. Real-valued
  6342. v : array_like
  6343. Positive, real-valued parameters
  6344. l : array_like
  6345. Real-valued parameters
  6346. Returns
  6347. -------
  6348. scalar or ndarray
  6349. """)
  6350. add_newdoc(
  6351. "_nct_pdf",
  6352. """
  6353. _nct_pdf(x, v, l)
  6354. Probability density function of noncentral t-distribution.
  6355. Parameters
  6356. ----------
  6357. x : array_like
  6358. Real-valued
  6359. v : array_like
  6360. Positive, real-valued parameters
  6361. l : array_like
  6362. Real-valued parameters
  6363. Returns
  6364. -------
  6365. scalar or ndarray
  6366. """)
  6367. add_newdoc(
  6368. "_nct_ppf",
  6369. """
  6370. _nct_ppf(x, v, l)
  6371. Percent point function of noncentral t-distribution.
  6372. Parameters
  6373. ----------
  6374. x : array_like
  6375. Real-valued
  6376. v : array_like
  6377. Positive, real-valued parameters
  6378. l : array_like
  6379. Real-valued parameters
  6380. Returns
  6381. -------
  6382. scalar or ndarray
  6383. """)
  6384. add_newdoc(
  6385. "_nct_sf",
  6386. """
  6387. _nct_sf(x, v, l)
  6388. Survival function of noncentral t-distribution.
  6389. Parameters
  6390. ----------
  6391. x : array_like
  6392. Real-valued
  6393. v : array_like
  6394. Positive, real-valued parameters
  6395. l : array_like
  6396. Real-valued parameters
  6397. Returns
  6398. -------
  6399. scalar or ndarray
  6400. """)
  6401. add_newdoc(
  6402. "_nct_isf",
  6403. """
  6404. _nct_isf(x, v, l)
  6405. Inverse survival function of noncentral t-distribution.
  6406. Parameters
  6407. ----------
  6408. x : array_like
  6409. Real-valued
  6410. v : array_like
  6411. Positive, real-valued parameters
  6412. l : array_like
  6413. Real-valued parameters
  6414. Returns
  6415. -------
  6416. scalar or ndarray
  6417. """)
  6418. add_newdoc(
  6419. "_nct_mean",
  6420. """
  6421. _nct_mean(v, l)
  6422. Mean of noncentral t-distribution.
  6423. Parameters
  6424. ----------
  6425. v : array_like
  6426. Positive, real-valued parameters
  6427. l : array_like
  6428. Real-valued parameters
  6429. Returns
  6430. -------
  6431. scalar or ndarray
  6432. """)
  6433. add_newdoc(
  6434. "_nct_variance",
  6435. """
  6436. _nct_variance(v, l)
  6437. Variance of noncentral t-distribution.
  6438. Parameters
  6439. ----------
  6440. v : array_like
  6441. Positive, real-valued parameters
  6442. l : array_like
  6443. Real-valued parameters
  6444. Returns
  6445. -------
  6446. scalar or ndarray
  6447. """)
  6448. add_newdoc(
  6449. "_nct_skewness",
  6450. """
  6451. _nct_skewness(v, l)
  6452. Skewness of noncentral t-distribution.
  6453. Parameters
  6454. ----------
  6455. v : array_like
  6456. Positive, real-valued parameters
  6457. l : array_like
  6458. Real-valued parameters
  6459. Returns
  6460. -------
  6461. scalar or ndarray
  6462. """)
  6463. add_newdoc(
  6464. "_nct_kurtosis_excess",
  6465. """
  6466. _nct_kurtosis_excess(v, l)
  6467. Kurtosis excess of noncentral t-distribution.
  6468. Parameters
  6469. ----------
  6470. v : array_like
  6471. Positive, real-valued parameters
  6472. l : array_like
  6473. Real-valued parameters
  6474. Returns
  6475. -------
  6476. scalar or ndarray
  6477. """)
  6478. add_newdoc(
  6479. "_skewnorm_cdf",
  6480. """
  6481. _skewnorm_cdf(x, l, sc, sh)
  6482. Cumulative density function of skewnorm distribution.
  6483. Parameters
  6484. ----------
  6485. x : array_like
  6486. Real-valued
  6487. l : array_like
  6488. Real-valued parameters
  6489. sc : array_like
  6490. Positive, Real-valued parameters
  6491. sh : array_like
  6492. Real-valued parameters
  6493. Returns
  6494. -------
  6495. scalar or ndarray
  6496. """)
  6497. add_newdoc(
  6498. "_skewnorm_ppf",
  6499. """
  6500. _skewnorm_ppf(x, l, sc, sh)
  6501. Percent point function of skewnorm distribution.
  6502. Parameters
  6503. ----------
  6504. x : array_like
  6505. Real-valued
  6506. l : array_like
  6507. Real-valued parameters
  6508. sc : array_like
  6509. Positive, Real-valued parameters
  6510. sh : array_like
  6511. Real-valued parameters
  6512. Returns
  6513. -------
  6514. scalar or ndarray
  6515. """)
  6516. add_newdoc(
  6517. "_skewnorm_isf",
  6518. """
  6519. _skewnorm_isf(x, l, sc, sh)
  6520. Inverse survival function of skewnorm distribution.
  6521. Parameters
  6522. ----------
  6523. x : array_like
  6524. Real-valued
  6525. l : array_like
  6526. Real-valued parameters
  6527. sc : array_like
  6528. Positive, Real-valued parameters
  6529. sh : array_like
  6530. Real-valued parameters
  6531. Returns
  6532. -------
  6533. scalar or ndarray
  6534. """)
  6535. add_newdoc(
  6536. "_binom_pmf",
  6537. """
  6538. _binom_pmf(x, n, p)
  6539. Probability mass function of binomial distribution.
  6540. Parameters
  6541. ----------
  6542. x : array_like
  6543. Real-valued
  6544. n : array_like
  6545. Positive, integer-valued parameter
  6546. p : array_like
  6547. Positive, real-valued parameter
  6548. Returns
  6549. -------
  6550. scalar or ndarray
  6551. """)
  6552. add_newdoc(
  6553. "_binom_cdf",
  6554. """
  6555. _binom_cdf(x, n, p)
  6556. Cumulative density function of binomial distribution.
  6557. Parameters
  6558. ----------
  6559. x : array_like
  6560. Real-valued
  6561. n : array_like
  6562. Positive, integer-valued parameter
  6563. p : array_like
  6564. Positive, real-valued parameter
  6565. Returns
  6566. -------
  6567. scalar or ndarray
  6568. """)
  6569. add_newdoc(
  6570. "_binom_ppf",
  6571. """
  6572. _binom_ppf(x, n, p)
  6573. Percent point function of binomial distribution.
  6574. Parameters
  6575. ----------
  6576. x : array_like
  6577. Real-valued
  6578. n : array_like
  6579. Positive, integer-valued parameter
  6580. p : array_like
  6581. Positive, real-valued parameter
  6582. Returns
  6583. -------
  6584. scalar or ndarray
  6585. """)
  6586. add_newdoc(
  6587. "_binom_sf",
  6588. """
  6589. _binom_sf(x, n, p)
  6590. Survival function of binomial distribution.
  6591. Parameters
  6592. ----------
  6593. x : array_like
  6594. Real-valued
  6595. n : array_like
  6596. Positive, integer-valued parameter
  6597. p : array_like
  6598. Positive, real-valued parameter
  6599. Returns
  6600. -------
  6601. scalar or ndarray
  6602. """)
  6603. add_newdoc(
  6604. "_binom_isf",
  6605. """
  6606. _binom_isf(x, n, p)
  6607. Inverse survival function of binomial distribution.
  6608. Parameters
  6609. ----------
  6610. x : array_like
  6611. Real-valued
  6612. n : array_like
  6613. Positive, integer-valued parameter
  6614. p : array_like
  6615. Positive, real-valued parameter
  6616. Returns
  6617. -------
  6618. scalar or ndarray
  6619. """)
  6620. add_newdoc(
  6621. "_nbinom_pmf",
  6622. """
  6623. _nbinom_pmf(x, r, p)
  6624. Probability mass function of negative binomial distribution.
  6625. Parameters
  6626. ----------
  6627. x : array_like
  6628. Real-valued
  6629. r : array_like
  6630. Positive, integer-valued parameter
  6631. p : array_like
  6632. Positive, real-valued parameter
  6633. Returns
  6634. -------
  6635. scalar or ndarray
  6636. """)
  6637. add_newdoc(
  6638. "_nbinom_cdf",
  6639. """
  6640. _nbinom_cdf(x, r, p)
  6641. Cumulative density function of negative binomial distribution.
  6642. Parameters
  6643. ----------
  6644. x : array_like
  6645. Real-valued
  6646. r : array_like
  6647. Positive, integer-valued parameter
  6648. p : array_like
  6649. Positive, real-valued parameter
  6650. Returns
  6651. -------
  6652. scalar or ndarray
  6653. """)
  6654. add_newdoc(
  6655. "_nbinom_ppf",
  6656. """
  6657. _nbinom_ppf(x, r, p)
  6658. Percent point function of negative binomial distribution.
  6659. Parameters
  6660. ----------
  6661. x : array_like
  6662. Real-valued
  6663. r : array_like
  6664. Positive, integer-valued parameter
  6665. p : array_like
  6666. Positive, real-valued parameter
  6667. Returns
  6668. -------
  6669. scalar or ndarray
  6670. """)
  6671. add_newdoc(
  6672. "_nbinom_sf",
  6673. """
  6674. _nbinom_sf(x, r, p)
  6675. Survival function of negative binomial distribution.
  6676. Parameters
  6677. ----------
  6678. x : array_like
  6679. Real-valued
  6680. r : array_like
  6681. Positive, integer-valued parameter
  6682. p : array_like
  6683. Positive, real-valued parameter
  6684. Returns
  6685. -------
  6686. scalar or ndarray
  6687. """)
  6688. add_newdoc(
  6689. "_nbinom_isf",
  6690. """
  6691. _nbinom_isf(x, r, p)
  6692. Inverse survival function of negative binomial distribution.
  6693. Parameters
  6694. ----------
  6695. x : array_like
  6696. Real-valued
  6697. r : array_like
  6698. Positive, integer-valued parameter
  6699. p : array_like
  6700. Positive, real-valued parameter
  6701. Returns
  6702. -------
  6703. scalar or ndarray
  6704. """)
  6705. add_newdoc(
  6706. "_nbinom_mean",
  6707. """
  6708. _nbinom_mean(r, p)
  6709. Mean of negative binomial distribution.
  6710. Parameters
  6711. ----------
  6712. r : array_like
  6713. Positive, integer-valued parameter
  6714. p : array_like
  6715. Positive, real-valued parameter
  6716. Returns
  6717. -------
  6718. scalar or ndarray
  6719. """)
  6720. add_newdoc(
  6721. "_nbinom_variance",
  6722. """
  6723. _nbinom_variance(r, p)
  6724. Variance of negative binomial distribution.
  6725. Parameters
  6726. ----------
  6727. r : array_like
  6728. Positive, integer-valued parameter
  6729. p : array_like
  6730. Positive, real-valued parameter
  6731. Returns
  6732. -------
  6733. scalar or ndarray
  6734. """)
  6735. add_newdoc(
  6736. "_nbinom_skewness",
  6737. """
  6738. _nbinom_skewness(r, p)
  6739. Skewness of negative binomial distribution.
  6740. Parameters
  6741. ----------
  6742. r : array_like
  6743. Positive, integer-valued parameter
  6744. p : array_like
  6745. Positive, real-valued parameter
  6746. Returns
  6747. -------
  6748. scalar or ndarray
  6749. """)
  6750. add_newdoc(
  6751. "_nbinom_kurtosis_excess",
  6752. """
  6753. _nbinom_kurtosis_excess(r, p)
  6754. Kurtosis excess of negative binomial distribution.
  6755. Parameters
  6756. ----------
  6757. r : array_like
  6758. Positive, integer-valued parameter
  6759. p : array_like
  6760. Positive, real-valued parameter
  6761. Returns
  6762. -------
  6763. scalar or ndarray
  6764. """)
  6765. add_newdoc(
  6766. "_hypergeom_pmf",
  6767. """
  6768. _hypergeom_pmf(x, r, N, M)
  6769. Probability mass function of hypergeometric distribution.
  6770. Parameters
  6771. ----------
  6772. x : array_like
  6773. Real-valued
  6774. r, N, M : array_like
  6775. Positive, integer-valued parameter
  6776. Returns
  6777. -------
  6778. scalar or ndarray
  6779. """)
  6780. add_newdoc(
  6781. "_hypergeom_cdf",
  6782. """
  6783. _hypergeom_cdf(x, r, N, M)
  6784. Cumulative density function of hypergeometric distribution.
  6785. Parameters
  6786. ----------
  6787. x : array_like
  6788. Real-valued
  6789. r, N, M : array_like
  6790. Positive, integer-valued parameter
  6791. Returns
  6792. -------
  6793. scalar or ndarray
  6794. """)
  6795. add_newdoc(
  6796. "_hypergeom_sf",
  6797. """
  6798. _hypergeom_sf(x, r, N, M)
  6799. Survival function of hypergeometric distribution.
  6800. Parameters
  6801. ----------
  6802. x : array_like
  6803. Real-valued
  6804. r, N, M : array_like
  6805. Positive, integer-valued parameter
  6806. Returns
  6807. -------
  6808. scalar or ndarray
  6809. """)
  6810. add_newdoc(
  6811. "_hypergeom_mean",
  6812. """
  6813. _hypergeom_mean(r, N, M)
  6814. Mean of hypergeometric distribution.
  6815. Parameters
  6816. ----------
  6817. r, N, M : array_like
  6818. Positive, integer-valued parameter
  6819. Returns
  6820. -------
  6821. scalar or ndarray
  6822. """)
  6823. add_newdoc(
  6824. "_hypergeom_variance",
  6825. """
  6826. _hypergeom_variance(r, N, M)
  6827. Mean of hypergeometric distribution.
  6828. Parameters
  6829. ----------
  6830. r, N, M : array_like
  6831. Positive, integer-valued parameter
  6832. Returns
  6833. -------
  6834. scalar or ndarray
  6835. """)
  6836. add_newdoc(
  6837. "_hypergeom_skewness",
  6838. """
  6839. _hypergeom_skewness(r, N, M)
  6840. Skewness of hypergeometric distribution.
  6841. Parameters
  6842. ----------
  6843. r, N, M : array_like
  6844. Positive, integer-valued parameter
  6845. Returns
  6846. -------
  6847. scalar or ndarray
  6848. """)