diff --git a/.github/workflows/test-parallel-windows.yaml b/.github/workflows/test-parallel-windows.yaml deleted file mode 100644 index 03a6e90..0000000 --- a/.github/workflows/test-parallel-windows.yaml +++ /dev/null @@ -1,39 +0,0 @@ -name: Test-parallel-windows - -on: - push: - branches: - - master - pull_request: - branches: - - master - -jobs: - R-CMD-check: - runs-on: windows-latest - - steps: - - uses: actions/checkout@v2 - - - uses: r-lib/actions/setup-r@v1 - with: - r-version: '4.0.5' # Substitua pela versão do R que você está usando - - - uses: r-lib/actions/setup-pandoc@v1 - - - name: Install dependencies - run: | - install - remotes::install_github('prdm0/AcceptReject') - remotes::install_deps(dependencies = TRUE) - shell: Rscript {0} - - - name: Check package - run: | - devtools::check() - shell: Rscript {0} - - - name: Run tests - run: | - testthat::test_file("tests/testthat/test-time-parallel.R") - shell: Rscript {0} diff --git a/R/accept_reject.r b/R/accept_reject.r index fac4d3c..73abf1c 100644 --- a/R/accept_reject.r +++ b/R/accept_reject.r @@ -244,14 +244,6 @@ accept_reject <- FUN = one_step, mc.cores = n_cores ))) - } else if(parallel && .Platform$OS.type == "windows"){ - cl <- parallel::makeCluster(getOption("cl.cores", 1L)) - capture.output( - r <- unlist(parallel::parLapply( - X = n_each_core, - fun = one_step - ))) - parallel::stopCluster(cl) } else { r <- one_step(n) } diff --git a/README.md b/README.md index b02e850..e65b389 100644 --- a/README.md +++ b/README.md @@ -289,7 +289,7 @@ case_1 <- accept_reject( xlim = c(0, 10) ) toc() -#> 7.294 sec elapsed +#> 0.491 sec elapsed # Specifying the base probability density function tic() @@ -305,7 +305,7 @@ case_2 <- accept_reject( c = 1.2 ) toc() -#> 2.633 sec elapsed +#> 0.153 sec elapsed # Visualizing the results p1 <- plot(case_1) diff --git a/docs/articles/accept_reject.html b/docs/articles/accept_reject.html index 5e1f9ec..9b96d2f 100644 --- a/docs/articles/accept_reject.html +++ b/docs/articles/accept_reject.html @@ -561,7 +561,7 @@

Accessing metadata#> <partialised> #> function (...) #> f(mean = 0, sd = 1, ...) -#> <environment: 0x60509d218b60> +#> <environment: 0x577673074758> #> #> $args_f #> $args_f$mean diff --git a/docs/articles/inspect.html b/docs/articles/inspect.html index 3681aa5..9178be6 100644 --- a/docs/articles/inspect.html +++ b/docs/articles/inspect.html @@ -197,7 +197,7 @@

Example of inspection xlim = c(0, 10) ) toc() -#> 0.442 sec elapsed +#> 0.434 sec elapsed # Specifying the base probability density function tic() @@ -213,7 +213,7 @@

Example of inspection c = 1.2 ) toc() -#> 0.153 sec elapsed +#> 0.156 sec elapsed # Visualizing the results p1 <- plot(case_1) diff --git a/docs/index.html b/docs/index.html index 32ed665..9c64038 100644 --- a/docs/index.html +++ b/docs/index.html @@ -234,7 +234,7 @@

Example of inspection xlim = c(0, 10) ) toc() -#> 7.294 sec elapsed +#> 0.491 sec elapsed # Specifying the base probability density function tic() @@ -250,7 +250,7 @@

