| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850 |
- # Docstrings for generated ufuncs
- #
- # The syntax is designed to look like the function add_newdoc is being
- # called from numpy.lib, but in this file add_newdoc puts the
- # docstrings in a dictionary. This dictionary is used in
- # _generate_pyx.py to generate the docstrings for the ufuncs in
- # scipy.special at the C level when the ufuncs are created at compile
- # time.
- docdict: dict[str, str] = {}
- def get(name):
- return docdict.get(name)
- def add_newdoc(name, doc):
- docdict[name] = doc
- add_newdoc("_sf_error_test_function",
- """
- Private function; do not use.
- """)
- add_newdoc("_cosine_cdf",
- """
- _cosine_cdf(x)
- Cumulative distribution function (CDF) of the cosine distribution::
- { 0, x < -pi
- cdf(x) = { (pi + x + sin(x))/(2*pi), -pi <= x <= pi
- { 1, x > pi
- Parameters
- ----------
- x : array_like
- `x` must contain real numbers.
- Returns
- -------
- scalar or ndarray
- The cosine distribution CDF evaluated at `x`.
- """)
- add_newdoc("_cosine_invcdf",
- """
- _cosine_invcdf(p)
- Inverse of the cumulative distribution function (CDF) of the cosine
- distribution.
- The CDF of the cosine distribution is::
- cdf(x) = (pi + x + sin(x))/(2*pi)
- This function computes the inverse of cdf(x).
- Parameters
- ----------
- p : array_like
- `p` must contain real numbers in the interval ``0 <= p <= 1``.
- `nan` is returned for values of `p` outside the interval [0, 1].
- Returns
- -------
- scalar or ndarray
- The inverse of the cosine distribution CDF evaluated at `p`.
- """)
- add_newdoc("_ellip_harm",
- """
- Internal function, use `ellip_harm` instead.
- """)
- add_newdoc("_ellip_norm",
- """
- Internal function, use `ellip_norm` instead.
- """)
- add_newdoc("wrightomega",
- r"""
- wrightomega(z, out=None)
- Wright Omega function.
- Defined as the solution to
- .. math::
- \omega + \log(\omega) = z
- where :math:`\log` is the principal branch of the complex logarithm.
- Parameters
- ----------
- z : array_like
- Points at which to evaluate the Wright Omega function
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- omega : scalar or ndarray
- Values of the Wright Omega function
- See Also
- --------
- lambertw : The Lambert W function
- Notes
- -----
- .. versionadded:: 0.19.0
- The function can also be defined as
- .. math::
- \omega(z) = W_{K(z)}(e^z)
- where :math:`K(z) = \lceil (\Im(z) - \pi)/(2\pi) \rceil` is the
- unwinding number and :math:`W` is the Lambert W function.
- The implementation here is taken from [1]_.
- References
- ----------
- .. [1] Lawrence, Corless, and Jeffrey, "Algorithm 917: Complex
- Double-Precision Evaluation of the Wright :math:`\omega`
- Function." ACM Transactions on Mathematical Software,
- 2012. :doi:`10.1145/2168773.2168779`.
- Examples
- --------
- >>> import numpy as np
- >>> from scipy.special import wrightomega, lambertw
- >>> wrightomega([-2, -1, 0, 1, 2])
- array([0.12002824, 0.27846454, 0.56714329, 1. , 1.5571456 ])
- Complex input:
- >>> wrightomega(3 + 5j)
- (1.5804428632097158+3.8213626783287937j)
- Verify that ``wrightomega(z)`` satisfies ``w + log(w) = z``:
- >>> w = -5 + 4j
- >>> wrightomega(w + np.log(w))
- (-5+4j)
- Verify the connection to ``lambertw``:
- >>> z = 0.5 + 3j
- >>> wrightomega(z)
- (0.0966015889280649+1.4937828458191993j)
- >>> lambertw(np.exp(z))
- (0.09660158892806493+1.4937828458191993j)
- >>> z = 0.5 + 4j
- >>> wrightomega(z)
- (-0.3362123489037213+2.282986001579032j)
- >>> lambertw(np.exp(z), k=1)
- (-0.33621234890372115+2.282986001579032j)
- """)
- add_newdoc("agm",
- """
- agm(a, b, out=None)
- Compute the arithmetic-geometric mean of `a` and `b`.
- Start with a_0 = a and b_0 = b and iteratively compute::
- a_{n+1} = (a_n + b_n)/2
- b_{n+1} = sqrt(a_n*b_n)
- a_n and b_n converge to the same limit as n increases; their common
- limit is agm(a, b).
- Parameters
- ----------
- a, b : array_like
- Real values only. If the values are both negative, the result
- is negative. If one value is negative and the other is positive,
- `nan` is returned.
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- scalar or ndarray
- The arithmetic-geometric mean of `a` and `b`.
- Examples
- --------
- >>> import numpy as np
- >>> from scipy.special import agm
- >>> a, b = 24.0, 6.0
- >>> agm(a, b)
- 13.458171481725614
- Compare that result to the iteration:
- >>> while a != b:
- ... a, b = (a + b)/2, np.sqrt(a*b)
- ... print("a = %19.16f b=%19.16f" % (a, b))
- ...
- a = 15.0000000000000000 b=12.0000000000000000
- a = 13.5000000000000000 b=13.4164078649987388
- a = 13.4582039324993694 b=13.4581390309909850
- a = 13.4581714817451772 b=13.4581714817060547
- a = 13.4581714817256159 b=13.4581714817256159
- When array-like arguments are given, broadcasting applies:
- >>> a = np.array([[1.5], [3], [6]]) # a has shape (3, 1).
- >>> b = np.array([6, 12, 24, 48]) # b has shape (4,).
- >>> agm(a, b)
- array([[ 3.36454287, 5.42363427, 9.05798751, 15.53650756],
- [ 4.37037309, 6.72908574, 10.84726853, 18.11597502],
- [ 6. , 8.74074619, 13.45817148, 21.69453707]])
- """)
- add_newdoc("bdtr",
- r"""
- bdtr(k, n, p, out=None)
- Binomial distribution cumulative distribution function.
- Sum of the terms 0 through `floor(k)` of the Binomial probability density.
- .. math::
- \mathrm{bdtr}(k, n, p) =
- \sum_{j=0}^{\lfloor k \rfloor} {{n}\choose{j}} p^j (1-p)^{n-j}
- Parameters
- ----------
- k : array_like
- Number of successes (double), rounded down to the nearest integer.
- n : array_like
- Number of events (int).
- p : array_like
- Probability of success in a single event (float).
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- y : scalar or ndarray
- Probability of `floor(k)` or fewer successes in `n` independent events with
- success probabilities of `p`.
- Notes
- -----
- The terms are not summed directly; instead the regularized incomplete beta
- function is employed, according to the formula,
- .. math::
- \mathrm{bdtr}(k, n, p) =
- I_{1 - p}(n - \lfloor k \rfloor, \lfloor k \rfloor + 1).
- Wrapper for the Cephes [1]_ routine `bdtr`.
- References
- ----------
- .. [1] Cephes Mathematical Functions Library,
- http://www.netlib.org/cephes/
- """)
- add_newdoc("bdtrc",
- r"""
- bdtrc(k, n, p, out=None)
- Binomial distribution survival function.
- Sum of the terms `floor(k) + 1` through `n` of the binomial probability
- density,
- .. math::
- \mathrm{bdtrc}(k, n, p) =
- \sum_{j=\lfloor k \rfloor +1}^n {{n}\choose{j}} p^j (1-p)^{n-j}
- Parameters
- ----------
- k : array_like
- Number of successes (double), rounded down to nearest integer.
- n : array_like
- Number of events (int)
- p : array_like
- Probability of success in a single event.
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- y : scalar or ndarray
- Probability of `floor(k) + 1` or more successes in `n` independent
- events with success probabilities of `p`.
- See Also
- --------
- bdtr
- betainc
- Notes
- -----
- The terms are not summed directly; instead the regularized incomplete beta
- function is employed, according to the formula,
- .. math::
- \mathrm{bdtrc}(k, n, p) = I_{p}(\lfloor k \rfloor + 1, n - \lfloor k \rfloor).
- Wrapper for the Cephes [1]_ routine `bdtrc`.
- References
- ----------
- .. [1] Cephes Mathematical Functions Library,
- http://www.netlib.org/cephes/
- """)
- add_newdoc("bdtri",
- r"""
- bdtri(k, n, y, out=None)
- Inverse function to `bdtr` with respect to `p`.
- Finds the event probability `p` such that the sum of the terms 0 through
- `k` of the binomial probability density is equal to the given cumulative
- probability `y`.
- Parameters
- ----------
- k : array_like
- Number of successes (float), rounded down to the nearest integer.
- n : array_like
- Number of events (float)
- y : array_like
- Cumulative probability (probability of `k` or fewer successes in `n`
- events).
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- p : scalar or ndarray
- The event probability such that `bdtr(\lfloor k \rfloor, n, p) = y`.
- See Also
- --------
- bdtr
- betaincinv
- Notes
- -----
- The computation is carried out using the inverse beta integral function
- and the relation,::
- 1 - p = betaincinv(n - k, k + 1, y).
- Wrapper for the Cephes [1]_ routine `bdtri`.
- References
- ----------
- .. [1] Cephes Mathematical Functions Library,
- http://www.netlib.org/cephes/
- """)
- add_newdoc("bdtrik",
- """
- bdtrik(y, n, p, out=None)
- Inverse function to `bdtr` with respect to `k`.
- Finds the number of successes `k` such that the sum of the terms 0 through
- `k` of the Binomial probability density for `n` events with probability
- `p` is equal to the given cumulative probability `y`.
- Parameters
- ----------
- y : array_like
- Cumulative probability (probability of `k` or fewer successes in `n`
- events).
- n : array_like
- Number of events (float).
- p : array_like
- Success probability (float).
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- k : scalar or ndarray
- The number of successes `k` such that `bdtr(k, n, p) = y`.
- See Also
- --------
- bdtr
- Notes
- -----
- Formula 26.5.24 of [1]_ (or equivalently [2]_) is used to reduce the binomial
- distribution to the cumulative incomplete beta distribution.
- Computation of `k` involves a search for a value that produces the desired
- value of `y`. The search relies on the monotonicity of `y` with `k`.
- Wrapper for the CDFLIB [3]_ Fortran routine `cdfbin`.
- References
- ----------
- .. [1] Milton Abramowitz and Irene A. Stegun, eds.
- Handbook of Mathematical Functions with Formulas,
- Graphs, and Mathematical Tables. New York: Dover, 1972.
- .. [2] NIST Digital Library of Mathematical Functions
- https://dlmf.nist.gov/8.17.5#E5
- .. [3] Barry Brown, James Lovato, and Kathy Russell,
- CDFLIB: Library of Fortran Routines for Cumulative Distribution
- Functions, Inverses, and Other Parameters.
- """)
- add_newdoc("bdtrin",
- """
- bdtrin(k, y, p, out=None)
- Inverse function to `bdtr` with respect to `n`.
- Finds the number of events `n` such that the sum of the terms 0 through
- `k` of the Binomial probability density for events with probability `p` is
- equal to the given cumulative probability `y`.
- Parameters
- ----------
- k : array_like
- Number of successes (float).
- y : array_like
- Cumulative probability (probability of `k` or fewer successes in `n`
- events).
- p : array_like
- Success probability (float).
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- n : scalar or ndarray
- The number of events `n` such that `bdtr(k, n, p) = y`.
- See Also
- --------
- bdtr
- Notes
- -----
- Formula 26.5.24 of [1]_ (or equivalently [2]_) is used to reduce the binomial
- distribution to the cumulative incomplete beta distribution.
- Computation of `n` involves a search for a value that produces the desired
- value of `y`. The search relies on the monotonicity of `y` with `n`.
- Wrapper for the CDFLIB [3]_ Fortran routine `cdfbin`.
- References
- ----------
- .. [1] Milton Abramowitz and Irene A. Stegun, eds.
- Handbook of Mathematical Functions with Formulas,
- Graphs, and Mathematical Tables. New York: Dover, 1972.
- .. [2] NIST Digital Library of Mathematical Functions
- https://dlmf.nist.gov/8.17.5#E5
- .. [3] Barry Brown, James Lovato, and Kathy Russell,
- CDFLIB: Library of Fortran Routines for Cumulative Distribution
- Functions, Inverses, and Other Parameters.
- """)
- add_newdoc("btdtria",
- r"""
- btdtria(p, b, x, out=None)
- Inverse of `betainc` with respect to `a`.
- This is the inverse of the beta cumulative distribution function, `betainc`,
- considered as a function of `a`, returning the value of `a` for which
- `betainc(a, b, x) = p`, or
- .. math::
- p = \int_0^x \frac{\Gamma(a + b)}{\Gamma(a)\Gamma(b)} t^{a-1} (1-t)^{b-1}\,dt
- Parameters
- ----------
- p : array_like
- Cumulative probability, in [0, 1].
- b : array_like
- Shape parameter (`b` > 0).
- x : array_like
- The quantile, in [0, 1].
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- a : scalar or ndarray
- The value of the shape parameter `a` such that `betainc(a, b, x) = p`.
- See Also
- --------
- betainc : Regularized incomplete beta function
- betaincinv : Inverse of the regularized incomplete beta function
- btdtrib : Inverse of the beta cumulative distribution function, with respect to `b`.
- Notes
- -----
- This function wraps the ``ibeta_inva`` routine from the
- Boost Math C++ library [1]_.
- References
- ----------
- .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
- Examples
- --------
- >>> import scipy.special as sc
- This function is the inverse of `betainc` for fixed
- values of :math:`b` and :math:`x`.
- >>> a, b, x = 1.2, 3.1, 0.2
- >>> y = sc.betainc(a, b, x)
- >>> sc.btdtria(y, b, x)
- 1.2
- """)
- add_newdoc("btdtrib",
- r"""
- btdtria(a, p, x, out=None)
- Inverse of `betainc` with respect to `b`.
- This is the inverse of the beta cumulative distribution function, `betainc`,
- considered as a function of `b`, returning the value of `b` for which
- `betainc(a, b, x) = p`, or
- .. math::
- p = \int_0^x \frac{\Gamma(a + b)}{\Gamma(a)\Gamma(b)} t^{a-1} (1-t)^{b-1}\,dt
- Parameters
- ----------
- a : array_like
- Shape parameter (`a` > 0).
- p : array_like
- Cumulative probability, in [0, 1].
- x : array_like
- The quantile, in [0, 1].
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- b : scalar or ndarray
- The value of the shape parameter `b` such that `betainc(a, b, x) = p`.
- See Also
- --------
- betainc : Regularized incomplete beta function
- betaincinv : Inverse of the regularized incomplete beta function with
- respect to `x`.
- btdtria : Inverse of the beta cumulative distribution function, with respect to `a`.
- Notes
- -----
- Wrapper for the `ibeta_invb` routine from the Boost Math C++ library [1]_.
- References
- ----------
- .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
- Examples
- --------
- >>> import scipy.special as sc
- >>> a, b, x = 1.2, 3.1, 0.2
- >>> y = sc.betainc(a, b, x)
- `btdtrib` is the inverse of `betainc` for fixed values of :math:`a` and
- :math:`x`:
- >>> sc.btdtrib(a, y, x)
- 3.1
- """)
- add_newdoc(
- "betainc",
- r"""
- betainc(a, b, x, out=None)
- Regularized incomplete beta function.
- Computes the regularized incomplete beta function, defined as [1]_:
- .. math::
- I_x(a, b) = \frac{\Gamma(a+b)}{\Gamma(a)\Gamma(b)} \int_0^x
- t^{a-1}(1-t)^{b-1}dt,
- for :math:`0 \leq x \leq 1`.
- This function is the cumulative distribution function for the beta
- distribution; its range is [0, 1].
- Parameters
- ----------
- a, b : array_like
- Positive, real-valued parameters
- x : array_like
- Real-valued such that :math:`0 \leq x \leq 1`,
- the upper limit of integration
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- scalar or ndarray
- Value of the regularized incomplete beta function
- See Also
- --------
- beta : beta function
- betaincinv : inverse of the regularized incomplete beta function
- betaincc : complement of the regularized incomplete beta function
- scipy.stats.beta : beta distribution
- Notes
- -----
- The term *regularized* in the name of this function refers to the
- scaling of the function by the gamma function terms shown in the
- formula. When not qualified as *regularized*, the name *incomplete
- beta function* often refers to just the integral expression,
- without the gamma terms. One can use the function `beta` from
- `scipy.special` to get this "nonregularized" incomplete beta
- function by multiplying the result of ``betainc(a, b, x)`` by
- ``beta(a, b)``.
- ``betainc(a, b, x)`` is treated as a two parameter family of functions
- of a single variable `x`, rather than as a function of three variables.
- This impacts only the limiting cases ``a = 0``, ``b = 0``, ``a = inf``,
- ``b = inf``.
- In general
- .. math::
- \lim_{(a, b) \rightarrow (a_0, b_0)} \mathrm{betainc}(a, b, x)
- is treated as a pointwise limit in ``x``. Thus for example,
- ``betainc(0, b, 0)`` equals ``0`` for ``b > 0``, although it would be
- indeterminate when considering the simultaneous limit ``(a, x) -> (0+, 0+)``.
- This function wraps the ``ibeta`` routine from the
- Boost Math C++ library [2]_.
- References
- ----------
- .. [1] NIST Digital Library of Mathematical Functions
- https://dlmf.nist.gov/8.17
- .. [2] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
- Examples
- --------
- Let :math:`B(a, b)` be the `beta` function.
- >>> import scipy.special as sc
- The coefficient in terms of `gamma` is equal to
- :math:`1/B(a, b)`. Also, when :math:`x=1`
- the integral is equal to :math:`B(a, b)`.
- Therefore, :math:`I_{x=1}(a, b) = 1` for any :math:`a, b`.
- >>> sc.betainc(0.2, 3.5, 1.0)
- 1.0
- It satisfies
- :math:`I_x(a, b) = x^a F(a, 1-b, a+1, x)/ (aB(a, b))`,
- where :math:`F` is the hypergeometric function `hyp2f1`:
- >>> a, b, x = 1.4, 3.1, 0.5
- >>> x**a * sc.hyp2f1(a, 1 - b, a + 1, x)/(a * sc.beta(a, b))
- 0.8148904036225295
- >>> sc.betainc(a, b, x)
- 0.8148904036225296
- This functions satisfies the relationship
- :math:`I_x(a, b) = 1 - I_{1-x}(b, a)`:
- >>> sc.betainc(2.2, 3.1, 0.4)
- 0.49339638807619446
- >>> 1 - sc.betainc(3.1, 2.2, 1 - 0.4)
- 0.49339638807619446
- """)
- add_newdoc(
- "betaincc",
- r"""
- betaincc(a, b, x, out=None)
- Complement of the regularized incomplete beta function.
- Computes the complement of the regularized incomplete beta function,
- defined as [1]_:
- .. math::
- \bar{I}_x(a, b) = 1 - I_x(a, b)
- = 1 - \frac{\Gamma(a+b)}{\Gamma(a)\Gamma(b)} \int_0^x
- t^{a-1}(1-t)^{b-1}dt,
- for :math:`0 \leq x \leq 1`.
- Parameters
- ----------
- a, b : array_like
- Positive, real-valued parameters
- x : array_like
- Real-valued such that :math:`0 \leq x \leq 1`,
- the upper limit of integration
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- scalar or ndarray
- Value of the regularized incomplete beta function
- See Also
- --------
- betainc : regularized incomplete beta function
- betaincinv : inverse of the regularized incomplete beta function
- betainccinv :
- inverse of the complement of the regularized incomplete beta function
- beta : beta function
- scipy.stats.beta : beta distribution
- Notes
- -----
- .. versionadded:: 1.11.0
- Like `betainc`, ``betaincc(a, b, x)`` is treated as a two parameter
- family of functions of a single variable `x`, rather than as a function of
- three variables. See the `betainc` docstring for more info on how this
- impacts limiting cases.
- This function wraps the ``ibetac`` routine from the
- Boost Math C++ library [2]_.
- References
- ----------
- .. [1] NIST Digital Library of Mathematical Functions
- https://dlmf.nist.gov/8.17
- .. [2] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
- Examples
- --------
- >>> from scipy.special import betaincc, betainc
- The naive calculation ``1 - betainc(a, b, x)`` loses precision when
- the values of ``betainc(a, b, x)`` are close to 1:
- >>> 1 - betainc(0.5, 8, [0.9, 0.99, 0.999])
- array([2.0574632e-09, 0.0000000e+00, 0.0000000e+00])
- By using ``betaincc``, we get the correct values:
- >>> betaincc(0.5, 8, [0.9, 0.99, 0.999])
- array([2.05746321e-09, 1.97259354e-17, 1.96467954e-25])
- """)
- add_newdoc(
- "betaincinv",
- r"""
- betaincinv(a, b, y, out=None)
- Inverse of the regularized incomplete beta function.
- Computes :math:`x` such that:
- .. math::
- y = I_x(a, b) = \frac{\Gamma(a+b)}{\Gamma(a)\Gamma(b)}
- \int_0^x t^{a-1}(1-t)^{b-1}dt,
- where :math:`I_x` is the normalized incomplete beta function `betainc`
- and :math:`\Gamma` is the `gamma` function [1]_.
- Parameters
- ----------
- a, b : array_like
- Positive, real-valued parameters
- y : array_like
- Real-valued input
- out : ndarray, optional
- Optional output array for function values
- Returns
- -------
- scalar or ndarray
- Value of the inverse of the regularized incomplete beta function
- See Also
- --------
- betainc : regularized incomplete beta function
- gamma : gamma function
- Notes
- -----
- This function wraps the ``ibeta_inv`` routine from the
- Boost Math C++ library [2]_.
- References
- ----------
- .. [1] NIST Digital Library of Mathematical Functions
- https://dlmf.nist.gov/8.17
- .. [2] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
- Examples
- --------
- >>> import scipy.special as sc
- This function is the inverse of `betainc` for fixed
- values of :math:`a` and :math:`b`.
- >>> a, b = 1.2, 3.1
- >>> y = sc.betainc(a, b, 0.2)
- >>> sc.betaincinv(a, b, y)
- 0.2
- >>>
- >>> a, b = 7.5, 0.4
- >>> x = sc.betaincinv(a, b, 0.5)
- >>> sc.betainc(a, b, x)
- 0.5
- """)
- add_newdoc(
- "betainccinv",
- r"""
- betainccinv(a, b, y, out=None)
- Inverse of the complemented regularized incomplete beta function.
- Computes :math:`x` such that:
- .. math::
- y = 1 - I_x(a, b) = 1 - \frac{\Gamma(a+b)}{\Gamma(a)\Gamma(b)}
- \int_0^x t^{a-1}(1-t)^{b-1}dt,
- where :math:`I_x` is the normalized incomplete beta function `betainc`
- and :math:`\Gamma` is the `gamma` function [1]_.
- Parameters
- ----------
- a, b : array_like
- Positive, real-valued parameters
- y : array_like
- Real-valued input
- out : ndarray, optional
- Optional output array for function values
- Returns
- -------
- scalar or ndarray
- Value of the inverse of the regularized incomplete beta function
- See Also
- --------
- betainc : regularized incomplete beta function
- betaincc : complement of the regularized incomplete beta function
- Notes
- -----
- .. versionadded:: 1.11.0
- This function wraps the ``ibetac_inv`` routine from the
- Boost Math C++ library [2]_.
- References
- ----------
- .. [1] NIST Digital Library of Mathematical Functions
- https://dlmf.nist.gov/8.17
- .. [2] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
- Examples
- --------
- >>> from scipy.special import betainccinv, betaincc
- This function is the inverse of `betaincc` for fixed
- values of :math:`a` and :math:`b`.
- >>> a, b = 1.2, 3.1
- >>> y = betaincc(a, b, 0.2)
- >>> betainccinv(a, b, y)
- 0.2
- >>> a, b = 7, 2.5
- >>> x = betainccinv(a, b, 0.875)
- >>> betaincc(a, b, x)
- 0.875
- """)
- add_newdoc("boxcox",
- """
- boxcox(x, lmbda, out=None)
- Compute the Box-Cox transformation.
- The Box-Cox transformation is::
- y = (x**lmbda - 1) / lmbda if lmbda != 0
- log(x) if lmbda == 0
- Returns `nan` if ``x < 0``.
- Returns `-inf` if ``x == 0`` and ``lmbda < 0``.
- Parameters
- ----------
- x : array_like
- Data to be transformed.
- lmbda : array_like
- Power parameter of the Box-Cox transform.
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- y : scalar or ndarray
- Transformed data.
- Notes
- -----
- .. versionadded:: 0.14.0
- Examples
- --------
- >>> from scipy.special import boxcox
- >>> boxcox([1, 4, 10], 2.5)
- array([ 0. , 12.4 , 126.09110641])
- >>> boxcox(2, [0, 1, 2])
- array([ 0.69314718, 1. , 1.5 ])
- """)
- add_newdoc("boxcox1p",
- """
- boxcox1p(x, lmbda, out=None)
- Compute the Box-Cox transformation of 1 + `x`.
- The Box-Cox transformation computed by `boxcox1p` is::
- y = ((1+x)**lmbda - 1) / lmbda if lmbda != 0
- log(1+x) if lmbda == 0
- Returns `nan` if ``x < -1``.
- Returns `-inf` if ``x == -1`` and ``lmbda < 0``.
- Parameters
- ----------
- x : array_like
- Data to be transformed.
- lmbda : array_like
- Power parameter of the Box-Cox transform.
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- y : scalar or ndarray
- Transformed data.
- Notes
- -----
- .. versionadded:: 0.14.0
- Examples
- --------
- >>> from scipy.special import boxcox1p
- >>> boxcox1p(1e-4, [0, 0.5, 1])
- array([ 9.99950003e-05, 9.99975001e-05, 1.00000000e-04])
- >>> boxcox1p([0.01, 0.1], 0.25)
- array([ 0.00996272, 0.09645476])
- """)
- add_newdoc("inv_boxcox",
- """
- inv_boxcox(y, lmbda, out=None)
- Compute the inverse of the Box-Cox transformation.
- Find ``x`` such that::
- y = (x**lmbda - 1) / lmbda if lmbda != 0
- log(x) if lmbda == 0
- Parameters
- ----------
- y : array_like
- Data to be transformed.
- lmbda : array_like
- Power parameter of the Box-Cox transform.
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- x : scalar or ndarray
- Transformed data.
- Notes
- -----
- .. versionadded:: 0.16.0
- Examples
- --------
- >>> from scipy.special import boxcox, inv_boxcox
- >>> y = boxcox([1, 4, 10], 2.5)
- >>> inv_boxcox(y, 2.5)
- array([1., 4., 10.])
- """)
- add_newdoc("inv_boxcox1p",
- """
- inv_boxcox1p(y, lmbda, out=None)
- Compute the inverse of the Box-Cox transformation.
- Find ``x`` such that::
- y = ((1+x)**lmbda - 1) / lmbda if lmbda != 0
- log(1+x) if lmbda == 0
- Parameters
- ----------
- y : array_like
- Data to be transformed.
- lmbda : array_like
- Power parameter of the Box-Cox transform.
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- x : scalar or ndarray
- Transformed data.
- Notes
- -----
- .. versionadded:: 0.16.0
- Examples
- --------
- >>> from scipy.special import boxcox1p, inv_boxcox1p
- >>> y = boxcox1p([1, 4, 10], 2.5)
- >>> inv_boxcox1p(y, 2.5)
- array([1., 4., 10.])
- """)
- add_newdoc("chdtr",
- r"""
- chdtr(v, x, out=None)
- Chi square cumulative distribution function.
- Returns the area under the left tail (from 0 to `x`) of the Chi
- square probability density function with `v` degrees of freedom:
- .. math::
- \frac{1}{2^{v/2} \Gamma(v/2)} \int_0^x t^{v/2 - 1} e^{-t/2} dt
- Here :math:`\Gamma` is the Gamma function; see `gamma`. This
- integral can be expressed in terms of the regularized lower
- incomplete gamma function `gammainc` as
- ``gammainc(v / 2, x / 2)``. [1]_
- Parameters
- ----------
- v : array_like
- Degrees of freedom.
- x : array_like
- Upper bound of the integral.
- out : ndarray, optional
- Optional output array for the function results.
- Returns
- -------
- scalar or ndarray
- Values of the cumulative distribution function.
- See Also
- --------
- chdtrc, chdtri, chdtriv, gammainc
- References
- ----------
- .. [1] Chi-Square distribution,
- https://www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm
- Examples
- --------
- >>> import numpy as np
- >>> import scipy.special as sc
- It can be expressed in terms of the regularized lower incomplete
- gamma function.
- >>> v = 1
- >>> x = np.arange(4)
- >>> sc.chdtr(v, x)
- array([0. , 0.68268949, 0.84270079, 0.91673548])
- >>> sc.gammainc(v / 2, x / 2)
- array([0. , 0.68268949, 0.84270079, 0.91673548])
- """)
- add_newdoc("chdtrc",
- r"""
- chdtrc(v, x, out=None)
- Chi square survival function.
- Returns the area under the right hand tail (from `x` to infinity)
- of the Chi square probability density function with `v` degrees of
- freedom:
- .. math::
- \frac{1}{2^{v/2} \Gamma(v/2)} \int_x^\infty t^{v/2 - 1} e^{-t/2} dt
- Here :math:`\Gamma` is the Gamma function; see `gamma`. This
- integral can be expressed in terms of the regularized upper
- incomplete gamma function `gammaincc` as
- ``gammaincc(v / 2, x / 2)``. [1]_
- Parameters
- ----------
- v : array_like
- Degrees of freedom.
- x : array_like
- Lower bound of the integral.
- out : ndarray, optional
- Optional output array for the function results.
- Returns
- -------
- scalar or ndarray
- Values of the survival function.
- See Also
- --------
- chdtr, chdtri, chdtriv, gammaincc
- References
- ----------
- .. [1] Chi-Square distribution,
- https://www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm
- Examples
- --------
- >>> import numpy as np
- >>> import scipy.special as sc
- It can be expressed in terms of the regularized upper incomplete
- gamma function.
- >>> v = 1
- >>> x = np.arange(4)
- >>> sc.chdtrc(v, x)
- array([1. , 0.31731051, 0.15729921, 0.08326452])
- >>> sc.gammaincc(v / 2, x / 2)
- array([1. , 0.31731051, 0.15729921, 0.08326452])
- """)
- add_newdoc("chdtri",
- """
- chdtri(v, p, out=None)
- Inverse to `chdtrc` with respect to `x`.
- Returns `x` such that ``chdtrc(v, x) == p``.
- Parameters
- ----------
- v : array_like
- Degrees of freedom.
- p : array_like
- Probability.
- out : ndarray, optional
- Optional output array for the function results.
- Returns
- -------
- x : scalar or ndarray
- Value so that the probability a Chi square random variable
- with `v` degrees of freedom is greater than `x` equals `p`.
- See Also
- --------
- chdtrc, chdtr, chdtriv
- References
- ----------
- .. [1] Chi-Square distribution,
- https://www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm
- Examples
- --------
- >>> import scipy.special as sc
- It inverts `chdtrc`.
- >>> v, p = 1, 0.3
- >>> sc.chdtrc(v, sc.chdtri(v, p))
- 0.3
- >>> x = 1
- >>> sc.chdtri(v, sc.chdtrc(v, x))
- 1.0
- """)
- add_newdoc("chdtriv",
- """
- chdtriv(p, x, out=None)
- Inverse to `chdtr` with respect to `v`.
- Returns `v` such that ``chdtr(v, x) == p``.
- Parameters
- ----------
- p : array_like
- Probability that the Chi square random variable is less than
- or equal to `x`.
- x : array_like
- Nonnegative input.
- out : ndarray, optional
- Optional output array for the function results.
- Returns
- -------
- scalar or ndarray
- Degrees of freedom.
- See Also
- --------
- chdtr, chdtrc, chdtri
- Notes
- -----
- This function wraps routines from the Boost Math C++ library [1]_.
- References
- ----------
- .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
- .. [2] Chi-Square distribution,
- https://www.itl.nist.gov/div898/handbook/eda/section3/eda3666.htm
- Examples
- --------
- >>> import scipy.special as sc
- It inverts `chdtr`.
- >>> p, x = 0.5, 1
- >>> sc.chdtr(sc.chdtriv(p, x), x)
- 0.5000000000000003
- >>> v = 1
- >>> sc.chdtriv(sc.chdtr(v, x), v)
- 1.0
- """)
- add_newdoc("chndtr",
- r"""
- chndtr(x, df, nc, out=None)
- Non-central chi square cumulative distribution function
- The cumulative distribution function is given by:
- .. math::
- P(\chi^{\prime 2} \vert \nu, \lambda) =\sum_{j=0}^{\infty}
- e^{-\lambda /2}
- \frac{(\lambda /2)^j}{j!} P(\chi^{\prime 2} \vert \nu + 2j),
- where :math:`\nu > 0` is the degrees of freedom (``df``) and
- :math:`\lambda \geq 0` is the non-centrality parameter (``nc``).
- Parameters
- ----------
- x : array_like
- Upper bound of the integral; must satisfy ``x >= 0``
- df : array_like
- Degrees of freedom; must satisfy ``df > 0``
- nc : array_like
- Non-centrality parameter; must satisfy ``nc >= 0``
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- x : scalar or ndarray
- Value of the non-central chi square cumulative distribution function.
- See Also
- --------
- chndtrix: Noncentral Chi Squared distribution quantile
- chndtridf: Inverse of `chndtr` with respect to `df`
- chndtrinc: Inverse of `chndtr` with respect to `nc`
- scipy.stats.ncx2: Non-central chi-squared distribution
- Notes
- -----
- The noncentral chi squared distribution is also available in
- `scipy.stats.ncx2`. ``scipy.stats.ncx2.cdf`` is equivalent to `chndtr`.
- This function wraps routines from the Boost Math C++ library [1]_.
- References
- ----------
- .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
- Examples
- --------
- >>> import numpy as np
- >>> import scipy.special as sc
- Compute the noncentral chi squared distribution CDF at one point.
- >>> x = 4.0
- >>> df = 1.0
- >>> nc = 5.0
- >>> sc.chndtr(x, df, nc)
- 0.40667858759710945
- Plot the noncentral chi squared distribution CDF for different parameters.
- >>> import matplotlib.pyplot as plt
- >>> x = np.linspace(0, 40, 1000)
- >>> plt.plot(x, sc.chndtr(x, 1, 5), label=r"$df=1,\ nc=5$")
- >>> plt.plot(x, sc.chndtr(x, 5, 10), label=r"$df=5,\ nc=10$")
- >>> plt.legend()
- >>> plt.show()
- """)
- add_newdoc("chndtrix",
- """
- chndtrix(p, df, nc, out=None)
- Inverse to `chndtr` vs `x`
- Calculated using a search to find a value for `x` that produces the
- desired value of `p`.
- Parameters
- ----------
- p : array_like
- Probability; must satisfy ``0 <= p < 1``
- df : array_like
- Degrees of freedom; must satisfy ``df > 0``
- nc : array_like
- Non-centrality parameter; must satisfy ``nc >= 0``
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- x : scalar or ndarray
- Value so that the probability a non-central Chi square random variable
- with `df` degrees of freedom and non-centrality, `nc`, is greater than
- `x` equals `p`.
- See Also
- --------
- chndtr : Noncentral chi-squared distribution CDF
- chndtridf : inverse of `chndtr` with respect to `cdf`
- chndtrinc : inverse of `chndtr` with respect to `nc`
- scipy.stats.ncx2 : Non-central chi-squared distribution
- Notes
- -----
- The noncentral chi squared distribution is also available in
- `scipy.stats.ncx2`. ``scipy.stats.ncx2.ppf`` is equivalent to `chndtrix`.
- This function wraps routines from the Boost Math C++ library [1]_.
- References
- ----------
- .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
- Examples
- --------
- >>> from scipy.special import chndtrix, chndtr
- Compute the noncentral chi squared distribution CDF at one point.
- >>> x, df, nc = 3, 5, 10
- >>> p = chndtr(x, df, nc)
- `chndtrix` is the inverse of `chndtr` with respect to `x`:
- >>> chndtrix(p, df, nc)
- 3.0
- """)
- add_newdoc("chndtridf",
- """
- chndtridf(x, p, nc, out=None)
- Inverse to `chndtr` vs `df`
- Calculated using a search to find a value for `df` that produces the
- desired value of `p`.
- Parameters
- ----------
- x : array_like
- Upper bound of the integral; must satisfy ``x >= 0``
- p : array_like
- Probability; must satisfy ``0 <= p < 1``
- nc : array_like
- Non-centrality parameter; must satisfy ``nc >= 0``
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- df : scalar or ndarray
- Degrees of freedom
- See Also
- --------
- chndtr : Noncentral chi-squared distribution CDF
- chndtrix : inverse of `chndtr` with respect to `x`
- chndtrinc : inverse of `chndtr` with respect to `nc`
- scipy.stats.ncx2 : Non-central chi-squared distribution
- Notes
- -----
- The noncentral chi squared distribution is also available in
- `scipy.stats.ncx2`.
- This function wraps routines from the Boost Math C++ library [1]_.
- References
- ----------
- .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
- Examples
- --------
- >>> from scipy.special import chndtridf, chndtr
- Compute the noncentral chi squared distribution CDF at one point.
- >>> x, df, nc = 3, 5, 10
- >>> p = chndtr(x, df, nc)
- `chndtridf` is the inverse of `chndtr` with respect to `df`:
- >>> chndtridf(x, p, nc)
- 5.0
- """)
- add_newdoc("chndtrinc",
- """
- chndtrinc(x, df, p, out=None)
- Inverse to `chndtr` vs `nc`
- Calculated using a search to find a value for `df` that produces the
- desired value of `p`.
- Parameters
- ----------
- x : array_like
- Upper bound of the integral; must satisfy ``x >= 0``
- df : array_like
- Degrees of freedom; must satisfy ``df > 0``
- p : array_like
- Probability; must satisfy ``0 <= p < 1``
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- nc : scalar or ndarray
- Non-centrality
- See Also
- --------
- chndtr : Noncentral chi-squared distribution CDF
- chndtridf : inverse of `chndtr` with respect to `df`
- chndtrinc : inverse of `chndtr` with respect to `nc`
- scipy.stats.ncx2 : Non-central chi-squared distribution
- Notes
- -----
- The noncentral chi squared distribution is also available in
- `scipy.stats.ncx2`.
- This function wraps routines from the Boost Math C++ library [1]_.
- References
- ----------
- .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
- Examples
- --------
- >>> from scipy.special import chndtrinc, chndtr
- Compute the noncentral chi squared distribution CDF at one point.
- >>> x, df, nc = 3, 5, 10
- >>> p = chndtr(x, df, nc)
- `chndtrinc` is the inverse of `chndtr` with respect to `nc`:
- >>> chndtrinc(x, df, p)
- 10.0
- """)
- add_newdoc(
- "elliprc",
- r"""
- elliprc(x, y, out=None)
- Degenerate symmetric elliptic integral.
- The function RC is defined as [1]_
- .. math::
- R_{\mathrm{C}}(x, y) =
- \frac{1}{2} \int_0^{+\infty} (t + x)^{-1/2} (t + y)^{-1} dt
- = R_{\mathrm{F}}(x, y, y)
- Parameters
- ----------
- x, y : array_like
- Real or complex input parameters. `x` can be any number in the
- complex plane cut along the negative real axis. `y` must be non-zero.
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- R : scalar or ndarray
- Value of the integral. If `y` is real and negative, the Cauchy
- principal value is returned. If both of `x` and `y` are real, the
- return value is real. Otherwise, the return value is complex.
- See Also
- --------
- elliprf : Completely-symmetric elliptic integral of the first kind.
- elliprd : Symmetric elliptic integral of the second kind.
- elliprg : Completely-symmetric elliptic integral of the second kind.
- elliprj : Symmetric elliptic integral of the third kind.
- Notes
- -----
- RC is a degenerate case of the symmetric integral RF: ``elliprc(x, y) ==
- elliprf(x, y, y)``. It is an elementary function rather than an elliptic
- integral.
- The code implements Carlson's algorithm based on the duplication theorems
- and series expansion up to the 7th order. [2]_
- .. versionadded:: 1.8.0
- References
- ----------
- .. [1] B. C. Carlson, ed., Chapter 19 in "Digital Library of Mathematical
- Functions," NIST, US Dept. of Commerce.
- https://dlmf.nist.gov/19.16.E6
- .. [2] B. C. Carlson, "Numerical computation of real or complex elliptic
- integrals," Numer. Algorithm, vol. 10, no. 1, pp. 13-26, 1995.
- https://arxiv.org/abs/math/9409227
- https://doi.org/10.1007/BF02198293
- Examples
- --------
- Basic homogeneity property:
- >>> import numpy as np
- >>> from scipy.special import elliprc
- >>> x = 1.2 + 3.4j
- >>> y = 5.
- >>> scale = 0.3 + 0.4j
- >>> elliprc(scale*x, scale*y)
- (0.5484493976710874-0.4169557678995833j)
- >>> elliprc(x, y)/np.sqrt(scale)
- (0.5484493976710874-0.41695576789958333j)
- When the two arguments coincide, the integral is particularly
- simple:
- >>> x = 1.2 + 3.4j
- >>> elliprc(x, x)
- (0.4299173120614631-0.3041729818745595j)
- >>> 1/np.sqrt(x)
- (0.4299173120614631-0.30417298187455954j)
- Another simple case: the first argument vanishes:
- >>> y = 1.2 + 3.4j
- >>> elliprc(0, y)
- (0.6753125346116815-0.47779380263880866j)
- >>> np.pi/2/np.sqrt(y)
- (0.6753125346116815-0.4777938026388088j)
- When `x` and `y` are both positive, we can express
- :math:`R_C(x,y)` in terms of more elementary functions. For the
- case :math:`0 \le x < y`,
- >>> x = 3.2
- >>> y = 6.
- >>> elliprc(x, y)
- 0.44942991498453444
- >>> np.arctan(np.sqrt((y-x)/x))/np.sqrt(y-x)
- 0.44942991498453433
- And for the case :math:`0 \le y < x`,
- >>> x = 6.
- >>> y = 3.2
- >>> elliprc(x,y)
- 0.4989837501576147
- >>> np.log((np.sqrt(x)+np.sqrt(x-y))/np.sqrt(y))/np.sqrt(x-y)
- 0.49898375015761476
- """)
- add_newdoc(
- "elliprd",
- r"""
- elliprd(x, y, z, out=None)
- Symmetric elliptic integral of the second kind.
- The function RD is defined as [1]_
- .. math::
- R_{\mathrm{D}}(x, y, z) =
- \frac{3}{2} \int_0^{+\infty} [(t + x) (t + y)]^{-1/2} (t + z)^{-3/2}
- dt
- Parameters
- ----------
- x, y, z : array_like
- Real or complex input parameters. `x` or `y` can be any number in the
- complex plane cut along the negative real axis, but at most one of them
- can be zero, while `z` must be non-zero.
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- R : scalar or ndarray
- Value of the integral. If all of `x`, `y`, and `z` are real, the
- return value is real. Otherwise, the return value is complex.
- See Also
- --------
- elliprc : Degenerate symmetric elliptic integral.
- elliprf : Completely-symmetric elliptic integral of the first kind.
- elliprg : Completely-symmetric elliptic integral of the second kind.
- elliprj : Symmetric elliptic integral of the third kind.
- Notes
- -----
- RD is a degenerate case of the elliptic integral RJ: ``elliprd(x, y, z) ==
- elliprj(x, y, z, z)``.
- The code implements Carlson's algorithm based on the duplication theorems
- and series expansion up to the 7th order. [2]_
- .. versionadded:: 1.8.0
- References
- ----------
- .. [1] B. C. Carlson, ed., Chapter 19 in "Digital Library of Mathematical
- Functions," NIST, US Dept. of Commerce.
- https://dlmf.nist.gov/19.16.E5
- .. [2] B. C. Carlson, "Numerical computation of real or complex elliptic
- integrals," Numer. Algorithm, vol. 10, no. 1, pp. 13-26, 1995.
- https://arxiv.org/abs/math/9409227
- https://doi.org/10.1007/BF02198293
- Examples
- --------
- Basic homogeneity property:
- >>> import numpy as np
- >>> from scipy.special import elliprd
- >>> x = 1.2 + 3.4j
- >>> y = 5.
- >>> z = 6.
- >>> scale = 0.3 + 0.4j
- >>> elliprd(scale*x, scale*y, scale*z)
- (-0.03703043835680379-0.24500934665683802j)
- >>> elliprd(x, y, z)*np.power(scale, -1.5)
- (-0.0370304383568038-0.24500934665683805j)
- All three arguments coincide:
- >>> x = 1.2 + 3.4j
- >>> elliprd(x, x, x)
- (-0.03986825876151896-0.14051741840449586j)
- >>> np.power(x, -1.5)
- (-0.03986825876151894-0.14051741840449583j)
- The so-called "second lemniscate constant":
- >>> elliprd(0, 2, 1)/3
- 0.5990701173677961
- >>> from scipy.special import gamma
- >>> gamma(0.75)**2/np.sqrt(2*np.pi)
- 0.5990701173677959
- """)
- add_newdoc(
- "elliprf",
- r"""
- elliprf(x, y, z, out=None)
- Completely-symmetric elliptic integral of the first kind.
- The function RF is defined as [1]_
- .. math::
- R_{\mathrm{F}}(x, y, z) =
- \frac{1}{2} \int_0^{+\infty} [(t + x) (t + y) (t + z)]^{-1/2} dt
- Parameters
- ----------
- x, y, z : array_like
- Real or complex input parameters. `x`, `y`, or `z` can be any number in
- the complex plane cut along the negative real axis, but at most one of
- them can be zero.
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- R : scalar or ndarray
- Value of the integral. If all of `x`, `y`, and `z` are real, the return
- value is real. Otherwise, the return value is complex.
- See Also
- --------
- elliprc : Degenerate symmetric integral.
- elliprd : Symmetric elliptic integral of the second kind.
- elliprg : Completely-symmetric elliptic integral of the second kind.
- elliprj : Symmetric elliptic integral of the third kind.
- Notes
- -----
- The code implements Carlson's algorithm based on the duplication theorems
- and series expansion up to the 7th order (cf.:
- https://dlmf.nist.gov/19.36.i) and the AGM algorithm for the complete
- integral. [2]_
- .. versionadded:: 1.8.0
- References
- ----------
- .. [1] B. C. Carlson, ed., Chapter 19 in "Digital Library of Mathematical
- Functions," NIST, US Dept. of Commerce.
- https://dlmf.nist.gov/19.16.E1
- .. [2] B. C. Carlson, "Numerical computation of real or complex elliptic
- integrals," Numer. Algorithm, vol. 10, no. 1, pp. 13-26, 1995.
- https://arxiv.org/abs/math/9409227
- https://doi.org/10.1007/BF02198293
- Examples
- --------
- Basic homogeneity property:
- >>> import numpy as np
- >>> from scipy.special import elliprf
- >>> x = 1.2 + 3.4j
- >>> y = 5.
- >>> z = 6.
- >>> scale = 0.3 + 0.4j
- >>> elliprf(scale*x, scale*y, scale*z)
- (0.5328051227278146-0.4008623567957094j)
- >>> elliprf(x, y, z)/np.sqrt(scale)
- (0.5328051227278147-0.4008623567957095j)
- All three arguments coincide:
- >>> x = 1.2 + 3.4j
- >>> elliprf(x, x, x)
- (0.42991731206146316-0.30417298187455954j)
- >>> 1/np.sqrt(x)
- (0.4299173120614631-0.30417298187455954j)
- The so-called "first lemniscate constant":
- >>> elliprf(0, 1, 2)
- 1.3110287771460598
- >>> from scipy.special import gamma
- >>> gamma(0.25)**2/(4*np.sqrt(2*np.pi))
- 1.3110287771460598
- """)
- add_newdoc(
- "elliprg",
- r"""
- elliprg(x, y, z, out=None)
- Completely-symmetric elliptic integral of the second kind.
- The function RG is defined as [1]_
- .. math::
- R_{\mathrm{G}}(x, y, z) =
- \frac{1}{4} \int_0^{+\infty} [(t + x) (t + y) (t + z)]^{-1/2}
- \left(\frac{x}{t + x} + \frac{y}{t + y} + \frac{z}{t + z}\right) t
- dt
- Parameters
- ----------
- x, y, z : array_like
- Real or complex input parameters. `x`, `y`, or `z` can be any number in
- the complex plane cut along the negative real axis.
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- R : scalar or ndarray
- Value of the integral. If all of `x`, `y`, and `z` are real, the return
- value is real. Otherwise, the return value is complex.
- See Also
- --------
- elliprc : Degenerate symmetric integral.
- elliprd : Symmetric elliptic integral of the second kind.
- elliprf : Completely-symmetric elliptic integral of the first kind.
- elliprj : Symmetric elliptic integral of the third kind.
- Notes
- -----
- The implementation uses the relation [1]_
- .. math::
- 2 R_{\mathrm{G}}(x, y, z) =
- z R_{\mathrm{F}}(x, y, z) -
- \frac{1}{3} (x - z) (y - z) R_{\mathrm{D}}(x, y, z) +
- \sqrt{\frac{x y}{z}}
- and the symmetry of `x`, `y`, `z` when at least one non-zero parameter can
- be chosen as the pivot. When one of the arguments is close to zero, the AGM
- method is applied instead. Other special cases are computed following Ref.
- [2]_
- .. versionadded:: 1.8.0
- References
- ----------
- .. [1] B. C. Carlson, "Numerical computation of real or complex elliptic
- integrals," Numer. Algorithm, vol. 10, no. 1, pp. 13-26, 1995.
- https://arxiv.org/abs/math/9409227
- https://doi.org/10.1007/BF02198293
- .. [2] B. C. Carlson, ed., Chapter 19 in "Digital Library of Mathematical
- Functions," NIST, US Dept. of Commerce.
- https://dlmf.nist.gov/19.16.E1
- https://dlmf.nist.gov/19.20.ii
- Examples
- --------
- Basic homogeneity property:
- >>> import numpy as np
- >>> from scipy.special import elliprg
- >>> x = 1.2 + 3.4j
- >>> y = 5.
- >>> z = 6.
- >>> scale = 0.3 + 0.4j
- >>> elliprg(scale*x, scale*y, scale*z)
- (1.195936862005246+0.8470988320464167j)
- >>> elliprg(x, y, z)*np.sqrt(scale)
- (1.195936862005246+0.8470988320464165j)
- Simplifications:
- >>> elliprg(0, y, y)
- 1.756203682760182
- >>> 0.25*np.pi*np.sqrt(y)
- 1.7562036827601817
- >>> elliprg(0, 0, z)
- 1.224744871391589
- >>> 0.5*np.sqrt(z)
- 1.224744871391589
- The surface area of a triaxial ellipsoid with semiaxes ``a``, ``b``, and
- ``c`` is given by
- .. math::
- S = 4 \pi a b c R_{\mathrm{G}}(1 / a^2, 1 / b^2, 1 / c^2).
- >>> def ellipsoid_area(a, b, c):
- ... r = 4.0 * np.pi * a * b * c
- ... return r * elliprg(1.0 / (a * a), 1.0 / (b * b), 1.0 / (c * c))
- >>> print(ellipsoid_area(1, 3, 5))
- 108.62688289491807
- """)
- add_newdoc(
- "elliprj",
- r"""
- elliprj(x, y, z, p, out=None)
- Symmetric elliptic integral of the third kind.
- The function RJ is defined as [1]_
- .. math::
- R_{\mathrm{J}}(x, y, z, p) =
- \frac{3}{2} \int_0^{+\infty} [(t + x) (t + y) (t + z)]^{-1/2}
- (t + p)^{-1} dt
- .. warning::
- This function should be considered experimental when the inputs are
- unbalanced. Check correctness with another independent implementation.
- Parameters
- ----------
- x, y, z, p : array_like
- Real or complex input parameters. `x`, `y`, or `z` are numbers in
- the complex plane cut along the negative real axis (subject to further
- constraints, see Notes), and at most one of them can be zero. `p` must
- be non-zero.
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- R : scalar or ndarray
- Value of the integral. If all of `x`, `y`, `z`, and `p` are real, the
- return value is real. Otherwise, the return value is complex.
- If `p` is real and negative, while `x`, `y`, and `z` are real,
- non-negative, and at most one of them is zero, the Cauchy principal
- value is returned. [1]_ [2]_
- See Also
- --------
- elliprc : Degenerate symmetric integral.
- elliprd : Symmetric elliptic integral of the second kind.
- elliprf : Completely-symmetric elliptic integral of the first kind.
- elliprg : Completely-symmetric elliptic integral of the second kind.
- Notes
- -----
- The code implements Carlson's algorithm based on the duplication theorems
- and series expansion up to the 7th order. [3]_ The algorithm is slightly
- different from its earlier incarnation as it appears in [1]_, in that the
- call to `elliprc` (or ``atan``/``atanh``, see [4]_) is no longer needed in
- the inner loop. Asymptotic approximations are used where arguments differ
- widely in the order of magnitude. [5]_
- The input values are subject to certain sufficient but not necessary
- constraints when input arguments are complex. Notably, ``x``, ``y``, and
- ``z`` must have non-negative real parts, unless two of them are
- non-negative and complex-conjugates to each other while the other is a real
- non-negative number. [1]_ If the inputs do not satisfy the sufficient
- condition described in Ref. [1]_ they are rejected outright with the output
- set to NaN.
- In the case where one of ``x``, ``y``, and ``z`` is equal to ``p``, the
- function ``elliprd`` should be preferred because of its less restrictive
- domain.
- .. versionadded:: 1.8.0
- References
- ----------
- .. [1] B. C. Carlson, "Numerical computation of real or complex elliptic
- integrals," Numer. Algorithm, vol. 10, no. 1, pp. 13-26, 1995.
- https://arxiv.org/abs/math/9409227
- https://doi.org/10.1007/BF02198293
- .. [2] B. C. Carlson, ed., Chapter 19 in "Digital Library of Mathematical
- Functions," NIST, US Dept. of Commerce.
- https://dlmf.nist.gov/19.20.iii
- .. [3] B. C. Carlson, J. FitzSimmons, "Reduction Theorems for Elliptic
- Integrands with the Square Root of Two Quadratic Factors," J.
- Comput. Appl. Math., vol. 118, nos. 1-2, pp. 71-85, 2000.
- https://doi.org/10.1016/S0377-0427(00)00282-X
- .. [4] F. Johansson, "Numerical Evaluation of Elliptic Functions, Elliptic
- Integrals and Modular Forms," in J. Blumlein, C. Schneider, P.
- Paule, eds., "Elliptic Integrals, Elliptic Functions and Modular
- Forms in Quantum Field Theory," pp. 269-293, 2019 (Cham,
- Switzerland: Springer Nature Switzerland)
- https://arxiv.org/abs/1806.06725
- https://doi.org/10.1007/978-3-030-04480-0
- .. [5] B. C. Carlson, J. L. Gustafson, "Asymptotic Approximations for
- Symmetric Elliptic Integrals," SIAM J. Math. Anls., vol. 25, no. 2,
- pp. 288-303, 1994.
- https://arxiv.org/abs/math/9310223
- https://doi.org/10.1137/S0036141092228477
- Examples
- --------
- Basic homogeneity property:
- >>> import numpy as np
- >>> from scipy.special import elliprj
- >>> x = 1.2 + 3.4j
- >>> y = 5.
- >>> z = 6.
- >>> p = 7.
- >>> scale = 0.3 - 0.4j
- >>> elliprj(scale*x, scale*y, scale*z, scale*p)
- (0.10834905565679157+0.19694950747103812j)
- >>> elliprj(x, y, z, p)*np.power(scale, -1.5)
- (0.10834905565679556+0.19694950747103854j)
- Reduction to simpler elliptic integral:
- >>> elliprj(x, y, z, z)
- (0.08288462362195129-0.028376809745123258j)
- >>> from scipy.special import elliprd
- >>> elliprd(x, y, z)
- (0.08288462362195136-0.028376809745123296j)
- All arguments coincide:
- >>> elliprj(x, x, x, x)
- (-0.03986825876151896-0.14051741840449586j)
- >>> np.power(x, -1.5)
- (-0.03986825876151894-0.14051741840449583j)
- """)
- add_newdoc("entr",
- r"""
- entr(x, out=None)
- Elementwise function for computing entropy.
- .. math:: \text{entr}(x) = \begin{cases} - x \log(x) & x > 0 \\ 0 & x = 0
- \\ -\infty & \text{otherwise} \end{cases}
- Parameters
- ----------
- x : ndarray
- Input array.
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- res : scalar or ndarray
- The value of the elementwise entropy function at the given points `x`.
- See Also
- --------
- kl_div, rel_entr, scipy.stats.entropy
- Notes
- -----
- .. versionadded:: 0.15.0
- This function is concave.
- The origin of this function is in convex programming; see [1]_.
- Given a probability distribution :math:`p_1, \ldots, p_n`,
- the definition of entropy in the context of *information theory* is
- .. math::
- \sum_{i = 1}^n \mathrm{entr}(p_i).
- To compute the latter quantity, use `scipy.stats.entropy`.
- References
- ----------
- .. [1] Boyd, Stephen and Lieven Vandenberghe. *Convex optimization*.
- Cambridge University Press, 2004.
- :doi:`https://doi.org/10.1017/CBO9780511804441`
- """)
- add_newdoc(
- "erfinv",
- """
- erfinv(y, out=None)
- Inverse of the error function.
- Computes the inverse of the error function.
- In the complex domain, there is no unique complex number w satisfying
- erf(w)=z. This indicates a true inverse function would be multivalued.
- When the domain restricts to the real, -1 < x < 1, there is a unique real
- number satisfying erf(erfinv(x)) = x.
- Parameters
- ----------
- y : ndarray
- Argument at which to evaluate. Domain: [-1, 1]
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- erfinv : scalar or ndarray
- The inverse of erf of y, element-wise
- See Also
- --------
- erf : Error function of a complex argument
- erfc : Complementary error function, ``1 - erf(x)``
- erfcinv : Inverse of the complementary error function
- Notes
- -----
- This function wraps the ``erf_inv`` routine from the
- Boost Math C++ library [1]_.
- References
- ----------
- .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
- Examples
- --------
- >>> import numpy as np
- >>> import matplotlib.pyplot as plt
- >>> from scipy.special import erfinv, erf
- >>> erfinv(0.5)
- 0.4769362762044699
- >>> y = np.linspace(-1.0, 1.0, num=9)
- >>> x = erfinv(y)
- >>> x
- array([ -inf, -0.81341985, -0.47693628, -0.22531206, 0. ,
- 0.22531206, 0.47693628, 0.81341985, inf])
- Verify that ``erf(erfinv(y))`` is ``y``.
- >>> erf(x)
- array([-1. , -0.75, -0.5 , -0.25, 0. , 0.25, 0.5 , 0.75, 1. ])
- Plot the function:
- >>> y = np.linspace(-1, 1, 200)
- >>> fig, ax = plt.subplots()
- >>> ax.plot(y, erfinv(y))
- >>> ax.grid(True)
- >>> ax.set_xlabel('y')
- >>> ax.set_title('erfinv(y)')
- >>> plt.show()
- """)
- add_newdoc(
- "erfcinv",
- """
- erfcinv(y, out=None)
- Inverse of the complementary error function.
- Computes the inverse of the complementary error function.
- In the complex domain, there is no unique complex number w satisfying
- erfc(w)=z. This indicates a true inverse function would be multivalued.
- When the domain restricts to the real, 0 < x < 2, there is a unique real
- number satisfying erfc(erfcinv(x)) = erfcinv(erfc(x)).
- It is related to inverse of the error function by erfcinv(1-x) = erfinv(x)
- Parameters
- ----------
- y : ndarray
- Argument at which to evaluate. Domain: [0, 2]
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- erfcinv : scalar or ndarray
- The inverse of erfc of y, element-wise
- See Also
- --------
- erf : Error function of a complex argument
- erfc : Complementary error function, ``1 - erf(x)``
- erfinv : Inverse of the error function
- Examples
- --------
- >>> import numpy as np
- >>> import matplotlib.pyplot as plt
- >>> from scipy.special import erfcinv
- >>> erfcinv(0.5)
- 0.4769362762044699
- >>> y = np.linspace(0.0, 2.0, num=11)
- >>> erfcinv(y)
- array([ inf, 0.9061938 , 0.59511608, 0.37080716, 0.17914345,
- -0. , -0.17914345, -0.37080716, -0.59511608, -0.9061938 ,
- -inf])
- Plot the function:
- >>> y = np.linspace(0, 2, 200)
- >>> fig, ax = plt.subplots()
- >>> ax.plot(y, erfcinv(y))
- >>> ax.grid(True)
- >>> ax.set_xlabel('y')
- >>> ax.set_title('erfcinv(y)')
- >>> plt.show()
- """)
- add_newdoc("eval_jacobi",
- r"""
- eval_jacobi(n, alpha, beta, x, out=None)
- Evaluate Jacobi polynomial at a point.
- The Jacobi polynomials can be defined via the Gauss hypergeometric
- function :math:`{}_2F_1` as
- .. math::
- P_n^{(\alpha, \beta)}(x) = \frac{(\alpha + 1)_n}{\Gamma(n + 1)}
- {}_2F_1(-n, 1 + \alpha + \beta + n; \alpha + 1; (1 - z)/2)
- where :math:`(\cdot)_n` is the Pochhammer symbol; see `poch`. When
- :math:`n` is an integer the result is a polynomial of degree
- :math:`n`. See 22.5.42 in [AS]_ or [DLMF]_ for details.
- Parameters
- ----------
- n : array_like
- Degree of the polynomial. If not an integer the result is
- determined via the relation to the Gauss hypergeometric
- function.
- alpha : array_like
- Parameter
- beta : array_like
- Parameter
- x : array_like
- Points at which to evaluate the polynomial
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- P : scalar or ndarray
- Values of the Jacobi polynomial
- See Also
- --------
- roots_jacobi : roots and quadrature weights of Jacobi polynomials
- jacobi : Jacobi polynomial object
- hyp2f1 : Gauss hypergeometric function
- References
- ----------
- .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
- Handbook of Mathematical Functions with Formulas,
- Graphs, and Mathematical Tables. New York: Dover, 1972.
- .. [DLMF] NIST Digital Library of Mathematical Functions,
- https://dlmf.nist.gov/18.5.E7
- """)
- add_newdoc("eval_sh_jacobi",
- r"""
- eval_sh_jacobi(n, p, q, x, out=None)
- Evaluate shifted Jacobi polynomial at a point.
- Defined by
- .. math::
- G_n^{(p, q)}(x)
- = \binom{2n + p - 1}{n}^{-1} P_n^{(p - q, q - 1)}(2x - 1),
- where :math:`P_n^{(\cdot, \cdot)}` is the n-th Jacobi polynomial.
- See 22.5.2 in [AS]_ (or equivalently [DLMF]_) for details.
- Parameters
- ----------
- n : int
- Degree of the polynomial. If not an integer, the result is
- determined via the relation to `binom` and `eval_jacobi`.
- p : float
- Parameter
- q : float
- Parameter
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- G : scalar or ndarray
- Values of the shifted Jacobi polynomial.
- See Also
- --------
- roots_sh_jacobi : roots and quadrature weights of shifted Jacobi
- polynomials
- sh_jacobi : shifted Jacobi polynomial object
- eval_jacobi : evaluate Jacobi polynomials
- References
- ----------
- .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
- Handbook of Mathematical Functions with Formulas,
- Graphs, and Mathematical Tables. New York: Dover, 1972.
- .. [DLMF] NIST Digital Library of Mathematical Functions,
- https://dlmf.nist.gov/18.1.E2
- """)
- add_newdoc("eval_gegenbauer",
- r"""
- eval_gegenbauer(n, alpha, x, out=None)
- Evaluate Gegenbauer polynomial at a point.
- The Gegenbauer polynomials can be defined via the Gauss
- hypergeometric function :math:`{}_2F_1` as
- .. math::
- C_n^{(\alpha)} = \frac{(2\alpha)_n}{\Gamma(n + 1)}
- {}_2F_1(-n, 2\alpha + n; \alpha + 1/2; (1 - z)/2).
- When :math:`n` is an integer the result is a polynomial of degree
- :math:`n`. See 22.5.46 in [AS]_ (or equivalently [DLMF]_) for details.
- Parameters
- ----------
- n : array_like
- Degree of the polynomial. If not an integer, the result is
- determined via the relation to the Gauss hypergeometric
- function.
- alpha : array_like
- Parameter
- x : array_like
- Points at which to evaluate the Gegenbauer polynomial
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- C : scalar or ndarray
- Values of the Gegenbauer polynomial
- See Also
- --------
- roots_gegenbauer : roots and quadrature weights of Gegenbauer
- polynomials
- gegenbauer : Gegenbauer polynomial object
- hyp2f1 : Gauss hypergeometric function
- References
- ----------
- .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
- Handbook of Mathematical Functions with Formulas,
- Graphs, and Mathematical Tables. New York: Dover, 1972.
- .. [DLMF] NIST Digital Library of Mathematical Functions,
- https://dlmf.nist.gov/18.5.E9
- """)
- add_newdoc("eval_chebyt",
- r"""
- eval_chebyt(n, x, out=None)
- Evaluate Chebyshev polynomial of the first kind at a point.
- The Chebyshev polynomials of the first kind can be defined via the
- Gauss hypergeometric function :math:`{}_2F_1` as
- .. math::
- T_n(x) = {}_2F_1(n, -n; 1/2; (1 - x)/2).
- When :math:`n` is an integer the result is a polynomial of degree
- :math:`n`. See 22.5.47 in [AS]_ (or equivalently [DLMF]_) for details.
- Parameters
- ----------
- n : array_like
- Degree of the polynomial. If not an integer, the result is
- determined via the relation to the Gauss hypergeometric
- function.
- x : array_like
- Points at which to evaluate the Chebyshev polynomial
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- T : scalar or ndarray
- Values of the Chebyshev polynomial
- See Also
- --------
- roots_chebyt : roots and quadrature weights of Chebyshev
- polynomials of the first kind
- chebyu : Chebychev polynomial object
- eval_chebyu : evaluate Chebyshev polynomials of the second kind
- hyp2f1 : Gauss hypergeometric function
- numpy.polynomial.chebyshev.Chebyshev : Chebyshev series
- Notes
- -----
- This routine is numerically stable for `x` in ``[-1, 1]`` at least
- up to order ``10000``.
- References
- ----------
- .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
- Handbook of Mathematical Functions with Formulas,
- Graphs, and Mathematical Tables. New York: Dover, 1972.
- .. [DLMF] NIST Digital Library of Mathematical Functions,
- https://dlmf.nist.gov/18.5.E11_2
- """)
- add_newdoc("eval_chebyu",
- r"""
- eval_chebyu(n, x, out=None)
- Evaluate Chebyshev polynomial of the second kind at a point.
- The Chebyshev polynomials of the second kind can be defined via
- the Gauss hypergeometric function :math:`{}_2F_1` as
- .. math::
- U_n(x) = (n + 1) {}_2F_1(-n, n + 2; 3/2; (1 - x)/2).
- When :math:`n` is an integer the result is a polynomial of degree
- :math:`n`. See 22.5.48 in [AS]_ (or equivalently [DLMF]_) for details.
- Parameters
- ----------
- n : array_like
- Degree of the polynomial. If not an integer, the result is
- determined via the relation to the Gauss hypergeometric
- function.
- x : array_like
- Points at which to evaluate the Chebyshev polynomial
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- U : scalar or ndarray
- Values of the Chebyshev polynomial
- See Also
- --------
- roots_chebyu : roots and quadrature weights of Chebyshev
- polynomials of the second kind
- chebyu : Chebyshev polynomial object
- eval_chebyt : evaluate Chebyshev polynomials of the first kind
- hyp2f1 : Gauss hypergeometric function
- References
- ----------
- .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
- Handbook of Mathematical Functions with Formulas,
- Graphs, and Mathematical Tables. New York: Dover, 1972.
- .. [DLMF] NIST Digital Library of Mathematical Functions,
- https://dlmf.nist.gov/18.5.E11_4
- """)
- add_newdoc("eval_chebys",
- r"""
- eval_chebys(n, x, out=None)
- Evaluate Chebyshev polynomial of the second kind on [-2, 2] at a
- point.
- These polynomials are defined as
- .. math::
- S_n(x) = U_n(x/2)
- where :math:`U_n` is a Chebyshev polynomial of the second kind.
- See 22.5.13 in [AS]_ (or equivalently [DLMF]_) for details.
- Parameters
- ----------
- n : array_like
- Degree of the polynomial. If not an integer, the result is
- determined via the relation to `eval_chebyu`.
- x : array_like
- Points at which to evaluate the Chebyshev polynomial
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- S : scalar or ndarray
- Values of the Chebyshev polynomial
- See Also
- --------
- roots_chebys : roots and quadrature weights of Chebyshev
- polynomials of the second kind on [-2, 2]
- chebys : Chebyshev polynomial object
- eval_chebyu : evaluate Chebyshev polynomials of the second kind
- References
- ----------
- .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
- Handbook of Mathematical Functions with Formulas,
- Graphs, and Mathematical Tables. New York: Dover, 1972.
- .. [DLMF] NIST Digital Library of Mathematical Functions,
- https://dlmf.nist.gov/18.1.E3
- Examples
- --------
- >>> import numpy as np
- >>> import scipy.special as sc
- They are a scaled version of the Chebyshev polynomials of the
- second kind.
- >>> x = np.linspace(-2, 2, 6)
- >>> sc.eval_chebys(3, x)
- array([-4. , 0.672, 0.736, -0.736, -0.672, 4. ])
- >>> sc.eval_chebyu(3, x / 2)
- array([-4. , 0.672, 0.736, -0.736, -0.672, 4. ])
- """)
- add_newdoc("eval_chebyc",
- r"""
- eval_chebyc(n, x, out=None)
- Evaluate Chebyshev polynomial of the first kind on [-2, 2] at a
- point.
- These polynomials are defined as
- .. math::
- C_n(x) = 2 T_n(x/2)
- where :math:`T_n` is a Chebyshev polynomial of the first kind. See
- 22.5.11 in [AS]_ (or equivalently [DLMF]_) for details.
- Parameters
- ----------
- n : array_like
- Degree of the polynomial. If not an integer, the result is
- determined via the relation to `eval_chebyt`.
- x : array_like
- Points at which to evaluate the Chebyshev polynomial
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- C : scalar or ndarray
- Values of the Chebyshev polynomial
- See Also
- --------
- roots_chebyc : roots and quadrature weights of Chebyshev
- polynomials of the first kind on [-2, 2]
- chebyc : Chebyshev polynomial object
- numpy.polynomial.chebyshev.Chebyshev : Chebyshev series
- eval_chebyt : evaluate Chebycshev polynomials of the first kind
- References
- ----------
- .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
- Handbook of Mathematical Functions with Formulas,
- Graphs, and Mathematical Tables. New York: Dover, 1972.
- .. [DLMF] NIST Digital Library of Mathematical Functions,
- https://dlmf.nist.gov/18.1.E3
- Examples
- --------
- >>> import numpy as np
- >>> import scipy.special as sc
- They are a scaled version of the Chebyshev polynomials of the
- first kind.
- >>> x = np.linspace(-2, 2, 6)
- >>> sc.eval_chebyc(3, x)
- array([-2. , 1.872, 1.136, -1.136, -1.872, 2. ])
- >>> 2 * sc.eval_chebyt(3, x / 2)
- array([-2. , 1.872, 1.136, -1.136, -1.872, 2. ])
- """)
- add_newdoc("eval_sh_chebyt",
- r"""
- eval_sh_chebyt(n, x, out=None)
- Evaluate shifted Chebyshev polynomial of the first kind at a
- point.
- These polynomials are defined as
- .. math::
- T_n^*(x) = T_n(2x - 1)
- where :math:`T_n` is a Chebyshev polynomial of the first kind. See
- 22.5.14 in [AS]_ (or equivalently [DLMF]_) for details.
- Parameters
- ----------
- n : array_like
- Degree of the polynomial. If not an integer, the result is
- determined via the relation to `eval_chebyt`.
- x : array_like
- Points at which to evaluate the shifted Chebyshev polynomial
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- T : scalar or ndarray
- Values of the shifted Chebyshev polynomial
- See Also
- --------
- roots_sh_chebyt : roots and quadrature weights of shifted
- Chebyshev polynomials of the first kind
- sh_chebyt : shifted Chebyshev polynomial object
- eval_chebyt : evaluate Chebyshev polynomials of the first kind
- numpy.polynomial.chebyshev.Chebyshev : Chebyshev series
- References
- ----------
- .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
- Handbook of Mathematical Functions with Formulas,
- Graphs, and Mathematical Tables. New York: Dover, 1972.
- .. [DLMF] NIST Digital Library of Mathematical Functions,
- https://dlmf.nist.gov/18.7.E7
- """)
- add_newdoc("eval_sh_chebyu",
- r"""
- eval_sh_chebyu(n, x, out=None)
- Evaluate shifted Chebyshev polynomial of the second kind at a
- point.
- These polynomials are defined as
- .. math::
- U_n^*(x) = U_n(2x - 1)
- where :math:`U_n` is a Chebyshev polynomial of the first kind. See
- 22.5.15 in [AS]_ (or equivalently [DLMF]_) for details.
- Parameters
- ----------
- n : array_like
- Degree of the polynomial. If not an integer, the result is
- determined via the relation to `eval_chebyu`.
- x : array_like
- Points at which to evaluate the shifted Chebyshev polynomial
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- U : scalar or ndarray
- Values of the shifted Chebyshev polynomial
- See Also
- --------
- roots_sh_chebyu : roots and quadrature weights of shifted
- Chebychev polynomials of the second kind
- sh_chebyu : shifted Chebyshev polynomial object
- eval_chebyu : evaluate Chebyshev polynomials of the second kind
- References
- ----------
- .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
- Handbook of Mathematical Functions with Formulas,
- Graphs, and Mathematical Tables. New York: Dover, 1972.
- .. [DLMF] NIST Digital Library of Mathematical Functions,
- https://dlmf.nist.gov/18.7.E8
- """)
- add_newdoc("eval_legendre",
- r"""
- eval_legendre(n, x, out=None)
- Evaluate Legendre polynomial at a point.
- The Legendre polynomials can be defined via the Gauss
- hypergeometric function :math:`{}_2F_1` as
- .. math::
- P_n(x) = {}_2F_1(-n, n + 1; 1; (1 - x)/2).
- When :math:`n` is an integer the result is a polynomial of degree
- :math:`n`. See 22.5.49 in [AS]_ (or equivalently [DLMF]_) for details.
- Parameters
- ----------
- n : array_like
- Degree of the polynomial. If not an integer, the result is
- determined via the relation to the Gauss hypergeometric
- function.
- x : array_like
- Points at which to evaluate the Legendre polynomial
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- P : scalar or ndarray
- Values of the Legendre polynomial
- See Also
- --------
- roots_legendre : roots and quadrature weights of Legendre
- polynomials
- legendre : Legendre polynomial object
- hyp2f1 : Gauss hypergeometric function
- numpy.polynomial.legendre.Legendre : Legendre series
- References
- ----------
- .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
- Handbook of Mathematical Functions with Formulas,
- Graphs, and Mathematical Tables. New York: Dover, 1972.
- .. [DLMF] NIST Digital Library of Mathematical Functions,
- https://dlmf.nist.gov/15.9.E7
- Examples
- --------
- >>> import numpy as np
- >>> from scipy.special import eval_legendre
- Evaluate the zero-order Legendre polynomial at x = 0
- >>> eval_legendre(0, 0)
- 1.0
- Evaluate the first-order Legendre polynomial between -1 and 1
- >>> X = np.linspace(-1, 1, 5) # Domain of Legendre polynomials
- >>> eval_legendre(1, X)
- array([-1. , -0.5, 0. , 0.5, 1. ])
- Evaluate Legendre polynomials of order 0 through 4 at x = 0
- >>> N = range(0, 5)
- >>> eval_legendre(N, 0)
- array([ 1. , 0. , -0.5 , 0. , 0.375])
- Plot Legendre polynomials of order 0 through 4
- >>> X = np.linspace(-1, 1)
- >>> import matplotlib.pyplot as plt
- >>> for n in range(0, 5):
- ... y = eval_legendre(n, X)
- ... plt.plot(X, y, label=r'$P_{}(x)$'.format(n))
- >>> plt.title("Legendre Polynomials")
- >>> plt.xlabel("x")
- >>> plt.ylabel(r'$P_n(x)$')
- >>> plt.legend(loc='lower right')
- >>> plt.show()
- """)
- add_newdoc("eval_sh_legendre",
- r"""
- eval_sh_legendre(n, x, out=None)
- Evaluate shifted Legendre polynomial at a point.
- These polynomials are defined as
- .. math::
- P_n^*(x) = P_n(2x - 1)
- where :math:`P_n` is a Legendre polynomial. See 2.2.11 in [AS]_
- or [DLMF]_ for details.
- Parameters
- ----------
- n : array_like
- Degree of the polynomial. If not an integer, the value is
- determined via the relation to `eval_legendre`.
- x : array_like
- Points at which to evaluate the shifted Legendre polynomial
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- P : scalar or ndarray
- Values of the shifted Legendre polynomial
- See Also
- --------
- roots_sh_legendre : roots and quadrature weights of shifted
- Legendre polynomials
- sh_legendre : shifted Legendre polynomial object
- eval_legendre : evaluate Legendre polynomials
- numpy.polynomial.legendre.Legendre : Legendre series
- References
- ----------
- .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
- Handbook of Mathematical Functions with Formulas,
- Graphs, and Mathematical Tables. New York: Dover, 1972.
- .. [DLMF] NIST Digital Library of Mathematical Functions,
- https://dlmf.nist.gov/18.7.E10
- """)
- add_newdoc("eval_genlaguerre",
- r"""
- eval_genlaguerre(n, alpha, x, out=None)
- Evaluate generalized Laguerre polynomial at a point.
- The generalized Laguerre polynomials can be defined via the
- confluent hypergeometric function :math:`{}_1F_1` as
- .. math::
- L_n^{(\alpha)}(x) = \binom{n + \alpha}{n}
- {}_1F_1(-n, \alpha + 1, x).
- When :math:`n` is an integer the result is a polynomial of degree
- :math:`n`. See 22.5.54 in [AS]_ or [DLMF]_ for details. The Laguerre
- polynomials are the special case where :math:`\alpha = 0`.
- Parameters
- ----------
- n : array_like
- Degree of the polynomial. If not an integer, the result is
- determined via the relation to the confluent hypergeometric
- function.
- alpha : array_like
- Parameter; must have ``alpha > -1``
- x : array_like
- Points at which to evaluate the generalized Laguerre
- polynomial
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- L : scalar or ndarray
- Values of the generalized Laguerre polynomial
- See Also
- --------
- roots_genlaguerre : roots and quadrature weights of generalized
- Laguerre polynomials
- genlaguerre : generalized Laguerre polynomial object
- hyp1f1 : confluent hypergeometric function
- eval_laguerre : evaluate Laguerre polynomials
- References
- ----------
- .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
- Handbook of Mathematical Functions with Formulas,
- Graphs, and Mathematical Tables. New York: Dover, 1972.
- .. [DLMF] NIST Digital Library of Mathematical Functions,
- https://dlmf.nist.gov/18.5.E12
- """)
- add_newdoc("eval_laguerre",
- r"""
- eval_laguerre(n, x, out=None)
- Evaluate Laguerre polynomial at a point.
- The Laguerre polynomials can be defined via the confluent
- hypergeometric function :math:`{}_1F_1` as
- .. math::
- L_n(x) = {}_1F_1(-n, 1, x).
- See 22.5.16 and 22.5.54 in [AS]_ (or equivalently [DLMF1]_ and [DLMF2]_)
- for details. When :math:`n` is an integer the result is a polynomial
- of degree :math:`n`.
- Parameters
- ----------
- n : array_like
- Degree of the polynomial. If not an integer the result is
- determined via the relation to the confluent hypergeometric
- function.
- x : array_like
- Points at which to evaluate the Laguerre polynomial
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- L : scalar or ndarray
- Values of the Laguerre polynomial
- See Also
- --------
- roots_laguerre : roots and quadrature weights of Laguerre
- polynomials
- laguerre : Laguerre polynomial object
- numpy.polynomial.laguerre.Laguerre : Laguerre series
- eval_genlaguerre : evaluate generalized Laguerre polynomials
- References
- ----------
- .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
- Handbook of Mathematical Functions with Formulas,
- Graphs, and Mathematical Tables. New York: Dover, 1972.
- .. [DLMF1] NIST Digital Library of Mathematical Functions,
- https://dlmf.nist.gov/18.1#I1.ix7.p1
- .. [DLMF2] NIST Digital Library of Mathematical Functions,
- https://dlmf.nist.gov/18.5.E12
- """)
- add_newdoc("eval_hermite",
- r"""
- eval_hermite(n, x, out=None)
- Evaluate physicist's Hermite polynomial at a point.
- Defined by
- .. math::
- H_n(x) = (-1)^n e^{x^2} \frac{d^n}{dx^n} e^{-x^2};
- :math:`H_n` is a polynomial of degree :math:`n`. See 22.11.7 in
- [AS]_ or [DLMF]_ for details.
- Parameters
- ----------
- n : array_like
- Degree of the polynomial
- x : array_like
- Points at which to evaluate the Hermite polynomial
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- H : scalar or ndarray
- Values of the Hermite polynomial
- See Also
- --------
- roots_hermite : roots and quadrature weights of physicist's
- Hermite polynomials
- hermite : physicist's Hermite polynomial object
- numpy.polynomial.hermite.Hermite : Physicist's Hermite series
- eval_hermitenorm : evaluate Probabilist's Hermite polynomials
- References
- ----------
- .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
- Handbook of Mathematical Functions with Formulas,
- Graphs, and Mathematical Tables. New York: Dover, 1972.
- .. [DLMF] NIST Digital Library of Mathematical Functions,
- https://dlmf.nist.gov/18.5.T1
- """)
- add_newdoc("eval_hermitenorm",
- r"""
- eval_hermitenorm(n, x, out=None)
- Evaluate probabilist's (normalized) Hermite polynomial at a
- point.
- Defined by
- .. math::
- He_n(x) = (-1)^n e^{x^2/2} \frac{d^n}{dx^n} e^{-x^2/2};
- :math:`He_n` is a polynomial of degree :math:`n`. See 22.11.8 in
- [AS]_ or [DLMF]_ for details.
- Parameters
- ----------
- n : array_like
- Degree of the polynomial
- x : array_like
- Points at which to evaluate the Hermite polynomial
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- He : scalar or ndarray
- Values of the Hermite polynomial
- See Also
- --------
- roots_hermitenorm : roots and quadrature weights of probabilist's
- Hermite polynomials
- hermitenorm : probabilist's Hermite polynomial object
- numpy.polynomial.hermite_e.HermiteE : Probabilist's Hermite series
- eval_hermite : evaluate physicist's Hermite polynomials
- References
- ----------
- .. [AS] Milton Abramowitz and Irene A. Stegun, eds.
- Handbook of Mathematical Functions with Formulas,
- Graphs, and Mathematical Tables. New York: Dover, 1972.
- .. [DLMF] NIST Digital Library of Mathematical Functions,
- https://dlmf.nist.gov/18.5.T1
- """)
- add_newdoc("expn",
- r"""
- expn(n, x, out=None)
- Generalized exponential integral En.
- For integer :math:`n \geq 0` and real :math:`x \geq 0` the
- generalized exponential integral is defined as [DLMF]_
- .. math::
- E_n(x) = x^{n - 1} \int_x^\infty \frac{e^{-t}}{t^n} dt.
- Parameters
- ----------
- n : array_like
- Non-negative integers
- x : array_like
- Real argument
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- scalar or ndarray
- Values of the generalized exponential integral
- See Also
- --------
- exp1 : special case of :math:`E_n` for :math:`n = 1`
- expi : related to :math:`E_n` when :math:`n = 1`
- References
- ----------
- .. [DLMF] Digital Library of Mathematical Functions, 8.19.2
- https://dlmf.nist.gov/8.19#E2
- Examples
- --------
- >>> import numpy as np
- >>> import scipy.special as sc
- Its domain is nonnegative n and x.
- >>> sc.expn(-1, 1.0), sc.expn(1, -1.0)
- (nan, nan)
- It has a pole at ``x = 0`` for ``n = 1, 2``; for larger ``n`` it
- is equal to ``1 / (n - 1)``.
- >>> sc.expn([0, 1, 2, 3, 4], 0)
- array([ inf, inf, 1. , 0.5 , 0.33333333])
- For n equal to 0 it reduces to ``exp(-x) / x``.
- >>> x = np.array([1, 2, 3, 4])
- >>> sc.expn(0, x)
- array([0.36787944, 0.06766764, 0.01659569, 0.00457891])
- >>> np.exp(-x) / x
- array([0.36787944, 0.06766764, 0.01659569, 0.00457891])
- For n equal to 1 it reduces to `exp1`.
- >>> sc.expn(1, x)
- array([0.21938393, 0.04890051, 0.01304838, 0.00377935])
- >>> sc.exp1(x)
- array([0.21938393, 0.04890051, 0.01304838, 0.00377935])
- """)
- add_newdoc("fdtr",
- r"""
- fdtr(dfn, dfd, x, out=None)
- F cumulative distribution function.
- Returns the value of the cumulative distribution function of the
- F-distribution, also known as Snedecor's F-distribution or the
- Fisher-Snedecor distribution.
- The F-distribution with parameters :math:`d_n` and :math:`d_d` is the
- distribution of the random variable,
- .. math::
- X = \frac{U_n/d_n}{U_d/d_d},
- where :math:`U_n` and :math:`U_d` are random variables distributed
- :math:`\chi^2`, with :math:`d_n` and :math:`d_d` degrees of freedom,
- respectively.
- Parameters
- ----------
- dfn : array_like
- First parameter (positive float).
- dfd : array_like
- Second parameter (positive float).
- x : array_like
- Argument (nonnegative float).
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- y : scalar or ndarray
- The CDF of the F-distribution with parameters `dfn` and `dfd` at `x`.
- See Also
- --------
- fdtrc : F distribution survival function
- fdtri : F distribution inverse cumulative distribution
- scipy.stats.f : F distribution
- Notes
- -----
- The regularized incomplete beta function is used, according to the
- formula,
- .. math::
- F(d_n, d_d; x) = I_{xd_n/(d_d + xd_n)}(d_n/2, d_d/2).
- Wrapper for a routine from the Boost Math C++ library [1]_. The
- F distribution is also available as `scipy.stats.f`. Calling
- `fdtr` directly can improve performance compared to the ``cdf``
- method of `scipy.stats.f` (see last example below).
- References
- ----------
- .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
- Examples
- --------
- Calculate the function for ``dfn=1`` and ``dfd=2`` at ``x=1``.
- >>> import numpy as np
- >>> from scipy.special import fdtr
- >>> fdtr(1, 2, 1)
- 0.5773502691896258
- Calculate the function at several points by providing a NumPy array for
- `x`.
- >>> x = np.array([0.5, 2., 3.])
- >>> fdtr(1, 2, x)
- array([0.4472136 , 0.70710678, 0.77459667])
- Plot the function for several parameter sets.
- >>> import matplotlib.pyplot as plt
- >>> dfn_parameters = [1, 5, 10, 50]
- >>> dfd_parameters = [1, 1, 2, 3]
- >>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
- >>> parameters_list = list(zip(dfn_parameters, dfd_parameters,
- ... linestyles))
- >>> x = np.linspace(0, 30, 1000)
- >>> fig, ax = plt.subplots()
- >>> for parameter_set in parameters_list:
- ... dfn, dfd, style = parameter_set
- ... fdtr_vals = fdtr(dfn, dfd, x)
- ... ax.plot(x, fdtr_vals, label=rf"$d_n={dfn},\, d_d={dfd}$",
- ... ls=style)
- >>> ax.legend()
- >>> ax.set_xlabel("$x$")
- >>> ax.set_title("F distribution cumulative distribution function")
- >>> plt.show()
- The F distribution is also available as `scipy.stats.f`. Using `fdtr`
- directly can be much faster than calling the ``cdf`` method of
- `scipy.stats.f`, especially for small arrays or individual values.
- To get the same results one must use the following parametrization:
- ``stats.f(dfn, dfd).cdf(x)=fdtr(dfn, dfd, x)``.
- >>> from scipy.stats import f
- >>> dfn, dfd = 1, 2
- >>> x = 1
- >>> fdtr_res = fdtr(dfn, dfd, x) # this will often be faster than below
- >>> f_dist_res = f(dfn, dfd).cdf(x)
- >>> fdtr_res == f_dist_res # test that results are equal
- True
- """)
- add_newdoc("fdtrc",
- r"""
- fdtrc(dfn, dfd, x, out=None)
- F survival function.
- Returns the complemented F-distribution function (the integral of the
- density from `x` to infinity).
- Parameters
- ----------
- dfn : array_like
- First parameter (positive float).
- dfd : array_like
- Second parameter (positive float).
- x : array_like
- Argument (nonnegative float).
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- y : scalar or ndarray
- The complemented F-distribution function with parameters `dfn` and
- `dfd` at `x`.
- See Also
- --------
- fdtr : F distribution cumulative distribution function
- fdtri : F distribution inverse cumulative distribution function
- scipy.stats.f : F distribution
- Notes
- -----
- The regularized incomplete beta function is used, according to the
- formula,
- .. math::
- F(d_n, d_d; x) = I_{d_d/(d_d + xd_n)}(d_d/2, d_n/2).
- Wrapper for a routine from the Boost Math C++ library [1]_. The
- F distribution is also available as `scipy.stats.f`. Calling
- `fdtrc` directly can improve performance compared to the ``sf``
- method of `scipy.stats.f` (see last example below).
- References
- ----------
- .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
- Examples
- --------
- Calculate the function for ``dfn=1`` and ``dfd=2`` at ``x=1``.
- >>> import numpy as np
- >>> from scipy.special import fdtrc
- >>> fdtrc(1, 2, 1)
- 0.42264973081037427
- Calculate the function at several points by providing a NumPy array for
- `x`.
- >>> x = np.array([0.5, 2., 3.])
- >>> fdtrc(1, 2, x)
- array([0.5527864 , 0.29289322, 0.22540333])
- Plot the function for several parameter sets.
- >>> import matplotlib.pyplot as plt
- >>> dfn_parameters = [1, 5, 10, 50]
- >>> dfd_parameters = [1, 1, 2, 3]
- >>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
- >>> parameters_list = list(zip(dfn_parameters, dfd_parameters,
- ... linestyles))
- >>> x = np.linspace(0, 30, 1000)
- >>> fig, ax = plt.subplots()
- >>> for parameter_set in parameters_list:
- ... dfn, dfd, style = parameter_set
- ... fdtrc_vals = fdtrc(dfn, dfd, x)
- ... ax.plot(x, fdtrc_vals, label=rf"$d_n={dfn},\, d_d={dfd}$",
- ... ls=style)
- >>> ax.legend()
- >>> ax.set_xlabel("$x$")
- >>> ax.set_title("F distribution survival function")
- >>> plt.show()
- The F distribution is also available as `scipy.stats.f`. Using `fdtrc`
- directly can be much faster than calling the ``sf`` method of
- `scipy.stats.f`, especially for small arrays or individual values.
- To get the same results one must use the following parametrization:
- ``stats.f(dfn, dfd).sf(x)=fdtrc(dfn, dfd, x)``.
- >>> from scipy.stats import f
- >>> dfn, dfd = 1, 2
- >>> x = 1
- >>> fdtrc_res = fdtrc(dfn, dfd, x) # this will often be faster than below
- >>> f_dist_res = f(dfn, dfd).sf(x)
- >>> f_dist_res == fdtrc_res # test that results are equal
- True
- """)
- add_newdoc("fdtri",
- r"""
- fdtri(dfn, dfd, p, out=None)
- The `p`-th quantile of the F-distribution.
- This function is the inverse of the F-distribution CDF, `fdtr`, returning
- the `x` such that `fdtr(dfn, dfd, x) = p`.
- Parameters
- ----------
- dfn : array_like
- First parameter (positive float).
- dfd : array_like
- Second parameter (positive float).
- p : array_like
- Cumulative probability, in [0, 1].
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- x : scalar or ndarray
- The quantile corresponding to `p`.
- See Also
- --------
- fdtr : F distribution cumulative distribution function
- fdtrc : F distribution survival function
- scipy.stats.f : F distribution
- Notes
- -----
- Wrapper for a routine from the Boost Math C++ library [1]_. The
- F distribution is also available as `scipy.stats.f`. Calling
- `fdtri` directly can improve performance compared to the ``ppf``
- method of `scipy.stats.f` (see last example below).
- References
- ----------
- .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
- Examples
- --------
- `fdtri` represents the inverse of the F distribution CDF which is
- available as `fdtr`. Here, we calculate the CDF for ``df1=1``, ``df2=2``
- at ``x=3``. `fdtri` then returns ``3`` given the same values for `df1`,
- `df2` and the computed CDF value.
- >>> import numpy as np
- >>> from scipy.special import fdtri, fdtr
- >>> df1, df2 = 1, 2
- >>> x = 3
- >>> cdf_value = fdtr(df1, df2, x)
- >>> fdtri(df1, df2, cdf_value)
- 3.000000000000006
- Calculate the function at several points by providing a NumPy array for
- `x`.
- >>> x = np.array([0.1, 0.4, 0.7])
- >>> fdtri(1, 2, x)
- array([0.02020202, 0.38095238, 1.92156863])
- Plot the function for several parameter sets.
- >>> import matplotlib.pyplot as plt
- >>> dfn_parameters = [50, 10, 1, 50]
- >>> dfd_parameters = [0.5, 1, 1, 5]
- >>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
- >>> parameters_list = list(zip(dfn_parameters, dfd_parameters,
- ... linestyles))
- >>> x = np.linspace(0, 1, 1000)
- >>> fig, ax = plt.subplots()
- >>> for parameter_set in parameters_list:
- ... dfn, dfd, style = parameter_set
- ... fdtri_vals = fdtri(dfn, dfd, x)
- ... ax.plot(x, fdtri_vals, label=rf"$d_n={dfn},\, d_d={dfd}$",
- ... ls=style)
- >>> ax.legend()
- >>> ax.set_xlabel("$x$")
- >>> title = "F distribution inverse cumulative distribution function"
- >>> ax.set_title(title)
- >>> ax.set_ylim(0, 30)
- >>> plt.show()
- The F distribution is also available as `scipy.stats.f`. Using `fdtri`
- directly can be much faster than calling the ``ppf`` method of
- `scipy.stats.f`, especially for small arrays or individual values.
- To get the same results one must use the following parametrization:
- ``stats.f(dfn, dfd).ppf(x)=fdtri(dfn, dfd, x)``.
- >>> from scipy.stats import f
- >>> dfn, dfd = 1, 2
- >>> x = 0.7
- >>> fdtri_res = fdtri(dfn, dfd, x) # this will often be faster than below
- >>> f_dist_res = f(dfn, dfd).ppf(x)
- >>> f_dist_res == fdtri_res # test that results are equal
- True
- """)
- add_newdoc("fdtridfd",
- """
- fdtridfd(dfn, p, x, out=None)
- Inverse to `fdtr` vs dfd
- Finds the F density argument dfd such that ``fdtr(dfn, dfd, x) == p``.
- Parameters
- ----------
- dfn : array_like
- First parameter (positive float).
- p : array_like
- Cumulative probability, in [0, 1].
- x : array_like
- Argument (nonnegative float).
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- dfd : scalar or ndarray
- `dfd` such that ``fdtr(dfn, dfd, x) == p``.
- See Also
- --------
- fdtr : F distribution cumulative distribution function
- fdtrc : F distribution survival function
- fdtri : F distribution quantile function
- scipy.stats.f : F distribution
- Examples
- --------
- Compute the F distribution cumulative distribution function for one
- parameter set.
- >>> from scipy.special import fdtridfd, fdtr
- >>> dfn, dfd, x = 10, 5, 2
- >>> cdf_value = fdtr(dfn, dfd, x)
- >>> cdf_value
- 0.7700248806501017
- Verify that `fdtridfd` recovers the original value for `dfd`:
- >>> fdtridfd(dfn, cdf_value, x)
- 5.0
- """)
- '''
- commented out as fdtridfn seems to have bugs and is not in functions.json
- see: https://github.com/scipy/scipy/pull/15622#discussion_r811440983
- add_newdoc(
- "fdtridfn",
- """
- fdtridfn(p, dfd, x, out=None)
- Inverse to `fdtr` vs dfn
- finds the F density argument dfn such that ``fdtr(dfn, dfd, x) == p``.
- Parameters
- ----------
- p : array_like
- Cumulative probability, in [0, 1].
- dfd : array_like
- Second parameter (positive float).
- x : array_like
- Argument (nonnegative float).
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- dfn : scalar or ndarray
- `dfn` such that ``fdtr(dfn, dfd, x) == p``.
- See Also
- --------
- fdtr, fdtrc, fdtri, fdtridfd
- """)
- '''
- add_newdoc("gdtr",
- r"""
- gdtr(a, b, x, out=None)
- Gamma distribution cumulative distribution function.
- Returns the integral from zero to `x` of the gamma probability density
- function,
- .. math::
- F = \int_0^x \frac{a^b}{\Gamma(b)} t^{b-1} e^{-at}\,dt,
- where :math:`\Gamma` is the gamma function.
- Parameters
- ----------
- a : array_like
- The rate parameter of the gamma distribution, sometimes denoted
- :math:`\beta` (float). It is also the reciprocal of the scale
- parameter :math:`\theta`.
- b : array_like
- The shape parameter of the gamma distribution, sometimes denoted
- :math:`\alpha` (float).
- x : array_like
- The quantile (upper limit of integration; float).
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- F : scalar or ndarray
- The CDF of the gamma distribution with parameters `a` and `b`
- evaluated at `x`.
- See Also
- --------
- gdtrc : 1 - CDF of the gamma distribution.
- scipy.stats.gamma: Gamma distribution
- Notes
- -----
- The evaluation is carried out using the relation to the incomplete gamma
- integral (regularized gamma function).
- Wrapper for the Cephes [1]_ routine `gdtr`. Calling `gdtr` directly can
- improve performance compared to the ``cdf`` method of `scipy.stats.gamma`
- (see last example below).
- References
- ----------
- .. [1] Cephes Mathematical Functions Library,
- http://www.netlib.org/cephes/
- Examples
- --------
- Compute the function for ``a=1``, ``b=2`` at ``x=5``.
- >>> import numpy as np
- >>> from scipy.special import gdtr
- >>> import matplotlib.pyplot as plt
- >>> gdtr(1., 2., 5.)
- 0.9595723180054873
- Compute the function for ``a=1`` and ``b=2`` at several points by
- providing a NumPy array for `x`.
- >>> xvalues = np.array([1., 2., 3., 4])
- >>> gdtr(1., 1., xvalues)
- array([0.63212056, 0.86466472, 0.95021293, 0.98168436])
- `gdtr` can evaluate different parameter sets by providing arrays with
- broadcasting compatible shapes for `a`, `b` and `x`. Here we compute the
- function for three different `a` at four positions `x` and ``b=3``,
- resulting in a 3x4 array.
- >>> a = np.array([[0.5], [1.5], [2.5]])
- >>> x = np.array([1., 2., 3., 4])
- >>> a.shape, x.shape
- ((3, 1), (4,))
- >>> gdtr(a, 3., x)
- array([[0.01438768, 0.0803014 , 0.19115317, 0.32332358],
- [0.19115317, 0.57680992, 0.82642193, 0.9380312 ],
- [0.45618688, 0.87534798, 0.97974328, 0.9972306 ]])
- Plot the function for four different parameter sets.
- >>> a_parameters = [0.3, 1, 2, 6]
- >>> b_parameters = [2, 10, 15, 20]
- >>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
- >>> parameters_list = list(zip(a_parameters, b_parameters, linestyles))
- >>> x = np.linspace(0, 30, 1000)
- >>> fig, ax = plt.subplots()
- >>> for parameter_set in parameters_list:
- ... a, b, style = parameter_set
- ... gdtr_vals = gdtr(a, b, x)
- ... ax.plot(x, gdtr_vals, label=fr"$a= {a},\, b={b}$", ls=style)
- >>> ax.legend()
- >>> ax.set_xlabel("$x$")
- >>> ax.set_title("Gamma distribution cumulative distribution function")
- >>> plt.show()
- The gamma distribution is also available as `scipy.stats.gamma`. Using
- `gdtr` directly can be much faster than calling the ``cdf`` method of
- `scipy.stats.gamma`, especially for small arrays or individual values.
- To get the same results one must use the following parametrization:
- ``stats.gamma(b, scale=1/a).cdf(x)=gdtr(a, b, x)``.
- >>> from scipy.stats import gamma
- >>> a = 2.
- >>> b = 3
- >>> x = 1.
- >>> gdtr_result = gdtr(a, b, x) # this will often be faster than below
- >>> gamma_dist_result = gamma(b, scale=1/a).cdf(x)
- >>> gdtr_result == gamma_dist_result # test that results are equal
- True
- """)
- add_newdoc("gdtrc",
- r"""
- gdtrc(a, b, x, out=None)
- Gamma distribution survival function.
- Integral from `x` to infinity of the gamma probability density function,
- .. math::
- F = \int_x^\infty \frac{a^b}{\Gamma(b)} t^{b-1} e^{-at}\,dt,
- where :math:`\Gamma` is the gamma function.
- Parameters
- ----------
- a : array_like
- The rate parameter of the gamma distribution, sometimes denoted
- :math:`\beta` (float). It is also the reciprocal of the scale
- parameter :math:`\theta`.
- b : array_like
- The shape parameter of the gamma distribution, sometimes denoted
- :math:`\alpha` (float).
- x : array_like
- The quantile (lower limit of integration; float).
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- F : scalar or ndarray
- The survival function of the gamma distribution with parameters `a`
- and `b` evaluated at `x`.
- See Also
- --------
- gdtr: Gamma distribution cumulative distribution function
- scipy.stats.gamma: Gamma distribution
- gdtrix
- Notes
- -----
- The evaluation is carried out using the relation to the incomplete gamma
- integral (regularized gamma function).
- Wrapper for the Cephes [1]_ routine `gdtrc`. Calling `gdtrc` directly can
- improve performance compared to the ``sf`` method of `scipy.stats.gamma`
- (see last example below).
- References
- ----------
- .. [1] Cephes Mathematical Functions Library,
- http://www.netlib.org/cephes/
- Examples
- --------
- Compute the function for ``a=1`` and ``b=2`` at ``x=5``.
- >>> import numpy as np
- >>> from scipy.special import gdtrc
- >>> import matplotlib.pyplot as plt
- >>> gdtrc(1., 2., 5.)
- 0.04042768199451279
- Compute the function for ``a=1``, ``b=2`` at several points by providing
- a NumPy array for `x`.
- >>> xvalues = np.array([1., 2., 3., 4])
- >>> gdtrc(1., 1., xvalues)
- array([0.36787944, 0.13533528, 0.04978707, 0.01831564])
- `gdtrc` can evaluate different parameter sets by providing arrays with
- broadcasting compatible shapes for `a`, `b` and `x`. Here we compute the
- function for three different `a` at four positions `x` and ``b=3``,
- resulting in a 3x4 array.
- >>> a = np.array([[0.5], [1.5], [2.5]])
- >>> x = np.array([1., 2., 3., 4])
- >>> a.shape, x.shape
- ((3, 1), (4,))
- >>> gdtrc(a, 3., x)
- array([[0.98561232, 0.9196986 , 0.80884683, 0.67667642],
- [0.80884683, 0.42319008, 0.17357807, 0.0619688 ],
- [0.54381312, 0.12465202, 0.02025672, 0.0027694 ]])
- Plot the function for four different parameter sets.
- >>> a_parameters = [0.3, 1, 2, 6]
- >>> b_parameters = [2, 10, 15, 20]
- >>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
- >>> parameters_list = list(zip(a_parameters, b_parameters, linestyles))
- >>> x = np.linspace(0, 30, 1000)
- >>> fig, ax = plt.subplots()
- >>> for parameter_set in parameters_list:
- ... a, b, style = parameter_set
- ... gdtrc_vals = gdtrc(a, b, x)
- ... ax.plot(x, gdtrc_vals, label=fr"$a= {a},\, b={b}$", ls=style)
- >>> ax.legend()
- >>> ax.set_xlabel("$x$")
- >>> ax.set_title("Gamma distribution survival function")
- >>> plt.show()
- The gamma distribution is also available as `scipy.stats.gamma`.
- Using `gdtrc` directly can be much faster than calling the ``sf`` method
- of `scipy.stats.gamma`, especially for small arrays or individual
- values. To get the same results one must use the following parametrization:
- ``stats.gamma(b, scale=1/a).sf(x)=gdtrc(a, b, x)``.
- >>> from scipy.stats import gamma
- >>> a = 2
- >>> b = 3
- >>> x = 1.
- >>> gdtrc_result = gdtrc(a, b, x) # this will often be faster than below
- >>> gamma_dist_result = gamma(b, scale=1/a).sf(x)
- >>> gdtrc_result == gamma_dist_result # test that results are equal
- True
- """)
- add_newdoc("gdtria",
- """
- gdtria(p, b, x, out=None)
- Inverse of `gdtr` vs a.
- Returns the inverse with respect to the parameter `a` of ``p =
- gdtr(a, b, x)``, the cumulative distribution function of the gamma
- distribution.
- Parameters
- ----------
- p : array_like
- Probability values.
- b : array_like
- `b` parameter values of `gdtr(a, b, x)`. `b` is the "shape" parameter
- of the gamma distribution.
- x : array_like
- Nonnegative real values, from the domain of the gamma distribution.
- out : ndarray, optional
- If a fourth argument is given, it must be a numpy.ndarray whose size
- matches the broadcast result of `a`, `b` and `x`. `out` is then the
- array returned by the function.
- Returns
- -------
- a : scalar or ndarray
- Values of the `a` parameter such that ``p = gdtr(a, b, x)`. ``1/a``
- is the "scale" parameter of the gamma distribution.
- See Also
- --------
- gdtr : CDF of the gamma distribution.
- gdtrib : Inverse with respect to `b` of `gdtr(a, b, x)`.
- gdtrix : Inverse with respect to `x` of `gdtr(a, b, x)`.
- Notes
- -----
- Wrapper for the CDFLIB [1]_ Fortran routine `cdfgam`.
- The cumulative distribution function `p` is computed using a routine by
- DiDinato and Morris [2]_. Computation of `a` involves a search for a value
- that produces the desired value of `p`. The search relies on the
- monotonicity of `p` with `a`.
- References
- ----------
- .. [1] Barry Brown, James Lovato, and Kathy Russell,
- CDFLIB: Library of Fortran Routines for Cumulative Distribution
- Functions, Inverses, and Other Parameters.
- .. [2] DiDinato, A. R. and Morris, A. H.,
- Computation of the incomplete gamma function ratios and their
- inverse. ACM Trans. Math. Softw. 12 (1986), 377-393.
- Examples
- --------
- First evaluate `gdtr`.
- >>> from scipy.special import gdtr, gdtria
- >>> p = gdtr(1.2, 3.4, 5.6)
- >>> print(p)
- 0.94378087442
- Verify the inverse.
- >>> gdtria(p, 3.4, 5.6)
- 1.2
- """)
- add_newdoc("gdtrib",
- """
- gdtrib(a, p, x, out=None)
- Inverse of `gdtr` vs b.
- Returns the inverse with respect to the parameter `b` of ``p =
- gdtr(a, b, x)``, the cumulative distribution function of the gamma
- distribution.
- Parameters
- ----------
- a : array_like
- `a` parameter values of ``gdtr(a, b, x)`. ``1/a`` is the "scale"
- parameter of the gamma distribution.
- p : array_like
- Probability values.
- x : array_like
- Nonnegative real values, from the domain of the gamma distribution.
- out : ndarray, optional
- If a fourth argument is given, it must be a numpy.ndarray whose size
- matches the broadcast result of `a`, `b` and `x`. `out` is then the
- array returned by the function.
- Returns
- -------
- b : scalar or ndarray
- Values of the `b` parameter such that `p = gdtr(a, b, x)`. `b` is
- the "shape" parameter of the gamma distribution.
- See Also
- --------
- gdtr : CDF of the gamma distribution.
- gdtria : Inverse with respect to `a` of `gdtr(a, b, x)`.
- gdtrix : Inverse with respect to `x` of `gdtr(a, b, x)`.
- Notes
- -----
- The cumulative distribution function `p` is computed using the Cephes [1]_
- routines `igam` and `igamc`. Computation of `b` involves a search for a value
- that produces the desired value of `p` using Chandrupatla's bracketing
- root finding algorithm [2]_.
- Note that there are some edge cases where `gdtrib` is extended by taking
- limits where they are uniquely defined. In particular
- ``x == 0`` with ``p > 0`` and ``p == 0`` with ``x > 0``.
- For these edge cases, a numerical result will be returned for
- ``gdtrib(a, p, x)`` even though ``gdtr(a, gdtrib(a, p, x), x)`` is
- undefined.
- References
- ----------
- .. [1] Cephes Mathematical Functions Library,
- http://www.netlib.org/cephes/
- .. [2] Chandrupatla, Tirupathi R.
- "A new hybrid quadratic/bisection algorithm for finding the zero of a
- nonlinear function without using derivatives".
- Advances in Engineering Software, 28(3), 145-149.
- https://doi.org/10.1016/s0965-9978(96)00051-8
- Examples
- --------
- First evaluate `gdtr`.
- >>> from scipy.special import gdtr, gdtrib
- >>> p = gdtr(1.2, 3.4, 5.6)
- >>> print(p)
- 0.94378087442
- Verify the inverse.
- >>> gdtrib(1.2, p, 5.6)
- 3.3999999999999995
- """)
- add_newdoc("gdtrix",
- """
- gdtrix(a, b, p, out=None)
- Inverse of `gdtr` vs x.
- Returns the inverse with respect to the parameter `x` of ``p =
- gdtr(a, b, x)``, the cumulative distribution function of the gamma
- distribution. This is also known as the pth quantile of the
- distribution.
- Parameters
- ----------
- a : array_like
- `a` parameter values of ``gdtr(a, b, x)``. ``1/a`` is the "scale"
- parameter of the gamma distribution.
- b : array_like
- `b` parameter values of ``gdtr(a, b, x)``. `b` is the "shape" parameter
- of the gamma distribution.
- p : array_like
- Probability values.
- out : ndarray, optional
- If a fourth argument is given, it must be a numpy.ndarray whose size
- matches the broadcast result of `a`, `b` and `x`. `out` is then the
- array returned by the function.
- Returns
- -------
- x : scalar or ndarray
- Values of the `x` parameter such that `p = gdtr(a, b, x)`.
- See Also
- --------
- gdtr : CDF of the gamma distribution.
- gdtria : Inverse with respect to `a` of ``gdtr(a, b, x)``.
- gdtrib : Inverse with respect to `b` of ``gdtr(a, b, x)``.
- Notes
- -----
- Wrapper for the CDFLIB [1]_ Fortran routine `cdfgam`.
- The cumulative distribution function `p` is computed using a routine by
- DiDinato and Morris [2]_. Computation of `x` involves a search for a value
- that produces the desired value of `p`. The search relies on the
- monotonicity of `p` with `x`.
- References
- ----------
- .. [1] Barry Brown, James Lovato, and Kathy Russell,
- CDFLIB: Library of Fortran Routines for Cumulative Distribution
- Functions, Inverses, and Other Parameters.
- .. [2] DiDinato, A. R. and Morris, A. H.,
- Computation of the incomplete gamma function ratios and their
- inverse. ACM Trans. Math. Softw. 12 (1986), 377-393.
- Examples
- --------
- First evaluate `gdtr`.
- >>> from scipy.special import gdtr, gdtrix
- >>> p = gdtr(1.2, 3.4, 5.6)
- >>> print(p)
- 0.94378087442
- Verify the inverse.
- >>> gdtrix(1.2, 3.4, p)
- 5.5999999999999996
- """)
- add_newdoc("huber",
- r"""
- huber(delta, r, out=None)
- Huber loss function.
- .. math:: \text{huber}(\delta, r) = \begin{cases} \infty & \delta < 0 \\
- \frac{1}{2}r^2 & 0 \le \delta, | r | \le \delta \\
- \delta ( |r| - \frac{1}{2}\delta ) & \text{otherwise} \end{cases}
- Parameters
- ----------
- delta : ndarray
- Input array, indicating the quadratic vs. linear loss changepoint.
- r : ndarray
- Input array, possibly representing residuals.
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- scalar or ndarray
- The computed Huber loss function values.
- See Also
- --------
- pseudo_huber : smooth approximation of this function
- Notes
- -----
- `huber` is useful as a loss function in robust statistics or machine
- learning to reduce the influence of outliers as compared to the common
- squared error loss, residuals with a magnitude higher than `delta` are
- not squared [1]_.
- Typically, `r` represents residuals, the difference
- between a model prediction and data. Then, for :math:`|r|\leq\delta`,
- `huber` resembles the squared error and for :math:`|r|>\delta` the
- absolute error. This way, the Huber loss often achieves
- a fast convergence in model fitting for small residuals like the squared
- error loss function and still reduces the influence of outliers
- (:math:`|r|>\delta`) like the absolute error loss. As :math:`\delta` is
- the cutoff between squared and absolute error regimes, it has
- to be tuned carefully for each problem. `huber` is also
- convex, making it suitable for gradient based optimization.
- .. versionadded:: 0.15.0
- References
- ----------
- .. [1] Peter Huber. "Robust Estimation of a Location Parameter",
- 1964. Annals of Statistics. 53 (1): 73 - 101.
- Examples
- --------
- Import all necessary modules.
- >>> import numpy as np
- >>> from scipy.special import huber
- >>> import matplotlib.pyplot as plt
- Compute the function for ``delta=1`` at ``r=2``
- >>> huber(1., 2.)
- 1.5
- Compute the function for different `delta` by providing a NumPy array or
- list for `delta`.
- >>> huber([1., 3., 5.], 4.)
- array([3.5, 7.5, 8. ])
- Compute the function at different points by providing a NumPy array or
- list for `r`.
- >>> huber(2., np.array([1., 1.5, 3.]))
- array([0.5 , 1.125, 4. ])
- The function can be calculated for different `delta` and `r` by
- providing arrays for both with compatible shapes for broadcasting.
- >>> r = np.array([1., 2.5, 8., 10.])
- >>> deltas = np.array([[1.], [5.], [9.]])
- >>> print(r.shape, deltas.shape)
- (4,) (3, 1)
- >>> huber(deltas, r)
- array([[ 0.5 , 2. , 7.5 , 9.5 ],
- [ 0.5 , 3.125, 27.5 , 37.5 ],
- [ 0.5 , 3.125, 32. , 49.5 ]])
- Plot the function for different `delta`.
- >>> x = np.linspace(-4, 4, 500)
- >>> deltas = [1, 2, 3]
- >>> linestyles = ["dashed", "dotted", "dashdot"]
- >>> fig, ax = plt.subplots()
- >>> combined_plot_parameters = list(zip(deltas, linestyles))
- >>> for delta, style in combined_plot_parameters:
- ... ax.plot(x, huber(delta, x), label=fr"$\delta={delta}$", ls=style)
- >>> ax.legend(loc="upper center")
- >>> ax.set_xlabel("$x$")
- >>> ax.set_title(r"Huber loss function $h_{\delta}(x)$")
- >>> ax.set_xlim(-4, 4)
- >>> ax.set_ylim(0, 8)
- >>> plt.show()
- """)
- add_newdoc("hyp0f1",
- r"""
- hyp0f1(v, z, out=None)
- Confluent hypergeometric limit function 0F1.
- Parameters
- ----------
- v : array_like
- Real-valued parameter
- z : array_like
- Real- or complex-valued argument
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- scalar or ndarray
- The confluent hypergeometric limit function
- Notes
- -----
- This function is defined as:
- .. math:: _0F_1(v, z) = \sum_{k=0}^{\infty}\frac{z^k}{(v)_k k!}.
- It's also the limit as :math:`q \to \infty` of :math:`_1F_1(q; v; z/q)`,
- and satisfies the differential equation :math:`f''(z) + vf'(z) =
- f(z)`. See [1]_ for more information.
- References
- ----------
- .. [1] Wolfram MathWorld, "Confluent Hypergeometric Limit Function",
- http://mathworld.wolfram.com/ConfluentHypergeometricLimitFunction.html
- Examples
- --------
- >>> import numpy as np
- >>> import scipy.special as sc
- It is one when `z` is zero.
- >>> sc.hyp0f1(1, 0)
- 1.0
- It is the limit of the confluent hypergeometric function as `q`
- goes to infinity.
- >>> q = np.array([1, 10, 100, 1000])
- >>> v = 1
- >>> z = 1
- >>> sc.hyp1f1(q, v, z / q)
- array([2.71828183, 2.31481985, 2.28303778, 2.27992985])
- >>> sc.hyp0f1(v, z)
- 2.2795853023360673
- It is related to Bessel functions.
- >>> n = 1
- >>> x = np.linspace(0, 1, 5)
- >>> sc.jv(n, x)
- array([0. , 0.12402598, 0.24226846, 0.3492436 , 0.44005059])
- >>> (0.5 * x)**n / sc.factorial(n) * sc.hyp0f1(n + 1, -0.25 * x**2)
- array([0. , 0.12402598, 0.24226846, 0.3492436 , 0.44005059])
- """)
- add_newdoc("hyp1f1",
- r"""
- hyp1f1(a, b, x, out=None)
- Confluent hypergeometric function 1F1.
- The confluent hypergeometric function is defined by the series
- .. math::
- {}_1F_1(a; b; x) = \sum_{k = 0}^\infty \frac{(a)_k}{(b)_k k!} x^k.
- See [DLMF]_ for more details. Here :math:`(\cdot)_k` is the
- Pochhammer symbol; see `poch`.
- Parameters
- ----------
- a, b : array_like
- Real parameters
- x : array_like
- Real or complex argument
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- scalar or ndarray
- Values of the confluent hypergeometric function
- See Also
- --------
- hyperu : another confluent hypergeometric function
- hyp0f1 : confluent hypergeometric limit function
- hyp2f1 : Gaussian hypergeometric function
- Notes
- -----
- For real values, this function uses the ``hyp1f1`` routine from the C++ Boost
- library [2]_, for complex values a C translation of the specfun
- Fortran library [3]_.
- References
- ----------
- .. [DLMF] NIST Digital Library of Mathematical Functions
- https://dlmf.nist.gov/13.2#E2
- .. [2] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
- .. [3] Zhang, Jin, "Computation of Special Functions", John Wiley
- and Sons, Inc, 1996.
- Examples
- --------
- >>> import numpy as np
- >>> import scipy.special as sc
- It is one when `x` is zero:
- >>> sc.hyp1f1(0.5, 0.5, 0)
- 1.0
- It is singular when `b` is a nonpositive integer.
- >>> sc.hyp1f1(0.5, -1, 0)
- inf
- It is a polynomial when `a` is a nonpositive integer.
- >>> a, b, x = -1, 0.5, np.array([1.0, 2.0, 3.0, 4.0])
- >>> sc.hyp1f1(a, b, x)
- array([-1., -3., -5., -7.])
- >>> 1 + (a / b) * x
- array([-1., -3., -5., -7.])
- It reduces to the exponential function when ``a = b``.
- >>> sc.hyp1f1(2, 2, [1, 2, 3, 4])
- array([ 2.71828183, 7.3890561 , 20.08553692, 54.59815003])
- >>> np.exp([1, 2, 3, 4])
- array([ 2.71828183, 7.3890561 , 20.08553692, 54.59815003])
- """)
- add_newdoc("hyperu",
- r"""
- hyperu(a, b, x, out=None)
- Confluent hypergeometric function U
- It is defined as the solution to the equation
- .. math::
- x \frac{d^2w}{dx^2} + (b - x) \frac{dw}{dx} - aw = 0
- which satisfies the property
- .. math::
- U(a, b, x) \sim x^{-a}
- as :math:`x \to \infty`. See [DLMF]_ for more details.
- Parameters
- ----------
- a, b : array_like
- Real-valued parameters
- x : array_like
- Real-valued argument
- out : ndarray, optional
- Optional output array for the function values
- Returns
- -------
- scalar or ndarray
- Values of `U`
- References
- ----------
- .. [DLMF] NIST Digital Library of Mathematics Functions
- https://dlmf.nist.gov/13.2#E6
- Examples
- --------
- >>> import numpy as np
- >>> import scipy.special as sc
- It has a branch cut along the negative `x` axis.
- >>> x = np.linspace(-0.1, -10, 5)
- >>> sc.hyperu(1, 1, x)
- array([nan, nan, nan, nan, nan])
- It approaches zero as `x` goes to infinity.
- >>> x = np.array([1, 10, 100])
- >>> sc.hyperu(1, 1, x)
- array([0.59634736, 0.09156333, 0.00990194])
- It satisfies Kummer's transformation.
- >>> a, b, x = 2, 1, 1
- >>> sc.hyperu(a, b, x)
- 0.1926947246463881
- >>> x**(1 - b) * sc.hyperu(a - b + 1, 2 - b, x)
- 0.1926947246463881
- """)
- add_newdoc("_igam_fac",
- """
- Internal function, do not use.
- """)
- add_newdoc("kl_div",
- r"""
- kl_div(x, y, out=None)
- Elementwise function for computing Kullback-Leibler divergence.
- .. math::
- \mathrm{kl\_div}(x, y) =
- \begin{cases}
- x \log(x / y) - x + y & x > 0, y > 0 \\
- y & x = 0, y \ge 0 \\
- \infty & \text{otherwise}
- \end{cases}
- Parameters
- ----------
- x, y : array_like
- Real arguments
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- scalar or ndarray
- Values of the Kullback-Liebler divergence.
- See Also
- --------
- entr, rel_entr, scipy.stats.entropy
- Notes
- -----
- .. versionadded:: 0.15.0
- This function is non-negative and is jointly convex in `x` and `y`.
- The origin of this function is in convex programming; see [1]_ for
- details. This is why the function contains the extra :math:`-x
- + y` terms over what might be expected from the Kullback-Leibler
- divergence. For a version of the function without the extra terms,
- see `rel_entr`.
- References
- ----------
- .. [1] Boyd, Stephen and Lieven Vandenberghe. *Convex optimization*.
- Cambridge University Press, 2004.
- :doi:`https://doi.org/10.1017/CBO9780511804441`
- """)
- add_newdoc("kn",
- r"""
- kn(n, x, out=None)
- Modified Bessel function of the second kind of integer order `n`
- Returns the modified Bessel function of the second kind for integer order
- `n` at real `z`.
- These are also sometimes called functions of the third kind, Basset
- functions, or Macdonald functions.
- Parameters
- ----------
- n : array_like of int
- Order of Bessel functions (floats will truncate with a warning)
- x : array_like of float
- Argument at which to evaluate the Bessel functions
- out : ndarray, optional
- Optional output array for the function results.
- Returns
- -------
- scalar or ndarray
- Value of the Modified Bessel function of the second kind,
- :math:`K_n(x)`.
- See Also
- --------
- kv : Same function, but accepts real order and complex argument
- kvp : Derivative of this function
- Notes
- -----
- Wrapper for AMOS [1]_ routine `zbesk`. For a discussion of the
- algorithm used, see [2]_ and the references therein.
- References
- ----------
- .. [1] Donald E. Amos, "AMOS, A Portable Package for Bessel Functions
- of a Complex Argument and Nonnegative Order",
- http://netlib.org/amos/
- .. [2] Donald E. Amos, "Algorithm 644: A portable package for Bessel
- functions of a complex argument and nonnegative order", ACM
- TOMS Vol. 12 Issue 3, Sept. 1986, p. 265
- Examples
- --------
- Plot the function of several orders for real input:
- >>> import numpy as np
- >>> from scipy.special import kn
- >>> import matplotlib.pyplot as plt
- >>> x = np.linspace(0, 5, 1000)
- >>> for N in range(6):
- ... plt.plot(x, kn(N, x), label='$K_{}(x)$'.format(N))
- >>> plt.ylim(0, 10)
- >>> plt.legend()
- >>> plt.title(r'Modified Bessel function of the second kind $K_n(x)$')
- >>> plt.show()
- Calculate for a single value at multiple orders:
- >>> kn([4, 5, 6], 1)
- array([ 44.23241585, 360.9605896 , 3653.83831186])
- """)
- add_newdoc("kolmogi",
- """
- kolmogi(p, out=None)
- Inverse Survival Function of Kolmogorov distribution
- It is the inverse function to `kolmogorov`.
- Returns y such that ``kolmogorov(y) == p``.
- Parameters
- ----------
- p : float array_like
- Probability
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- scalar or ndarray
- The value(s) of kolmogi(p)
- See Also
- --------
- kolmogorov : The Survival Function for the distribution
- scipy.stats.kstwobign : Provides the functionality as a continuous distribution
- smirnov, smirnovi : Functions for the one-sided distribution
- Notes
- -----
- `kolmogorov` is used by `stats.kstest` in the application of the
- Kolmogorov-Smirnov Goodness of Fit test. For historical reasons this
- function is exposed in `scpy.special`, but the recommended way to achieve
- the most accurate CDF/SF/PDF/PPF/ISF computations is to use the
- `stats.kstwobign` distribution.
- Examples
- --------
- >>> from scipy.special import kolmogi
- >>> kolmogi([0, 0.1, 0.25, 0.5, 0.75, 0.9, 1.0])
- array([ inf, 1.22384787, 1.01918472, 0.82757356, 0.67644769,
- 0.57117327, 0. ])
- """)
- add_newdoc("kolmogorov",
- r"""
- kolmogorov(y, out=None)
- Complementary cumulative distribution (Survival Function) function of
- Kolmogorov distribution.
- Returns the complementary cumulative distribution function of
- Kolmogorov's limiting distribution (``D_n*\sqrt(n)`` as n goes to infinity)
- of a two-sided test for equality between an empirical and a theoretical
- distribution. It is equal to the (limit as n->infinity of the)
- probability that ``sqrt(n) * max absolute deviation > y``.
- Parameters
- ----------
- y : float array_like
- Absolute deviation between the Empirical CDF (ECDF) and the target CDF,
- multiplied by sqrt(n).
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- scalar or ndarray
- The value(s) of kolmogorov(y)
- See Also
- --------
- kolmogi : The Inverse Survival Function for the distribution
- scipy.stats.kstwobign : Provides the functionality as a continuous distribution
- smirnov, smirnovi : Functions for the one-sided distribution
- Notes
- -----
- `kolmogorov` is used by `stats.kstest` in the application of the
- Kolmogorov-Smirnov Goodness of Fit test. For historical reasons this
- function is exposed in `scpy.special`, but the recommended way to achieve
- the most accurate CDF/SF/PDF/PPF/ISF computations is to use the
- `stats.kstwobign` distribution.
- Examples
- --------
- Show the probability of a gap at least as big as 0, 0.5 and 1.0.
- >>> import numpy as np
- >>> from scipy.special import kolmogorov
- >>> from scipy.stats import kstwobign
- >>> kolmogorov([0, 0.5, 1.0])
- array([ 1. , 0.96394524, 0.26999967])
- Compare a sample of size 1000 drawn from a Laplace(0, 1) distribution against
- the target distribution, a Normal(0, 1) distribution.
- >>> from scipy.stats import norm, laplace
- >>> rng = np.random.default_rng()
- >>> n = 1000
- >>> lap01 = laplace(0, 1)
- >>> x = np.sort(lap01.rvs(n, random_state=rng))
- >>> np.mean(x), np.std(x)
- (-0.05841730131499543, 1.3968109101997568)
- Construct the Empirical CDF and the K-S statistic Dn.
- >>> target = norm(0,1) # Normal mean 0, stddev 1
- >>> cdfs = target.cdf(x)
- >>> ecdfs = np.arange(n+1, dtype=float)/n
- >>> gaps = np.column_stack([cdfs - ecdfs[:n], ecdfs[1:] - cdfs])
- >>> Dn = np.max(gaps)
- >>> Kn = np.sqrt(n) * Dn
- >>> print('Dn=%f, sqrt(n)*Dn=%f' % (Dn, Kn))
- Dn=0.043363, sqrt(n)*Dn=1.371265
- >>> print(chr(10).join(['For a sample of size n drawn from a N(0, 1) distribution:',
- ... ' the approximate Kolmogorov probability that sqrt(n)*Dn>=%f is %f' %
- ... (Kn, kolmogorov(Kn)),
- ... ' the approximate Kolmogorov probability that sqrt(n)*Dn<=%f is %f' %
- ... (Kn, kstwobign.cdf(Kn))]))
- For a sample of size n drawn from a N(0, 1) distribution:
- the approximate Kolmogorov probability that sqrt(n)*Dn>=1.371265 is 0.046533
- the approximate Kolmogorov probability that sqrt(n)*Dn<=1.371265 is 0.953467
- Plot the Empirical CDF against the target N(0, 1) CDF.
- >>> import matplotlib.pyplot as plt
- >>> plt.step(np.concatenate([[-3], x]), ecdfs, where='post', label='Empirical CDF')
- >>> x3 = np.linspace(-3, 3, 100)
- >>> plt.plot(x3, target.cdf(x3), label='CDF for N(0, 1)')
- >>> plt.ylim([0, 1]); plt.grid(True); plt.legend();
- >>> # Add vertical lines marking Dn+ and Dn-
- >>> iminus, iplus = np.argmax(gaps, axis=0)
- >>> plt.vlines([x[iminus]], ecdfs[iminus], cdfs[iminus],
- ... color='r', linestyle='dashed', lw=4)
- >>> plt.vlines([x[iplus]], cdfs[iplus], ecdfs[iplus+1],
- ... color='r', linestyle='dashed', lw=4)
- >>> plt.show()
- """)
- add_newdoc("_kolmogc",
- r"""
- Internal function, do not use.
- """)
- add_newdoc("_kolmogci",
- r"""
- Internal function, do not use.
- """)
- add_newdoc("_kolmogp",
- r"""
- Internal function, do not use.
- """)
- add_newdoc("_lanczos_sum_expg_scaled",
- """
- Internal function, do not use.
- """)
- add_newdoc(
- "_landau_pdf",
- """
- _landau_pdf(x, loc, scale)
- Probability density function of the Landau distribution.
- Parameters
- ----------
- x : array_like
- Real-valued argument
- loc : array_like
- Real-valued distribution location
- scale : array_like
- Positive, real-valued distribution scale
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_landau_cdf",
- """
- _landau_cdf(x, loc, scale)
- Cumulative distribution function of the Landau distribution.
- Parameters
- ----------
- x : array_like
- Real-valued argument
- loc : array_like
- Real-valued distribution location
- scale : array_like
- Positive, real-valued distribution scale
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_landau_sf",
- """
- _landau_sf(x, loc, scale)
- Survival function of the Landau distribution.
- Parameters
- ----------
- x : array_like
- Real-valued argument
- loc : array_like
- Real-valued distribution location
- scale : array_like
- Positive, real-valued distribution scale
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_landau_ppf",
- """
- _landau_ppf(p, loc, scale)
- Percent point function of the Landau distribution.
- Parameters
- ----------
- p : array_like
- Real-valued argument between 0 and 1
- loc : array_like
- Real-valued distribution location
- scale : array_like
- Positive, real-valued distribution scale
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_landau_isf",
- """
- _landau_isf(p, loc, scale)
- Inverse survival function of the Landau distribution.
- Parameters
- ----------
- p : array_like
- Real-valued argument between 0 and 1
- loc : array_like
- Real-valued distribution location
- scale : array_like
- Positive, real-valued distribution scale
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc("_lgam1p",
- """
- Internal function, do not use.
- """)
- add_newdoc("lpmv",
- r"""
- lpmv(m, v, x, out=None)
- Associated Legendre function of integer order and real degree.
- Defined as
- .. math::
- P_v^m = (-1)^m (1 - x^2)^{m/2} \frac{d^m}{dx^m} P_v(x)
- where
- .. math::
- P_v = \sum_{k = 0}^\infty \frac{(-v)_k (v + 1)_k}{(k!)^2}
- \left(\frac{1 - x}{2}\right)^k
- is the Legendre function of the first kind. Here :math:`(\cdot)_k`
- is the Pochhammer symbol; see `poch`.
- Parameters
- ----------
- m : array_like
- Order (int or float). If passed a float not equal to an
- integer the function returns NaN.
- v : array_like
- Degree (float).
- x : array_like
- Argument (float). Must have ``|x| <= 1``.
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- pmv : scalar or ndarray
- Value of the associated Legendre function.
- Notes
- -----
- Note that this implementation includes the Condon-Shortley phase.
- References
- ----------
- .. [1] Zhang, Jin, "Computation of Special Functions", John Wiley
- and Sons, Inc, 1996.
- """)
- add_newdoc("nbdtr",
- r"""
- nbdtr(k, n, p, out=None)
- Negative binomial cumulative distribution function.
- Returns the sum of the terms 0 through `k` of the negative binomial
- distribution probability mass function,
- .. math::
- F = \sum_{j=0}^k {{n + j - 1}\choose{j}} p^n (1 - p)^j.
- In a sequence of Bernoulli trials with individual success probabilities
- `p`, this is the probability that `k` or fewer failures precede the nth
- success.
- Parameters
- ----------
- k : array_like
- The maximum number of allowed failures (nonnegative int).
- n : array_like
- The target number of successes (positive int).
- p : array_like
- Probability of success in a single event (float).
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- F : scalar or ndarray
- The probability of `k` or fewer failures before `n` successes in a
- sequence of events with individual success probability `p`.
- See Also
- --------
- nbdtrc : Negative binomial survival function
- nbdtrik : Negative binomial quantile function
- scipy.stats.nbinom : Negative binomial distribution
- Notes
- -----
- If floating point values are passed for `k` or `n`, they will be truncated
- to integers.
- The terms are not summed directly; instead the regularized incomplete beta
- function is employed, according to the formula,
- .. math::
- \mathrm{nbdtr}(k, n, p) = I_{p}(n, k + 1).
- Wrapper for the Cephes [1]_ routine `nbdtr`.
- The negative binomial distribution is also available as
- `scipy.stats.nbinom`. Using `nbdtr` directly can improve performance
- compared to the ``cdf`` method of `scipy.stats.nbinom` (see last example).
- References
- ----------
- .. [1] Cephes Mathematical Functions Library,
- http://www.netlib.org/cephes/
- Examples
- --------
- Compute the function for ``k=10`` and ``n=5`` at ``p=0.5``.
- >>> import numpy as np
- >>> from scipy.special import nbdtr
- >>> nbdtr(10, 5, 0.5)
- 0.940765380859375
- Compute the function for ``n=10`` and ``p=0.5`` at several points by
- providing a NumPy array or list for `k`.
- >>> nbdtr([5, 10, 15], 10, 0.5)
- array([0.15087891, 0.58809853, 0.88523853])
- Plot the function for four different parameter sets.
- >>> import matplotlib.pyplot as plt
- >>> k = np.arange(130)
- >>> n_parameters = [20, 20, 20, 80]
- >>> p_parameters = [0.2, 0.5, 0.8, 0.5]
- >>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
- >>> parameters_list = list(zip(p_parameters, n_parameters,
- ... linestyles))
- >>> fig, ax = plt.subplots(figsize=(8, 8))
- >>> for parameter_set in parameters_list:
- ... p, n, style = parameter_set
- ... nbdtr_vals = nbdtr(k, n, p)
- ... ax.plot(k, nbdtr_vals, label=rf"$n={n},\, p={p}$",
- ... ls=style)
- >>> ax.legend()
- >>> ax.set_xlabel("$k$")
- >>> ax.set_title("Negative binomial cumulative distribution function")
- >>> plt.show()
- The negative binomial distribution is also available as
- `scipy.stats.nbinom`. Using `nbdtr` directly can be much faster than
- calling the ``cdf`` method of `scipy.stats.nbinom`, especially for small
- arrays or individual values. To get the same results one must use the
- following parametrization: ``nbinom(n, p).cdf(k)=nbdtr(k, n, p)``.
- >>> from scipy.stats import nbinom
- >>> k, n, p = 5, 3, 0.5
- >>> nbdtr_res = nbdtr(k, n, p) # this will often be faster than below
- >>> stats_res = nbinom(n, p).cdf(k)
- >>> stats_res, nbdtr_res # test that results are equal
- (0.85546875, 0.85546875)
- `nbdtr` can evaluate different parameter sets by providing arrays with
- shapes compatible for broadcasting for `k`, `n` and `p`. Here we compute
- the function for three different `k` at four locations `p`, resulting in
- a 3x4 array.
- >>> k = np.array([[5], [10], [15]])
- >>> p = np.array([0.3, 0.5, 0.7, 0.9])
- >>> k.shape, p.shape
- ((3, 1), (4,))
- >>> nbdtr(k, 5, p)
- array([[0.15026833, 0.62304687, 0.95265101, 0.9998531 ],
- [0.48450894, 0.94076538, 0.99932777, 0.99999999],
- [0.76249222, 0.99409103, 0.99999445, 1. ]])
- """)
- add_newdoc("nbdtrc",
- r"""
- nbdtrc(k, n, p, out=None)
- Negative binomial survival function.
- Returns the sum of the terms `k + 1` to infinity of the negative binomial
- distribution probability mass function,
- .. math::
- F = \sum_{j=k + 1}^\infty {{n + j - 1}\choose{j}} p^n (1 - p)^j.
- In a sequence of Bernoulli trials with individual success probabilities
- `p`, this is the probability that more than `k` failures precede the nth
- success.
- Parameters
- ----------
- k : array_like
- The maximum number of allowed failures (nonnegative int).
- n : array_like
- The target number of successes (positive int).
- p : array_like
- Probability of success in a single event (float).
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- F : scalar or ndarray
- The probability of `k + 1` or more failures before `n` successes in a
- sequence of events with individual success probability `p`.
- See Also
- --------
- nbdtr : Negative binomial cumulative distribution function
- nbdtrik : Negative binomial percentile function
- scipy.stats.nbinom : Negative binomial distribution
- Notes
- -----
- If floating point values are passed for `k` or `n`, they will be truncated
- to integers.
- The terms are not summed directly; instead the regularized incomplete beta
- function is employed, according to the formula,
- .. math::
- \mathrm{nbdtrc}(k, n, p) = I_{1 - p}(k + 1, n).
- Wrapper for the Cephes [1]_ routine `nbdtrc`.
- The negative binomial distribution is also available as
- `scipy.stats.nbinom`. Using `nbdtrc` directly can improve performance
- compared to the ``sf`` method of `scipy.stats.nbinom` (see last example).
- References
- ----------
- .. [1] Cephes Mathematical Functions Library,
- http://www.netlib.org/cephes/
- Examples
- --------
- Compute the function for ``k=10`` and ``n=5`` at ``p=0.5``.
- >>> import numpy as np
- >>> from scipy.special import nbdtrc
- >>> nbdtrc(10, 5, 0.5)
- 0.059234619140624986
- Compute the function for ``n=10`` and ``p=0.5`` at several points by
- providing a NumPy array or list for `k`.
- >>> nbdtrc([5, 10, 15], 10, 0.5)
- array([0.84912109, 0.41190147, 0.11476147])
- Plot the function for four different parameter sets.
- >>> import matplotlib.pyplot as plt
- >>> k = np.arange(130)
- >>> n_parameters = [20, 20, 20, 80]
- >>> p_parameters = [0.2, 0.5, 0.8, 0.5]
- >>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
- >>> parameters_list = list(zip(p_parameters, n_parameters,
- ... linestyles))
- >>> fig, ax = plt.subplots(figsize=(8, 8))
- >>> for parameter_set in parameters_list:
- ... p, n, style = parameter_set
- ... nbdtrc_vals = nbdtrc(k, n, p)
- ... ax.plot(k, nbdtrc_vals, label=rf"$n={n},\, p={p}$",
- ... ls=style)
- >>> ax.legend()
- >>> ax.set_xlabel("$k$")
- >>> ax.set_title("Negative binomial distribution survival function")
- >>> plt.show()
- The negative binomial distribution is also available as
- `scipy.stats.nbinom`. Using `nbdtrc` directly can be much faster than
- calling the ``sf`` method of `scipy.stats.nbinom`, especially for small
- arrays or individual values. To get the same results one must use the
- following parametrization: ``nbinom(n, p).sf(k)=nbdtrc(k, n, p)``.
- >>> from scipy.stats import nbinom
- >>> k, n, p = 3, 5, 0.5
- >>> nbdtr_res = nbdtrc(k, n, p) # this will often be faster than below
- >>> stats_res = nbinom(n, p).sf(k)
- >>> stats_res, nbdtr_res # test that results are equal
- (0.6367187499999999, 0.6367187499999999)
- `nbdtrc` can evaluate different parameter sets by providing arrays with
- shapes compatible for broadcasting for `k`, `n` and `p`. Here we compute
- the function for three different `k` at four locations `p`, resulting in
- a 3x4 array.
- >>> k = np.array([[5], [10], [15]])
- >>> p = np.array([0.3, 0.5, 0.7, 0.9])
- >>> k.shape, p.shape
- ((3, 1), (4,))
- >>> nbdtrc(k, 5, p)
- array([[8.49731667e-01, 3.76953125e-01, 4.73489874e-02, 1.46902600e-04],
- [5.15491059e-01, 5.92346191e-02, 6.72234070e-04, 9.29610100e-09],
- [2.37507779e-01, 5.90896606e-03, 5.55025308e-06, 3.26346760e-13]])
- """)
- add_newdoc(
- "nbdtri",
- r"""
- nbdtri(k, n, y, out=None)
- Returns the inverse with respect to the parameter `p` of
- ``y = nbdtr(k, n, p)``, the negative binomial cumulative distribution
- function.
- Parameters
- ----------
- k : array_like
- The maximum number of allowed failures (nonnegative int).
- n : array_like
- The target number of successes (positive int).
- y : array_like
- The probability of `k` or fewer failures before `n` successes (float).
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- p : scalar or ndarray
- Probability of success in a single event (float) such that
- `nbdtr(k, n, p) = y`.
- See Also
- --------
- nbdtr : Cumulative distribution function of the negative binomial.
- nbdtrc : Negative binomial survival function.
- scipy.stats.nbinom : negative binomial distribution.
- nbdtrik : Inverse with respect to `k` of `nbdtr(k, n, p)`.
- nbdtrin : Inverse with respect to `n` of `nbdtr(k, n, p)`.
- scipy.stats.nbinom : Negative binomial distribution
- Notes
- -----
- Wrapper for the Cephes [1]_ routine `nbdtri`.
- The negative binomial distribution is also available as
- `scipy.stats.nbinom`. Using `nbdtri` directly can improve performance
- compared to the ``ppf`` method of `scipy.stats.nbinom`.
- References
- ----------
- .. [1] Cephes Mathematical Functions Library,
- http://www.netlib.org/cephes/
- Examples
- --------
- `nbdtri` is the inverse of `nbdtr` with respect to `p`.
- Up to floating point errors the following holds:
- ``nbdtri(k, n, nbdtr(k, n, p))=p``.
- >>> import numpy as np
- >>> from scipy.special import nbdtri, nbdtr
- >>> k, n, y = 5, 10, 0.2
- >>> cdf_val = nbdtr(k, n, y)
- >>> nbdtri(k, n, cdf_val)
- 0.20000000000000004
- Compute the function for ``k=10`` and ``n=5`` at several points by
- providing a NumPy array or list for `y`.
- >>> y = np.array([0.1, 0.4, 0.8])
- >>> nbdtri(3, 5, y)
- array([0.34462319, 0.51653095, 0.69677416])
- Plot the function for three different parameter sets.
- >>> import matplotlib.pyplot as plt
- >>> n_parameters = [5, 20, 30, 30]
- >>> k_parameters = [20, 20, 60, 80]
- >>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
- >>> parameters_list = list(zip(n_parameters, k_parameters, linestyles))
- >>> cdf_vals = np.linspace(0, 1, 1000)
- >>> fig, ax = plt.subplots(figsize=(8, 8))
- >>> for parameter_set in parameters_list:
- ... n, k, style = parameter_set
- ... nbdtri_vals = nbdtri(k, n, cdf_vals)
- ... ax.plot(cdf_vals, nbdtri_vals, label=rf"$k={k},\ n={n}$",
- ... ls=style)
- >>> ax.legend()
- >>> ax.set_ylabel("$p$")
- >>> ax.set_xlabel("$CDF$")
- >>> title = "nbdtri: inverse of negative binomial CDF with respect to $p$"
- >>> ax.set_title(title)
- >>> plt.show()
- `nbdtri` can evaluate different parameter sets by providing arrays with
- shapes compatible for broadcasting for `k`, `n` and `p`. Here we compute
- the function for three different `k` at four locations `p`, resulting in
- a 3x4 array.
- >>> k = np.array([[5], [10], [15]])
- >>> y = np.array([0.3, 0.5, 0.7, 0.9])
- >>> k.shape, y.shape
- ((3, 1), (4,))
- >>> nbdtri(k, 5, y)
- array([[0.37258157, 0.45169416, 0.53249956, 0.64578407],
- [0.24588501, 0.30451981, 0.36778453, 0.46397088],
- [0.18362101, 0.22966758, 0.28054743, 0.36066188]])
- """)
- add_newdoc("nbdtrik",
- r"""
- nbdtrik(y, n, p, out=None)
- Negative binomial percentile function.
- Returns the inverse with respect to the parameter `k` of
- ``y = nbdtr(k, n, p)``, the negative binomial cumulative distribution
- function.
- Parameters
- ----------
- y : array_like
- The probability of `k` or fewer failures before `n` successes (float).
- n : array_like
- The target number of successes (positive int).
- p : array_like
- Probability of success in a single event (float).
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- k : scalar or ndarray
- The maximum number of allowed failures such that `nbdtr(k, n, p) = y`.
- See Also
- --------
- nbdtr : Cumulative distribution function of the negative binomial.
- nbdtrc : Survival function of the negative binomial.
- nbdtri : Inverse with respect to `p` of `nbdtr(k, n, p)`.
- nbdtrin : Inverse with respect to `n` of `nbdtr(k, n, p)`.
- scipy.stats.nbinom : Negative binomial distribution
- Notes
- -----
- Wrapper for the CDFLIB [1]_ Fortran routine `cdfnbn`.
- Formula 26.5.26 of [2]_ or [3]_,
- .. math::
- \sum_{j=k + 1}^\infty {{n + j - 1}
- \choose{j}} p^n (1 - p)^j = I_{1 - p}(k + 1, n),
- is used to reduce calculation of the cumulative distribution function to
- that of a regularized incomplete beta :math:`I`.
- Computation of `k` involves a search for a value that produces the desired
- value of `y`. The search relies on the monotonicity of `y` with `k`.
- References
- ----------
- .. [1] Barry Brown, James Lovato, and Kathy Russell,
- CDFLIB: Library of Fortran Routines for Cumulative Distribution
- Functions, Inverses, and Other Parameters.
- .. [2] Milton Abramowitz and Irene A. Stegun, eds.
- Handbook of Mathematical Functions with Formulas,
- Graphs, and Mathematical Tables. New York: Dover, 1972.
- .. [3] NIST Digital Library of Mathematical Functions
- https://dlmf.nist.gov/8.17.E24
- Examples
- --------
- Compute the negative binomial cumulative distribution function for an
- exemplary parameter set.
- >>> import numpy as np
- >>> from scipy.special import nbdtr, nbdtrik
- >>> k, n, p = 5, 2, 0.5
- >>> cdf_value = nbdtr(k, n, p)
- >>> cdf_value
- 0.9375
- Verify that `nbdtrik` recovers the original value for `k`.
- >>> nbdtrik(cdf_value, n, p)
- 5.0
- Plot the function for different parameter sets.
- >>> import matplotlib.pyplot as plt
- >>> p_parameters = [0.2, 0.5, 0.7, 0.5]
- >>> n_parameters = [30, 30, 30, 80]
- >>> linestyles = ['solid', 'dashed', 'dotted', 'dashdot']
- >>> parameters_list = list(zip(p_parameters, n_parameters, linestyles))
- >>> cdf_vals = np.linspace(0, 1, 1000)
- >>> fig, ax = plt.subplots(figsize=(8, 8))
- >>> for parameter_set in parameters_list:
- ... p, n, style = parameter_set
- ... nbdtrik_vals = nbdtrik(cdf_vals, n, p)
- ... ax.plot(cdf_vals, nbdtrik_vals, label=rf"$n={n},\ p={p}$",
- ... ls=style)
- >>> ax.legend()
- >>> ax.set_ylabel("$k$")
- >>> ax.set_xlabel("$CDF$")
- >>> ax.set_title("Negative binomial percentile function")
- >>> plt.show()
- The negative binomial distribution is also available as
- `scipy.stats.nbinom`. The percentile function method ``ppf``
- returns the result of `nbdtrik` rounded up to integers:
- >>> from scipy.stats import nbinom
- >>> q, n, p = 0.6, 5, 0.5
- >>> nbinom.ppf(q, n, p), nbdtrik(q, n, p)
- (5.0, 4.800428460273882)
- """)
- add_newdoc("nbdtrin",
- r"""
- nbdtrin(k, y, p, out=None)
- Inverse of `nbdtr` vs `n`.
- Returns the inverse with respect to the parameter `n` of
- ``y = nbdtr(k, n, p)``, the negative binomial cumulative distribution
- function.
- Parameters
- ----------
- k : array_like
- The maximum number of allowed failures (nonnegative int).
- y : array_like
- The probability of `k` or fewer failures before `n` successes (float).
- p : array_like
- Probability of success in a single event (float).
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- n : scalar or ndarray
- The number of successes `n` such that `nbdtr(k, n, p) = y`.
- See Also
- --------
- nbdtr : Cumulative distribution function of the negative binomial.
- nbdtri : Inverse with respect to `p` of `nbdtr(k, n, p)`.
- nbdtrik : Inverse with respect to `k` of `nbdtr(k, n, p)`.
- Notes
- -----
- Wrapper for the CDFLIB [1]_ Fortran routine `cdfnbn`.
- Formula 26.5.26 of [2]_ or [3]_,
- .. math::
- \sum_{j=k + 1}^\infty {{n + j - 1}
- \choose{j}} p^n (1 - p)^j = I_{1 - p}(k + 1, n),
- is used to reduce calculation of the cumulative distribution function to
- that of a regularized incomplete beta :math:`I`.
- Computation of `n` involves a search for a value that produces the desired
- value of `y`. The search relies on the monotonicity of `y` with `n`.
- References
- ----------
- .. [1] Barry Brown, James Lovato, and Kathy Russell,
- CDFLIB: Library of Fortran Routines for Cumulative Distribution
- Functions, Inverses, and Other Parameters.
- .. [2] Milton Abramowitz and Irene A. Stegun, eds.
- Handbook of Mathematical Functions with Formulas,
- Graphs, and Mathematical Tables. New York: Dover, 1972.
- .. [3] NIST Digital Library of Mathematical Functions
- https://dlmf.nist.gov/8.17.E24
- Examples
- --------
- Compute the negative binomial cumulative distribution function for an
- exemplary parameter set.
- >>> from scipy.special import nbdtr, nbdtrin
- >>> k, n, p = 5, 2, 0.5
- >>> cdf_value = nbdtr(k, n, p)
- >>> cdf_value
- 0.9375
- Verify that `nbdtrin` recovers the original value for `n` up to floating
- point accuracy.
- >>> nbdtrin(k, cdf_value, p)
- 1.999999999998137
- """)
- add_newdoc("ncfdtr",
- r"""
- ncfdtr(dfn, dfd, nc, f, out=None)
- Cumulative distribution function of the non-central F distribution.
- The non-central F describes the distribution of,
- .. math::
- Z = \frac{X/d_n}{Y/d_d}
- where :math:`X` and :math:`Y` are independently distributed, with
- :math:`X` distributed non-central :math:`\chi^2` with noncentrality
- parameter `nc` and :math:`d_n` degrees of freedom, and :math:`Y`
- distributed :math:`\chi^2` with :math:`d_d` degrees of freedom.
- Parameters
- ----------
- dfn : array_like
- Degrees of freedom of the numerator sum of squares. Range (0, inf).
- dfd : array_like
- Degrees of freedom of the denominator sum of squares. Range (0, inf).
- nc : array_like
- Noncentrality parameter. Range [0, inf).
- f : array_like
- Quantiles, i.e. the upper limit of integration.
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- cdf : scalar or ndarray
- The calculated CDF. If all inputs are scalar, the return will be a
- float. Otherwise it will be an array.
- See Also
- --------
- ncfdtri : Quantile function; inverse of `ncfdtr` with respect to `f`.
- ncfdtridfd : Inverse of `ncfdtr` with respect to `dfd`.
- ncfdtridfn : Inverse of `ncfdtr` with respect to `dfn`.
- ncfdtrinc : Inverse of `ncfdtr` with respect to `nc`.
- scipy.stats.ncf : Non-central F distribution.
- Notes
- -----
- This function calculates the CDF of the non-central f distribution using
- the Boost Math C++ library [1]_.
- The cumulative distribution function is computed using Formula 26.6.20 of
- [2]_:
- .. math::
- F(d_n, d_d, n_c, f) = \sum_{j=0}^\infty e^{-n_c/2}
- \frac{(n_c/2)^j}{j!} I_{x}(\frac{d_n}{2} + j, \frac{d_d}{2}),
- where :math:`I` is the regularized incomplete beta function, and
- :math:`x = f d_n/(f d_n + d_d)`.
- Note that argument order of `ncfdtr` is different from that of the
- similar ``cdf`` method of `scipy.stats.ncf`: `f` is the last
- parameter of `ncfdtr` but the first parameter of ``scipy.stats.ncf.cdf``.
- References
- ----------
- .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
- .. [2] Milton Abramowitz and Irene A. Stegun, eds.
- Handbook of Mathematical Functions with Formulas,
- Graphs, and Mathematical Tables. New York: Dover, 1972.
- Examples
- --------
- >>> import numpy as np
- >>> from scipy import special
- >>> from scipy import stats
- >>> import matplotlib.pyplot as plt
- Plot the CDF of the non-central F distribution, for nc=0. Compare with the
- F-distribution from scipy.stats:
- >>> x = np.linspace(-1, 8, num=500)
- >>> dfn = 3
- >>> dfd = 2
- >>> ncf_stats = stats.f.cdf(x, dfn, dfd)
- >>> ncf_special = special.ncfdtr(dfn, dfd, 0, x)
- >>> fig = plt.figure()
- >>> ax = fig.add_subplot(111)
- >>> ax.plot(x, ncf_stats, 'b-', lw=3)
- >>> ax.plot(x, ncf_special, 'r-')
- >>> plt.show()
- """)
- add_newdoc("ncfdtri",
- """
- ncfdtri(dfn, dfd, nc, p, out=None)
- Inverse with respect to `f` of the CDF of the non-central F distribution.
- See `ncfdtr` for more details.
- Parameters
- ----------
- dfn : array_like
- Degrees of freedom of the numerator sum of squares. Range (0, inf).
- dfd : array_like
- Degrees of freedom of the denominator sum of squares. Range (0, inf).
- nc : array_like
- Noncentrality parameter. Range [0, inf).
- p : array_like
- Value of the cumulative distribution function. Must be in the
- range [0, 1].
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- f : scalar or ndarray
- Quantiles, i.e., the upper limit of integration.
- See Also
- --------
- ncfdtr : CDF of the non-central F distribution.
- ncfdtridfd : Inverse of `ncfdtr` with respect to `dfd`.
- ncfdtridfn : Inverse of `ncfdtr` with respect to `dfn`.
- ncfdtrinc : Inverse of `ncfdtr` with respect to `nc`.
- scipy.stats.ncf : Non-central F distribution.
- Notes
- -----
- This function calculates the Quantile of the non-central f distribution
- using the Boost Math C++ library [1]_.
- Note that argument order of `ncfdtri` is different from that of the
- similar ``ppf`` method of `scipy.stats.ncf`. `p` is the last parameter
- of `ncfdtri` but the first parameter of ``scipy.stats.ncf.ppf``.
- References
- ----------
- .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
- Examples
- --------
- >>> from scipy.special import ncfdtr, ncfdtri
- Compute the CDF for several values of `f`:
- >>> f = [0.5, 1, 1.5]
- >>> p = ncfdtr(2, 3, 1.5, f)
- >>> p
- array([ 0.20782291, 0.36107392, 0.47345752])
- Compute the inverse. We recover the values of `f`, as expected:
- >>> ncfdtri(2, 3, 1.5, p)
- array([ 0.5, 1. , 1.5])
- """)
- add_newdoc("ncfdtridfd",
- """
- ncfdtridfd(dfn, p, nc, f, out=None)
- Calculate degrees of freedom (denominator) for the noncentral F-distribution.
- This is the inverse with respect to `dfd` of `ncfdtr`.
- See `ncfdtr` for more details.
- Parameters
- ----------
- dfn : array_like
- Degrees of freedom of the numerator sum of squares. Range (0, inf).
- p : array_like
- Value of the cumulative distribution function. Must be in the
- range [0, 1].
- nc : array_like
- Noncentrality parameter. Should be in range (0, 1e4).
- f : array_like
- Quantiles, i.e., the upper limit of integration.
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- dfd : scalar or ndarray
- Degrees of freedom of the denominator sum of squares.
- See Also
- --------
- ncfdtr : CDF of the non-central F distribution.
- ncfdtri : Quantile function; inverse of `ncfdtr` with respect to `f`.
- ncfdtridfn : Inverse of `ncfdtr` with respect to `dfn`.
- ncfdtrinc : Inverse of `ncfdtr` with respect to `nc`.
- Notes
- -----
- The value of the cumulative noncentral F distribution is not necessarily
- monotone in either degrees of freedom. There thus may be two values that
- provide a given CDF value. This routine assumes monotonicity and will
- find an arbitrary one of the two values.
- Examples
- --------
- >>> from scipy.special import ncfdtr, ncfdtridfd
- Compute the CDF for several values of `dfd`:
- >>> dfd = [1, 2, 3]
- >>> p = ncfdtr(2, dfd, 0.25, 15)
- >>> p
- array([ 0.8097138 , 0.93020416, 0.96787852])
- Compute the inverse. We recover the values of `dfd`, as expected:
- >>> ncfdtridfd(2, p, 0.25, 15)
- array([ 1., 2., 3.])
- """)
- add_newdoc("ncfdtridfn",
- """
- ncfdtridfn(p, dfd, nc, f, out=None)
- Calculate degrees of freedom (numerator) for the noncentral F-distribution.
- This is the inverse with respect to `dfn` of `ncfdtr`.
- See `ncfdtr` for more details.
- Parameters
- ----------
- p : array_like
- Value of the cumulative distribution function. Must be in the
- range [0, 1].
- dfd : array_like
- Degrees of freedom of the denominator sum of squares. Range (0, inf).
- nc : array_like
- Noncentrality parameter. Should be in range (0, 1e4).
- f : float
- Quantiles, i.e., the upper limit of integration.
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- dfn : scalar or ndarray
- Degrees of freedom of the numerator sum of squares.
- See Also
- --------
- ncfdtr : CDF of the non-central F distribution.
- ncfdtri : Quantile function; inverse of `ncfdtr` with respect to `f`.
- ncfdtridfd : Inverse of `ncfdtr` with respect to `dfd`.
- ncfdtrinc : Inverse of `ncfdtr` with respect to `nc`.
- Notes
- -----
- The value of the cumulative noncentral F distribution is not necessarily
- monotone in either degrees of freedom. There thus may be two values that
- provide a given CDF value. This routine assumes monotonicity and will
- find an arbitrary one of the two values.
- Examples
- --------
- >>> from scipy.special import ncfdtr, ncfdtridfn
- Compute the CDF for several values of `dfn`:
- >>> dfn = [1, 2, 3]
- >>> p = ncfdtr(dfn, 2, 0.25, 15)
- >>> p
- array([ 0.92562363, 0.93020416, 0.93188394])
- Compute the inverse. We recover the values of `dfn`, as expected:
- >>> ncfdtridfn(p, 2, 0.25, 15)
- array([ 1., 2., 3.])
- """)
- add_newdoc("ncfdtrinc",
- """
- ncfdtrinc(dfn, dfd, p, f, out=None)
- Calculate non-centrality parameter for non-central F distribution.
- This is the inverse with respect to `nc` of `ncfdtr`.
- See `ncfdtr` for more details.
- Parameters
- ----------
- dfn : array_like
- Degrees of freedom of the numerator sum of squares. Range (0, inf).
- dfd : array_like
- Degrees of freedom of the denominator sum of squares. Range (0, inf).
- p : array_like
- Value of the cumulative distribution function. Must be in the
- range [0, 1].
- f : array_like
- Quantiles, i.e., the upper limit of integration.
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- nc : scalar or ndarray
- Noncentrality parameter.
- See Also
- --------
- ncfdtr : CDF of the non-central F distribution.
- ncfdtri : Quantile function; inverse of `ncfdtr` with respect to `f`.
- ncfdtridfd : Inverse of `ncfdtr` with respect to `dfd`.
- ncfdtridfn : Inverse of `ncfdtr` with respect to `dfn`.
- Examples
- --------
- >>> from scipy.special import ncfdtr, ncfdtrinc
- Compute the CDF for several values of `nc`:
- >>> nc = [0.5, 1.5, 2.0]
- >>> p = ncfdtr(2, 3, nc, 15)
- >>> p
- array([ 0.96309246, 0.94327955, 0.93304098])
- Compute the inverse. We recover the values of `nc`, as expected:
- >>> ncfdtrinc(2, 3, p, 15)
- array([ 0.5, 1.5, 2. ])
- """)
- add_newdoc("nctdtr",
- """
- nctdtr(df, nc, t, out=None)
- Cumulative distribution function of the non-central `t` distribution.
- Parameters
- ----------
- df : array_like
- Degrees of freedom of the distribution. Should be in range (0, inf).
- nc : array_like
- Noncentrality parameter.
- t : array_like
- Quantiles, i.e., the upper limit of integration.
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- cdf : scalar or ndarray
- The calculated CDF. If all inputs are scalar, the return will be a
- float. Otherwise, it will be an array.
- See Also
- --------
- nctdtrit : Inverse CDF (iCDF) of the non-central t distribution.
- nctdtridf : Calculate degrees of freedom, given CDF and iCDF values.
- nctdtrinc : Calculate non-centrality parameter, given CDF iCDF values.
- Notes
- -----
- This function calculates the CDF of the non-central t distribution using
- the Boost Math C++ library [1]_.
- Note that the argument order of `nctdtr` is different from that of the
- similar ``cdf`` method of `scipy.stats.nct`: `t` is the last
- parameter of `nctdtr` but the first parameter of ``scipy.stats.nct.cdf``.
- References
- ----------
- .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
- Examples
- --------
- >>> import numpy as np
- >>> from scipy import special
- >>> from scipy import stats
- >>> import matplotlib.pyplot as plt
- Plot the CDF of the non-central t distribution, for nc=0. Compare with the
- t-distribution from scipy.stats:
- >>> x = np.linspace(-5, 5, num=500)
- >>> df = 3
- >>> nct_stats = stats.t.cdf(x, df)
- >>> nct_special = special.nctdtr(df, 0, x)
- >>> fig = plt.figure()
- >>> ax = fig.add_subplot(111)
- >>> ax.plot(x, nct_stats, 'b-', lw=3)
- >>> ax.plot(x, nct_special, 'r-')
- >>> plt.show()
- """)
- add_newdoc("nctdtridf",
- """
- nctdtridf(p, nc, t, out=None)
- Calculate degrees of freedom for non-central t distribution.
- See `nctdtr` for more details.
- Parameters
- ----------
- p : array_like
- CDF values, in range (0, 1].
- nc : array_like
- Noncentrality parameter. Should be in range (-1e6, 1e6).
- t : array_like
- Quantiles, i.e., the upper limit of integration.
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- df : scalar or ndarray
- The degrees of freedom. If all inputs are scalar, the return will be a
- float. Otherwise, it will be an array.
- See Also
- --------
- nctdtr : CDF of the non-central `t` distribution.
- nctdtrit : Inverse CDF (iCDF) of the non-central t distribution.
- nctdtrinc : Calculate non-centrality parameter, given CDF iCDF values.
- Examples
- --------
- >>> from scipy.special import nctdtr, nctdtridf
- Compute the CDF for several values of `df`:
- >>> df = [1, 2, 3]
- >>> p = nctdtr(df, 0.25, 1)
- >>> p
- array([0.67491974, 0.716464 , 0.73349456])
- Compute the inverse. We recover the values of `df`, as expected:
- >>> nctdtridf(p, 0.25, 1)
- array([1., 2., 3.])
- """)
- add_newdoc("nctdtrinc",
- """
- nctdtrinc(df, p, t, out=None)
- Calculate non-centrality parameter for non-central t distribution.
- See `nctdtr` for more details.
- Parameters
- ----------
- df : array_like
- Degrees of freedom of the distribution. Should be in range (0, inf).
- p : array_like
- CDF values, in range (0, 1].
- t : array_like
- Quantiles, i.e., the upper limit of integration.
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- nc : scalar or ndarray
- Noncentrality parameter
- See Also
- --------
- nctdtr : CDF of the non-central `t` distribution.
- nctdtrit : Inverse CDF (iCDF) of the non-central t distribution.
- nctdtridf : Calculate degrees of freedom, given CDF and iCDF values.
- Examples
- --------
- >>> from scipy.special import nctdtr, nctdtrinc
- Compute the CDF for several values of `nc`:
- >>> nc = [0.5, 1.5, 2.5]
- >>> p = nctdtr(3, nc, 1.5)
- >>> p
- array([0.77569497, 0.45524533, 0.1668691 ])
- Compute the inverse. We recover the values of `nc`, as expected:
- >>> nctdtrinc(3, p, 1.5)
- array([0.5, 1.5, 2.5])
- """)
- add_newdoc("nctdtrit",
- """
- nctdtrit(df, nc, p, out=None)
- Inverse cumulative distribution function of the non-central t distribution.
- See `nctdtr` for more details.
- Parameters
- ----------
- df : array_like
- Degrees of freedom of the distribution. Should be in range (0, inf).
- nc : array_like
- Noncentrality parameter.
- p : array_like
- CDF values, in range (0, 1].
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- t : scalar or ndarray
- Quantiles
- See Also
- --------
- nctdtr : CDF of the non-central `t` distribution.
- nctdtridf : Calculate degrees of freedom, given CDF and iCDF values.
- nctdtrinc : Calculate non-centrality parameter, given CDF iCDF values.
- Notes
- -----
- This function calculates the quantile of the non-central t distribution using
- the Boost Math C++ library [1]_.
- Note that the argument order of `nctdtrit` is different from that of the
- similar ``ppf`` method of `scipy.stats.nct`: `t` is the last
- parameter of `nctdtrit` but the first parameter of ``scipy.stats.nct.ppf``.
- References
- ----------
- .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
- Examples
- --------
- >>> from scipy.special import nctdtr, nctdtrit
- Compute the CDF for several values of `t`:
- >>> t = [0.5, 1, 1.5]
- >>> p = nctdtr(3, 1, t)
- >>> p
- array([0.29811049, 0.46922687, 0.6257559 ])
- Compute the inverse. We recover the values of `t`, as expected:
- >>> nctdtrit(3, 1, p)
- array([0.5, 1. , 1.5])
- """)
- add_newdoc("nrdtrimn",
- """
- nrdtrimn(p, std, x, out=None)
- Calculate mean of normal distribution given other params.
- Parameters
- ----------
- p : array_like
- CDF values, in range (0, 1].
- std : array_like
- Standard deviation.
- x : array_like
- Quantiles, i.e. the upper limit of integration.
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- mn : scalar or ndarray
- The mean of the normal distribution.
- See Also
- --------
- scipy.stats.norm : Normal distribution
- ndtr : Standard normal cumulative probability distribution
- ndtri : Inverse of standard normal CDF with respect to quantile
- nrdtrisd : Inverse of normal distribution CDF with respect to
- standard deviation
- Examples
- --------
- `nrdtrimn` can be used to recover the mean of a normal distribution
- if we know the CDF value `p` for a given quantile `x` and the
- standard deviation `std`. First, we calculate
- the normal distribution CDF for an exemplary parameter set.
- >>> from scipy.stats import norm
- >>> mean = 3.
- >>> std = 2.
- >>> x = 6.
- >>> p = norm.cdf(x, loc=mean, scale=std)
- >>> p
- 0.9331927987311419
- Verify that `nrdtrimn` returns the original value for `mean`.
- >>> from scipy.special import nrdtrimn
- >>> nrdtrimn(p, std, x)
- 3.0000000000000004
- """)
- add_newdoc("nrdtrisd",
- """
- nrdtrisd(mn, p, x, out=None)
- Calculate standard deviation of normal distribution given other params.
- Parameters
- ----------
- mn : scalar or ndarray
- The mean of the normal distribution.
- p : array_like
- CDF values, in range (0, 1].
- x : array_like
- Quantiles, i.e. the upper limit of integration.
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- std : scalar or ndarray
- Standard deviation.
- See Also
- --------
- scipy.stats.norm : Normal distribution
- ndtr : Standard normal cumulative probability distribution
- ndtri : Inverse of standard normal CDF with respect to quantile
- nrdtrimn : Inverse of normal distribution CDF with respect to
- mean
- Examples
- --------
- `nrdtrisd` can be used to recover the standard deviation of a normal
- distribution if we know the CDF value `p` for a given quantile `x` and
- the mean `mn`. First, we calculate the normal distribution CDF for an
- exemplary parameter set.
- >>> from scipy.stats import norm
- >>> mean = 3.
- >>> std = 2.
- >>> x = 6.
- >>> p = norm.cdf(x, loc=mean, scale=std)
- >>> p
- 0.9331927987311419
- Verify that `nrdtrisd` returns the original value for `std`.
- >>> from scipy.special import nrdtrisd
- >>> nrdtrisd(mean, p, x)
- 2.0000000000000004
- """)
- add_newdoc("ndtri",
- """
- ndtri(y, out=None)
- Inverse of `ndtr` vs x
- Returns the argument x for which the area under the standard normal
- probability density function (integrated from minus infinity to `x`)
- is equal to y.
- Parameters
- ----------
- p : array_like
- Probability
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- x : scalar or ndarray
- Value of x such that ``ndtr(x) == p``.
- See Also
- --------
- ndtr : Standard normal cumulative probability distribution
- ndtri_exp : Inverse of log_ndtr
- Examples
- --------
- `ndtri` is the percentile function of the standard normal distribution.
- This means it returns the inverse of the cumulative density `ndtr`. First,
- let us compute a cumulative density value.
- >>> import numpy as np
- >>> from scipy.special import ndtri, ndtr
- >>> cdf_val = ndtr(2)
- >>> cdf_val
- 0.9772498680518208
- Verify that `ndtri` yields the original value for `x` up to floating point
- errors.
- >>> ndtri(cdf_val)
- 2.0000000000000004
- Plot the function. For that purpose, we provide a NumPy array as argument.
- >>> import matplotlib.pyplot as plt
- >>> x = np.linspace(0.01, 1, 200)
- >>> fig, ax = plt.subplots()
- >>> ax.plot(x, ndtri(x))
- >>> ax.set_title("Standard normal percentile function")
- >>> plt.show()
- """)
- add_newdoc("pdtr",
- r"""
- pdtr(k, m, out=None)
- Poisson cumulative distribution function.
- Defined as the probability that a Poisson-distributed random
- variable with event rate :math:`m` is less than or equal to
- :math:`k`. More concretely, this works out to be [1]_
- .. math::
- \exp(-m) \sum_{j = 0}^{\lfloor{k}\rfloor} \frac{m^j}{j!}.
- Parameters
- ----------
- k : array_like
- Number of occurrences (nonnegative, real)
- m : array_like
- Shape parameter (nonnegative, real)
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- scalar or ndarray
- Values of the Poisson cumulative distribution function
- See Also
- --------
- pdtrc : Poisson survival function
- pdtrik : inverse of `pdtr` with respect to `k`
- pdtri : inverse of `pdtr` with respect to `m`
- References
- ----------
- .. [1] https://en.wikipedia.org/wiki/Poisson_distribution
- Examples
- --------
- >>> import numpy as np
- >>> import scipy.special as sc
- It is a cumulative distribution function, so it converges to 1
- monotonically as `k` goes to infinity.
- >>> sc.pdtr([1, 10, 100, np.inf], 1)
- array([0.73575888, 0.99999999, 1. , 1. ])
- It is discontinuous at integers and constant between integers.
- >>> sc.pdtr([1, 1.5, 1.9, 2], 1)
- array([0.73575888, 0.73575888, 0.73575888, 0.9196986 ])
- """)
- add_newdoc("pdtrc",
- """
- pdtrc(k, m, out=None)
- Poisson survival function
- Returns the sum of the terms from k+1 to infinity of the Poisson
- distribution: sum(exp(-m) * m**j / j!, j=k+1..inf) = gammainc(
- k+1, m). Arguments must both be non-negative doubles.
- Parameters
- ----------
- k : array_like
- Number of occurrences (nonnegative, real)
- m : array_like
- Shape parameter (nonnegative, real)
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- scalar or ndarray
- Values of the Poisson survival function
- See Also
- --------
- pdtr : Poisson cumulative distribution function
- pdtrik : inverse of `pdtr` with respect to `k`
- pdtri : inverse of `pdtr` with respect to `m`
- Examples
- --------
- >>> import numpy as np
- >>> import scipy.special as sc
- It is a survival function, so it decreases to 0
- monotonically as `k` goes to infinity.
- >>> k = np.array([1, 10, 100, np.inf])
- >>> sc.pdtrc(k, 1)
- array([2.64241118e-001, 1.00477664e-008, 3.94147589e-161, 0.00000000e+000])
- It can be expressed in terms of the lower incomplete gamma
- function `gammainc`.
- >>> sc.gammainc(k + 1, 1)
- array([2.64241118e-001, 1.00477664e-008, 3.94147589e-161, 0.00000000e+000])
- """)
- add_newdoc("pdtri",
- """
- pdtri(k, y, out=None)
- Inverse to `pdtr` vs m
- Returns the Poisson variable `m` such that the sum from 0 to `k` of
- the Poisson density is equal to the given probability `y`:
- calculated by ``gammaincinv(k + 1, y)``. `k` must be a nonnegative
- integer and `y` between 0 and 1.
- Parameters
- ----------
- k : array_like
- Number of occurrences (nonnegative, real)
- y : array_like
- Probability
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- scalar or ndarray
- Values of the shape parameter `m` such that ``pdtr(k, m) = p``
- See Also
- --------
- pdtr : Poisson cumulative distribution function
- pdtrc : Poisson survival function
- pdtrik : inverse of `pdtr` with respect to `k`
- Examples
- --------
- >>> import scipy.special as sc
- Compute the CDF for several values of `m`:
- >>> m = [0.5, 1, 1.5]
- >>> p = sc.pdtr(1, m)
- >>> p
- array([0.90979599, 0.73575888, 0.5578254 ])
- Compute the inverse. We recover the values of `m`, as expected:
- >>> sc.pdtri(1, p)
- array([0.5, 1. , 1.5])
- """)
- add_newdoc("pdtrik",
- """
- pdtrik(p, m, out=None)
- Inverse to `pdtr` vs `k`.
- Parameters
- ----------
- p : array_like
- Probability
- m : array_like
- Shape parameter (nonnegative, real)
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- scalar or ndarray
- The number of occurrences `k` such that ``pdtr(k, m) = p``
- Notes
- -----
- This function relies on the ``gamma_q_inva`` function from the Boost
- Math C++ library [1]_.
- References
- ----------
- .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
- See Also
- --------
- pdtr : Poisson cumulative distribution function
- pdtrc : Poisson survival function
- pdtri : inverse of `pdtr` with respect to `m`
- Examples
- --------
- >>> import scipy.special as sc
- Compute the CDF for several values of `k`:
- >>> k = [1, 2, 3]
- >>> p = sc.pdtr(k, 2)
- >>> p
- array([0.40600585, 0.67667642, 0.85712346])
- Compute the inverse. We recover the values of `k`, as expected:
- >>> sc.pdtrik(p, 2)
- array([1., 2., 3.])
- """)
- add_newdoc("poch",
- r"""
- poch(z, m, out=None)
- Pochhammer symbol.
- The Pochhammer symbol (rising factorial) is defined as
- .. math::
- (z)_m = \frac{\Gamma(z + m)}{\Gamma(z)}
- For positive integer `m` it reads
- .. math::
- (z)_m = z (z + 1) ... (z + m - 1)
- See [DLMF]_ for more details.
- Parameters
- ----------
- z, m : array_like
- Real-valued arguments.
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- scalar or ndarray
- The value of the function.
- References
- ----------
- .. [DLMF] Nist, Digital Library of Mathematical Functions
- https://dlmf.nist.gov/5.2#iii
- Examples
- --------
- >>> import scipy.special as sc
- It is 1 when m is 0.
- >>> sc.poch([1, 2, 3, 4], 0)
- array([1., 1., 1., 1.])
- For z equal to 1 it reduces to the factorial function.
- >>> sc.poch(1, 5)
- 120.0
- >>> 1 * 2 * 3 * 4 * 5
- 120
- It can be expressed in terms of the gamma function.
- >>> z, m = 3.7, 2.1
- >>> sc.poch(z, m)
- 20.529581933776953
- >>> sc.gamma(z + m) / sc.gamma(z)
- 20.52958193377696
- """)
- add_newdoc("powm1", """
- powm1(x, y, out=None)
- Computes ``x**y - 1``.
- This function is useful when `y` is near 0, or when `x` is near 1.
- The function is implemented for real types only (unlike ``numpy.power``,
- which accepts complex inputs).
- Parameters
- ----------
- x : array_like
- The base. Must be a real type (i.e. integer or float, not complex).
- y : array_like
- The exponent. Must be a real type (i.e. integer or float, not complex).
- Returns
- -------
- array_like
- Result of the calculation
- Notes
- -----
- .. versionadded:: 1.10.0
- The underlying code is implemented for single precision and double
- precision floats only. Unlike `numpy.power`, integer inputs to
- `powm1` are converted to floating point, and complex inputs are
- not accepted.
- Note the following edge cases:
- * ``powm1(x, 0)`` returns 0 for any ``x``, including 0, ``inf``
- and ``nan``.
- * ``powm1(1, y)`` returns 0 for any ``y``, including ``nan``
- and ``inf``.
- This function wraps the ``powm1`` routine from the
- Boost Math C++ library [1]_.
- References
- ----------
- .. [1] The Boost Developers. "Boost C++ Libraries". https://www.boost.org/.
- Examples
- --------
- >>> import numpy as np
- >>> from scipy.special import powm1
- >>> x = np.array([1.2, 10.0, 0.9999999975])
- >>> y = np.array([1e-9, 1e-11, 0.1875])
- >>> powm1(x, y)
- array([ 1.82321557e-10, 2.30258509e-11, -4.68749998e-10])
- It can be verified that the relative errors in those results
- are less than 2.5e-16.
- Compare that to the result of ``x**y - 1``, where the
- relative errors are all larger than 8e-8:
- >>> x**y - 1
- array([ 1.82321491e-10, 2.30258035e-11, -4.68750039e-10])
- """)
- add_newdoc("pseudo_huber",
- r"""
- pseudo_huber(delta, r, out=None)
- Pseudo-Huber loss function.
- .. math:: \mathrm{pseudo\_huber}(\delta, r) =
- \delta^2 \left( \sqrt{ 1 + \left( \frac{r}{\delta} \right)^2 } - 1 \right)
- Parameters
- ----------
- delta : array_like
- Input array, indicating the soft quadratic vs. linear loss changepoint.
- r : array_like
- Input array, possibly representing residuals.
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- res : scalar or ndarray
- The computed Pseudo-Huber loss function values.
- See Also
- --------
- huber: Similar function which this function approximates
- Notes
- -----
- Like `huber`, `pseudo_huber` often serves as a robust loss function
- in statistics or machine learning to reduce the influence of outliers.
- Unlike `huber`, `pseudo_huber` is smooth.
- Typically, `r` represents residuals, the difference
- between a model prediction and data. Then, for :math:`|r|\leq\delta`,
- `pseudo_huber` resembles the squared error and for :math:`|r|>\delta` the
- absolute error. This way, the Pseudo-Huber loss often achieves
- a fast convergence in model fitting for small residuals like the squared
- error loss function and still reduces the influence of outliers
- (:math:`|r|>\delta`) like the absolute error loss. As :math:`\delta` is
- the cutoff between squared and absolute error regimes, it has
- to be tuned carefully for each problem. `pseudo_huber` is also
- convex, making it suitable for gradient based optimization. [1]_ [2]_
- .. versionadded:: 0.15.0
- References
- ----------
- .. [1] Hartley, Zisserman, "Multiple View Geometry in Computer Vision".
- 2003. Cambridge University Press. p. 619
- .. [2] Charbonnier et al. "Deterministic edge-preserving regularization
- in computed imaging". 1997. IEEE Trans. Image Processing.
- 6 (2): 298 - 311.
- Examples
- --------
- Import all necessary modules.
- >>> import numpy as np
- >>> from scipy.special import pseudo_huber, huber
- >>> import matplotlib.pyplot as plt
- Calculate the function for ``delta=1`` at ``r=2``.
- >>> pseudo_huber(1., 2.)
- 1.2360679774997898
- Calculate the function at ``r=2`` for different `delta` by providing
- a list or NumPy array for `delta`.
- >>> pseudo_huber([1., 2., 4.], 3.)
- array([2.16227766, 3.21110255, 4. ])
- Calculate the function for ``delta=1`` at several points by providing
- a list or NumPy array for `r`.
- >>> pseudo_huber(2., np.array([1., 1.5, 3., 4.]))
- array([0.47213595, 1. , 3.21110255, 4.94427191])
- The function can be calculated for different `delta` and `r` by
- providing arrays for both with compatible shapes for broadcasting.
- >>> r = np.array([1., 2.5, 8., 10.])
- >>> deltas = np.array([[1.], [5.], [9.]])
- >>> print(r.shape, deltas.shape)
- (4,) (3, 1)
- >>> pseudo_huber(deltas, r)
- array([[ 0.41421356, 1.6925824 , 7.06225775, 9.04987562],
- [ 0.49509757, 2.95084972, 22.16990566, 30.90169944],
- [ 0.49846624, 3.06693762, 27.37435121, 40.08261642]])
- Plot the function for different `delta`.
- >>> x = np.linspace(-4, 4, 500)
- >>> deltas = [1, 2, 3]
- >>> linestyles = ["dashed", "dotted", "dashdot"]
- >>> fig, ax = plt.subplots()
- >>> combined_plot_parameters = list(zip(deltas, linestyles))
- >>> for delta, style in combined_plot_parameters:
- ... ax.plot(x, pseudo_huber(delta, x), label=rf"$\delta={delta}$",
- ... ls=style)
- >>> ax.legend(loc="upper center")
- >>> ax.set_xlabel("$x$")
- >>> ax.set_title(r"Pseudo-Huber loss function $h_{\delta}(x)$")
- >>> ax.set_xlim(-4, 4)
- >>> ax.set_ylim(0, 8)
- >>> plt.show()
- Finally, illustrate the difference between `huber` and `pseudo_huber` by
- plotting them and their gradients with respect to `r`. The plot shows
- that `pseudo_huber` is continuously differentiable while `huber` is not
- at the points :math:`\pm\delta`.
- >>> def huber_grad(delta, x):
- ... grad = np.copy(x)
- ... linear_area = np.argwhere(np.abs(x) > delta)
- ... grad[linear_area]=delta*np.sign(x[linear_area])
- ... return grad
- >>> def pseudo_huber_grad(delta, x):
- ... return x* (1+(x/delta)**2)**(-0.5)
- >>> x=np.linspace(-3, 3, 500)
- >>> delta = 1.
- >>> fig, ax = plt.subplots(figsize=(7, 7))
- >>> ax.plot(x, huber(delta, x), label="Huber", ls="dashed")
- >>> ax.plot(x, huber_grad(delta, x), label="Huber Gradient", ls="dashdot")
- >>> ax.plot(x, pseudo_huber(delta, x), label="Pseudo-Huber", ls="dotted")
- >>> ax.plot(x, pseudo_huber_grad(delta, x), label="Pseudo-Huber Gradient",
- ... ls="solid")
- >>> ax.legend(loc="upper center")
- >>> plt.show()
- """)
- add_newdoc("rel_entr",
- r"""
- rel_entr(x, y, out=None)
- Elementwise function for computing relative entropy.
- .. math::
- \mathrm{rel\_entr}(x, y) =
- \begin{cases}
- x \log(x / y) & x > 0, y > 0 \\
- 0 & x = 0, y \ge 0 \\
- \infty & \text{otherwise}
- \end{cases}
- Parameters
- ----------
- x, y : array_like
- Input arrays
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- scalar or ndarray
- Relative entropy of the inputs
- See Also
- --------
- entr, kl_div, scipy.stats.entropy
- Notes
- -----
- .. versionadded:: 0.15.0
- This function is jointly convex in x and y.
- The origin of this function is in convex programming; see
- [1]_. Given two discrete probability distributions :math:`p_1,
- \ldots, p_n` and :math:`q_1, \ldots, q_n`, the definition of relative
- entropy in the context of *information theory* is
- .. math::
- \sum_{i = 1}^n \mathrm{rel\_entr}(p_i, q_i).
- To compute the latter quantity, use `scipy.stats.entropy`.
- See [2]_ for details.
- References
- ----------
- .. [1] Boyd, Stephen and Lieven Vandenberghe. *Convex optimization*.
- Cambridge University Press, 2004.
- :doi:`https://doi.org/10.1017/CBO9780511804441`
- .. [2] Kullback-Leibler divergence,
- https://en.wikipedia.org/wiki/Kullback%E2%80%93Leibler_divergence
- """)
- add_newdoc("round",
- """
- round(x, out=None)
- Round to the nearest integer.
- Returns the nearest integer to `x`. If `x` ends in 0.5 exactly,
- the nearest even integer is chosen.
- Parameters
- ----------
- x : array_like
- Real valued input.
- out : ndarray, optional
- Optional output array for the function results.
- Returns
- -------
- scalar or ndarray
- The nearest integers to the elements of `x`. The result is of
- floating type, not integer type.
- Examples
- --------
- >>> import scipy.special as sc
- It rounds to even.
- >>> sc.round([0.5, 1.5])
- array([0., 2.])
- """)
- add_newdoc("shichi",
- r"""
- shichi(x, out=None)
- Hyperbolic sine and cosine integrals.
- The hyperbolic sine integral is
- .. math::
- \int_0^x \frac{\sinh{t}}{t}dt
- and the hyperbolic cosine integral is
- .. math::
- \gamma + \log(x) + \int_0^x \frac{\cosh{t} - 1}{t} dt
- where :math:`\gamma` is Euler's constant and :math:`\log` is the
- principal branch of the logarithm [1]_ (see also [2]_).
- Parameters
- ----------
- x : array_like
- Real or complex points at which to compute the hyperbolic sine
- and cosine integrals.
- out : tuple of ndarray, optional
- Optional output arrays for the function results
- Returns
- -------
- si : scalar or ndarray
- Hyperbolic sine integral at ``x``
- ci : scalar or ndarray
- Hyperbolic cosine integral at ``x``
- See Also
- --------
- sici : Sine and cosine integrals.
- exp1 : Exponential integral E1.
- expi : Exponential integral Ei.
- Notes
- -----
- For real arguments with ``x < 0``, ``chi`` is the real part of the
- hyperbolic cosine integral. For such points ``chi(x)`` and ``chi(x
- + 0j)`` differ by a factor of ``1j*pi``.
- For real arguments the function is computed by calling Cephes'
- [3]_ *shichi* routine. For complex arguments the algorithm is based
- on Mpmath's [4]_ *shi* and *chi* routines.
- References
- ----------
- .. [1] Milton Abramowitz and Irene A. Stegun, eds.
- Handbook of Mathematical Functions with Formulas,
- Graphs, and Mathematical Tables. New York: Dover, 1972.
- (See Section 5.2.)
- .. [2] NIST Digital Library of Mathematical Functions
- https://dlmf.nist.gov/6.2.E15 and https://dlmf.nist.gov/6.2.E16
- .. [3] Cephes Mathematical Functions Library,
- http://www.netlib.org/cephes/
- .. [4] Fredrik Johansson and others.
- "mpmath: a Python library for arbitrary-precision floating-point
- arithmetic" (Version 0.19) http://mpmath.org/
- Examples
- --------
- >>> import numpy as np
- >>> import matplotlib.pyplot as plt
- >>> from scipy.special import shichi, sici
- `shichi` accepts real or complex input:
- >>> shichi(0.5)
- (0.5069967498196671, -0.05277684495649357)
- >>> shichi(0.5 + 2.5j)
- ((0.11772029666668238+1.831091777729851j),
- (0.29912435887648825+1.7395351121166562j))
- The hyperbolic sine and cosine integrals Shi(z) and Chi(z) are
- related to the sine and cosine integrals Si(z) and Ci(z) by
- * Shi(z) = -i*Si(i*z)
- * Chi(z) = Ci(-i*z) + i*pi/2
- >>> z = 0.25 + 5j
- >>> shi, chi = shichi(z)
- >>> shi, -1j*sici(1j*z)[0] # Should be the same.
- ((-0.04834719325101729+1.5469354086921228j),
- (-0.04834719325101729+1.5469354086921228j))
- >>> chi, sici(-1j*z)[1] + 1j*np.pi/2 # Should be the same.
- ((-0.19568708973868087+1.556276312103824j),
- (-0.19568708973868087+1.556276312103824j))
- Plot the functions evaluated on the real axis:
- >>> xp = np.geomspace(1e-8, 4.0, 250)
- >>> x = np.concatenate((-xp[::-1], xp))
- >>> shi, chi = shichi(x)
- >>> fig, ax = plt.subplots()
- >>> ax.plot(x, shi, label='Shi(x)')
- >>> ax.plot(x, chi, '--', label='Chi(x)')
- >>> ax.set_xlabel('x')
- >>> ax.set_title('Hyperbolic Sine and Cosine Integrals')
- >>> ax.legend(shadow=True, framealpha=1, loc='lower right')
- >>> ax.grid(True)
- >>> plt.show()
- """)
- add_newdoc("sici",
- r"""
- sici(x, out=None)
- Sine and cosine integrals.
- The sine integral is
- .. math::
- \int_0^x \frac{\sin{t}}{t}dt
- and the cosine integral is
- .. math::
- \gamma + \log(x) + \int_0^x \frac{\cos{t} - 1}{t}dt
- where :math:`\gamma` is Euler's constant and :math:`\log` is the
- principal branch of the logarithm [1]_ (see also [2]_).
- Parameters
- ----------
- x : array_like
- Real or complex points at which to compute the sine and cosine
- integrals.
- out : tuple of ndarray, optional
- Optional output arrays for the function results
- Returns
- -------
- si : scalar or ndarray
- Sine integral at ``x``
- ci : scalar or ndarray
- Cosine integral at ``x``
- See Also
- --------
- shichi : Hyperbolic sine and cosine integrals.
- exp1 : Exponential integral E1.
- expi : Exponential integral Ei.
- Notes
- -----
- For real arguments with ``x < 0``, ``ci`` is the real part of the
- cosine integral. For such points ``ci(x)`` and ``ci(x + 0j)``
- differ by a factor of ``1j*pi``.
- For real arguments the function is computed by calling Cephes'
- [3]_ *sici* routine. For complex arguments the algorithm is based
- on Mpmath's [4]_ *si* and *ci* routines.
- References
- ----------
- .. [1] Milton Abramowitz and Irene A. Stegun, eds.
- Handbook of Mathematical Functions with Formulas,
- Graphs, and Mathematical Tables. New York: Dover, 1972.
- (See Section 5.2.)
- .. [2] NIST Digital Library of Mathematical Functions
- https://dlmf.nist.gov/6.2.E9, https://dlmf.nist.gov/6.2.E12,
- and https://dlmf.nist.gov/6.2.E13
- .. [3] Cephes Mathematical Functions Library,
- http://www.netlib.org/cephes/
- .. [4] Fredrik Johansson and others.
- "mpmath: a Python library for arbitrary-precision floating-point
- arithmetic" (Version 0.19) http://mpmath.org/
- Examples
- --------
- >>> import numpy as np
- >>> import matplotlib.pyplot as plt
- >>> from scipy.special import sici, exp1
- `sici` accepts real or complex input:
- >>> sici(2.5)
- (1.7785201734438267, 0.2858711963653835)
- >>> sici(2.5 + 3j)
- ((4.505735874563953+0.06863305018999577j),
- (0.0793644206906966-2.935510262937543j))
- For z in the right half plane, the sine and cosine integrals are
- related to the exponential integral E1 (implemented in SciPy as
- `scipy.special.exp1`) by
- * Si(z) = (E1(i*z) - E1(-i*z))/2i + pi/2
- * Ci(z) = -(E1(i*z) + E1(-i*z))/2
- See [1]_ (equations 5.2.21 and 5.2.23).
- We can verify these relations:
- >>> z = 2 - 3j
- >>> sici(z)
- ((4.54751388956229-1.3991965806460565j),
- (1.408292501520851+2.9836177420296055j))
- >>> (exp1(1j*z) - exp1(-1j*z))/2j + np.pi/2 # Same as sine integral
- (4.54751388956229-1.3991965806460565j)
- >>> -(exp1(1j*z) + exp1(-1j*z))/2 # Same as cosine integral
- (1.408292501520851+2.9836177420296055j)
- Plot the functions evaluated on the real axis; the dotted horizontal
- lines are at pi/2 and -pi/2:
- >>> x = np.linspace(-16, 16, 150)
- >>> si, ci = sici(x)
- >>> fig, ax = plt.subplots()
- >>> ax.plot(x, si, label='Si(x)')
- >>> ax.plot(x, ci, '--', label='Ci(x)')
- >>> ax.legend(shadow=True, framealpha=1, loc='upper left')
- >>> ax.set_xlabel('x')
- >>> ax.set_title('Sine and Cosine Integrals')
- >>> ax.axhline(np.pi/2, linestyle=':', alpha=0.5, color='k')
- >>> ax.axhline(-np.pi/2, linestyle=':', alpha=0.5, color='k')
- >>> ax.grid(True)
- >>> plt.show()
- """)
- add_newdoc("smirnov",
- r"""
- smirnov(n, d, out=None)
- Kolmogorov-Smirnov complementary cumulative distribution function
- Returns the exact Kolmogorov-Smirnov complementary cumulative
- distribution function,(aka the Survival Function) of Dn+ (or Dn-)
- for a one-sided test of equality between an empirical and a
- theoretical distribution. It is equal to the probability that the
- maximum difference between a theoretical distribution and an empirical
- one based on `n` samples is greater than d.
- Parameters
- ----------
- n : int
- Number of samples
- d : float array_like
- Deviation between the Empirical CDF (ECDF) and the target CDF.
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- scalar or ndarray
- The value(s) of smirnov(n, d), Prob(Dn+ >= d) (Also Prob(Dn- >= d))
- See Also
- --------
- smirnovi : The Inverse Survival Function for the distribution
- scipy.stats.ksone : Provides the functionality as a continuous distribution
- kolmogorov, kolmogi : Functions for the two-sided distribution
- Notes
- -----
- `smirnov` is used by `stats.kstest` in the application of the
- Kolmogorov-Smirnov Goodness of Fit test. For historical reasons this
- function is exposed in `scpy.special`, but the recommended way to achieve
- the most accurate CDF/SF/PDF/PPF/ISF computations is to use the
- `stats.ksone` distribution.
- Examples
- --------
- >>> import numpy as np
- >>> from scipy.special import smirnov
- >>> from scipy.stats import norm
- Show the probability of a gap at least as big as 0, 0.5 and 1.0 for a
- sample of size 5.
- >>> smirnov(5, [0, 0.5, 1.0])
- array([ 1. , 0.056, 0. ])
- Compare a sample of size 5 against N(0, 1), the standard normal
- distribution with mean 0 and standard deviation 1.
- `x` is the sample.
- >>> x = np.array([-1.392, -0.135, 0.114, 0.190, 1.82])
- >>> target = norm(0, 1)
- >>> cdfs = target.cdf(x)
- >>> cdfs
- array([0.0819612 , 0.44630594, 0.5453811 , 0.57534543, 0.9656205 ])
- Construct the empirical CDF and the K-S statistics (Dn+, Dn-, Dn).
- >>> n = len(x)
- >>> ecdfs = np.arange(n+1, dtype=float)/n
- >>> cols = np.column_stack([x, ecdfs[1:], cdfs, cdfs - ecdfs[:n],
- ... ecdfs[1:] - cdfs])
- >>> with np.printoptions(precision=3):
- ... print(cols)
- [[-1.392 0.2 0.082 0.082 0.118]
- [-0.135 0.4 0.446 0.246 -0.046]
- [ 0.114 0.6 0.545 0.145 0.055]
- [ 0.19 0.8 0.575 -0.025 0.225]
- [ 1.82 1. 0.966 0.166 0.034]]
- >>> gaps = cols[:, -2:]
- >>> Dnpm = np.max(gaps, axis=0)
- >>> print(f'Dn-={Dnpm[0]:f}, Dn+={Dnpm[1]:f}')
- Dn-=0.246306, Dn+=0.224655
- >>> probs = smirnov(n, Dnpm)
- >>> print(f'For a sample of size {n} drawn from N(0, 1):',
- ... f' Smirnov n={n}: Prob(Dn- >= {Dnpm[0]:f}) = {probs[0]:.4f}',
- ... f' Smirnov n={n}: Prob(Dn+ >= {Dnpm[1]:f}) = {probs[1]:.4f}',
- ... sep='\n')
- For a sample of size 5 drawn from N(0, 1):
- Smirnov n=5: Prob(Dn- >= 0.246306) = 0.4711
- Smirnov n=5: Prob(Dn+ >= 0.224655) = 0.5245
- Plot the empirical CDF and the standard normal CDF.
- >>> import matplotlib.pyplot as plt
- >>> plt.step(np.concatenate(([-2.5], x, [2.5])),
- ... np.concatenate((ecdfs, [1])),
- ... where='post', label='Empirical CDF')
- >>> xx = np.linspace(-2.5, 2.5, 100)
- >>> plt.plot(xx, target.cdf(xx), '--', label='CDF for N(0, 1)')
- Add vertical lines marking Dn+ and Dn-.
- >>> iminus, iplus = np.argmax(gaps, axis=0)
- >>> plt.vlines([x[iminus]], ecdfs[iminus], cdfs[iminus], color='r',
- ... alpha=0.5, lw=4)
- >>> plt.vlines([x[iplus]], cdfs[iplus], ecdfs[iplus+1], color='m',
- ... alpha=0.5, lw=4)
- >>> plt.grid(True)
- >>> plt.legend(framealpha=1, shadow=True)
- >>> plt.show()
- """)
- add_newdoc("smirnovi",
- """
- smirnovi(n, p, out=None)
- Inverse to `smirnov`
- Returns `d` such that ``smirnov(n, d) == p``, the critical value
- corresponding to `p`.
- Parameters
- ----------
- n : int
- Number of samples
- p : float array_like
- Probability
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- scalar or ndarray
- The value(s) of smirnovi(n, p), the critical values.
- See Also
- --------
- smirnov : The Survival Function (SF) for the distribution
- scipy.stats.ksone : Provides the functionality as a continuous distribution
- kolmogorov, kolmogi : Functions for the two-sided distribution
- scipy.stats.kstwobign : Two-sided Kolmogorov-Smirnov distribution, large n
- Notes
- -----
- `smirnov` is used by `stats.kstest` in the application of the
- Kolmogorov-Smirnov Goodness of Fit test. For historical reasons this
- function is exposed in `scpy.special`, but the recommended way to achieve
- the most accurate CDF/SF/PDF/PPF/ISF computations is to use the
- `stats.ksone` distribution.
- Examples
- --------
- >>> from scipy.special import smirnovi, smirnov
- >>> n = 24
- >>> deviations = [0.1, 0.2, 0.3]
- Use `smirnov` to compute the complementary CDF of the Smirnov
- distribution for the given number of samples and deviations.
- >>> p = smirnov(n, deviations)
- >>> p
- array([0.58105083, 0.12826832, 0.01032231])
- The inverse function ``smirnovi(n, p)`` returns ``deviations``.
- >>> smirnovi(n, p)
- array([0.1, 0.2, 0.3])
- """)
- add_newdoc("_smirnovc",
- """
- _smirnovc(n, d)
- Internal function, do not use.
- """)
- add_newdoc("_smirnovci",
- """
- Internal function, do not use.
- """)
- add_newdoc("_smirnovp",
- """
- _smirnovp(n, p)
- Internal function, do not use.
- """)
- add_newdoc("spence",
- r"""
- spence(z, out=None)
- Spence's function, also known as the dilogarithm.
- It is defined to be
- .. math::
- \int_1^z \frac{\log(t)}{1 - t}dt
- for complex :math:`z`, where the contour of integration is taken
- to avoid the branch cut of the logarithm. Spence's function is
- analytic everywhere except the negative real axis where it has a
- branch cut.
- Parameters
- ----------
- z : array_like
- Points at which to evaluate Spence's function
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- s : scalar or ndarray
- Computed values of Spence's function
- Notes
- -----
- There is a different convention which defines Spence's function by
- the integral
- .. math::
- -\int_0^z \frac{\log(1 - t)}{t}dt;
- this is our ``spence(1 - z)``.
- Examples
- --------
- >>> import numpy as np
- >>> from scipy.special import spence
- >>> import matplotlib.pyplot as plt
- The function is defined for complex inputs:
- >>> spence([1-1j, 1.5+2j, 3j, -10-5j])
- array([-0.20561676+0.91596559j, -0.86766909-1.39560134j,
- -0.59422064-2.49129918j, -1.14044398+6.80075924j])
- For complex inputs on the branch cut, which is the negative real axis,
- the function returns the limit for ``z`` with positive imaginary part.
- For example, in the following, note the sign change of the imaginary
- part of the output for ``z = -2`` and ``z = -2 - 1e-8j``:
- >>> spence([-2 + 1e-8j, -2, -2 - 1e-8j])
- array([2.32018041-3.45139229j, 2.32018042-3.4513923j ,
- 2.32018041+3.45139229j])
- The function returns ``nan`` for real inputs on the branch cut:
- >>> spence(-1.5)
- nan
- Verify some particular values: ``spence(0) = pi**2/6``,
- ``spence(1) = 0`` and ``spence(2) = -pi**2/12``.
- >>> spence([0, 1, 2])
- array([ 1.64493407, 0. , -0.82246703])
- >>> np.pi**2/6, -np.pi**2/12
- (1.6449340668482264, -0.8224670334241132)
- Verify the identity::
- spence(z) + spence(1 - z) = pi**2/6 - log(z)*log(1 - z)
- >>> z = 3 + 4j
- >>> spence(z) + spence(1 - z)
- (-2.6523186143876067+1.8853470951513935j)
- >>> np.pi**2/6 - np.log(z)*np.log(1 - z)
- (-2.652318614387606+1.885347095151394j)
- Plot the function for positive real input.
- >>> fig, ax = plt.subplots()
- >>> x = np.linspace(0, 6, 400)
- >>> ax.plot(x, spence(x))
- >>> ax.grid()
- >>> ax.set_xlabel('x')
- >>> ax.set_title('spence(x)')
- >>> plt.show()
- """)
- add_newdoc(
- "stdtr",
- r"""
- stdtr(df, t, out=None)
- Student t distribution cumulative distribution function
- Returns the integral:
- .. math::
- \frac{\Gamma((df+1)/2)}{\sqrt{\pi df} \Gamma(df/2)}
- \int_{-\infty}^t (1+x^2/df)^{-(df+1)/2}\, dx
- Parameters
- ----------
- df : array_like
- Degrees of freedom
- t : array_like
- Upper bound of the integral
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- scalar or ndarray
- Value of the Student t CDF at t
- See Also
- --------
- stdtridf : inverse of stdtr with respect to `df`
- stdtrit : inverse of stdtr with respect to `t`
- scipy.stats.t : student t distribution
- Notes
- -----
- The student t distribution is also available as `scipy.stats.t`.
- Calling `stdtr` directly can improve performance compared to the
- ``cdf`` method of `scipy.stats.t` (see last example below).
- The function is computed using the Boost Math library [1]_, which
- relies on the incomplete beta function.
- References
- ----------
- .. [1] Boost C++ Libraries, http://www.boost.org/
- Examples
- --------
- Calculate the function for ``df=3`` at ``t=1``.
- >>> import numpy as np
- >>> from scipy.special import stdtr
- >>> import matplotlib.pyplot as plt
- >>> stdtr(3, 1)
- 0.8044988905221148
- Plot the function for three different degrees of freedom.
- >>> x = np.linspace(-10, 10, 1000)
- >>> fig, ax = plt.subplots()
- >>> parameters = [(1, "solid"), (3, "dashed"), (10, "dotted")]
- >>> for (df, linestyle) in parameters:
- ... ax.plot(x, stdtr(df, x), ls=linestyle, label=f"$df={df}$")
- >>> ax.legend()
- >>> ax.set_title("Student t distribution cumulative distribution function")
- >>> plt.show()
- The function can be computed for several degrees of freedom at the same
- time by providing a NumPy array or list for `df`:
- >>> stdtr([1, 2, 3], 1)
- array([0.75 , 0.78867513, 0.80449889])
- It is possible to calculate the function at several points for several
- different degrees of freedom simultaneously by providing arrays for `df`
- and `t` with shapes compatible for broadcasting. Compute `stdtr` at
- 4 points for 3 degrees of freedom resulting in an array of shape 3x4.
- >>> dfs = np.array([[1], [2], [3]])
- >>> t = np.array([2, 4, 6, 8])
- >>> dfs.shape, t.shape
- ((3, 1), (4,))
- >>> stdtr(dfs, t)
- array([[0.85241638, 0.92202087, 0.94743154, 0.96041658],
- [0.90824829, 0.97140452, 0.98666426, 0.99236596],
- [0.93033702, 0.98599577, 0.99536364, 0.99796171]])
- The t distribution is also available as `scipy.stats.t`. Calling `stdtr`
- directly can be much faster than calling the ``cdf`` method of
- `scipy.stats.t`. To get the same results, one must use the following
- parametrization: ``scipy.stats.t(df).cdf(x) = stdtr(df, x)``.
- >>> from scipy.stats import t
- >>> df, x = 3, 1
- >>> stdtr_result = stdtr(df, x) # this can be faster than below
- >>> stats_result = t(df).cdf(x)
- >>> stats_result == stdtr_result # test that results are equal
- True
- """)
- add_newdoc("stdtridf",
- """
- stdtridf(p, t, out=None)
- Inverse of `stdtr` vs df
- Returns the argument df such that stdtr(df, t) is equal to `p`.
- Parameters
- ----------
- p : array_like
- Probability
- t : array_like
- Upper bound of the integral
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- df : scalar or ndarray
- Value of `df` such that ``stdtr(df, t) == p``
- See Also
- --------
- stdtr : Student t CDF
- stdtrit : inverse of stdtr with respect to `t`
- scipy.stats.t : Student t distribution
- Examples
- --------
- Compute the student t cumulative distribution function for one
- parameter set.
- >>> from scipy.special import stdtr, stdtridf
- >>> df, x = 5, 2
- >>> cdf_value = stdtr(df, x)
- >>> cdf_value
- 0.9490302605850709
- Verify that `stdtridf` recovers the original value for `df` given
- the CDF value and `x`.
- >>> stdtridf(cdf_value, x)
- 5.0
- """)
- add_newdoc("stdtrit",
- """
- stdtrit(df, p, out=None)
- The `p`-th quantile of the student t distribution.
- This function is the inverse of the student t distribution cumulative
- distribution function (CDF), returning `t` such that `stdtr(df, t) = p`.
- Returns the argument `t` such that stdtr(df, t) is equal to `p`.
- Parameters
- ----------
- df : array_like
- Degrees of freedom
- p : array_like
- Probability
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- t : scalar or ndarray
- Value of `t` such that ``stdtr(df, t) == p``
- See Also
- --------
- stdtr : Student t CDF
- stdtridf : inverse of stdtr with respect to `df`
- scipy.stats.t : Student t distribution
- Notes
- -----
- The student t distribution is also available as `scipy.stats.t`. Calling
- `stdtrit` directly can improve performance compared to the ``ppf``
- method of `scipy.stats.t` (see last example below).
- The function is computed using the Boost Math library [1]_, which
- relies on the incomplete beta function.
- References
- ----------
- .. [1] Boost C++ Libraries, http://www.boost.org/
- Examples
- --------
- `stdtrit` represents the inverse of the student t distribution CDF which
- is available as `stdtr`. Here, we calculate the CDF for ``df`` at
- ``x=1``. `stdtrit` then returns ``1`` up to floating point errors
- given the same value for `df` and the computed CDF value.
- >>> import numpy as np
- >>> from scipy.special import stdtr, stdtrit
- >>> import matplotlib.pyplot as plt
- >>> df = 3
- >>> x = 1
- >>> cdf_value = stdtr(df, x)
- >>> stdtrit(df, cdf_value)
- 0.9999999994418539
- Plot the function for three different degrees of freedom.
- >>> x = np.linspace(0, 1, 1000)
- >>> parameters = [(1, "solid"), (2, "dashed"), (5, "dotted")]
- >>> fig, ax = plt.subplots()
- >>> for (df, linestyle) in parameters:
- ... ax.plot(x, stdtrit(df, x), ls=linestyle, label=f"$df={df}$")
- >>> ax.legend()
- >>> ax.set_ylim(-10, 10)
- >>> ax.set_title("Student t distribution quantile function")
- >>> plt.show()
- The function can be computed for several degrees of freedom at the same
- time by providing a NumPy array or list for `df`:
- >>> stdtrit([1, 2, 3], 0.7)
- array([0.72654253, 0.6172134 , 0.58438973])
- It is possible to calculate the function at several points for several
- different degrees of freedom simultaneously by providing arrays for `df`
- and `p` with shapes compatible for broadcasting. Compute `stdtrit` at
- 4 points for 3 degrees of freedom resulting in an array of shape 3x4.
- >>> dfs = np.array([[1], [2], [3]])
- >>> p = np.array([0.2, 0.4, 0.7, 0.8])
- >>> dfs.shape, p.shape
- ((3, 1), (4,))
- >>> stdtrit(dfs, p)
- array([[-1.37638192, -0.3249197 , 0.72654253, 1.37638192],
- [-1.06066017, -0.28867513, 0.6172134 , 1.06066017],
- [-0.97847231, -0.27667066, 0.58438973, 0.97847231]])
- The t distribution is also available as `scipy.stats.t`. Calling `stdtrit`
- directly can be much faster than calling the ``ppf`` method of
- `scipy.stats.t`. To get the same results, one must use the following
- parametrization: ``scipy.stats.t(df).ppf(x) = stdtrit(df, x)``.
- >>> from scipy.stats import t
- >>> df, x = 3, 0.5
- >>> stdtrit_result = stdtrit(df, x) # this can be faster than below
- >>> stats_result = t(df).ppf(x)
- >>> stats_result == stdtrit_result # test that results are equal
- True
- """)
- add_newdoc(
- "tklmbda",
- r"""
- tklmbda(x, lmbda, out=None)
- Cumulative distribution function of the Tukey lambda distribution.
- Parameters
- ----------
- x, lmbda : array_like
- Parameters
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- cdf : scalar or ndarray
- Value of the Tukey lambda CDF
- See Also
- --------
- scipy.stats.tukeylambda : Tukey lambda distribution
- Examples
- --------
- >>> import numpy as np
- >>> import matplotlib.pyplot as plt
- >>> from scipy.special import tklmbda, expit
- Compute the cumulative distribution function (CDF) of the Tukey lambda
- distribution at several ``x`` values for `lmbda` = -1.5.
- >>> x = np.linspace(-2, 2, 9)
- >>> x
- array([-2. , -1.5, -1. , -0.5, 0. , 0.5, 1. , 1.5, 2. ])
- >>> tklmbda(x, -1.5)
- array([0.34688734, 0.3786554 , 0.41528805, 0.45629737, 0.5 ,
- 0.54370263, 0.58471195, 0.6213446 , 0.65311266])
- When `lmbda` is 0, the function is the logistic sigmoid function,
- which is implemented in `scipy.special` as `expit`.
- >>> tklmbda(x, 0)
- array([0.11920292, 0.18242552, 0.26894142, 0.37754067, 0.5 ,
- 0.62245933, 0.73105858, 0.81757448, 0.88079708])
- >>> expit(x)
- array([0.11920292, 0.18242552, 0.26894142, 0.37754067, 0.5 ,
- 0.62245933, 0.73105858, 0.81757448, 0.88079708])
- When `lmbda` is 1, the Tukey lambda distribution is uniform on the
- interval [-1, 1], so the CDF increases linearly.
- >>> t = np.linspace(-1, 1, 9)
- >>> tklmbda(t, 1)
- array([0. , 0.125, 0.25 , 0.375, 0.5 , 0.625, 0.75 , 0.875, 1. ])
- In the following, we generate plots for several values of `lmbda`.
- The first figure shows graphs for `lmbda` <= 0.
- >>> styles = ['-', '-.', '--', ':']
- >>> fig, ax = plt.subplots()
- >>> x = np.linspace(-12, 12, 500)
- >>> for k, lmbda in enumerate([-1.0, -0.5, 0.0]):
- ... y = tklmbda(x, lmbda)
- ... ax.plot(x, y, styles[k], label=rf'$\lambda$ = {lmbda:-4.1f}')
- >>> ax.set_title(r'tklmbda(x, $\lambda$)')
- >>> ax.set_label('x')
- >>> ax.legend(framealpha=1, shadow=True)
- >>> ax.grid(True)
- The second figure shows graphs for `lmbda` > 0. The dots in the
- graphs show the bounds of the support of the distribution.
- >>> fig, ax = plt.subplots()
- >>> x = np.linspace(-4.2, 4.2, 500)
- >>> lmbdas = [0.25, 0.5, 1.0, 1.5]
- >>> for k, lmbda in enumerate(lmbdas):
- ... y = tklmbda(x, lmbda)
- ... ax.plot(x, y, styles[k], label=fr'$\lambda$ = {lmbda}')
- >>> ax.set_prop_cycle(None)
- >>> for lmbda in lmbdas:
- ... ax.plot([-1/lmbda, 1/lmbda], [0, 1], '.', ms=8)
- >>> ax.set_title(r'tklmbda(x, $\lambda$)')
- >>> ax.set_xlabel('x')
- >>> ax.legend(framealpha=1, shadow=True)
- >>> ax.grid(True)
- >>> plt.tight_layout()
- >>> plt.show()
- The CDF of the Tukey lambda distribution is also implemented as the
- ``cdf`` method of `scipy.stats.tukeylambda`. In the following,
- ``tukeylambda.cdf(x, -0.5)`` and ``tklmbda(x, -0.5)`` compute the
- same values:
- >>> from scipy.stats import tukeylambda
- >>> x = np.linspace(-2, 2, 9)
- >>> tukeylambda.cdf(x, -0.5)
- array([0.21995157, 0.27093858, 0.33541677, 0.41328161, 0.5 ,
- 0.58671839, 0.66458323, 0.72906142, 0.78004843])
- >>> tklmbda(x, -0.5)
- array([0.21995157, 0.27093858, 0.33541677, 0.41328161, 0.5 ,
- 0.58671839, 0.66458323, 0.72906142, 0.78004843])
- The implementation in ``tukeylambda`` also provides location and scale
- parameters, and other methods such as ``pdf()`` (the probability
- density function) and ``ppf()`` (the inverse of the CDF), so for
- working with the Tukey lambda distribution, ``tukeylambda`` is more
- generally useful. The primary advantage of ``tklmbda`` is that it is
- significantly faster than ``tukeylambda.cdf``.
- """)
- add_newdoc("yn",
- r"""
- yn(n, x, out=None)
- Bessel function of the second kind of integer order and real argument.
- Parameters
- ----------
- n : array_like
- Order (integer).
- x : array_like
- Argument (float).
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- Y : scalar or ndarray
- Value of the Bessel function, :math:`Y_n(x)`.
- See Also
- --------
- yv : For real order and real or complex argument.
- y0: faster implementation of this function for order 0
- y1: faster implementation of this function for order 1
- Notes
- -----
- Wrapper for the Cephes [1]_ routine `yn`.
- The function is evaluated by forward recurrence on `n`, starting with
- values computed by the Cephes routines `y0` and `y1`. If ``n = 0`` or 1,
- the routine for `y0` or `y1` is called directly.
- References
- ----------
- .. [1] Cephes Mathematical Functions Library,
- http://www.netlib.org/cephes/
- Examples
- --------
- Evaluate the function of order 0 at one point.
- >>> from scipy.special import yn
- >>> yn(0, 1.)
- 0.08825696421567697
- Evaluate the function at one point for different orders.
- >>> yn(0, 1.), yn(1, 1.), yn(2, 1.)
- (0.08825696421567697, -0.7812128213002888, -1.6506826068162546)
- The evaluation for different orders can be carried out in one call by
- providing a list or NumPy array as argument for the `v` parameter:
- >>> yn([0, 1, 2], 1.)
- array([ 0.08825696, -0.78121282, -1.65068261])
- Evaluate the function at several points for order 0 by providing an
- array for `z`.
- >>> import numpy as np
- >>> points = np.array([0.5, 3., 8.])
- >>> yn(0, points)
- array([-0.44451873, 0.37685001, 0.22352149])
- If `z` is an array, the order parameter `v` must be broadcastable to
- the correct shape if different orders shall be computed in one call.
- To calculate the orders 0 and 1 for a 1D array:
- >>> orders = np.array([[0], [1]])
- >>> orders.shape
- (2, 1)
- >>> yn(orders, points)
- array([[-0.44451873, 0.37685001, 0.22352149],
- [-1.47147239, 0.32467442, -0.15806046]])
- Plot the functions of order 0 to 3 from 0 to 10.
- >>> import matplotlib.pyplot as plt
- >>> fig, ax = plt.subplots()
- >>> x = np.linspace(0., 10., 1000)
- >>> for i in range(4):
- ... ax.plot(x, yn(i, x), label=f'$Y_{i!r}$')
- >>> ax.set_ylim(-3, 1)
- >>> ax.legend()
- >>> plt.show()
- """)
- add_newdoc("_struve_asymp_large_z",
- """
- _struve_asymp_large_z(v, z, is_h)
- Internal function for testing `struve` & `modstruve`
- Evaluates using asymptotic expansion
- Returns
- -------
- v, err
- """)
- add_newdoc("_struve_power_series",
- """
- _struve_power_series(v, z, is_h)
- Internal function for testing `struve` & `modstruve`
- Evaluates using power series
- Returns
- -------
- v, err
- """)
- add_newdoc("_struve_bessel_series",
- """
- _struve_bessel_series(v, z, is_h)
- Internal function for testing `struve` & `modstruve`
- Evaluates using Bessel function series
- Returns
- -------
- v, err
- """)
- add_newdoc("_spherical_jn",
- """
- Internal function, use `spherical_jn` instead.
- """)
- add_newdoc("_spherical_jn_d",
- """
- Internal function, use `spherical_jn` instead.
- """)
- add_newdoc("_spherical_yn",
- """
- Internal function, use `spherical_yn` instead.
- """)
- add_newdoc("_spherical_yn_d",
- """
- Internal function, use `spherical_yn` instead.
- """)
- add_newdoc("_spherical_in",
- """
- Internal function, use `spherical_in` instead.
- """)
- add_newdoc("_spherical_in_d",
- """
- Internal function, use `spherical_in` instead.
- """)
- add_newdoc("_spherical_kn",
- """
- Internal function, use `spherical_kn` instead.
- """)
- add_newdoc("_spherical_kn_d",
- """
- Internal function, use `spherical_kn` instead.
- """)
- add_newdoc("owens_t",
- """
- owens_t(h, a, out=None)
- Owen's T Function.
- The function T(h, a) gives the probability of the event
- (X > h and 0 < Y < a * X) where X and Y are independent
- standard normal random variables.
- Parameters
- ----------
- h: array_like
- Input value.
- a: array_like
- Input value.
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- t: scalar or ndarray
- Probability of the event (X > h and 0 < Y < a * X),
- where X and Y are independent standard normal random variables.
- References
- ----------
- .. [1] M. Patefield and D. Tandy, "Fast and accurate calculation of
- Owen's T Function", Statistical Software vol. 5, pp. 1-25, 2000.
- Examples
- --------
- >>> from scipy import special
- >>> a = 3.5
- >>> h = 0.78
- >>> special.owens_t(h, a)
- 0.10877216734852274
- """)
- add_newdoc("_factorial",
- """
- Internal function, do not use.
- """)
- add_newdoc("ndtri_exp",
- r"""
- ndtri_exp(y, out=None)
- Inverse of `log_ndtr` vs x. Allows for greater precision than
- `ndtri` composed with `numpy.exp` for very small values of y and for
- y close to 0.
- Parameters
- ----------
- y : array_like of float
- Function argument
- out : ndarray, optional
- Optional output array for the function results
- Returns
- -------
- scalar or ndarray
- Inverse of the log CDF of the standard normal distribution, evaluated
- at y.
- See Also
- --------
- log_ndtr : log of the standard normal cumulative distribution function
- ndtr : standard normal cumulative distribution function
- ndtri : standard normal percentile function
- Examples
- --------
- >>> import numpy as np
- >>> import scipy.special as sc
- `ndtri_exp` agrees with the naive implementation when the latter does
- not suffer from underflow.
- >>> sc.ndtri_exp(-1)
- -0.33747496376420244
- >>> sc.ndtri(np.exp(-1))
- -0.33747496376420244
- For extreme values of y, the naive approach fails
- >>> sc.ndtri(np.exp(-800))
- -inf
- >>> sc.ndtri(np.exp(-1e-20))
- inf
- whereas `ndtri_exp` is still able to compute the result to high precision.
- >>> sc.ndtri_exp(-800)
- -39.88469483825668
- >>> sc.ndtri_exp(-1e-20)
- 9.262340089798409
- """)
- add_newdoc("_stirling2_inexact",
- r"""
- Internal function, do not use.
- """)
- add_newdoc(
- "_beta_pdf",
- r"""
- _beta_pdf(x, a, b)
- Probability density function of beta distribution.
- Parameters
- ----------
- x : array_like
- Real-valued such that :math:`0 \leq x \leq 1`,
- the upper limit of integration
- a, b : array_like
- Positive, real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_beta_ppf",
- r"""
- _beta_ppf(x, a, b)
- Percent point function of beta distribution.
- Parameters
- ----------
- x : array_like
- Real-valued such that :math:`0 \leq x \leq 1`,
- the upper limit of integration
- a, b : array_like
- Positive, real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_invgauss_ppf",
- """
- _invgauss_ppf(x, mu)
- Percent point function of inverse gaussian distribution.
- Parameters
- ----------
- x : array_like
- Positive real-valued
- mu : array_like
- Positive, real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_invgauss_isf",
- """
- _invgauss_isf(x, mu, s)
- Inverse survival function of inverse gaussian distribution.
- Parameters
- ----------
- x : array_like
- Positive real-valued
- mu : array_like
- Positive, real-valued parameters
- s : array_like
- Positive, real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_cauchy_ppf",
- """
- _cauchy_ppf(p, loc, scale)
- Percent point function (i.e. quantile) of the Cauchy distribution.
- Parameters
- ----------
- p : array_like
- Probabilities
- loc : array_like
- Location parameter of the distribution.
- scale : array_like
- Scale parameter of the distribution.
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_cauchy_isf",
- """
- _cauchy_isf(p, loc, scale)
- Inverse survival function of the Cauchy distribution.
- Parameters
- ----------
- p : array_like
- Probabilities
- loc : array_like
- Location parameter of the distribution.
- scale : array_like
- Scale parameter of the distribution.
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_ncx2_pdf",
- """
- _ncx2_pdf(x, k, l)
- Probability density function of Non-central chi-squared distribution.
- Parameters
- ----------
- x : array_like
- Positive real-valued
- k, l : array_like
- Positive, real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_ncx2_cdf",
- """
- _ncx2_cdf(x, k, l)
- Cumulative density function of Non-central chi-squared distribution.
- Parameters
- ----------
- x : array_like
- Positive real-valued
- k, l : array_like
- Positive, real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_ncx2_ppf",
- """
- _ncx2_ppf(x, k, l)
- Percent point function of Non-central chi-squared distribution.
- Parameters
- ----------
- x : array_like
- Positive real-valued
- k, l : array_like
- Positive, real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_ncx2_sf",
- """
- _ncx2_sf(x, k, l)
- Survival function of Non-central chi-squared distribution.
- Parameters
- ----------
- x : array_like
- Positive real-valued
- k, l : array_like
- Positive, real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_ncx2_isf",
- """
- _ncx2_isf(x, k, l)
- Inverse survival function of Non-central chi-squared distribution.
- Parameters
- ----------
- x : array_like
- Positive real-valued
- k, l : array_like
- Positive, real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_ncf_pdf",
- """
- _ncf_pdf(x, v1, v2, l)
- Probability density function of noncentral F-distribution.
- Parameters
- ----------
- x : array_like
- Positive real-valued
- v1, v2, l : array_like
- Positive, real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_ncf_cdf",
- """
- _ncf_cdf(x, v1, v2, l)
- Cumulative density function of noncentral F-distribution.
- Parameters
- ----------
- x : array_like
- Positive real-valued
- v1, v2, l : array_like
- Positive, real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_ncf_ppf",
- """
- _ncf_ppf(x, v1, v2, l)
- Percent point function of noncentral F-distribution.
- Parameters
- ----------
- x : array_like
- Positive real-valued
- v1, v2, l : array_like
- Positive, real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_ncf_sf",
- """
- _ncf_sf(x, v1, v2, l)
- Survival function of noncentral F-distribution.
- Parameters
- ----------
- x : array_like
- Positive real-valued
- v1, v2, l : array_like
- Positive, real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_ncf_isf",
- """
- _ncf_isf(x, v1, v2, l)
- Inverse survival function of noncentral F-distribution.
- Parameters
- ----------
- x : array_like
- Positive real-valued
- v1, v2, l : array_like
- Positive, real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_ncf_mean",
- """
- _ncf_mean(v1, v2, l)
- Mean of noncentral F-distribution.
- Parameters
- ----------
- v1, v2, l : array_like
- Positive, real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_ncf_variance",
- """
- _ncf_variance(v1, v2, l)
- Variance of noncentral F-distribution.
- Parameters
- ----------
- v1, v2, l : array_like
- Positive, real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_ncf_skewness",
- """
- _ncf_skewness(v1, v2, l)
- Skewness of noncentral F-distribution.
- Parameters
- ----------
- v1, v2, l : array_like
- Positive, real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_ncf_kurtosis_excess",
- """
- _ncf_kurtosis_excess(v1, v2, l)
- Kurtosis excess of noncentral F-distribution.
- Parameters
- ----------
- v1, v2, l : array_like
- Positive, real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_nct_cdf",
- """
- _nct_cdf(x, v, l)
- Cumulative density function of noncentral t-distribution.
- Parameters
- ----------
- x : array_like
- Real-valued
- v : array_like
- Positive, real-valued parameters
- l : array_like
- Real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_nct_pdf",
- """
- _nct_pdf(x, v, l)
- Probability density function of noncentral t-distribution.
- Parameters
- ----------
- x : array_like
- Real-valued
- v : array_like
- Positive, real-valued parameters
- l : array_like
- Real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_nct_ppf",
- """
- _nct_ppf(x, v, l)
- Percent point function of noncentral t-distribution.
- Parameters
- ----------
- x : array_like
- Real-valued
- v : array_like
- Positive, real-valued parameters
- l : array_like
- Real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_nct_sf",
- """
- _nct_sf(x, v, l)
- Survival function of noncentral t-distribution.
- Parameters
- ----------
- x : array_like
- Real-valued
- v : array_like
- Positive, real-valued parameters
- l : array_like
- Real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_nct_isf",
- """
- _nct_isf(x, v, l)
- Inverse survival function of noncentral t-distribution.
- Parameters
- ----------
- x : array_like
- Real-valued
- v : array_like
- Positive, real-valued parameters
- l : array_like
- Real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_nct_mean",
- """
- _nct_mean(v, l)
- Mean of noncentral t-distribution.
- Parameters
- ----------
- v : array_like
- Positive, real-valued parameters
- l : array_like
- Real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_nct_variance",
- """
- _nct_variance(v, l)
- Variance of noncentral t-distribution.
- Parameters
- ----------
- v : array_like
- Positive, real-valued parameters
- l : array_like
- Real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_nct_skewness",
- """
- _nct_skewness(v, l)
- Skewness of noncentral t-distribution.
- Parameters
- ----------
- v : array_like
- Positive, real-valued parameters
- l : array_like
- Real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_nct_kurtosis_excess",
- """
- _nct_kurtosis_excess(v, l)
- Kurtosis excess of noncentral t-distribution.
- Parameters
- ----------
- v : array_like
- Positive, real-valued parameters
- l : array_like
- Real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_skewnorm_cdf",
- """
- _skewnorm_cdf(x, l, sc, sh)
- Cumulative density function of skewnorm distribution.
- Parameters
- ----------
- x : array_like
- Real-valued
- l : array_like
- Real-valued parameters
- sc : array_like
- Positive, Real-valued parameters
- sh : array_like
- Real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_skewnorm_ppf",
- """
- _skewnorm_ppf(x, l, sc, sh)
- Percent point function of skewnorm distribution.
- Parameters
- ----------
- x : array_like
- Real-valued
- l : array_like
- Real-valued parameters
- sc : array_like
- Positive, Real-valued parameters
- sh : array_like
- Real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_skewnorm_isf",
- """
- _skewnorm_isf(x, l, sc, sh)
- Inverse survival function of skewnorm distribution.
- Parameters
- ----------
- x : array_like
- Real-valued
- l : array_like
- Real-valued parameters
- sc : array_like
- Positive, Real-valued parameters
- sh : array_like
- Real-valued parameters
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_binom_pmf",
- """
- _binom_pmf(x, n, p)
- Probability mass function of binomial distribution.
- Parameters
- ----------
- x : array_like
- Real-valued
- n : array_like
- Positive, integer-valued parameter
- p : array_like
- Positive, real-valued parameter
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_binom_cdf",
- """
- _binom_cdf(x, n, p)
- Cumulative density function of binomial distribution.
- Parameters
- ----------
- x : array_like
- Real-valued
- n : array_like
- Positive, integer-valued parameter
- p : array_like
- Positive, real-valued parameter
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_binom_ppf",
- """
- _binom_ppf(x, n, p)
- Percent point function of binomial distribution.
- Parameters
- ----------
- x : array_like
- Real-valued
- n : array_like
- Positive, integer-valued parameter
- p : array_like
- Positive, real-valued parameter
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_binom_sf",
- """
- _binom_sf(x, n, p)
- Survival function of binomial distribution.
- Parameters
- ----------
- x : array_like
- Real-valued
- n : array_like
- Positive, integer-valued parameter
- p : array_like
- Positive, real-valued parameter
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_binom_isf",
- """
- _binom_isf(x, n, p)
- Inverse survival function of binomial distribution.
- Parameters
- ----------
- x : array_like
- Real-valued
- n : array_like
- Positive, integer-valued parameter
- p : array_like
- Positive, real-valued parameter
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_nbinom_pmf",
- """
- _nbinom_pmf(x, r, p)
- Probability mass function of negative binomial distribution.
- Parameters
- ----------
- x : array_like
- Real-valued
- r : array_like
- Positive, integer-valued parameter
- p : array_like
- Positive, real-valued parameter
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_nbinom_cdf",
- """
- _nbinom_cdf(x, r, p)
- Cumulative density function of negative binomial distribution.
- Parameters
- ----------
- x : array_like
- Real-valued
- r : array_like
- Positive, integer-valued parameter
- p : array_like
- Positive, real-valued parameter
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_nbinom_ppf",
- """
- _nbinom_ppf(x, r, p)
- Percent point function of negative binomial distribution.
- Parameters
- ----------
- x : array_like
- Real-valued
- r : array_like
- Positive, integer-valued parameter
- p : array_like
- Positive, real-valued parameter
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_nbinom_sf",
- """
- _nbinom_sf(x, r, p)
- Survival function of negative binomial distribution.
- Parameters
- ----------
- x : array_like
- Real-valued
- r : array_like
- Positive, integer-valued parameter
- p : array_like
- Positive, real-valued parameter
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_nbinom_isf",
- """
- _nbinom_isf(x, r, p)
- Inverse survival function of negative binomial distribution.
- Parameters
- ----------
- x : array_like
- Real-valued
- r : array_like
- Positive, integer-valued parameter
- p : array_like
- Positive, real-valued parameter
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_nbinom_mean",
- """
- _nbinom_mean(r, p)
- Mean of negative binomial distribution.
- Parameters
- ----------
- r : array_like
- Positive, integer-valued parameter
- p : array_like
- Positive, real-valued parameter
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_nbinom_variance",
- """
- _nbinom_variance(r, p)
- Variance of negative binomial distribution.
- Parameters
- ----------
- r : array_like
- Positive, integer-valued parameter
- p : array_like
- Positive, real-valued parameter
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_nbinom_skewness",
- """
- _nbinom_skewness(r, p)
- Skewness of negative binomial distribution.
- Parameters
- ----------
- r : array_like
- Positive, integer-valued parameter
- p : array_like
- Positive, real-valued parameter
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_nbinom_kurtosis_excess",
- """
- _nbinom_kurtosis_excess(r, p)
- Kurtosis excess of negative binomial distribution.
- Parameters
- ----------
- r : array_like
- Positive, integer-valued parameter
- p : array_like
- Positive, real-valued parameter
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_hypergeom_pmf",
- """
- _hypergeom_pmf(x, r, N, M)
- Probability mass function of hypergeometric distribution.
- Parameters
- ----------
- x : array_like
- Real-valued
- r, N, M : array_like
- Positive, integer-valued parameter
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_hypergeom_cdf",
- """
- _hypergeom_cdf(x, r, N, M)
- Cumulative density function of hypergeometric distribution.
- Parameters
- ----------
- x : array_like
- Real-valued
- r, N, M : array_like
- Positive, integer-valued parameter
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_hypergeom_sf",
- """
- _hypergeom_sf(x, r, N, M)
- Survival function of hypergeometric distribution.
- Parameters
- ----------
- x : array_like
- Real-valued
- r, N, M : array_like
- Positive, integer-valued parameter
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_hypergeom_mean",
- """
- _hypergeom_mean(r, N, M)
- Mean of hypergeometric distribution.
- Parameters
- ----------
- r, N, M : array_like
- Positive, integer-valued parameter
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_hypergeom_variance",
- """
- _hypergeom_variance(r, N, M)
- Mean of hypergeometric distribution.
- Parameters
- ----------
- r, N, M : array_like
- Positive, integer-valued parameter
- Returns
- -------
- scalar or ndarray
- """)
- add_newdoc(
- "_hypergeom_skewness",
- """
- _hypergeom_skewness(r, N, M)
- Skewness of hypergeometric distribution.
- Parameters
- ----------
- r, N, M : array_like
- Positive, integer-valued parameter
- Returns
- -------
- scalar or ndarray
- """)
|