Example of inspection c = 1.2 ) toc() -#> 2.633 sec elapsed +#> 0.153 sec elapsed # Visualizing the results p1 <- plot(case_1) diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 1297545..531f51b 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -4,5 +4,5 @@ pkgdown_sha: ~ articles: accept_reject: accept_reject.html inspect: inspect.html -last_built: 2024-04-23T11:53Z +last_built: 2024-04-23T17:24Z diff --git a/docs/reference/figures/README-unnamed-chunk-2-1.png b/docs/reference/figures/README-unnamed-chunk-2-1.png index b188725..4af487d 100644 Binary files a/docs/reference/figures/README-unnamed-chunk-2-1.png and b/docs/reference/figures/README-unnamed-chunk-2-1.png differ diff --git a/docs/reference/figures/README-unnamed-chunk-3-1.png b/docs/reference/figures/README-unnamed-chunk-3-1.png index 6094db1..ee5ee4d 100644 Binary files a/docs/reference/figures/README-unnamed-chunk-3-1.png and b/docs/reference/figures/README-unnamed-chunk-3-1.png differ diff --git a/docs/reference/figures/README-unnamed-chunk-5-1.png b/docs/reference/figures/README-unnamed-chunk-5-1.png index 7442eea..74a02b0 100644 Binary files a/docs/reference/figures/README-unnamed-chunk-5-1.png and b/docs/reference/figures/README-unnamed-chunk-5-1.png differ diff --git a/docs/search.json b/docs/search.json index 97c613e..e96f471 100644 --- a/docs/search.json +++ b/docs/search.json @@ -1 +1 @@ -[{"path":"/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"GNU General Public License","title":"GNU General Public License","text":"Version 3, 29 June 2007Copyright © 2007 Free Software Foundation, Inc.  Everyone permitted copy distribute verbatim copies license document, changing allowed.","code":""},{"path":"/LICENSE.html","id":"preamble","dir":"","previous_headings":"","what":"Preamble","title":"GNU General Public License","text":"GNU General Public License free, copyleft license software kinds works. licenses software practical works designed take away freedom share change works. contrast, GNU General Public License intended guarantee freedom share change versions program–make sure remains free software users. , Free Software Foundation, use GNU General Public License software; applies also work released way authors. can apply programs, . speak free software, referring freedom, price. General Public Licenses designed make sure freedom distribute copies free software (charge wish), receive source code can get want , can change software use pieces new free programs, know can things. protect rights, need prevent others denying rights asking surrender rights. Therefore, certain responsibilities distribute copies software, modify : responsibilities respect freedom others. example, distribute copies program, whether gratis fee, must pass recipients freedoms received. must make sure , , receive can get source code. must show terms know rights. Developers use GNU GPL protect rights two steps: (1) assert copyright software, (2) offer License giving legal permission copy, distribute /modify . developers’ authors’ protection, GPL clearly explains warranty free software. users’ authors’ sake, GPL requires modified versions marked changed, problems attributed erroneously authors previous versions. devices designed deny users access install run modified versions software inside , although manufacturer can . fundamentally incompatible aim protecting users’ freedom change software. systematic pattern abuse occurs area products individuals use, precisely unacceptable. Therefore, designed version GPL prohibit practice products. problems arise substantially domains, stand ready extend provision domains future versions GPL, needed protect freedom users. Finally, every program threatened constantly software patents. States allow patents restrict development use software general-purpose computers, , wish avoid special danger patents applied free program make effectively proprietary. prevent , GPL assures patents used render program non-free. precise terms conditions copying, distribution modification follow.","code":""},{"path":[]},{"path":"/LICENSE.html","id":"id_0-definitions","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"0. Definitions","title":"GNU General Public License","text":"“License” refers version 3 GNU General Public License. “Copyright” also means copyright-like laws apply kinds works, semiconductor masks. “Program” refers copyrightable work licensed License. licensee addressed “”. “Licensees” “recipients” may individuals organizations. “modify” work means copy adapt part work fashion requiring copyright permission, making exact copy. resulting work called “modified version” earlier work work “based ” earlier work. “covered work” means either unmodified Program work based Program. “propagate” work means anything , without permission, make directly secondarily liable infringement applicable copyright law, except executing computer modifying private copy. Propagation includes copying, distribution (without modification), making available public, countries activities well. “convey” work means kind propagation enables parties make receive copies. Mere interaction user computer network, transfer copy, conveying. interactive user interface displays “Appropriate Legal Notices” extent includes convenient prominently visible feature (1) displays appropriate copyright notice, (2) tells user warranty work (except extent warranties provided), licensees may convey work License, view copy License. interface presents list user commands options, menu, prominent item list meets criterion.","code":""},{"path":"/LICENSE.html","id":"id_1-source-code","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"1. Source Code","title":"GNU General Public License","text":"“source code” work means preferred form work making modifications . “Object code” means non-source form work. “Standard Interface” means interface either official standard defined recognized standards body, , case interfaces specified particular programming language, one widely used among developers working language. “System Libraries” executable work include anything, work whole, () included normal form packaging Major Component, part Major Component, (b) serves enable use work Major Component, implement Standard Interface implementation available public source code form. “Major Component”, context, means major essential component (kernel, window system, ) specific operating system () executable work runs, compiler used produce work, object code interpreter used run . “Corresponding Source” work object code form means source code needed generate, install, (executable work) run object code modify work, including scripts control activities. However, include work’s System Libraries, general-purpose tools generally available free programs used unmodified performing activities part work. example, Corresponding Source includes interface definition files associated source files work, source code shared libraries dynamically linked subprograms work specifically designed require, intimate data communication control flow subprograms parts work. Corresponding Source need include anything users can regenerate automatically parts Corresponding Source. Corresponding Source work source code form work.","code":""},{"path":"/LICENSE.html","id":"id_2-basic-permissions","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"2. Basic Permissions","title":"GNU General Public License","text":"rights granted License granted term copyright Program, irrevocable provided stated conditions met. License explicitly affirms unlimited permission run unmodified Program. output running covered work covered License output, given content, constitutes covered work. License acknowledges rights fair use equivalent, provided copyright law. may make, run propagate covered works convey, without conditions long license otherwise remains force. may convey covered works others sole purpose make modifications exclusively , provide facilities running works, provided comply terms License conveying material control copyright. thus making running covered works must exclusively behalf, direction control, terms prohibit making copies copyrighted material outside relationship . Conveying circumstances permitted solely conditions stated . Sublicensing allowed; section 10 makes unnecessary.","code":""},{"path":"/LICENSE.html","id":"id_3-protecting-users-legal-rights-from-anti-circumvention-law","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"3. Protecting Users’ Legal Rights From Anti-Circumvention Law","title":"GNU General Public License","text":"covered work shall deemed part effective technological measure applicable law fulfilling obligations article 11 WIPO copyright treaty adopted 20 December 1996, similar laws prohibiting restricting circumvention measures. convey covered work, waive legal power forbid circumvention technological measures extent circumvention effected exercising rights License respect covered work, disclaim intention limit operation modification work means enforcing, work’s users, third parties’ legal rights forbid circumvention technological measures.","code":""},{"path":"/LICENSE.html","id":"id_4-conveying-verbatim-copies","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"4. Conveying Verbatim Copies","title":"GNU General Public License","text":"may convey verbatim copies Program’s source code receive , medium, provided conspicuously appropriately publish copy appropriate copyright notice; keep intact notices stating License non-permissive terms added accord section 7 apply code; keep intact notices absence warranty; give recipients copy License along Program. may charge price price copy convey, may offer support warranty protection fee.","code":""},{"path":"/LICENSE.html","id":"id_5-conveying-modified-source-versions","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"5. Conveying Modified Source Versions","title":"GNU General Public License","text":"may convey work based Program, modifications produce Program, form source code terms section 4, provided also meet conditions: ) work must carry prominent notices stating modified , giving relevant date. b) work must carry prominent notices stating released License conditions added section 7. requirement modifies requirement section 4 “keep intact notices”. c) must license entire work, whole, License anyone comes possession copy. License therefore apply, along applicable section 7 additional terms, whole work, parts, regardless packaged. License gives permission license work way, invalidate permission separately received . d) work interactive user interfaces, must display Appropriate Legal Notices; however, Program interactive interfaces display Appropriate Legal Notices, work need make . compilation covered work separate independent works, nature extensions covered work, combined form larger program, volume storage distribution medium, called “aggregate” compilation resulting copyright used limit access legal rights compilation’s users beyond individual works permit. Inclusion covered work aggregate cause License apply parts aggregate.","code":""},{"path":"/LICENSE.html","id":"id_6-conveying-non-source-forms","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"6. Conveying Non-Source Forms","title":"GNU General Public License","text":"may convey covered work object code form terms sections 4 5, provided also convey machine-readable Corresponding Source terms License, one ways: ) Convey object code , embodied , physical product (including physical distribution medium), accompanied Corresponding Source fixed durable physical medium customarily used software interchange. b) Convey object code , embodied , physical product (including physical distribution medium), accompanied written offer, valid least three years valid long offer spare parts customer support product model, give anyone possesses object code either (1) copy Corresponding Source software product covered License, durable physical medium customarily used software interchange, price reasonable cost physically performing conveying source, (2) access copy Corresponding Source network server charge. c) Convey individual copies object code copy written offer provide Corresponding Source. alternative allowed occasionally noncommercially, received object code offer, accord subsection 6b. d) Convey object code offering access designated place (gratis charge), offer equivalent access Corresponding Source way place charge. need require recipients copy Corresponding Source along object code. place copy object code network server, Corresponding Source may different server (operated third party) supports equivalent copying facilities, provided maintain clear directions next object code saying find Corresponding Source. Regardless server hosts Corresponding Source, remain obligated ensure available long needed satisfy requirements. e) Convey object code using peer--peer transmission, provided inform peers object code Corresponding Source work offered general public charge subsection 6d. separable portion object code, whose source code excluded Corresponding Source System Library, need included conveying object code work. “User Product” either (1) “consumer product”, means tangible personal property normally used personal, family, household purposes, (2) anything designed sold incorporation dwelling. determining whether product consumer product, doubtful cases shall resolved favor coverage. particular product received particular user, “normally used” refers typical common use class product, regardless status particular user way particular user actually uses, expects expected use, product. product consumer product regardless whether product substantial commercial, industrial non-consumer uses, unless uses represent significant mode use product. “Installation Information” User Product means methods, procedures, authorization keys, information required install execute modified versions covered work User Product modified version Corresponding Source. information must suffice ensure continued functioning modified object code case prevented interfered solely modification made. convey object code work section , , specifically use , User Product, conveying occurs part transaction right possession use User Product transferred recipient perpetuity fixed term (regardless transaction characterized), Corresponding Source conveyed section must accompanied Installation Information. requirement apply neither third party retains ability install modified object code User Product (example, work installed ROM). requirement provide Installation Information include requirement continue provide support service, warranty, updates work modified installed recipient, User Product modified installed. Access network may denied modification materially adversely affects operation network violates rules protocols communication across network. Corresponding Source conveyed, Installation Information provided, accord section must format publicly documented (implementation available public source code form), must require special password key unpacking, reading copying.","code":""},{"path":"/LICENSE.html","id":"id_7-additional-terms","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"7. Additional Terms","title":"GNU General Public License","text":"“Additional permissions” terms supplement terms License making exceptions one conditions. Additional permissions applicable entire Program shall treated though included License, extent valid applicable law. additional permissions apply part Program, part may used separately permissions, entire Program remains governed License without regard additional permissions. convey copy covered work, may option remove additional permissions copy, part . (Additional permissions may written require removal certain cases modify work.) may place additional permissions material, added covered work, can give appropriate copyright permission. Notwithstanding provision License, material add covered work, may (authorized copyright holders material) supplement terms License terms: ) Disclaiming warranty limiting liability differently terms sections 15 16 License; b) Requiring preservation specified reasonable legal notices author attributions material Appropriate Legal Notices displayed works containing ; c) Prohibiting misrepresentation origin material, requiring modified versions material marked reasonable ways different original version; d) Limiting use publicity purposes names licensors authors material; e) Declining grant rights trademark law use trade names, trademarks, service marks; f) Requiring indemnification licensors authors material anyone conveys material (modified versions ) contractual assumptions liability recipient, liability contractual assumptions directly impose licensors authors. non-permissive additional terms considered “restrictions” within meaning section 10. Program received , part , contains notice stating governed License along term restriction, may remove term. license document contains restriction permits relicensing conveying License, may add covered work material governed terms license document, provided restriction survive relicensing conveying. add terms covered work accord section, must place, relevant source files, statement additional terms apply files, notice indicating find applicable terms. Additional terms, permissive non-permissive, may stated form separately written license, stated exceptions; requirements apply either way.","code":""},{"path":"/LICENSE.html","id":"id_8-termination","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"8. Termination","title":"GNU General Public License","text":"may propagate modify covered work except expressly provided License. attempt otherwise propagate modify void, automatically terminate rights License (including patent licenses granted third paragraph section 11). However, cease violation License, license particular copyright holder reinstated () provisionally, unless copyright holder explicitly finally terminates license, (b) permanently, copyright holder fails notify violation reasonable means prior 60 days cessation. Moreover, license particular copyright holder reinstated permanently copyright holder notifies violation reasonable means, first time received notice violation License (work) copyright holder, cure violation prior 30 days receipt notice. Termination rights section terminate licenses parties received copies rights License. rights terminated permanently reinstated, qualify receive new licenses material section 10.","code":""},{"path":"/LICENSE.html","id":"id_9-acceptance-not-required-for-having-copies","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"9. Acceptance Not Required for Having Copies","title":"GNU General Public License","text":"required accept License order receive run copy Program. Ancillary propagation covered work occurring solely consequence using peer--peer transmission receive copy likewise require acceptance. However, nothing License grants permission propagate modify covered work. actions infringe copyright accept License. Therefore, modifying propagating covered work, indicate acceptance License .","code":""},{"path":"/LICENSE.html","id":"id_10-automatic-licensing-of-downstream-recipients","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"10. Automatic Licensing of Downstream Recipients","title":"GNU General Public License","text":"time convey covered work, recipient automatically receives license original licensors, run, modify propagate work, subject License. responsible enforcing compliance third parties License. “entity transaction” transaction transferring control organization, substantially assets one, subdividing organization, merging organizations. propagation covered work results entity transaction, party transaction receives copy work also receives whatever licenses work party’s predecessor interest give previous paragraph, plus right possession Corresponding Source work predecessor interest, predecessor can get reasonable efforts. may impose restrictions exercise rights granted affirmed License. example, may impose license fee, royalty, charge exercise rights granted License, may initiate litigation (including cross-claim counterclaim lawsuit) alleging patent claim infringed making, using, selling, offering sale, importing Program portion .","code":""},{"path":"/LICENSE.html","id":"id_11-patents","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"11. Patents","title":"GNU General Public License","text":"“contributor” copyright holder authorizes use License Program work Program based. work thus licensed called contributor’s “contributor version”. contributor’s “essential patent claims” patent claims owned controlled contributor, whether already acquired hereafter acquired, infringed manner, permitted License, making, using, selling contributor version, include claims infringed consequence modification contributor version. purposes definition, “control” includes right grant patent sublicenses manner consistent requirements License. contributor grants non-exclusive, worldwide, royalty-free patent license contributor’s essential patent claims, make, use, sell, offer sale, import otherwise run, modify propagate contents contributor version. following three paragraphs, “patent license” express agreement commitment, however denominated, enforce patent (express permission practice patent covenant sue patent infringement). “grant” patent license party means make agreement commitment enforce patent party. convey covered work, knowingly relying patent license, Corresponding Source work available anyone copy, free charge terms License, publicly available network server readily accessible means, must either (1) cause Corresponding Source available, (2) arrange deprive benefit patent license particular work, (3) arrange, manner consistent requirements License, extend patent license downstream recipients. “Knowingly relying” means actual knowledge , patent license, conveying covered work country, recipient’s use covered work country, infringe one identifiable patents country reason believe valid. , pursuant connection single transaction arrangement, convey, propagate procuring conveyance , covered work, grant patent license parties receiving covered work authorizing use, propagate, modify convey specific copy covered work, patent license grant automatically extended recipients covered work works based . patent license “discriminatory” include within scope coverage, prohibits exercise , conditioned non-exercise one rights specifically granted License. may convey covered work party arrangement third party business distributing software, make payment third party based extent activity conveying work, third party grants, parties receive covered work , discriminatory patent license () connection copies covered work conveyed (copies made copies), (b) primarily connection specific products compilations contain covered work, unless entered arrangement, patent license granted, prior 28 March 2007. Nothing License shall construed excluding limiting implied license defenses infringement may otherwise available applicable patent law.","code":""},{"path":"/LICENSE.html","id":"id_12-no-surrender-of-others-freedom","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"12. No Surrender of Others’ Freedom","title":"GNU General Public License","text":"conditions imposed (whether court order, agreement otherwise) contradict conditions License, excuse conditions License. convey covered work satisfy simultaneously obligations License pertinent obligations, consequence may convey . example, agree terms obligate collect royalty conveying convey Program, way satisfy terms License refrain entirely conveying Program.","code":""},{"path":"/LICENSE.html","id":"id_13-use-with-the-gnu-affero-general-public-license","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"13. Use with the GNU Affero General Public License","title":"GNU General Public License","text":"Notwithstanding provision License, permission link combine covered work work licensed version 3 GNU Affero General Public License single combined work, convey resulting work. terms License continue apply part covered work, special requirements GNU Affero General Public License, section 13, concerning interaction network apply combination .","code":""},{"path":"/LICENSE.html","id":"id_14-revised-versions-of-this-license","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"14. Revised Versions of this License","title":"GNU General Public License","text":"Free Software Foundation may publish revised /new versions GNU General Public License time time. new versions similar spirit present version, may differ detail address new problems concerns. version given distinguishing version number. Program specifies certain numbered version GNU General Public License “later version” applies , option following terms conditions either numbered version later version published Free Software Foundation. Program specify version number GNU General Public License, may choose version ever published Free Software Foundation. Program specifies proxy can decide future versions GNU General Public License can used, proxy’s public statement acceptance version permanently authorizes choose version Program. Later license versions may give additional different permissions. However, additional obligations imposed author copyright holder result choosing follow later version.","code":""},{"path":"/LICENSE.html","id":"id_15-disclaimer-of-warranty","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"15. Disclaimer of Warranty","title":"GNU General Public License","text":"WARRANTY PROGRAM, EXTENT PERMITTED APPLICABLE LAW. EXCEPT OTHERWISE STATED WRITING COPYRIGHT HOLDERS /PARTIES PROVIDE PROGRAM “” WITHOUT WARRANTY KIND, EITHER EXPRESSED IMPLIED, INCLUDING, LIMITED , IMPLIED WARRANTIES MERCHANTABILITY FITNESS PARTICULAR PURPOSE. ENTIRE RISK QUALITY PERFORMANCE PROGRAM . PROGRAM PROVE DEFECTIVE, ASSUME COST NECESSARY SERVICING, REPAIR CORRECTION.","code":""},{"path":"/LICENSE.html","id":"id_16-limitation-of-liability","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"16. Limitation of Liability","title":"GNU General Public License","text":"EVENT UNLESS REQUIRED APPLICABLE LAW AGREED WRITING COPYRIGHT HOLDER, PARTY MODIFIES /CONVEYS PROGRAM PERMITTED , LIABLE DAMAGES, INCLUDING GENERAL, SPECIAL, INCIDENTAL CONSEQUENTIAL DAMAGES ARISING USE INABILITY USE PROGRAM (INCLUDING LIMITED LOSS DATA DATA RENDERED INACCURATE LOSSES SUSTAINED THIRD PARTIES FAILURE PROGRAM OPERATE PROGRAMS), EVEN HOLDER PARTY ADVISED POSSIBILITY DAMAGES.","code":""},{"path":"/LICENSE.html","id":"id_17-interpretation-of-sections-15-and-16","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"17. Interpretation of Sections 15 and 16","title":"GNU General Public License","text":"disclaimer warranty limitation liability provided given local legal effect according terms, reviewing courts shall apply local law closely approximates absolute waiver civil liability connection Program, unless warranty assumption liability accompanies copy Program return fee. END TERMS CONDITIONS","code":""},{"path":"/LICENSE.html","id":"how-to-apply-these-terms-to-your-new-programs","dir":"","previous_headings":"","what":"How to Apply These Terms to Your New Programs","title":"GNU General Public License","text":"develop new program, want greatest possible use public, best way achieve make free software everyone can redistribute change terms. , attach following notices program. safest attach start source file effectively state exclusion warranty; file least “copyright” line pointer full notice found. Also add information contact electronic paper mail. program terminal interaction, make output short notice like starts interactive mode: hypothetical commands show w show c show appropriate parts General Public License. course, program’s commands might different; GUI interface, use “box”. also get employer (work programmer) school, , sign “copyright disclaimer” program, necessary. information , apply follow GNU GPL, see . GNU General Public License permit incorporating program proprietary programs. program subroutine library, may consider useful permit linking proprietary applications library. want , use GNU Lesser General Public License instead License. first, please read .","code":" Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'. This is free software, and you are welcome to redistribute it under certain conditions; type 'show c' for details."},{"path":"/articles/accept_reject.html","id":"understanding-the-method","dir":"Articles","previous_headings":"","what":"Understanding the Method","title":"Acceptance and rejection method","text":"situations use inversion method (situations obtaining quantile function possible) neither know transformation involving random variable can generate observations, can make use acceptance-rejection method. Suppose \\(X\\) \\(Y\\) random variables probability density function (pdf) probability function (pf) \\(f\\) \\(g\\), respectively. Furthermore, suppose exists constant \\(c\\) \\[\\frac{f(x)}{g(y)} \\leq c,\\] every value \\(x\\), \\(f(x) > 0\\). use acceptance-rejection method generate observations random variable \\(X\\), using algorithm , first find random variable \\(Y\\) pdf pf \\(g\\), satisfies condition. Important: important chosen random variable \\(Y\\) can easily generate observations. acceptance-rejection method computationally intensive direct methods transformation method inversion method, requires generation pseudo-random numbers uniform distribution. Algorithm Acceptance-Rejection Method: 1 - Generate observation \\(y\\) random variable \\(Y\\) pdf/pf \\(g\\); 2 - Generate observation \\(u\\) random variable \\(U\\sim \\mathcal{U} (0, 1)\\); 3 - \\(u < \\frac{f(y)}{cg(y)}\\) accept \\(x = y\\); otherwise reject \\(y\\) observation random variable \\(X\\) go back step 1. Proof: Consider discrete case, , \\(X\\) \\(Y\\) random variables pfs \\(f\\) \\(g\\), respectively. step 3 algorithm , \\(\\{accept\\} = \\{x = y\\} = u < \\frac{f(y)}{cg(y)}\\). , \\[P(accept | Y = y) = \\frac{P(accept \\cap \\{Y = y\\})}{g(y)} = \\frac{P(U \\leq f(y)/cg(y)) \\times g(y)}{g(y)} = \\frac{f(y)}{cg(y)}.\\] Hence, Law Total Probability, : \\[P(accept) = \\sum_y P(accept|Y=y)\\times P(Y=y) = \\sum_y \\frac{f(y)}{cg(y)}\\times g(y) = \\frac{1}{c}.\\] Therefore, acceptance-rejection method, accept occurrence \\(Y\\) occurrence \\(X\\) probability \\(1/c\\). Moreover, Bayes’ Theorem, \\[P(Y = y | accept) = \\frac{P(accept|Y = y)\\times g(y)}{P(accept)} = \\frac{[f(y)/cg(y)] \\times g(y)}{1/c} = f(y).\\] result shows accepting \\(x = y\\) algorithm’s procedure equivalent accepting value \\(X\\) pf \\(f\\). continuous case, proof similar. Important: Notice reduce computational cost method, choose \\(c\\) way can maximize \\(P(accept)\\). Therefore, choosing excessively large value constant \\(c\\) reduce probability accepting observation \\(Y\\) observation random variable \\(X\\). Note: Computationally, convenient consider \\(Y\\) random variable uniform distribution support \\(f\\), since generating observations uniform distribution straightforward computer. discrete case, considering \\(Y\\) discrete uniform distribution might good alternative.","code":""},{"path":"/articles/accept_reject.html","id":"installation-and-loading-the-package","dir":"Articles","previous_headings":"","what":"Installation and loading the package","title":"Acceptance and rejection method","text":"AcceptReject package available CRAN can installed using following command:","code":"install.packages(\"AcceptReject\") # or install.packages(\"remotes\") remotes::install_github(\"prdm0/AcceptReject\", force = TRUE) # Load the package library(AcceptReject)"},{"path":"/articles/accept_reject.html","id":"using-the-accept_reject-function","dir":"Articles","previous_headings":"Installation and loading the package","what":"Using the accept_reject Function","title":"Acceptance and rejection method","text":"Among various functions provided AcceptReject library, acceptance_rejection function implements acceptance-rejection method. AcceptReject::accept_reject() function following signature: Many arguments user need change, AcceptReject::accept_reject() function already default values . However, important note f argument probability density function (pdf) probability function (pf) random variable \\(X\\) observations desired generated. args_f argument list arguments passed f function. c argument value constant c used acceptance-rejection method. user provide value c, AcceptReject::accept_reject() function calculate value c maximizes probability accepting observations \\(Y\\) observations \\(X\\). Note: need define c argument using AcceptReject::accept_reject() function. default, c = NULL, AcceptReject::accept_reject() function calculate value c maximizes probability accepting observations \\(Y\\) observations \\(X\\). However, want set value c, simply pass value c argument. Details optimization c: arguments linesearch_algorithm, max_iterations, epsilon, start_c, ... arguments control optimization algorithm c value. linesearch_algorithm argument line search algorithm used optimization c value. max_iterations argument maximum number iterations optimization algorithm perform. epsilon argument stopping criterion optimization algorithm. start_c argument initial value c used optimization algorithm. arguments passed lbfgs::lbfgs() function, generally, need change .","code":"accept_reject( n = 1L, continuous = TRUE, f = dweibull, args_f = list(shape = 1, scale = 1), xlim = c(0, 100), c = NULL, linesearch_algorithm = \"LBFGS_LINESEARCH_BACKTRACKING_ARMIJO\", max_iterations = 1000L, epsilon = 1e-06, start_c = 25, parallel = FALSE, ... )"},{"path":"/articles/accept_reject.html","id":"examples","dir":"Articles","previous_headings":"","what":"Examples","title":"Acceptance and rejection method","text":"examples using AcceptReject::accept_reject() function generate pseudo-random observations discrete continuous random variables. noted case \\(X\\) discrete random variable, necessary provide argument continuous = FALSE, whereas case \\(X\\) continuous (default), must consider continuous = TRUE.","code":""},{"path":"/articles/accept_reject.html","id":"generating-discrete-observations","dir":"Articles","previous_headings":"Examples","what":"Generating discrete observations","title":"Acceptance and rejection method","text":"example, let \\(X \\sim Poisson(\\lambda = 0.7)\\). generate \\(n = 1000\\) observations \\(X\\) using acceptance-rejection method, using AcceptReject::accept_reject() function. Note necessary provide xlim argument. Try set upper limit value probability \\(X\\) assuming value zero close zero. case, choose xlim = c(0, 20), dpois(x = 20, lambda = 0.7) close zero (1.6286586^{-22}). Note necessary specify nature random variable observations desired generated. case discrete variables, argument continuous = FALSE must passed. Now, consider want generate observations random variable \\(X \\sim Binomial(n = 5, p = 0.7)\\). , generate \\(n = 2000\\) observations \\(X\\).","code":"library(AcceptReject) # Ensuring Reproducibility set.seed(0) # Generating observations data <- AcceptReject::accept_reject( n = 1000L, f = dpois, continuous = FALSE, args_f = list(lambda = 0.7), xlim = c(0, 20), parallel = FALSE ) # Viewing organized output with useful information print(data) #> #> ── Accept-Reject Samples ─────────────────────────────────────────────────────── #> ℹ It's not necessary, but if you want to extract the observations, use as.vector(). #> ✔ Case: discrete #> ✔ Number of observations: 1000 #> ✔ c: 25 #> ✔ Probability of acceptance (1/c): 0.04 #> ✔ Observations: 1 0 0 0 1 1 2 1 0 0... #> ✔ xlim = 0 20 #> #> ──────────────────────────────────────────────────────────────────────────────── # Calculating the true probability function for each observed value values <- unique(data) true_prob <- dpois(values, lambda = 0.7) # Calculating the observed probability for each value in the observations vector obs_prob <- table(data) / length(data) # Plotting the probabilities and observations plot(values, true_prob, type = \"p\", pch = 16, col = \"blue\", xlab = \"x\", ylab = \"Probability\", main = \"Probability Function\") # Adding the observed probabilities points(as.numeric(names(obs_prob)), obs_prob, pch = 16L, col = \"red\") legend(\"topright\", legend = c(\"True probability\", \"Observed probability\"), col = c(\"blue\", \"red\"), pch = 16L, cex = 0.8) grid() library(AcceptReject) # Ensuring reproducibility set.seed(0) # Generating observations data <- AcceptReject::accept_reject( n = 2000L, f = dbinom, continuous = FALSE, args_f = list(size = 5, prob = 0.5), xlim = c(0, 20), parallel = FALSE ) # Viewing organized output with useful information print(data) #> #> ── Accept-Reject Samples ─────────────────────────────────────────────────────── #> ℹ It's not necessary, but if you want to extract the observations, use as.vector(). #> ✔ Case: discrete #> ✔ Number of observations: 2000 #> ✔ c: 25 #> ✔ Probability of acceptance (1/c): 0.04 #> ✔ Observations: 2 3 1 2 4 3 3 3 3 2... #> ✔ xlim = 0 20 #> #> ──────────────────────────────────────────────────────────────────────────────── # Calculating the true probability function for each observed value values <- unique(data) true_prob <- dbinom(values, size = 5, prob = 0.5) # Calculating the observed probability for each value in the observations vector obs_prob <- table(data) / length(data) # Plotting the probabilities and observations plot(values, true_prob, type = \"p\", pch = 16, col = \"blue\", xlab = \"x\", ylab = \"Probability\", main = \"Probability Function\") # Adding the observed probabilities points(as.numeric(names(obs_prob)), obs_prob, pch = 16L, col = \"red\") legend(\"topright\", legend = c(\"True probability\", \"Observed probability\"), col = c(\"blue\", \"red\"), pch = 16L, cex = 0.8) grid()"},{"path":"/articles/accept_reject.html","id":"generating-continuous-observations","dir":"Articles","previous_headings":"Examples","what":"Generating continuous observations","title":"Acceptance and rejection method","text":"expand beyond examples generating pseudo-random observations discrete random variables, consider now want generate observations random variable \\(X \\sim \\mathcal{N}(\\mu = 0, \\sigma^2 = 1)\\). chose normal distribution familiar form, can choose another distribution desired. , generate n = 2000 observations using acceptance-rejection method. Note continuous = TRUE. examples , graphs built without using AcceptReject::plot() function. just show can manipulate returning object using AcceptReject::accept_reject() function, , class object accept_reject. However, AcceptReject::plot() function can used generate graphs simpler way. , example use AcceptReject::plot() function generate probability density plot normal distribution. However, note AcceptReject::plot() function makes plotting task simpler direct. See following example: See another example, discrete case:","code":"library(AcceptReject) # Ensuring reproducibility set.seed(0) # Generating observations data <- AcceptReject::accept_reject( n = 2000L, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4), parallel = FALSE ) # Viewing organized output with useful information print(data) #> #> ── Accept-Reject Samples ─────────────────────────────────────────────────────── #> ℹ It's not necessary, but if you want to extract the observations, use as.vector(). #> ✔ Case: continuous #> ✔ Number of observations: 2000 #> ✔ c: 38.2549 #> ✔ Probability of acceptance (1/c): 0.0261 #> ✔ Observations: 0.4243 0.599 0.0035 0.3812 1.694 0.081 -0.563 0.6268 -0.1201 -1.0155... #> ✔ xlim = -4 4 #> #> ──────────────────────────────────────────────────────────────────────────────── hist( data, main = \"Generating Gaussian observations\", xlab = \"x\", probability = TRUE, ylim = c(0, 0.4) ) x <- seq(-4, 4, length.out = 500L) y <- dnorm(x, mean = 0, sd = 1) lines(x, y, col = \"red\", lwd = 2) legend(\"topright\", legend = \"True density\", col = \"red\", lwd = 2) library(AcceptReject) library(cowplot) # install.packages(\"cowplot\") # Ensuring reproducibility set.seed(0) simulation <- function(n){ AcceptReject::accept_reject( n = n, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4), parallel = FALSE ) } # Inspecting a <- plot(simulation(n = 250L)) b <- plot(simulation(n = 2500L)) c <- plot(simulation(n = 25000L)) d <- plot(simulation(n = 250000L)) plot_grid(a, b, c, d, nrow = 2L, labels = c(\"a\", \"b\", \"c\", \"d\")) library(AcceptReject) library(cowplot) # install.packages(\"cowplot\") # Ensuring Reproducibility set.seed(0) simulation <- function(n){ AcceptReject::accept_reject( n = n, f = dpois, continuous = FALSE, args_f = list(lambda = 0.7), xlim = c(0, 20), parallel = FALSE ) } a <- plot(simulation(25L)) b <- plot(simulation(250L)) c <- plot(simulation(2500L)) d <- plot(simulation(25000L)) plot_grid(a, b, c, d, nrow = 2L, labels = c(\"a\", \"b\", \"c\", \"d\"))"},{"path":"/articles/accept_reject.html","id":"accessing-metadata","dir":"Articles","previous_headings":"Examples","what":"Accessing metadata","title":"Acceptance and rejection method","text":"AcceptReject::accept_reject() function returns object class accept_reject. executing print() function object class, organized output shown. However, can operate instance accept_reject class atomic vector. example , notice can obtain histogram hist() function check size vector observations generated using length() function. want access metadata, use attr() function. Check list attributes : case, important highlight , general, need access attributes. greatest interest access vector observations generated. want access observation values directly atomic vector R without attributes, without organized printout, simply coerce object using .vector() function, shown following example: Important: need coerce object accept_reject class atomic vector attributes unless specific reason . object accept_reject class atomic vector attributes, can operate like atomic vector. Everything can atomic vector, can object accept_reject class.","code":"library(AcceptReject) data <- accept_reject( n = 1000L, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4) ) # Creating a histogram hist(data) # Checking the size of the vector of observations length(x) #> [1] 500 library(AcceptReject) data <- accept_reject( n = 100L, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4) ) attributes(data) #> $class #> [1] \"accept_reject\" #> #> $f #> #> function (...) #> f(mean = 0, sd = 1, ...) #> #> #> $args_f #> $args_f$mean #> [1] 0 #> #> $args_f$sd #> [1] 1 #> #> #> $c #> [1] 38.2549 #> #> $continuous #> [1] TRUE #> #> $xlim #> [1] -4 4 # Accessing the value c attr(data, \"c\") #> [1] 38.2549 library(AcceptReject) data <- accept_reject( n = 100L, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4) ) class(data) #> [1] \"accept_reject\" print(data) #> #> ── Accept-Reject Samples ─────────────────────────────────────────────────────── #> ℹ It's not necessary, but if you want to extract the observations, use as.vector(). #> ✔ Case: continuous #> ✔ Number of observations: 100 #> ✔ c: 38.2549 #> ✔ Probability of acceptance (1/c): 0.0261 #> ✔ Observations: -0.9116 -0.9773 -0.8328 -1.7554 0.3205 0.2271 0.5857 0.5872 0.0143 0.3097... #> ✔ xlim = -4 4 #> #> ──────────────────────────────────────────────────────────────────────────────── # Coercing the object into an atomic vector without attributes data <- as.vector(data) print(data) #> [1] -0.91157235 -0.97730458 -0.83279488 -1.75538689 0.32054036 0.22709815 #> [7] 0.58574094 0.58724381 0.01434882 0.30974479 -2.19669601 0.62127511 #> [13] 1.60171712 0.90850249 2.05355351 -2.17650113 0.60057436 -0.42051950 #> [19] -0.23232206 -1.55660906 -0.88425284 -0.52673517 -0.87943832 -0.63063285 #> [25] -0.85628026 -0.24591930 -1.01740081 0.79763561 1.39946376 0.54384696 #> [31] 0.28309924 0.19440448 -1.30929375 -2.34363151 0.88472824 0.10004806 #> [37] -0.37334603 -1.16272727 1.42066773 0.85311870 -0.72987775 -0.19328477 #> [43] -0.86285814 0.71666934 0.69502212 -0.25295744 -1.11561732 -0.07071140 #> [49] 1.40951045 0.91927889 0.74099312 1.02052561 -2.03183078 -0.67392395 #> [55] -0.60803784 -1.39868014 -0.24927761 0.46767154 -0.20196875 -0.53432214 #> [61] 0.10237354 -0.65235253 0.71854476 -0.41719143 1.77431837 -0.74298612 #> [67] -1.86710453 -0.65607749 -0.25607571 0.72290366 1.28796522 0.28634292 #> [73] 0.78000570 -0.16246228 -0.37944091 -0.54735621 -1.19424975 0.76440685 #> [79] 1.33546143 -0.23903133 0.99561439 -0.05855329 0.01292897 0.43525180 #> [85] -0.30473989 1.54150634 -1.13000945 -0.05852531 -1.21125887 0.96265198 #> [91] -0.73563223 0.46325579 -1.62444950 2.19485540 1.59486479 0.45293343 #> [97] 0.92180256 -0.85777644 0.22787886 1.90666291"},{"path":"/articles/inspect.html","id":"motivation","dir":"Articles","previous_headings":"","what":"Motivation","title":"Specifying a base probability density function","text":"Providing suitable probability density function can reduce computational cost increase acceptance probability. Therefore, inspecting alternative base probability density function good practice. accept_reject() function supports, continuous case, specifying base probability density function don’t want use continuous uniform distribution default base. choosing specify another probability density function different uniform one, ’s necessary specify following arguments: f_base: base probability density function; random_base: sampling base probability density function; args_f_base: list parameters base density. default, NULL, continuous uniform distribution xlim used base. least one arguments specified, error occur, continuous uniform distribution xlim still used base. discrete case, user mistakenly specifies arguments, .e., continuous = FALSE, accept_reject() function ignore arguments use discrete uniform distribution base. choose specify base density, ’s convenient inspect comparing base density function theoretical probability density function. inspect() function facilitates task. inspect() function plot base probability density function theoretical probability density function, find intersection densities, display value intersection area plot. important pieces information decide base probability density function specified args_f_base argument value c (default 1) appropriate.","code":""},{"path":"/articles/inspect.html","id":"example-of-inspection","dir":"Articles","previous_headings":"","what":"Example of inspection","title":"Specifying a base probability density function","text":"Notice considering distribution scenario “” code convenient. Note area approximately 1, base probability density function parameters shape = 2.8 rate = 1.2 provides shape close theoretical distribution, c = 1.2 ensures base density function upper bounds theoretical probability density function. Therefore, considering f_base \\(\\Gamma(\\alpha = 2.8, \\beta = 1.2)\\) c = 1.2 reasonable choice base distribution. Therefore, passing arguments f_base = dgamma, args_f_base = list(shape = 2.8, rate = 1.2), c = 1.2 accept_reject() function lead us even efficient code. Notice results close graphical analysis. However, execution time specifying convenient base density lower large sample. Important:","code":"library(AcceptReject) library(cowplot) # install.packages(\"cowplot\") # Ensuring reproducibility set.seed(0) # Inspecting # Case a a <- inspect( f = dweibull, args_f = list(shape = 2.1, scale = 2.2), f_base = dgamma, args_f_base = list(shape = 2.8, rate = 1.2), xlim = c(0, 10), c = 1.2 ) # Inspecting # Case b b <- inspect( f = dweibull, args_f = list(shape = 2.1, scale = 2.2), f_base = dgamma, args_f_base = list(shape = 2.9, rate = 2.5), xlim = c(0, 10), c = 1.4 ) plot_grid(a, b, nrow = 2L, labels = c(\"a\", \"b\")) library(AcceptReject) library(tictoc) # install.packages(\"tictoc\") # Ensuring reproducibility set.seed(0) # Não especificando a função densidade de probabilidade base tic() case_1 <- accept_reject( n = 200e3L, continuous = TRUE, f = dweibull, args_f = list(shape = 2.1, scale = 2.2), xlim = c(0, 10) ) toc() #> 0.442 sec elapsed # Specifying the base probability density function tic() case_2 <- accept_reject( n = 200e3L, continuous = TRUE, f = dweibull, args_f = list(shape = 2.1, scale = 2.2), f_base = dgamma, random_base = rgamma, args_f_base = list(shape = 2.8, rate = 1.2), xlim = c(0, 10), c = 1.2 ) toc() #> 0.153 sec elapsed # Visualizing the results p1 <- plot(case_1) p2 <- plot(case_2) plot_grid(p1, p2, nrow = 2L)"},{"path":"/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Pedro Rafael D. Marinho. Author, maintainer. Vera Lucia Damasceno Tomazella. Author.","code":""},{"path":"/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"D. Marinho P, Tomazella V (2024). AcceptReject: Acceptance-Rejection Method Generating Pseudo-Random Observations. R package version 0.1.1, https://prdm0.github.io/AcceptReject/.","code":"@Manual{, title = {AcceptReject: Acceptance-Rejection Method for Generating Pseudo-Random Observations}, author = {Pedro Rafael {D. Marinho} and Vera Lucia Damasceno Tomazella}, year = {2024}, note = {R package version 0.1.1}, url = {https://prdm0.github.io/AcceptReject/}, }"},{"path":"/index.html","id":"acceptreject-","dir":"","previous_headings":"","what":"Acceptance-Rejection Method for Generating Pseudo-Random Observations","title":"Acceptance-Rejection Method for Generating Pseudo-Random Observations","text":"Generating pseudo-random observations probability distribution common task statistics. able generate pseudo-random observations probability distribution useful simulating scenarios, Monte-Carlo methods, useful evaluating various statistical models. inversion method common way , always possible find closed-form formula inverse function cumulative distribution function random variable X, , q(u) = F−1(u) = x (quantile function), F cumulative distribution function X u uniformly distributed random variable interval (0,1). Whenever possible, preferable use inversion method generate pseudo-random observations probability distribution. However, possible find closed-form formula inverse function cumulative distribution function random variable, necessary resort methods. One way acceptance-rejection method, Monte-Carlo procedure. package aims provide function implements Acceptance Rejection method generating pseudo-random observations probability distributions difficult sample directly. package AcceptReject provides AcceptReject::accept_reject() function implements acceptance-rejection method optimized manner generate pseudo-random observations discrete continuous random variables. AcceptReject::accept_reject() function operates parallel Unix-based operating systems Linux MacOS operates sequentially Windows-based operating systems; however, still exhibits good performance. default, Unix-based systems, observations generated sequentially, possible generate observations parallel desired, using parallel = TRUE argument. AcceptReject::accept_reject() function, default, attempts maximize probability acceptance pseudo-random observations generated. Suppose X Y random variables probability density function (pdf) probability function (pf) f g, respectively. Furthermore, suppose exists constant c $$\\frac{f_X(x)}{g_Y(y)} \\leq c.$$ default, accept_reject function attempts find value c maximizes probability acceptance pseudo-random observations generated. However, possible provide value c AcceptReject::accept_reject() function argument c, Y random variable know generate observations. AcceptReject::accept_reject() function, necessary specify probability function probability density function Y generate observations X discrete continuous cases, respectively. discrete continuous cases, Y follows discrete uniform distribution function continuous uniform distribution function, respectively. Since probability acceptance 1/c, AcceptReject::accept_reject() function attempts find minimum value c satisfies description . Unless compelling reasons provide value c argument AcceptReject::accept_reject() function, recommended use c = NULL (default), allowing value c automatically determined.","code":""},{"path":"/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Acceptance-Rejection Method for Generating Pseudo-Random Observations","text":"package versioned GitHub. can install development version AcceptReject, , must first install remotes package run following command: force = TRUE argument necessary. needed situations already installed package want reinstall new version.","code":"# install.packages(\"remotes\") # or remotes::install_github(\"prdm0/AcceptReject\", force = TRUE) library(AcceptReject)"},{"path":"/index.html","id":"examples","dir":"","previous_headings":"","what":"Examples","title":"Acceptance-Rejection Method for Generating Pseudo-Random Observations","text":"Please note examples use AcceptReject::accept_reject() function generate pseudo-random observations discrete continuous random variables. details, refer function’s documentation Reference Vignette.","code":""},{"path":"/index.html","id":"generating-discrete-observations","dir":"","previous_headings":"Examples","what":"Generating discrete observations","title":"Acceptance-Rejection Method for Generating Pseudo-Random Observations","text":"example, let X ∼ Poisson(λ=0.7). generate n = 1000 observations X using acceptance-rejection method, using AcceptReject::accept_reject() function. Note necessary provide xlim argument. Try set upper limit value probability X assuming value zero close zero. case, choose xlim = c(0, 20), dpois(x = 20, lambda = 0.7) close zero (1.6286586^{-22}).","code":"library(AcceptReject) library(cowplot) # install.packages(\"cowplot\") # Ensuring Reproducibility set.seed(0) simulation <- function(n){ AcceptReject::accept_reject( n = n, f = dpois, continuous = FALSE, args_f = list(lambda = 0.7), xlim = c(0, 20), parallel = TRUE ) } a <- plot(simulation(25L)) b <- plot(simulation(250L)) c <- plot(simulation(2500L)) d <- plot(simulation(25000L)) plot_grid(a, b, c, d, nrow = 2L, labels = c(\"a\", \"b\", \"c\", \"d\"))"},{"path":"/index.html","id":"generating-continuous-observations","dir":"","previous_headings":"","what":"Generating continuous observations","title":"Acceptance-Rejection Method for Generating Pseudo-Random Observations","text":"expand beyond examples generating pseudo-random observations discrete random variables, consider now want generate observations random variable X ∼ 𝒩(μ=0,σ2=1). chose normal distribution familiar form, can choose another distribution desired. , generate n = 2000 observations using acceptance-rejection method. Note continuous = TRUE. accept_reject() function supports, continuous case, specifying base probability density function don’t want use continuous uniform distribution default base. choosing specify another probability density function different uniform one, ’s necessary specify following arguments: f_base: base probability density function; random_base: sampling base probability density function; args_f_base: list parameters base density. default, NULL, continuous uniform distribution xlim used base. least one arguments specified, error occur, continuous uniform distribution xlim still used base. discrete case, user mistakenly specifies arguments, .e., continuous = FALSE, accept_reject() function ignore arguments use discrete uniform distribution base. choose specify base density, ’s convenient inspect comparing base density function theoretical probability density function. inspect() function facilitates task. inspect() function plot base probability density function theoretical probability density function, find intersection densities, display value intersection area plot. important pieces information decide base probability density function specified args_f_base argument value c (default 1) appropriate.","code":"library(AcceptReject) library(cowplot) # install.packages(\"cowplot\") # Ensuring reproducibility set.seed(0) simulation <- function(n){ AcceptReject::accept_reject( n = n, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4), parallel = TRUE ) } # Inspecting a <- plot(simulation(n = 250L)) b <- plot(simulation(n = 2500L)) c <- plot(simulation(n = 25000L)) d <- plot(simulation(n = 250000L)) plot_grid(a, b, c, d, nrow = 2L, labels = c(\"a\", \"b\", \"c\", \"d\"))"},{"path":"/index.html","id":"example-of-inspection","dir":"","previous_headings":"","what":"Example of inspection","title":"Acceptance-Rejection Method for Generating Pseudo-Random Observations","text":"Notice considering distribution scenario “” code convenient. Note area approximately 1, base probability density function parameters shape = 2.8 rate = 1.2 provides shape close theoretical distribution, c = 1.2 ensures base density function upper bounds theoretical probability density function. Therefore, considering f_base Γ(α=2.8,β=1.2) c = 1.2 reasonable choice base distribution. Therefore, passing arguments f_base = dgamma, args_f_base = list(shape = 2.8, rate = 1.2), c = 1.2 accept_reject() function lead us even efficient code. Notice results close graphical analysis. However, execution time specifying convenient base density lower large sample.","code":"library(AcceptReject) library(cowplot) # install.packages(\"cowplot\") # Ensuring reproducibility set.seed(0) # Inspecting # Case a a <- inspect( f = dweibull, args_f = list(shape = 2.1, scale = 2.2), f_base = dgamma, args_f_base = list(shape = 2.8, rate = 1.2), xlim = c(0, 10), c = 1.2 ) # Inspecting # Case b b <- inspect( f = dweibull, args_f = list(shape = 2.1, scale = 2.2), f_base = dgamma, args_f_base = list(shape = 2.9, rate = 2.5), xlim = c(0, 10), c = 1.4 ) plot_grid(a, b, nrow = 2L, labels = c(\"a\", \"b\")) library(AcceptReject) library(tictoc) # install.packages(\"tictoc\") # Ensuring reproducibility set.seed(0) # Não especificando a função densidade de probabilidade base tic() case_1 <- accept_reject( n = 200e3L, continuous = TRUE, f = dweibull, args_f = list(shape = 2.1, scale = 2.2), xlim = c(0, 10) ) toc() #> 7.294 sec elapsed # Specifying the base probability density function tic() case_2 <- accept_reject( n = 200e3L, continuous = TRUE, f = dweibull, args_f = list(shape = 2.1, scale = 2.2), f_base = dgamma, random_base = rgamma, args_f_base = list(shape = 2.8, rate = 1.2), xlim = c(0, 10), c = 1.2 ) toc() #> 2.633 sec elapsed # Visualizing the results p1 <- plot(case_1) p2 <- plot(case_2) plot_grid(p1, p2, nrow = 2L)"},{"path":"/reference/accept_reject.html","id":null,"dir":"Reference","previous_headings":"","what":"Acceptance-Rejection Method — accept_reject","title":"Acceptance-Rejection Method — accept_reject","text":"function implements acceptance-rejection method generating random numbers given probability density function (pdf).","code":""},{"path":"/reference/accept_reject.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Acceptance-Rejection Method — accept_reject","text":"","code":"accept_reject( n = 1L, continuous = TRUE, f = NULL, args_f = NULL, f_base = NULL, random_base = NULL, args_f_base = NULL, xlim = NULL, c = NULL, linesearch_algorithm = \"LBFGS_LINESEARCH_BACKTRACKING_ARMIJO\", max_iterations = 0L, epsilon = 1e-05, start_c = 25, parallel = FALSE, warning = TRUE, ... )"},{"path":"/reference/accept_reject.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Acceptance-Rejection Method — accept_reject","text":"n number random numbers generate. continuous logical value indicating whether pdf continuous discrete. Default TRUE. f probability density function (continuous = TRUE), continuous case probability mass function, discrete case (continuous = FALSE). args_f list arguments passed f function. refers list arguments target distribution. f_base Base probability density function (continuous case).f_base = NULL, uniform distribution used. discrete case, argument ignored, uniform probability mass function used base. random_base Random number generation function base distribution passed argument f_base. random_base = NULL (default), uniform generator used. discrete case, argument disregarded, uniform random number generator function used. args_f_base list arguments base distribution. refers list arguments passed function f_base. disregarded discrete case. xlim vector specifying range values random numbers form c(min, max). Default c(0, 100). c constant value used acceptance-rejection method. NULL, estimated using lbfgs::lbfgs() optimization algorithm. Default NULL. linesearch_algorithm linesearch algorithm used lbfgs::lbfgs() optimization. Default \"LBFGS_LINESEARCH_BACKTRACKING_ARMIJO\". max_iterations maximum number iterations lbfgs::lbfgs() optimization. Default 1000. epsilon convergence criterion lbfgs::lbfgs() optimization. Default 1e-6. start_c initial value constant c lbfgs::lbfgs() optimization. Default 25. parallel logical value indicating whether use parallel processing generating random numbers. Default FALSE. warning logical value indicating whether show warnings. Default TRUE. ... Additional arguments passed lbfgs::lbfgs() optimization algorithm. details, see lbfgs::lbfgs().","code":""},{"path":"/reference/accept_reject.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Acceptance-Rejection Method — accept_reject","text":"vector random numbers generated using acceptance-rejection method. return object class accept_reject, can treated atomic vector.","code":""},{"path":"/reference/accept_reject.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Acceptance-Rejection Method — accept_reject","text":"situations use inversion method (situations possible obtain quantile function) know transformation involves random variable can generate observations, can use acceptance rejection method. Suppose \\(X\\) \\(Y\\) random variables probability density function (pdf) probability function (pf) \\(f\\) \\(g\\), respectively. addition, suppose constant \\(c\\) $$f(x) \\leq c \\cdot g(x), \\quad \\forall x \\\\mathbb{R}.$$ values \\(t\\), \\(f(t)>0\\). use acceptance rejection method generate observations random variable \\(X\\), using algorithm , first find random variable \\(Y\\) pdf pf \\(g\\), satisfies condition. Algorithm Acceptance Rejection Method: 1 - Generate observation \\(y\\) random variable \\(Y\\) pdf/pf \\(g\\); 2 - Generate observation \\(u\\) random variable \\(U\\sim \\mathcal{U} (0, 1)\\); 3 - \\(u < \\frac{f(y)}{cg(y)}\\) accept \\(x = y\\); otherwise reject \\(y\\) observation random variable \\(X\\) return step 1. Proof: consider discrete case, , \\(X\\) \\(Y\\) random variables pf's \\(f\\) \\(g\\), respectively. step 3 algorithm, \\({accept} = {x = y} = u < \\frac{f(y)}{cg(y)}\\). , \\(P(accept | Y = y) = \\frac{P(accept \\cap {Y = y})}{g(y)} = \\frac{P(U \\leq f(y)/cg(y)) \\times g(y)}{g(y)} = \\frac{f(y)}{cg(y)}.\\) Hence, Total Probability Theorem, : \\(P(accept) = \\sum_y P(accept|Y=y)\\times P(Y=y) = \\sum_y \\frac{f(y)}{cg(y)}\\times g(y) = \\frac{1}{c}.\\) Therefore, acceptance rejection method accept occurrence $Y$ occurrence \\(X\\) probability \\(1/c\\). addition, Bayes' Theorem, \\(P(Y = y | accept) = \\frac{P(accept|Y = y)\\times g(y)}{P(accept)} = \\frac{[f(y)/cg(y)] \\times g(y)}{1/c} = f(y).\\) result shows accepting \\(x = y\\) procedure algorithm equivalent accepting value \\(X\\) pf \\(f\\). argument c = NULL default. Thus, function accept_reject() estimates value c using optimization algorithm lbfgs::lbfgs(). details, see lbfgs::lbfgs(). value c provided, function accept_reject() use value generate random observations. inappropriate choice c can lead low efficiency acceptance rejection method. Unix-based operating systems, function accept_reject() can executed parallel. , simply set argument parallel = TRUE. function accept_reject() utilizes parallel::mclapply() function execute acceptance rejection method parallel. Windows operating systems, code parallelized even parallel = TRUE set. continuous case, base density function can used, arguments f_base, random_base args_f_base need passed. least one NULL, function assume uniform density function interval xlim. discrete case, arguments f_base, random_base args_f_base NULL, passed, disregarded, discrete case, discrete uniform distribution always considered base. Sampling discrete uniform distribution shown good performance discrete case.","code":""},{"path":"/reference/accept_reject.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Acceptance-Rejection Method — accept_reject","text":"CASELLA, George; ROBERT, Christian P.; WELLS, Martin T. Generalized accept-reject sampling schemes. Lecture Notes-Monograph Series, p. 342-347, 2004. NEAL, Radford M. Slice sampling. annals statistics, v. 31, n. 3, p. 705-767, 2003. BISHOP, Christopher. 11.4: Slice sampling. Pattern Recognition Machine Learning. Springer, 2006.","code":""},{"path":[]},{"path":"/reference/accept_reject.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Acceptance-Rejection Method — accept_reject","text":"","code":"set.seed(0) # setting a seed for reproducibility x <- accept_reject( n = 2000L, f = dbinom, continuous = FALSE, args_f = list(size = 5, prob = 0.5), xlim = c(0, 10) ) plot(x) y <- accept_reject( n = 1000L, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4) ) plot(y)"},{"path":"/reference/inspect.html","id":null,"dir":"Reference","previous_headings":"","what":"Inspecting the theoretical density with the base density — inspect","title":"Inspecting the theoretical density with the base density — inspect","text":"Inspect probability density function used base theoretical density function observations desired.","code":""},{"path":"/reference/inspect.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Inspecting the theoretical density with the base density — inspect","text":"","code":"inspect( f, args_f, f_base, args_f_base, xlim, c = 1, alpha = 0.4, color_intersection = \"#BB9FC9\", color_f = \"#FE4F0E\", color_f_base = \"#7BBDB3\" )"},{"path":"/reference/inspect.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Inspecting the theoretical density with the base density — inspect","text":"f Theoretical density function. args_f List arguments theoretical density function. f_base Base density function. args_f_base List arguments base density function. xlim range x-axis. c constant covers base density function, \\(c \\geq 1\\). default value 1. alpha transparency base density function. default value 0.4 color_intersection Color intersection base density function theoretical density functions. color_f Color base density function. color_f_base Color theoretical density function.","code":""},{"path":"/reference/inspect.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Inspecting the theoretical density with the base density — inspect","text":"object gg ggplot class comparing theoretical density function base density function. object shows compared density functions, intersection area , value area.","code":""},{"path":"/reference/inspect.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Inspecting the theoretical density with the base density — inspect","text":"function inspect() returns object gg ggplot class compares probability density two functions useful discrete case, continuous one. Finding parameters base distribution best approximate theoretical distribution smallest value c can cover base distribution great strategy. Something important note plot provides value area intersection theoretical probability density function want generate observations probability density function used base. desirable value close 1 possible, ideally intersection area probability density functions 1, means base probability density function passed f_base argument overlaps theoretical density function passed f argument. crucial acceptance-rejection method. However, even use inspect() function find suitable distribution, finding viable args_base (list arguments passed f_base) value c intersection area 1, accept_reject() function already . inspect() function helpful finding suitable base distribution, increases probability acceptance, reducing computational cost. Therefore, inspecting good practice. use accept_reject() function, even parallelism enabled specifying parallel = TRUE accept_reject() find generation time high needs, consider inspecting base distribution.","code":""},{"path":[]},{"path":"/reference/inspect.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Inspecting the theoretical density with the base density — inspect","text":"","code":"# Considering c = 1 (default) inspect( f = dweibull, f_base = dgamma, xlim = c(0,5), args_f = list(shape = 2, scale = 1), args_f_base = list(shape = 2.1, rate = 2), c = 1 ) # Considering c = 1.35. inspect( f = dweibull, f_base = dgamma, xlim = c(0,5), args_f = list(shape = 2, scale = 1), args_f_base = list(shape = 2.1, rate = 2), c = 1.35 ) # Plotting f equal to f_base. This would be the best-case scenario, which, # in practice, is unlikely. inspect( f = dgamma, f_base = dgamma, xlim = c(0,5), args_f = list(shape = 2.1, rate = 2), args_f_base = list(shape = 2.1, rate = 2), c = 1 )"},{"path":"/reference/plot.accept_reject.html","id":null,"dir":"Reference","previous_headings":"","what":"Plot Accept-Reject — plot.accept_reject","title":"Plot Accept-Reject — plot.accept_reject","text":"Inspects probability function (discrete case) probability density (continuous case) comparing theoretical case observed one.","code":""},{"path":"/reference/plot.accept_reject.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Plot Accept-Reject — plot.accept_reject","text":"","code":"# S3 method for accept_reject plot( x, color_observed_density = \"#BB9FC9\", color_true_density = \"#FE4F0E\", color_bar = \"#BB9FC9\", color_observable_point = \"#7BBDB3\", color_real_point = \"#FE4F0E\", alpha = 0.3, hist = TRUE, ... )"},{"path":"/reference/plot.accept_reject.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Plot Accept-Reject — plot.accept_reject","text":"x object class accept reject color_observed_density Observed density color (continuous case). color_true_density True histogram density color (continuous case) color_bar Bar chart fill color (discrete case) color_observable_point Color generated points (discrete case) color_real_point Color real probability points (discrete case) alpha Bar chart transparency (discrete case) observed density (continuous case) hist TRUE, histogram plotted continuous case, comparing theoretical density observed one. FALSE, ggplot2::geom_density() used instead histogram. ... Additional arguments.","code":""},{"path":"/reference/plot.accept_reject.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Plot Accept-Reject — plot.accept_reject","text":"object class gg ggplot package ggplot2. function plot.accept_reject() expects object class accept_reject argument.","code":""},{"path":"/reference/plot.accept_reject.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Plot Accept-Reject — plot.accept_reject","text":"function plot.accept_reject() responsible plotting probability function (discrete case) probability density (continuous case), comparing theoretical case observed one. useful, therefore, inspecting quality samples generated acceptance-rejection method. returned plot object classes gg ggplot. Easily, can customize plot. function plot.accept_reject(), simply plot(), constructs plot inspection expects object class accept_reject argument.","code":""},{"path":[]},{"path":"/reference/plot.accept_reject.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Plot Accept-Reject — plot.accept_reject","text":"","code":"x <- accept_reject( n = 1000L, f = dbinom, continuous = FALSE, args_f = list(size = 5, prob = 0.5), xlim = c(0, 10) ) plot(x) y <- accept_reject( n = 500L, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4) ) plot(y)"},{"path":"/reference/print.accept_reject.html","id":null,"dir":"Reference","previous_headings":"","what":"Print method for accept_reject objects — print.accept_reject","title":"Print method for accept_reject objects — print.accept_reject","text":"Print method accept_reject objects","code":""},{"path":"/reference/print.accept_reject.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Print method for accept_reject objects — print.accept_reject","text":"","code":"# S3 method for accept_reject print(x, n_min = 10L, ...)"},{"path":"/reference/print.accept_reject.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Print method for accept_reject objects — print.accept_reject","text":"x accept_reject object n_min Minimum number observations print ... Additional arguments","code":""},{"path":"/reference/print.accept_reject.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Print method for accept_reject objects — print.accept_reject","text":"object class character, providing formatted output information accept_reject object, including number observations, value constant \\(c\\) maximizes acceptance, acceptance probability \\(1/c\\). Additionally, prints first generated observations. function print.accept_reject() enables formatting executing object class 'accept_reject' console executing function print() object class accept_reject, returned function accept_reject().","code":""},{"path":"/reference/print.accept_reject.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Print method for accept_reject objects — print.accept_reject","text":"function print.accept_reject() responsible printing object class accept_reject formatted manner, providing information accept_reject object, including number observations, value constant \\(c\\) maximizes acceptance, acceptance probability \\(1/c\\). Additionally, prints first generated observations. function print.accept_reject() delivers formatted output executing object class accept_reject console executing function print() object class accept_reject, returned function accept_reject().","code":""},{"path":[]},{"path":"/reference/print.accept_reject.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Print method for accept_reject objects — print.accept_reject","text":"","code":"set.seed(0) # setting a seed for reproducibility x = accept_reject( n = 2000L, f = dbinom, continuous = FALSE, args_f = list(size = 5, prob = 0.5), xlim = c(0, 10) ) print(x) #> #> ── Accept-Reject Samples ─────────────────────────────────────────────────────── #> #> ℹ It's not necessary, but if you want to extract the observations, use as.vector(). #> #> ✔ Case: discrete #> ✔ Number of observations: 2000 #> ✔ c: 25 #> ✔ Probability of acceptance (1/c): 0.04 #> ✔ Observations: 3 2 2 2 2 1 4 2 3 2... #> ✔ xlim = 0 10 #> #> ────────────────────────────────────────────────────────────────────────────────"},{"path":"/news/index.html","id":"acceptreject-010","dir":"Changelog","previous_headings":"","what":"AcceptReject 0.1.0","title":"AcceptReject 0.1.0","text":"CRAN release: 2024-04-11 Initial CRAN submission.","code":""},{"path":"/news/index.html","id":"acceptreject-011","dir":"Changelog","previous_headings":"","what":"AcceptReject 0.1.1","title":"AcceptReject 0.1.1","text":"Improved performance serial parallel processing; Now possible specify different base density/probability mass function uniform one. none specified, uniform density (either discrete continuous) assumed case discrete continuous random variables, respectively; Now function inspect() available, allowing compare base probability density function theoretical density function. inspect() function useful finding reasonable base density function. returns object classes gg ggplot density curves, intersection area, value intersection. Users obligated use inspect() function since accept_reject() function already takes care lot. However, continuous case, providing f_base argument accept_reject() function good candidate base density function can good idea. generating observations continuous random variables, using histogram breaks R graphics hist() function, histogram created ggplot2; Providing alerts regarding limits passed xlim argument accept_reject() function. significant density/probability mass present, warning issued. alert can omitted setting warning = FALSE; plot.accept_reject() function, ’s additional argument hist = TRUE (default). hist = TRUE, histogram plotted along base density, case generating pseudo-random observations continuous random variable. hist = FALSE, theoretical density plotted alongside observed density; print.accept_reject() function now informs whether case discrete continuous xlim; Putting order specifications arguments exported functions order arguments functions; warning messages improved; Bug fix.","code":""}] +[{"path":"/LICENSE.html","id":null,"dir":"","previous_headings":"","what":"GNU General Public License","title":"GNU General Public License","text":"Version 3, 29 June 2007Copyright © 2007 Free Software Foundation, Inc.  Everyone permitted copy distribute verbatim copies license document, changing allowed.","code":""},{"path":"/LICENSE.html","id":"preamble","dir":"","previous_headings":"","what":"Preamble","title":"GNU General Public License","text":"GNU General Public License free, copyleft license software kinds works. licenses software practical works designed take away freedom share change works. contrast, GNU General Public License intended guarantee freedom share change versions program–make sure remains free software users. , Free Software Foundation, use GNU General Public License software; applies also work released way authors. can apply programs, . speak free software, referring freedom, price. General Public Licenses designed make sure freedom distribute copies free software (charge wish), receive source code can get want , can change software use pieces new free programs, know can things. protect rights, need prevent others denying rights asking surrender rights. Therefore, certain responsibilities distribute copies software, modify : responsibilities respect freedom others. example, distribute copies program, whether gratis fee, must pass recipients freedoms received. must make sure , , receive can get source code. must show terms know rights. Developers use GNU GPL protect rights two steps: (1) assert copyright software, (2) offer License giving legal permission copy, distribute /modify . developers’ authors’ protection, GPL clearly explains warranty free software. users’ authors’ sake, GPL requires modified versions marked changed, problems attributed erroneously authors previous versions. devices designed deny users access install run modified versions software inside , although manufacturer can . fundamentally incompatible aim protecting users’ freedom change software. systematic pattern abuse occurs area products individuals use, precisely unacceptable. Therefore, designed version GPL prohibit practice products. problems arise substantially domains, stand ready extend provision domains future versions GPL, needed protect freedom users. Finally, every program threatened constantly software patents. States allow patents restrict development use software general-purpose computers, , wish avoid special danger patents applied free program make effectively proprietary. prevent , GPL assures patents used render program non-free. precise terms conditions copying, distribution modification follow.","code":""},{"path":[]},{"path":"/LICENSE.html","id":"id_0-definitions","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"0. Definitions","title":"GNU General Public License","text":"“License” refers version 3 GNU General Public License. “Copyright” also means copyright-like laws apply kinds works, semiconductor masks. “Program” refers copyrightable work licensed License. licensee addressed “”. “Licensees” “recipients” may individuals organizations. “modify” work means copy adapt part work fashion requiring copyright permission, making exact copy. resulting work called “modified version” earlier work work “based ” earlier work. “covered work” means either unmodified Program work based Program. “propagate” work means anything , without permission, make directly secondarily liable infringement applicable copyright law, except executing computer modifying private copy. Propagation includes copying, distribution (without modification), making available public, countries activities well. “convey” work means kind propagation enables parties make receive copies. Mere interaction user computer network, transfer copy, conveying. interactive user interface displays “Appropriate Legal Notices” extent includes convenient prominently visible feature (1) displays appropriate copyright notice, (2) tells user warranty work (except extent warranties provided), licensees may convey work License, view copy License. interface presents list user commands options, menu, prominent item list meets criterion.","code":""},{"path":"/LICENSE.html","id":"id_1-source-code","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"1. Source Code","title":"GNU General Public License","text":"“source code” work means preferred form work making modifications . “Object code” means non-source form work. “Standard Interface” means interface either official standard defined recognized standards body, , case interfaces specified particular programming language, one widely used among developers working language. “System Libraries” executable work include anything, work whole, () included normal form packaging Major Component, part Major Component, (b) serves enable use work Major Component, implement Standard Interface implementation available public source code form. “Major Component”, context, means major essential component (kernel, window system, ) specific operating system () executable work runs, compiler used produce work, object code interpreter used run . “Corresponding Source” work object code form means source code needed generate, install, (executable work) run object code modify work, including scripts control activities. However, include work’s System Libraries, general-purpose tools generally available free programs used unmodified performing activities part work. example, Corresponding Source includes interface definition files associated source files work, source code shared libraries dynamically linked subprograms work specifically designed require, intimate data communication control flow subprograms parts work. Corresponding Source need include anything users can regenerate automatically parts Corresponding Source. Corresponding Source work source code form work.","code":""},{"path":"/LICENSE.html","id":"id_2-basic-permissions","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"2. Basic Permissions","title":"GNU General Public License","text":"rights granted License granted term copyright Program, irrevocable provided stated conditions met. License explicitly affirms unlimited permission run unmodified Program. output running covered work covered License output, given content, constitutes covered work. License acknowledges rights fair use equivalent, provided copyright law. may make, run propagate covered works convey, without conditions long license otherwise remains force. may convey covered works others sole purpose make modifications exclusively , provide facilities running works, provided comply terms License conveying material control copyright. thus making running covered works must exclusively behalf, direction control, terms prohibit making copies copyrighted material outside relationship . Conveying circumstances permitted solely conditions stated . Sublicensing allowed; section 10 makes unnecessary.","code":""},{"path":"/LICENSE.html","id":"id_3-protecting-users-legal-rights-from-anti-circumvention-law","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"3. Protecting Users’ Legal Rights From Anti-Circumvention Law","title":"GNU General Public License","text":"covered work shall deemed part effective technological measure applicable law fulfilling obligations article 11 WIPO copyright treaty adopted 20 December 1996, similar laws prohibiting restricting circumvention measures. convey covered work, waive legal power forbid circumvention technological measures extent circumvention effected exercising rights License respect covered work, disclaim intention limit operation modification work means enforcing, work’s users, third parties’ legal rights forbid circumvention technological measures.","code":""},{"path":"/LICENSE.html","id":"id_4-conveying-verbatim-copies","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"4. Conveying Verbatim Copies","title":"GNU General Public License","text":"may convey verbatim copies Program’s source code receive , medium, provided conspicuously appropriately publish copy appropriate copyright notice; keep intact notices stating License non-permissive terms added accord section 7 apply code; keep intact notices absence warranty; give recipients copy License along Program. may charge price price copy convey, may offer support warranty protection fee.","code":""},{"path":"/LICENSE.html","id":"id_5-conveying-modified-source-versions","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"5. Conveying Modified Source Versions","title":"GNU General Public License","text":"may convey work based Program, modifications produce Program, form source code terms section 4, provided also meet conditions: ) work must carry prominent notices stating modified , giving relevant date. b) work must carry prominent notices stating released License conditions added section 7. requirement modifies requirement section 4 “keep intact notices”. c) must license entire work, whole, License anyone comes possession copy. License therefore apply, along applicable section 7 additional terms, whole work, parts, regardless packaged. License gives permission license work way, invalidate permission separately received . d) work interactive user interfaces, must display Appropriate Legal Notices; however, Program interactive interfaces display Appropriate Legal Notices, work need make . compilation covered work separate independent works, nature extensions covered work, combined form larger program, volume storage distribution medium, called “aggregate” compilation resulting copyright used limit access legal rights compilation’s users beyond individual works permit. Inclusion covered work aggregate cause License apply parts aggregate.","code":""},{"path":"/LICENSE.html","id":"id_6-conveying-non-source-forms","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"6. Conveying Non-Source Forms","title":"GNU General Public License","text":"may convey covered work object code form terms sections 4 5, provided also convey machine-readable Corresponding Source terms License, one ways: ) Convey object code , embodied , physical product (including physical distribution medium), accompanied Corresponding Source fixed durable physical medium customarily used software interchange. b) Convey object code , embodied , physical product (including physical distribution medium), accompanied written offer, valid least three years valid long offer spare parts customer support product model, give anyone possesses object code either (1) copy Corresponding Source software product covered License, durable physical medium customarily used software interchange, price reasonable cost physically performing conveying source, (2) access copy Corresponding Source network server charge. c) Convey individual copies object code copy written offer provide Corresponding Source. alternative allowed occasionally noncommercially, received object code offer, accord subsection 6b. d) Convey object code offering access designated place (gratis charge), offer equivalent access Corresponding Source way place charge. need require recipients copy Corresponding Source along object code. place copy object code network server, Corresponding Source may different server (operated third party) supports equivalent copying facilities, provided maintain clear directions next object code saying find Corresponding Source. Regardless server hosts Corresponding Source, remain obligated ensure available long needed satisfy requirements. e) Convey object code using peer--peer transmission, provided inform peers object code Corresponding Source work offered general public charge subsection 6d. separable portion object code, whose source code excluded Corresponding Source System Library, need included conveying object code work. “User Product” either (1) “consumer product”, means tangible personal property normally used personal, family, household purposes, (2) anything designed sold incorporation dwelling. determining whether product consumer product, doubtful cases shall resolved favor coverage. particular product received particular user, “normally used” refers typical common use class product, regardless status particular user way particular user actually uses, expects expected use, product. product consumer product regardless whether product substantial commercial, industrial non-consumer uses, unless uses represent significant mode use product. “Installation Information” User Product means methods, procedures, authorization keys, information required install execute modified versions covered work User Product modified version Corresponding Source. information must suffice ensure continued functioning modified object code case prevented interfered solely modification made. convey object code work section , , specifically use , User Product, conveying occurs part transaction right possession use User Product transferred recipient perpetuity fixed term (regardless transaction characterized), Corresponding Source conveyed section must accompanied Installation Information. requirement apply neither third party retains ability install modified object code User Product (example, work installed ROM). requirement provide Installation Information include requirement continue provide support service, warranty, updates work modified installed recipient, User Product modified installed. Access network may denied modification materially adversely affects operation network violates rules protocols communication across network. Corresponding Source conveyed, Installation Information provided, accord section must format publicly documented (implementation available public source code form), must require special password key unpacking, reading copying.","code":""},{"path":"/LICENSE.html","id":"id_7-additional-terms","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"7. Additional Terms","title":"GNU General Public License","text":"“Additional permissions” terms supplement terms License making exceptions one conditions. Additional permissions applicable entire Program shall treated though included License, extent valid applicable law. additional permissions apply part Program, part may used separately permissions, entire Program remains governed License without regard additional permissions. convey copy covered work, may option remove additional permissions copy, part . (Additional permissions may written require removal certain cases modify work.) may place additional permissions material, added covered work, can give appropriate copyright permission. Notwithstanding provision License, material add covered work, may (authorized copyright holders material) supplement terms License terms: ) Disclaiming warranty limiting liability differently terms sections 15 16 License; b) Requiring preservation specified reasonable legal notices author attributions material Appropriate Legal Notices displayed works containing ; c) Prohibiting misrepresentation origin material, requiring modified versions material marked reasonable ways different original version; d) Limiting use publicity purposes names licensors authors material; e) Declining grant rights trademark law use trade names, trademarks, service marks; f) Requiring indemnification licensors authors material anyone conveys material (modified versions ) contractual assumptions liability recipient, liability contractual assumptions directly impose licensors authors. non-permissive additional terms considered “restrictions” within meaning section 10. Program received , part , contains notice stating governed License along term restriction, may remove term. license document contains restriction permits relicensing conveying License, may add covered work material governed terms license document, provided restriction survive relicensing conveying. add terms covered work accord section, must place, relevant source files, statement additional terms apply files, notice indicating find applicable terms. Additional terms, permissive non-permissive, may stated form separately written license, stated exceptions; requirements apply either way.","code":""},{"path":"/LICENSE.html","id":"id_8-termination","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"8. Termination","title":"GNU General Public License","text":"may propagate modify covered work except expressly provided License. attempt otherwise propagate modify void, automatically terminate rights License (including patent licenses granted third paragraph section 11). However, cease violation License, license particular copyright holder reinstated () provisionally, unless copyright holder explicitly finally terminates license, (b) permanently, copyright holder fails notify violation reasonable means prior 60 days cessation. Moreover, license particular copyright holder reinstated permanently copyright holder notifies violation reasonable means, first time received notice violation License (work) copyright holder, cure violation prior 30 days receipt notice. Termination rights section terminate licenses parties received copies rights License. rights terminated permanently reinstated, qualify receive new licenses material section 10.","code":""},{"path":"/LICENSE.html","id":"id_9-acceptance-not-required-for-having-copies","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"9. Acceptance Not Required for Having Copies","title":"GNU General Public License","text":"required accept License order receive run copy Program. Ancillary propagation covered work occurring solely consequence using peer--peer transmission receive copy likewise require acceptance. However, nothing License grants permission propagate modify covered work. actions infringe copyright accept License. Therefore, modifying propagating covered work, indicate acceptance License .","code":""},{"path":"/LICENSE.html","id":"id_10-automatic-licensing-of-downstream-recipients","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"10. Automatic Licensing of Downstream Recipients","title":"GNU General Public License","text":"time convey covered work, recipient automatically receives license original licensors, run, modify propagate work, subject License. responsible enforcing compliance third parties License. “entity transaction” transaction transferring control organization, substantially assets one, subdividing organization, merging organizations. propagation covered work results entity transaction, party transaction receives copy work also receives whatever licenses work party’s predecessor interest give previous paragraph, plus right possession Corresponding Source work predecessor interest, predecessor can get reasonable efforts. may impose restrictions exercise rights granted affirmed License. example, may impose license fee, royalty, charge exercise rights granted License, may initiate litigation (including cross-claim counterclaim lawsuit) alleging patent claim infringed making, using, selling, offering sale, importing Program portion .","code":""},{"path":"/LICENSE.html","id":"id_11-patents","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"11. Patents","title":"GNU General Public License","text":"“contributor” copyright holder authorizes use License Program work Program based. work thus licensed called contributor’s “contributor version”. contributor’s “essential patent claims” patent claims owned controlled contributor, whether already acquired hereafter acquired, infringed manner, permitted License, making, using, selling contributor version, include claims infringed consequence modification contributor version. purposes definition, “control” includes right grant patent sublicenses manner consistent requirements License. contributor grants non-exclusive, worldwide, royalty-free patent license contributor’s essential patent claims, make, use, sell, offer sale, import otherwise run, modify propagate contents contributor version. following three paragraphs, “patent license” express agreement commitment, however denominated, enforce patent (express permission practice patent covenant sue patent infringement). “grant” patent license party means make agreement commitment enforce patent party. convey covered work, knowingly relying patent license, Corresponding Source work available anyone copy, free charge terms License, publicly available network server readily accessible means, must either (1) cause Corresponding Source available, (2) arrange deprive benefit patent license particular work, (3) arrange, manner consistent requirements License, extend patent license downstream recipients. “Knowingly relying” means actual knowledge , patent license, conveying covered work country, recipient’s use covered work country, infringe one identifiable patents country reason believe valid. , pursuant connection single transaction arrangement, convey, propagate procuring conveyance , covered work, grant patent license parties receiving covered work authorizing use, propagate, modify convey specific copy covered work, patent license grant automatically extended recipients covered work works based . patent license “discriminatory” include within scope coverage, prohibits exercise , conditioned non-exercise one rights specifically granted License. may convey covered work party arrangement third party business distributing software, make payment third party based extent activity conveying work, third party grants, parties receive covered work , discriminatory patent license () connection copies covered work conveyed (copies made copies), (b) primarily connection specific products compilations contain covered work, unless entered arrangement, patent license granted, prior 28 March 2007. Nothing License shall construed excluding limiting implied license defenses infringement may otherwise available applicable patent law.","code":""},{"path":"/LICENSE.html","id":"id_12-no-surrender-of-others-freedom","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"12. No Surrender of Others’ Freedom","title":"GNU General Public License","text":"conditions imposed (whether court order, agreement otherwise) contradict conditions License, excuse conditions License. convey covered work satisfy simultaneously obligations License pertinent obligations, consequence may convey . example, agree terms obligate collect royalty conveying convey Program, way satisfy terms License refrain entirely conveying Program.","code":""},{"path":"/LICENSE.html","id":"id_13-use-with-the-gnu-affero-general-public-license","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"13. Use with the GNU Affero General Public License","title":"GNU General Public License","text":"Notwithstanding provision License, permission link combine covered work work licensed version 3 GNU Affero General Public License single combined work, convey resulting work. terms License continue apply part covered work, special requirements GNU Affero General Public License, section 13, concerning interaction network apply combination .","code":""},{"path":"/LICENSE.html","id":"id_14-revised-versions-of-this-license","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"14. Revised Versions of this License","title":"GNU General Public License","text":"Free Software Foundation may publish revised /new versions GNU General Public License time time. new versions similar spirit present version, may differ detail address new problems concerns. version given distinguishing version number. Program specifies certain numbered version GNU General Public License “later version” applies , option following terms conditions either numbered version later version published Free Software Foundation. Program specify version number GNU General Public License, may choose version ever published Free Software Foundation. Program specifies proxy can decide future versions GNU General Public License can used, proxy’s public statement acceptance version permanently authorizes choose version Program. Later license versions may give additional different permissions. However, additional obligations imposed author copyright holder result choosing follow later version.","code":""},{"path":"/LICENSE.html","id":"id_15-disclaimer-of-warranty","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"15. Disclaimer of Warranty","title":"GNU General Public License","text":"WARRANTY PROGRAM, EXTENT PERMITTED APPLICABLE LAW. EXCEPT OTHERWISE STATED WRITING COPYRIGHT HOLDERS /PARTIES PROVIDE PROGRAM “” WITHOUT WARRANTY KIND, EITHER EXPRESSED IMPLIED, INCLUDING, LIMITED , IMPLIED WARRANTIES MERCHANTABILITY FITNESS PARTICULAR PURPOSE. ENTIRE RISK QUALITY PERFORMANCE PROGRAM . PROGRAM PROVE DEFECTIVE, ASSUME COST NECESSARY SERVICING, REPAIR CORRECTION.","code":""},{"path":"/LICENSE.html","id":"id_16-limitation-of-liability","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"16. Limitation of Liability","title":"GNU General Public License","text":"EVENT UNLESS REQUIRED APPLICABLE LAW AGREED WRITING COPYRIGHT HOLDER, PARTY MODIFIES /CONVEYS PROGRAM PERMITTED , LIABLE DAMAGES, INCLUDING GENERAL, SPECIAL, INCIDENTAL CONSEQUENTIAL DAMAGES ARISING USE INABILITY USE PROGRAM (INCLUDING LIMITED LOSS DATA DATA RENDERED INACCURATE LOSSES SUSTAINED THIRD PARTIES FAILURE PROGRAM OPERATE PROGRAMS), EVEN HOLDER PARTY ADVISED POSSIBILITY DAMAGES.","code":""},{"path":"/LICENSE.html","id":"id_17-interpretation-of-sections-15-and-16","dir":"","previous_headings":"TERMS AND CONDITIONS","what":"17. Interpretation of Sections 15 and 16","title":"GNU General Public License","text":"disclaimer warranty limitation liability provided given local legal effect according terms, reviewing courts shall apply local law closely approximates absolute waiver civil liability connection Program, unless warranty assumption liability accompanies copy Program return fee. END TERMS CONDITIONS","code":""},{"path":"/LICENSE.html","id":"how-to-apply-these-terms-to-your-new-programs","dir":"","previous_headings":"","what":"How to Apply These Terms to Your New Programs","title":"GNU General Public License","text":"develop new program, want greatest possible use public, best way achieve make free software everyone can redistribute change terms. , attach following notices program. safest attach start source file effectively state exclusion warranty; file least “copyright” line pointer full notice found. Also add information contact electronic paper mail. program terminal interaction, make output short notice like starts interactive mode: hypothetical commands show w show c show appropriate parts General Public License. course, program’s commands might different; GUI interface, use “box”. also get employer (work programmer) school, , sign “copyright disclaimer” program, necessary. information , apply follow GNU GPL, see . GNU General Public License permit incorporating program proprietary programs. program subroutine library, may consider useful permit linking proprietary applications library. want , use GNU Lesser General Public License instead License. first, please read .","code":" Copyright (C) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type 'show w'. This is free software, and you are welcome to redistribute it under certain conditions; type 'show c' for details."},{"path":"/articles/accept_reject.html","id":"understanding-the-method","dir":"Articles","previous_headings":"","what":"Understanding the Method","title":"Acceptance and rejection method","text":"situations use inversion method (situations obtaining quantile function possible) neither know transformation involving random variable can generate observations, can make use acceptance-rejection method. Suppose \\(X\\) \\(Y\\) random variables probability density function (pdf) probability function (pf) \\(f\\) \\(g\\), respectively. Furthermore, suppose exists constant \\(c\\) \\[\\frac{f(x)}{g(y)} \\leq c,\\] every value \\(x\\), \\(f(x) > 0\\). use acceptance-rejection method generate observations random variable \\(X\\), using algorithm , first find random variable \\(Y\\) pdf pf \\(g\\), satisfies condition. Important: important chosen random variable \\(Y\\) can easily generate observations. acceptance-rejection method computationally intensive direct methods transformation method inversion method, requires generation pseudo-random numbers uniform distribution. Algorithm Acceptance-Rejection Method: 1 - Generate observation \\(y\\) random variable \\(Y\\) pdf/pf \\(g\\); 2 - Generate observation \\(u\\) random variable \\(U\\sim \\mathcal{U} (0, 1)\\); 3 - \\(u < \\frac{f(y)}{cg(y)}\\) accept \\(x = y\\); otherwise reject \\(y\\) observation random variable \\(X\\) go back step 1. Proof: Consider discrete case, , \\(X\\) \\(Y\\) random variables pfs \\(f\\) \\(g\\), respectively. step 3 algorithm , \\(\\{accept\\} = \\{x = y\\} = u < \\frac{f(y)}{cg(y)}\\). , \\[P(accept | Y = y) = \\frac{P(accept \\cap \\{Y = y\\})}{g(y)} = \\frac{P(U \\leq f(y)/cg(y)) \\times g(y)}{g(y)} = \\frac{f(y)}{cg(y)}.\\] Hence, Law Total Probability, : \\[P(accept) = \\sum_y P(accept|Y=y)\\times P(Y=y) = \\sum_y \\frac{f(y)}{cg(y)}\\times g(y) = \\frac{1}{c}.\\] Therefore, acceptance-rejection method, accept occurrence \\(Y\\) occurrence \\(X\\) probability \\(1/c\\). Moreover, Bayes’ Theorem, \\[P(Y = y | accept) = \\frac{P(accept|Y = y)\\times g(y)}{P(accept)} = \\frac{[f(y)/cg(y)] \\times g(y)}{1/c} = f(y).\\] result shows accepting \\(x = y\\) algorithm’s procedure equivalent accepting value \\(X\\) pf \\(f\\). continuous case, proof similar. Important: Notice reduce computational cost method, choose \\(c\\) way can maximize \\(P(accept)\\). Therefore, choosing excessively large value constant \\(c\\) reduce probability accepting observation \\(Y\\) observation random variable \\(X\\). Note: Computationally, convenient consider \\(Y\\) random variable uniform distribution support \\(f\\), since generating observations uniform distribution straightforward computer. discrete case, considering \\(Y\\) discrete uniform distribution might good alternative.","code":""},{"path":"/articles/accept_reject.html","id":"installation-and-loading-the-package","dir":"Articles","previous_headings":"","what":"Installation and loading the package","title":"Acceptance and rejection method","text":"AcceptReject package available CRAN can installed using following command:","code":"install.packages(\"AcceptReject\") # or install.packages(\"remotes\") remotes::install_github(\"prdm0/AcceptReject\", force = TRUE) # Load the package library(AcceptReject)"},{"path":"/articles/accept_reject.html","id":"using-the-accept_reject-function","dir":"Articles","previous_headings":"Installation and loading the package","what":"Using the accept_reject Function","title":"Acceptance and rejection method","text":"Among various functions provided AcceptReject library, acceptance_rejection function implements acceptance-rejection method. AcceptReject::accept_reject() function following signature: Many arguments user need change, AcceptReject::accept_reject() function already default values . However, important note f argument probability density function (pdf) probability function (pf) random variable \\(X\\) observations desired generated. args_f argument list arguments passed f function. c argument value constant c used acceptance-rejection method. user provide value c, AcceptReject::accept_reject() function calculate value c maximizes probability accepting observations \\(Y\\) observations \\(X\\). Note: need define c argument using AcceptReject::accept_reject() function. default, c = NULL, AcceptReject::accept_reject() function calculate value c maximizes probability accepting observations \\(Y\\) observations \\(X\\). However, want set value c, simply pass value c argument. Details optimization c: arguments linesearch_algorithm, max_iterations, epsilon, start_c, ... arguments control optimization algorithm c value. linesearch_algorithm argument line search algorithm used optimization c value. max_iterations argument maximum number iterations optimization algorithm perform. epsilon argument stopping criterion optimization algorithm. start_c argument initial value c used optimization algorithm. arguments passed lbfgs::lbfgs() function, generally, need change .","code":"accept_reject( n = 1L, continuous = TRUE, f = dweibull, args_f = list(shape = 1, scale = 1), xlim = c(0, 100), c = NULL, linesearch_algorithm = \"LBFGS_LINESEARCH_BACKTRACKING_ARMIJO\", max_iterations = 1000L, epsilon = 1e-06, start_c = 25, parallel = FALSE, ... )"},{"path":"/articles/accept_reject.html","id":"examples","dir":"Articles","previous_headings":"","what":"Examples","title":"Acceptance and rejection method","text":"examples using AcceptReject::accept_reject() function generate pseudo-random observations discrete continuous random variables. noted case \\(X\\) discrete random variable, necessary provide argument continuous = FALSE, whereas case \\(X\\) continuous (default), must consider continuous = TRUE.","code":""},{"path":"/articles/accept_reject.html","id":"generating-discrete-observations","dir":"Articles","previous_headings":"Examples","what":"Generating discrete observations","title":"Acceptance and rejection method","text":"example, let \\(X \\sim Poisson(\\lambda = 0.7)\\). generate \\(n = 1000\\) observations \\(X\\) using acceptance-rejection method, using AcceptReject::accept_reject() function. Note necessary provide xlim argument. Try set upper limit value probability \\(X\\) assuming value zero close zero. case, choose xlim = c(0, 20), dpois(x = 20, lambda = 0.7) close zero (1.6286586^{-22}). Note necessary specify nature random variable observations desired generated. case discrete variables, argument continuous = FALSE must passed. Now, consider want generate observations random variable \\(X \\sim Binomial(n = 5, p = 0.7)\\). , generate \\(n = 2000\\) observations \\(X\\).","code":"library(AcceptReject) # Ensuring Reproducibility set.seed(0) # Generating observations data <- AcceptReject::accept_reject( n = 1000L, f = dpois, continuous = FALSE, args_f = list(lambda = 0.7), xlim = c(0, 20), parallel = FALSE ) # Viewing organized output with useful information print(data) #> #> ── Accept-Reject Samples ─────────────────────────────────────────────────────── #> ℹ It's not necessary, but if you want to extract the observations, use as.vector(). #> ✔ Case: discrete #> ✔ Number of observations: 1000 #> ✔ c: 25 #> ✔ Probability of acceptance (1/c): 0.04 #> ✔ Observations: 1 0 0 0 1 1 2 1 0 0... #> ✔ xlim = 0 20 #> #> ──────────────────────────────────────────────────────────────────────────────── # Calculating the true probability function for each observed value values <- unique(data) true_prob <- dpois(values, lambda = 0.7) # Calculating the observed probability for each value in the observations vector obs_prob <- table(data) / length(data) # Plotting the probabilities and observations plot(values, true_prob, type = \"p\", pch = 16, col = \"blue\", xlab = \"x\", ylab = \"Probability\", main = \"Probability Function\") # Adding the observed probabilities points(as.numeric(names(obs_prob)), obs_prob, pch = 16L, col = \"red\") legend(\"topright\", legend = c(\"True probability\", \"Observed probability\"), col = c(\"blue\", \"red\"), pch = 16L, cex = 0.8) grid() library(AcceptReject) # Ensuring reproducibility set.seed(0) # Generating observations data <- AcceptReject::accept_reject( n = 2000L, f = dbinom, continuous = FALSE, args_f = list(size = 5, prob = 0.5), xlim = c(0, 20), parallel = FALSE ) # Viewing organized output with useful information print(data) #> #> ── Accept-Reject Samples ─────────────────────────────────────────────────────── #> ℹ It's not necessary, but if you want to extract the observations, use as.vector(). #> ✔ Case: discrete #> ✔ Number of observations: 2000 #> ✔ c: 25 #> ✔ Probability of acceptance (1/c): 0.04 #> ✔ Observations: 2 3 1 2 4 3 3 3 3 2... #> ✔ xlim = 0 20 #> #> ──────────────────────────────────────────────────────────────────────────────── # Calculating the true probability function for each observed value values <- unique(data) true_prob <- dbinom(values, size = 5, prob = 0.5) # Calculating the observed probability for each value in the observations vector obs_prob <- table(data) / length(data) # Plotting the probabilities and observations plot(values, true_prob, type = \"p\", pch = 16, col = \"blue\", xlab = \"x\", ylab = \"Probability\", main = \"Probability Function\") # Adding the observed probabilities points(as.numeric(names(obs_prob)), obs_prob, pch = 16L, col = \"red\") legend(\"topright\", legend = c(\"True probability\", \"Observed probability\"), col = c(\"blue\", \"red\"), pch = 16L, cex = 0.8) grid()"},{"path":"/articles/accept_reject.html","id":"generating-continuous-observations","dir":"Articles","previous_headings":"Examples","what":"Generating continuous observations","title":"Acceptance and rejection method","text":"expand beyond examples generating pseudo-random observations discrete random variables, consider now want generate observations random variable \\(X \\sim \\mathcal{N}(\\mu = 0, \\sigma^2 = 1)\\). chose normal distribution familiar form, can choose another distribution desired. , generate n = 2000 observations using acceptance-rejection method. Note continuous = TRUE. examples , graphs built without using AcceptReject::plot() function. just show can manipulate returning object using AcceptReject::accept_reject() function, , class object accept_reject. However, AcceptReject::plot() function can used generate graphs simpler way. , example use AcceptReject::plot() function generate probability density plot normal distribution. However, note AcceptReject::plot() function makes plotting task simpler direct. See following example: See another example, discrete case:","code":"library(AcceptReject) # Ensuring reproducibility set.seed(0) # Generating observations data <- AcceptReject::accept_reject( n = 2000L, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4), parallel = FALSE ) # Viewing organized output with useful information print(data) #> #> ── Accept-Reject Samples ─────────────────────────────────────────────────────── #> ℹ It's not necessary, but if you want to extract the observations, use as.vector(). #> ✔ Case: continuous #> ✔ Number of observations: 2000 #> ✔ c: 38.2549 #> ✔ Probability of acceptance (1/c): 0.0261 #> ✔ Observations: 0.4243 0.599 0.0035 0.3812 1.694 0.081 -0.563 0.6268 -0.1201 -1.0155... #> ✔ xlim = -4 4 #> #> ──────────────────────────────────────────────────────────────────────────────── hist( data, main = \"Generating Gaussian observations\", xlab = \"x\", probability = TRUE, ylim = c(0, 0.4) ) x <- seq(-4, 4, length.out = 500L) y <- dnorm(x, mean = 0, sd = 1) lines(x, y, col = \"red\", lwd = 2) legend(\"topright\", legend = \"True density\", col = \"red\", lwd = 2) library(AcceptReject) library(cowplot) # install.packages(\"cowplot\") # Ensuring reproducibility set.seed(0) simulation <- function(n){ AcceptReject::accept_reject( n = n, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4), parallel = FALSE ) } # Inspecting a <- plot(simulation(n = 250L)) b <- plot(simulation(n = 2500L)) c <- plot(simulation(n = 25000L)) d <- plot(simulation(n = 250000L)) plot_grid(a, b, c, d, nrow = 2L, labels = c(\"a\", \"b\", \"c\", \"d\")) library(AcceptReject) library(cowplot) # install.packages(\"cowplot\") # Ensuring Reproducibility set.seed(0) simulation <- function(n){ AcceptReject::accept_reject( n = n, f = dpois, continuous = FALSE, args_f = list(lambda = 0.7), xlim = c(0, 20), parallel = FALSE ) } a <- plot(simulation(25L)) b <- plot(simulation(250L)) c <- plot(simulation(2500L)) d <- plot(simulation(25000L)) plot_grid(a, b, c, d, nrow = 2L, labels = c(\"a\", \"b\", \"c\", \"d\"))"},{"path":"/articles/accept_reject.html","id":"accessing-metadata","dir":"Articles","previous_headings":"Examples","what":"Accessing metadata","title":"Acceptance and rejection method","text":"AcceptReject::accept_reject() function returns object class accept_reject. executing print() function object class, organized output shown. However, can operate instance accept_reject class atomic vector. example , notice can obtain histogram hist() function check size vector observations generated using length() function. want access metadata, use attr() function. Check list attributes : case, important highlight , general, need access attributes. greatest interest access vector observations generated. want access observation values directly atomic vector R without attributes, without organized printout, simply coerce object using .vector() function, shown following example: Important: need coerce object accept_reject class atomic vector attributes unless specific reason . object accept_reject class atomic vector attributes, can operate like atomic vector. Everything can atomic vector, can object accept_reject class.","code":"library(AcceptReject) data <- accept_reject( n = 1000L, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4) ) # Creating a histogram hist(data) # Checking the size of the vector of observations length(x) #> [1] 500 library(AcceptReject) data <- accept_reject( n = 100L, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4) ) attributes(data) #> $class #> [1] \"accept_reject\" #> #> $f #> #> function (...) #> f(mean = 0, sd = 1, ...) #> #> #> $args_f #> $args_f$mean #> [1] 0 #> #> $args_f$sd #> [1] 1 #> #> #> $c #> [1] 38.2549 #> #> $continuous #> [1] TRUE #> #> $xlim #> [1] -4 4 # Accessing the value c attr(data, \"c\") #> [1] 38.2549 library(AcceptReject) data <- accept_reject( n = 100L, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4) ) class(data) #> [1] \"accept_reject\" print(data) #> #> ── Accept-Reject Samples ─────────────────────────────────────────────────────── #> ℹ It's not necessary, but if you want to extract the observations, use as.vector(). #> ✔ Case: continuous #> ✔ Number of observations: 100 #> ✔ c: 38.2549 #> ✔ Probability of acceptance (1/c): 0.0261 #> ✔ Observations: -0.9116 -0.9773 -0.8328 -1.7554 0.3205 0.2271 0.5857 0.5872 0.0143 0.3097... #> ✔ xlim = -4 4 #> #> ──────────────────────────────────────────────────────────────────────────────── # Coercing the object into an atomic vector without attributes data <- as.vector(data) print(data) #> [1] -0.91157235 -0.97730458 -0.83279488 -1.75538689 0.32054036 0.22709815 #> [7] 0.58574094 0.58724381 0.01434882 0.30974479 -2.19669601 0.62127511 #> [13] 1.60171712 0.90850249 2.05355351 -2.17650113 0.60057436 -0.42051950 #> [19] -0.23232206 -1.55660906 -0.88425284 -0.52673517 -0.87943832 -0.63063285 #> [25] -0.85628026 -0.24591930 -1.01740081 0.79763561 1.39946376 0.54384696 #> [31] 0.28309924 0.19440448 -1.30929375 -2.34363151 0.88472824 0.10004806 #> [37] -0.37334603 -1.16272727 1.42066773 0.85311870 -0.72987775 -0.19328477 #> [43] -0.86285814 0.71666934 0.69502212 -0.25295744 -1.11561732 -0.07071140 #> [49] 1.40951045 0.91927889 0.74099312 1.02052561 -2.03183078 -0.67392395 #> [55] -0.60803784 -1.39868014 -0.24927761 0.46767154 -0.20196875 -0.53432214 #> [61] 0.10237354 -0.65235253 0.71854476 -0.41719143 1.77431837 -0.74298612 #> [67] -1.86710453 -0.65607749 -0.25607571 0.72290366 1.28796522 0.28634292 #> [73] 0.78000570 -0.16246228 -0.37944091 -0.54735621 -1.19424975 0.76440685 #> [79] 1.33546143 -0.23903133 0.99561439 -0.05855329 0.01292897 0.43525180 #> [85] -0.30473989 1.54150634 -1.13000945 -0.05852531 -1.21125887 0.96265198 #> [91] -0.73563223 0.46325579 -1.62444950 2.19485540 1.59486479 0.45293343 #> [97] 0.92180256 -0.85777644 0.22787886 1.90666291"},{"path":"/articles/inspect.html","id":"motivation","dir":"Articles","previous_headings":"","what":"Motivation","title":"Specifying a base probability density function","text":"Providing suitable probability density function can reduce computational cost increase acceptance probability. Therefore, inspecting alternative base probability density function good practice. accept_reject() function supports, continuous case, specifying base probability density function don’t want use continuous uniform distribution default base. choosing specify another probability density function different uniform one, ’s necessary specify following arguments: f_base: base probability density function; random_base: sampling base probability density function; args_f_base: list parameters base density. default, NULL, continuous uniform distribution xlim used base. least one arguments specified, error occur, continuous uniform distribution xlim still used base. discrete case, user mistakenly specifies arguments, .e., continuous = FALSE, accept_reject() function ignore arguments use discrete uniform distribution base. choose specify base density, ’s convenient inspect comparing base density function theoretical probability density function. inspect() function facilitates task. inspect() function plot base probability density function theoretical probability density function, find intersection densities, display value intersection area plot. important pieces information decide base probability density function specified args_f_base argument value c (default 1) appropriate.","code":""},{"path":"/articles/inspect.html","id":"example-of-inspection","dir":"Articles","previous_headings":"","what":"Example of inspection","title":"Specifying a base probability density function","text":"Notice considering distribution scenario “” code convenient. Note area approximately 1, base probability density function parameters shape = 2.8 rate = 1.2 provides shape close theoretical distribution, c = 1.2 ensures base density function upper bounds theoretical probability density function. Therefore, considering f_base \\(\\Gamma(\\alpha = 2.8, \\beta = 1.2)\\) c = 1.2 reasonable choice base distribution. Therefore, passing arguments f_base = dgamma, args_f_base = list(shape = 2.8, rate = 1.2), c = 1.2 accept_reject() function lead us even efficient code. Notice results close graphical analysis. However, execution time specifying convenient base density lower large sample. Important:","code":"library(AcceptReject) library(cowplot) # install.packages(\"cowplot\") # Ensuring reproducibility set.seed(0) # Inspecting # Case a a <- inspect( f = dweibull, args_f = list(shape = 2.1, scale = 2.2), f_base = dgamma, args_f_base = list(shape = 2.8, rate = 1.2), xlim = c(0, 10), c = 1.2 ) # Inspecting # Case b b <- inspect( f = dweibull, args_f = list(shape = 2.1, scale = 2.2), f_base = dgamma, args_f_base = list(shape = 2.9, rate = 2.5), xlim = c(0, 10), c = 1.4 ) plot_grid(a, b, nrow = 2L, labels = c(\"a\", \"b\")) library(AcceptReject) library(tictoc) # install.packages(\"tictoc\") # Ensuring reproducibility set.seed(0) # Não especificando a função densidade de probabilidade base tic() case_1 <- accept_reject( n = 200e3L, continuous = TRUE, f = dweibull, args_f = list(shape = 2.1, scale = 2.2), xlim = c(0, 10) ) toc() #> 0.434 sec elapsed # Specifying the base probability density function tic() case_2 <- accept_reject( n = 200e3L, continuous = TRUE, f = dweibull, args_f = list(shape = 2.1, scale = 2.2), f_base = dgamma, random_base = rgamma, args_f_base = list(shape = 2.8, rate = 1.2), xlim = c(0, 10), c = 1.2 ) toc() #> 0.156 sec elapsed # Visualizing the results p1 <- plot(case_1) p2 <- plot(case_2) plot_grid(p1, p2, nrow = 2L)"},{"path":"/authors.html","id":null,"dir":"","previous_headings":"","what":"Authors","title":"Authors and Citation","text":"Pedro Rafael D. Marinho. Author, maintainer. Vera Lucia Damasceno Tomazella. Author.","code":""},{"path":"/authors.html","id":"citation","dir":"","previous_headings":"","what":"Citation","title":"Authors and Citation","text":"D. Marinho P, Tomazella V (2024). AcceptReject: Acceptance-Rejection Method Generating Pseudo-Random Observations. R package version 0.1.1, https://prdm0.github.io/AcceptReject/.","code":"@Manual{, title = {AcceptReject: Acceptance-Rejection Method for Generating Pseudo-Random Observations}, author = {Pedro Rafael {D. Marinho} and Vera Lucia Damasceno Tomazella}, year = {2024}, note = {R package version 0.1.1}, url = {https://prdm0.github.io/AcceptReject/}, }"},{"path":"/index.html","id":"acceptreject-","dir":"","previous_headings":"","what":"Acceptance-Rejection Method for Generating Pseudo-Random Observations","title":"Acceptance-Rejection Method for Generating Pseudo-Random Observations","text":"Generating pseudo-random observations probability distribution common task statistics. able generate pseudo-random observations probability distribution useful simulating scenarios, Monte-Carlo methods, useful evaluating various statistical models. inversion method common way , always possible find closed-form formula inverse function cumulative distribution function random variable X, , q(u) = F−1(u) = x (quantile function), F cumulative distribution function X u uniformly distributed random variable interval (0,1). Whenever possible, preferable use inversion method generate pseudo-random observations probability distribution. However, possible find closed-form formula inverse function cumulative distribution function random variable, necessary resort methods. One way acceptance-rejection method, Monte-Carlo procedure. package aims provide function implements Acceptance Rejection method generating pseudo-random observations probability distributions difficult sample directly. package AcceptReject provides AcceptReject::accept_reject() function implements acceptance-rejection method optimized manner generate pseudo-random observations discrete continuous random variables. AcceptReject::accept_reject() function operates parallel Unix-based operating systems Linux MacOS operates sequentially Windows-based operating systems; however, still exhibits good performance. default, Unix-based systems, observations generated sequentially, possible generate observations parallel desired, using parallel = TRUE argument. AcceptReject::accept_reject() function, default, attempts maximize probability acceptance pseudo-random observations generated. Suppose X Y random variables probability density function (pdf) probability function (pf) f g, respectively. Furthermore, suppose exists constant c $$\\frac{f_X(x)}{g_Y(y)} \\leq c.$$ default, accept_reject function attempts find value c maximizes probability acceptance pseudo-random observations generated. However, possible provide value c AcceptReject::accept_reject() function argument c, Y random variable know generate observations. AcceptReject::accept_reject() function, necessary specify probability function probability density function Y generate observations X discrete continuous cases, respectively. discrete continuous cases, Y follows discrete uniform distribution function continuous uniform distribution function, respectively. Since probability acceptance 1/c, AcceptReject::accept_reject() function attempts find minimum value c satisfies description . Unless compelling reasons provide value c argument AcceptReject::accept_reject() function, recommended use c = NULL (default), allowing value c automatically determined.","code":""},{"path":"/index.html","id":"installation","dir":"","previous_headings":"","what":"Installation","title":"Acceptance-Rejection Method for Generating Pseudo-Random Observations","text":"package versioned GitHub. can install development version AcceptReject, , must first install remotes package run following command: force = TRUE argument necessary. needed situations already installed package want reinstall new version.","code":"# install.packages(\"remotes\") # or remotes::install_github(\"prdm0/AcceptReject\", force = TRUE) library(AcceptReject)"},{"path":"/index.html","id":"examples","dir":"","previous_headings":"","what":"Examples","title":"Acceptance-Rejection Method for Generating Pseudo-Random Observations","text":"Please note examples use AcceptReject::accept_reject() function generate pseudo-random observations discrete continuous random variables. details, refer function’s documentation Reference Vignette.","code":""},{"path":"/index.html","id":"generating-discrete-observations","dir":"","previous_headings":"Examples","what":"Generating discrete observations","title":"Acceptance-Rejection Method for Generating Pseudo-Random Observations","text":"example, let X ∼ Poisson(λ=0.7). generate n = 1000 observations X using acceptance-rejection method, using AcceptReject::accept_reject() function. Note necessary provide xlim argument. Try set upper limit value probability X assuming value zero close zero. case, choose xlim = c(0, 20), dpois(x = 20, lambda = 0.7) close zero (1.6286586^{-22}).","code":"library(AcceptReject) library(cowplot) # install.packages(\"cowplot\") # Ensuring Reproducibility set.seed(0) simulation <- function(n){ AcceptReject::accept_reject( n = n, f = dpois, continuous = FALSE, args_f = list(lambda = 0.7), xlim = c(0, 20), parallel = TRUE ) } a <- plot(simulation(25L)) b <- plot(simulation(250L)) c <- plot(simulation(2500L)) d <- plot(simulation(25000L)) plot_grid(a, b, c, d, nrow = 2L, labels = c(\"a\", \"b\", \"c\", \"d\"))"},{"path":"/index.html","id":"generating-continuous-observations","dir":"","previous_headings":"","what":"Generating continuous observations","title":"Acceptance-Rejection Method for Generating Pseudo-Random Observations","text":"expand beyond examples generating pseudo-random observations discrete random variables, consider now want generate observations random variable X ∼ 𝒩(μ=0,σ2=1). chose normal distribution familiar form, can choose another distribution desired. , generate n = 2000 observations using acceptance-rejection method. Note continuous = TRUE. accept_reject() function supports, continuous case, specifying base probability density function don’t want use continuous uniform distribution default base. choosing specify another probability density function different uniform one, ’s necessary specify following arguments: f_base: base probability density function; random_base: sampling base probability density function; args_f_base: list parameters base density. default, NULL, continuous uniform distribution xlim used base. least one arguments specified, error occur, continuous uniform distribution xlim still used base. discrete case, user mistakenly specifies arguments, .e., continuous = FALSE, accept_reject() function ignore arguments use discrete uniform distribution base. choose specify base density, ’s convenient inspect comparing base density function theoretical probability density function. inspect() function facilitates task. inspect() function plot base probability density function theoretical probability density function, find intersection densities, display value intersection area plot. important pieces information decide base probability density function specified args_f_base argument value c (default 1) appropriate.","code":"library(AcceptReject) library(cowplot) # install.packages(\"cowplot\") # Ensuring reproducibility set.seed(0) simulation <- function(n){ AcceptReject::accept_reject( n = n, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4), parallel = TRUE ) } # Inspecting a <- plot(simulation(n = 250L)) b <- plot(simulation(n = 2500L)) c <- plot(simulation(n = 25000L)) d <- plot(simulation(n = 250000L)) plot_grid(a, b, c, d, nrow = 2L, labels = c(\"a\", \"b\", \"c\", \"d\"))"},{"path":"/index.html","id":"example-of-inspection","dir":"","previous_headings":"","what":"Example of inspection","title":"Acceptance-Rejection Method for Generating Pseudo-Random Observations","text":"Notice considering distribution scenario “” code convenient. Note area approximately 1, base probability density function parameters shape = 2.8 rate = 1.2 provides shape close theoretical distribution, c = 1.2 ensures base density function upper bounds theoretical probability density function. Therefore, considering f_base Γ(α=2.8,β=1.2) c = 1.2 reasonable choice base distribution. Therefore, passing arguments f_base = dgamma, args_f_base = list(shape = 2.8, rate = 1.2), c = 1.2 accept_reject() function lead us even efficient code. Notice results close graphical analysis. However, execution time specifying convenient base density lower large sample.","code":"library(AcceptReject) library(cowplot) # install.packages(\"cowplot\") # Ensuring reproducibility set.seed(0) # Inspecting # Case a a <- inspect( f = dweibull, args_f = list(shape = 2.1, scale = 2.2), f_base = dgamma, args_f_base = list(shape = 2.8, rate = 1.2), xlim = c(0, 10), c = 1.2 ) # Inspecting # Case b b <- inspect( f = dweibull, args_f = list(shape = 2.1, scale = 2.2), f_base = dgamma, args_f_base = list(shape = 2.9, rate = 2.5), xlim = c(0, 10), c = 1.4 ) plot_grid(a, b, nrow = 2L, labels = c(\"a\", \"b\")) library(AcceptReject) library(tictoc) # install.packages(\"tictoc\") # Ensuring reproducibility set.seed(0) # Não especificando a função densidade de probabilidade base tic() case_1 <- accept_reject( n = 200e3L, continuous = TRUE, f = dweibull, args_f = list(shape = 2.1, scale = 2.2), xlim = c(0, 10) ) toc() #> 0.491 sec elapsed # Specifying the base probability density function tic() case_2 <- accept_reject( n = 200e3L, continuous = TRUE, f = dweibull, args_f = list(shape = 2.1, scale = 2.2), f_base = dgamma, random_base = rgamma, args_f_base = list(shape = 2.8, rate = 1.2), xlim = c(0, 10), c = 1.2 ) toc() #> 0.153 sec elapsed # Visualizing the results p1 <- plot(case_1) p2 <- plot(case_2) plot_grid(p1, p2, nrow = 2L)"},{"path":"/reference/accept_reject.html","id":null,"dir":"Reference","previous_headings":"","what":"Acceptance-Rejection Method — accept_reject","title":"Acceptance-Rejection Method — accept_reject","text":"function implements acceptance-rejection method generating random numbers given probability density function (pdf).","code":""},{"path":"/reference/accept_reject.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Acceptance-Rejection Method — accept_reject","text":"","code":"accept_reject( n = 1L, continuous = TRUE, f = NULL, args_f = NULL, f_base = NULL, random_base = NULL, args_f_base = NULL, xlim = NULL, c = NULL, linesearch_algorithm = \"LBFGS_LINESEARCH_BACKTRACKING_ARMIJO\", max_iterations = 0L, epsilon = 1e-05, start_c = 25, parallel = FALSE, warning = TRUE, ... )"},{"path":"/reference/accept_reject.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Acceptance-Rejection Method — accept_reject","text":"n number random numbers generate. continuous logical value indicating whether pdf continuous discrete. Default TRUE. f probability density function (continuous = TRUE), continuous case probability mass function, discrete case (continuous = FALSE). args_f list arguments passed f function. refers list arguments target distribution. f_base Base probability density function (continuous case).f_base = NULL, uniform distribution used. discrete case, argument ignored, uniform probability mass function used base. random_base Random number generation function base distribution passed argument f_base. random_base = NULL (default), uniform generator used. discrete case, argument disregarded, uniform random number generator function used. args_f_base list arguments base distribution. refers list arguments passed function f_base. disregarded discrete case. xlim vector specifying range values random numbers form c(min, max). Default c(0, 100). c constant value used acceptance-rejection method. NULL, estimated using lbfgs::lbfgs() optimization algorithm. Default NULL. linesearch_algorithm linesearch algorithm used lbfgs::lbfgs() optimization. Default \"LBFGS_LINESEARCH_BACKTRACKING_ARMIJO\". max_iterations maximum number iterations lbfgs::lbfgs() optimization. Default 1000. epsilon convergence criterion lbfgs::lbfgs() optimization. Default 1e-6. start_c initial value constant c lbfgs::lbfgs() optimization. Default 25. parallel logical value indicating whether use parallel processing generating random numbers. Default FALSE. warning logical value indicating whether show warnings. Default TRUE. ... Additional arguments passed lbfgs::lbfgs() optimization algorithm. details, see lbfgs::lbfgs().","code":""},{"path":"/reference/accept_reject.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Acceptance-Rejection Method — accept_reject","text":"vector random numbers generated using acceptance-rejection method. return object class accept_reject, can treated atomic vector.","code":""},{"path":"/reference/accept_reject.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Acceptance-Rejection Method — accept_reject","text":"situations use inversion method (situations possible obtain quantile function) know transformation involves random variable can generate observations, can use acceptance rejection method. Suppose \\(X\\) \\(Y\\) random variables probability density function (pdf) probability function (pf) \\(f\\) \\(g\\), respectively. addition, suppose constant \\(c\\) $$f(x) \\leq c \\cdot g(x), \\quad \\forall x \\\\mathbb{R}.$$ values \\(t\\), \\(f(t)>0\\). use acceptance rejection method generate observations random variable \\(X\\), using algorithm , first find random variable \\(Y\\) pdf pf \\(g\\), satisfies condition. Algorithm Acceptance Rejection Method: 1 - Generate observation \\(y\\) random variable \\(Y\\) pdf/pf \\(g\\); 2 - Generate observation \\(u\\) random variable \\(U\\sim \\mathcal{U} (0, 1)\\); 3 - \\(u < \\frac{f(y)}{cg(y)}\\) accept \\(x = y\\); otherwise reject \\(y\\) observation random variable \\(X\\) return step 1. Proof: consider discrete case, , \\(X\\) \\(Y\\) random variables pf's \\(f\\) \\(g\\), respectively. step 3 algorithm, \\({accept} = {x = y} = u < \\frac{f(y)}{cg(y)}\\). , \\(P(accept | Y = y) = \\frac{P(accept \\cap {Y = y})}{g(y)} = \\frac{P(U \\leq f(y)/cg(y)) \\times g(y)}{g(y)} = \\frac{f(y)}{cg(y)}.\\) Hence, Total Probability Theorem, : \\(P(accept) = \\sum_y P(accept|Y=y)\\times P(Y=y) = \\sum_y \\frac{f(y)}{cg(y)}\\times g(y) = \\frac{1}{c}.\\) Therefore, acceptance rejection method accept occurrence $Y$ occurrence \\(X\\) probability \\(1/c\\). addition, Bayes' Theorem, \\(P(Y = y | accept) = \\frac{P(accept|Y = y)\\times g(y)}{P(accept)} = \\frac{[f(y)/cg(y)] \\times g(y)}{1/c} = f(y).\\) result shows accepting \\(x = y\\) procedure algorithm equivalent accepting value \\(X\\) pf \\(f\\). argument c = NULL default. Thus, function accept_reject() estimates value c using optimization algorithm lbfgs::lbfgs(). details, see lbfgs::lbfgs(). value c provided, function accept_reject() use value generate random observations. inappropriate choice c can lead low efficiency acceptance rejection method. Unix-based operating systems, function accept_reject() can executed parallel. , simply set argument parallel = TRUE. function accept_reject() utilizes parallel::mclapply() function execute acceptance rejection method parallel. Windows operating systems, code parallelized even parallel = TRUE set. continuous case, base density function can used, arguments f_base, random_base args_f_base need passed. least one NULL, function assume uniform density function interval xlim. discrete case, arguments f_base, random_base args_f_base NULL, passed, disregarded, discrete case, discrete uniform distribution always considered base. Sampling discrete uniform distribution shown good performance discrete case.","code":""},{"path":"/reference/accept_reject.html","id":"references","dir":"Reference","previous_headings":"","what":"References","title":"Acceptance-Rejection Method — accept_reject","text":"CASELLA, George; ROBERT, Christian P.; WELLS, Martin T. Generalized accept-reject sampling schemes. Lecture Notes-Monograph Series, p. 342-347, 2004. NEAL, Radford M. Slice sampling. annals statistics, v. 31, n. 3, p. 705-767, 2003. BISHOP, Christopher. 11.4: Slice sampling. Pattern Recognition Machine Learning. Springer, 2006.","code":""},{"path":[]},{"path":"/reference/accept_reject.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Acceptance-Rejection Method — accept_reject","text":"","code":"set.seed(0) # setting a seed for reproducibility x <- accept_reject( n = 2000L, f = dbinom, continuous = FALSE, args_f = list(size = 5, prob = 0.5), xlim = c(0, 10) ) plot(x) y <- accept_reject( n = 1000L, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4) ) plot(y)"},{"path":"/reference/inspect.html","id":null,"dir":"Reference","previous_headings":"","what":"Inspecting the theoretical density with the base density — inspect","title":"Inspecting the theoretical density with the base density — inspect","text":"Inspect probability density function used base theoretical density function observations desired.","code":""},{"path":"/reference/inspect.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Inspecting the theoretical density with the base density — inspect","text":"","code":"inspect( f, args_f, f_base, args_f_base, xlim, c = 1, alpha = 0.4, color_intersection = \"#BB9FC9\", color_f = \"#FE4F0E\", color_f_base = \"#7BBDB3\" )"},{"path":"/reference/inspect.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Inspecting the theoretical density with the base density — inspect","text":"f Theoretical density function. args_f List arguments theoretical density function. f_base Base density function. args_f_base List arguments base density function. xlim range x-axis. c constant covers base density function, \\(c \\geq 1\\). default value 1. alpha transparency base density function. default value 0.4 color_intersection Color intersection base density function theoretical density functions. color_f Color base density function. color_f_base Color theoretical density function.","code":""},{"path":"/reference/inspect.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Inspecting the theoretical density with the base density — inspect","text":"object gg ggplot class comparing theoretical density function base density function. object shows compared density functions, intersection area , value area.","code":""},{"path":"/reference/inspect.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Inspecting the theoretical density with the base density — inspect","text":"function inspect() returns object gg ggplot class compares probability density two functions useful discrete case, continuous one. Finding parameters base distribution best approximate theoretical distribution smallest value c can cover base distribution great strategy. Something important note plot provides value area intersection theoretical probability density function want generate observations probability density function used base. desirable value close 1 possible, ideally intersection area probability density functions 1, means base probability density function passed f_base argument overlaps theoretical density function passed f argument. crucial acceptance-rejection method. However, even use inspect() function find suitable distribution, finding viable args_base (list arguments passed f_base) value c intersection area 1, accept_reject() function already . inspect() function helpful finding suitable base distribution, increases probability acceptance, reducing computational cost. Therefore, inspecting good practice. use accept_reject() function, even parallelism enabled specifying parallel = TRUE accept_reject() find generation time high needs, consider inspecting base distribution.","code":""},{"path":[]},{"path":"/reference/inspect.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Inspecting the theoretical density with the base density — inspect","text":"","code":"# Considering c = 1 (default) inspect( f = dweibull, f_base = dgamma, xlim = c(0,5), args_f = list(shape = 2, scale = 1), args_f_base = list(shape = 2.1, rate = 2), c = 1 ) # Considering c = 1.35. inspect( f = dweibull, f_base = dgamma, xlim = c(0,5), args_f = list(shape = 2, scale = 1), args_f_base = list(shape = 2.1, rate = 2), c = 1.35 ) # Plotting f equal to f_base. This would be the best-case scenario, which, # in practice, is unlikely. inspect( f = dgamma, f_base = dgamma, xlim = c(0,5), args_f = list(shape = 2.1, rate = 2), args_f_base = list(shape = 2.1, rate = 2), c = 1 )"},{"path":"/reference/plot.accept_reject.html","id":null,"dir":"Reference","previous_headings":"","what":"Plot Accept-Reject — plot.accept_reject","title":"Plot Accept-Reject — plot.accept_reject","text":"Inspects probability function (discrete case) probability density (continuous case) comparing theoretical case observed one.","code":""},{"path":"/reference/plot.accept_reject.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Plot Accept-Reject — plot.accept_reject","text":"","code":"# S3 method for accept_reject plot( x, color_observed_density = \"#BB9FC9\", color_true_density = \"#FE4F0E\", color_bar = \"#BB9FC9\", color_observable_point = \"#7BBDB3\", color_real_point = \"#FE4F0E\", alpha = 0.3, hist = TRUE, ... )"},{"path":"/reference/plot.accept_reject.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Plot Accept-Reject — plot.accept_reject","text":"x object class accept reject color_observed_density Observed density color (continuous case). color_true_density True histogram density color (continuous case) color_bar Bar chart fill color (discrete case) color_observable_point Color generated points (discrete case) color_real_point Color real probability points (discrete case) alpha Bar chart transparency (discrete case) observed density (continuous case) hist TRUE, histogram plotted continuous case, comparing theoretical density observed one. FALSE, ggplot2::geom_density() used instead histogram. ... Additional arguments.","code":""},{"path":"/reference/plot.accept_reject.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Plot Accept-Reject — plot.accept_reject","text":"object class gg ggplot package ggplot2. function plot.accept_reject() expects object class accept_reject argument.","code":""},{"path":"/reference/plot.accept_reject.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Plot Accept-Reject — plot.accept_reject","text":"function plot.accept_reject() responsible plotting probability function (discrete case) probability density (continuous case), comparing theoretical case observed one. useful, therefore, inspecting quality samples generated acceptance-rejection method. returned plot object classes gg ggplot. Easily, can customize plot. function plot.accept_reject(), simply plot(), constructs plot inspection expects object class accept_reject argument.","code":""},{"path":[]},{"path":"/reference/plot.accept_reject.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Plot Accept-Reject — plot.accept_reject","text":"","code":"x <- accept_reject( n = 1000L, f = dbinom, continuous = FALSE, args_f = list(size = 5, prob = 0.5), xlim = c(0, 10) ) plot(x) y <- accept_reject( n = 500L, f = dnorm, continuous = TRUE, args_f = list(mean = 0, sd = 1), xlim = c(-4, 4) ) plot(y)"},{"path":"/reference/print.accept_reject.html","id":null,"dir":"Reference","previous_headings":"","what":"Print method for accept_reject objects — print.accept_reject","title":"Print method for accept_reject objects — print.accept_reject","text":"Print method accept_reject objects","code":""},{"path":"/reference/print.accept_reject.html","id":"ref-usage","dir":"Reference","previous_headings":"","what":"Usage","title":"Print method for accept_reject objects — print.accept_reject","text":"","code":"# S3 method for accept_reject print(x, n_min = 10L, ...)"},{"path":"/reference/print.accept_reject.html","id":"arguments","dir":"Reference","previous_headings":"","what":"Arguments","title":"Print method for accept_reject objects — print.accept_reject","text":"x accept_reject object n_min Minimum number observations print ... Additional arguments","code":""},{"path":"/reference/print.accept_reject.html","id":"value","dir":"Reference","previous_headings":"","what":"Value","title":"Print method for accept_reject objects — print.accept_reject","text":"object class character, providing formatted output information accept_reject object, including number observations, value constant \\(c\\) maximizes acceptance, acceptance probability \\(1/c\\). Additionally, prints first generated observations. function print.accept_reject() enables formatting executing object class 'accept_reject' console executing function print() object class accept_reject, returned function accept_reject().","code":""},{"path":"/reference/print.accept_reject.html","id":"details","dir":"Reference","previous_headings":"","what":"Details","title":"Print method for accept_reject objects — print.accept_reject","text":"function print.accept_reject() responsible printing object class accept_reject formatted manner, providing information accept_reject object, including number observations, value constant \\(c\\) maximizes acceptance, acceptance probability \\(1/c\\). Additionally, prints first generated observations. function print.accept_reject() delivers formatted output executing object class accept_reject console executing function print() object class accept_reject, returned function accept_reject().","code":""},{"path":[]},{"path":"/reference/print.accept_reject.html","id":"ref-examples","dir":"Reference","previous_headings":"","what":"Examples","title":"Print method for accept_reject objects — print.accept_reject","text":"","code":"set.seed(0) # setting a seed for reproducibility x = accept_reject( n = 2000L, f = dbinom, continuous = FALSE, args_f = list(size = 5, prob = 0.5), xlim = c(0, 10) ) print(x) #> #> ── Accept-Reject Samples ─────────────────────────────────────────────────────── #> #> ℹ It's not necessary, but if you want to extract the observations, use as.vector(). #> #> ✔ Case: discrete #> ✔ Number of observations: 2000 #> ✔ c: 25 #> ✔ Probability of acceptance (1/c): 0.04 #> ✔ Observations: 3 2 2 2 2 1 4 2 3 2... #> ✔ xlim = 0 10 #> #> ────────────────────────────────────────────────────────────────────────────────"},{"path":"/news/index.html","id":"acceptreject-010","dir":"Changelog","previous_headings":"","what":"AcceptReject 0.1.0","title":"AcceptReject 0.1.0","text":"CRAN release: 2024-04-11 Initial CRAN submission.","code":""},{"path":"/news/index.html","id":"acceptreject-011","dir":"Changelog","previous_headings":"","what":"AcceptReject 0.1.1","title":"AcceptReject 0.1.1","text":"Improved performance serial parallel processing; Now possible specify different base density/probability mass function uniform one. none specified, uniform density (either discrete continuous) assumed case discrete continuous random variables, respectively; Now function inspect() available, allowing compare base probability density function theoretical density function. inspect() function useful finding reasonable base density function. returns object classes gg ggplot density curves, intersection area, value intersection. Users obligated use inspect() function since accept_reject() function already takes care lot. However, continuous case, providing f_base argument accept_reject() function good candidate base density function can good idea. generating observations continuous random variables, using histogram breaks R graphics hist() function, histogram created ggplot2; Providing alerts regarding limits passed xlim argument accept_reject() function. significant density/probability mass present, warning issued. alert can omitted setting warning = FALSE; plot.accept_reject() function, ’s additional argument hist = TRUE (default). hist = TRUE, histogram plotted along base density, case generating pseudo-random observations continuous random variable. hist = FALSE, theoretical density plotted alongside observed density; print.accept_reject() function now informs whether case discrete continuous xlim; Putting order specifications arguments exported functions order arguments functions; warning messages improved; Bug fix.","code":""}] diff --git a/man/figures/README-unnamed-chunk-2-1.png b/man/figures/README-unnamed-chunk-2-1.png index b188725..4af487d 100644 Binary files a/man/figures/README-unnamed-chunk-2-1.png and b/man/figures/README-unnamed-chunk-2-1.png differ diff --git a/man/figures/README-unnamed-chunk-3-1.png b/man/figures/README-unnamed-chunk-3-1.png index 6094db1..ee5ee4d 100644 Binary files a/man/figures/README-unnamed-chunk-3-1.png and b/man/figures/README-unnamed-chunk-3-1.png differ diff --git a/man/figures/README-unnamed-chunk-5-1.png b/man/figures/README-unnamed-chunk-5-1.png index 7442eea..74a02b0 100644 Binary files a/man/figures/README-unnamed-chunk-5-1.png and b/man/figures/README-unnamed-chunk-5-1.png differ diff --git a/tests/testthat/test-time-parallel.R b/tests/testthat/test-time-parallel.R index 093595a..d3bfb3c 100644 --- a/tests/testthat/test-time-parallel.R +++ b/tests/testthat/test-time-parallel.R @@ -12,20 +12,14 @@ simulation <- function(n, parallel = FALSE){ parallel = parallel ) - # Calcular o tempo de execução end_time <- Sys.time() execution_time <- end_time - start_time - # Imprimir o tempo de execução cat("Tempo de execução: ", execution_time, " segundos\n") - # Imprimir as primeiras observações cat("Primeiras observações:\n") print(head(x)) - # Retornar o resultado return(x) } simulation(n = 1000, parallel = FALSE) - -simulation(n = 1000, parallel = TRUE)