stors

Step Optimised Rejection Sampling - R Package

https://github.com/ahmad-alqabandi/stors

Science Score: 26.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (13.0%) to scientific vocabulary
Last synced: 9 months ago · JSON representation

Repository

Step Optimised Rejection Sampling - R Package

Basic Info
Statistics
  • Stars: 3
  • Watchers: 2
  • Forks: 0
  • Open Issues: 1
  • Releases: 0
Created over 2 years ago · Last pushed 9 months ago
Metadata Files
Readme License

README.md

📦 {stors} R package

StORS (Step Optimised Rejection Sampling) is an optimised rejection sampling method designed for efficient sampling from univariate probability density functions. It constructs a proposal distribution using computationally efficient steps that adapt around the target density.

Built-in distributions can have any type of unbounded tails, as Inverse Transform sampling is used when necessary. However, for user-provided distributions, if unbounded, the tails must be log-concave since Adaptive Rejection Sampling (ARS) is applied in this case.

Installation

The stable binary release can be install from CRAN:

r install.packages("stors")

The latest development binary can be installed from R-universe:

r install.packages('stors', repos = c('https://ahmad-alqabandi.r-universe.dev', 'https://cloud.r-project.org'))

Or from GitHub:

``` r

install.packages("pak")

pak::pak("ahmad-alqabandi/stors") ```

Example

Sampling from a Built-in Normal Distribution

The first example demonstrates sampling from a built-in Normal distribution using a pre-optimised proposal that is constructed at package installation time for efficiency.

``` r library("stors")

Generate 1000 samples from the standard normal distribution

x <- srnorm(1000)

Visualize the density

hist(x) ```

Re-optimizing the Built-in Normal Proposal

If needed, the user can re-optimize the proposal for the normal distribution. This can be useful for tasks such as sampling from a truncated normal distribution.

``` r

Re-optimize the proposal for a truncated normal distribution (e.g., between -2 and 2)

srnorm_optimize(xl = -2, xr = 2)

Generate new samples using the optimised proposal

x <- srnorm(1000)

Visualize the truncated normal density

hist(x) ```

Building a Proposal for a Custom Distribution

Users can build a custom proposal by passing a probability density function (PDF) to build_proposal(). The following example demonstrates building a proposal for a Pareto distribution.

``` r

Define the Pareto PDF

dpareto <- function(x, alpha) { alpha / x^(alpha + 1) }

Build a proposal distribution for Pareto

g <- build_proposal(f = dpareto, modes = 1, lower = 1, upper = Inf, steps = 256, alpha = 2)

Print and plot the proposal

print(g) plot(g)

Create a sampler from the proposal

rparetosampler <- buildsampler(g)

Generate 1000 samples from the Pareto distribution

x <- rpareto_sampler(1000)

Visualize the sampled distribution

hist(x) ```

For more details, please see the Getting Started vignette

Owner

  • Name: Ahmad ALQabandi
  • Login: ahmad-alqabandi
  • Kind: user

GitHub Events

Total
  • Watch event: 1
  • Push event: 39
  • Pull request event: 1
  • Create event: 2
Last Year
  • Watch event: 1
  • Push event: 39
  • Pull request event: 1
  • Create event: 2

Issues and Pull Requests

Last synced: 9 months ago

All Time
  • Total issues: 0
  • Total pull requests: 2
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Total issue authors: 0
  • Total pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 0
  • Pull requests: 2
  • Average time to close issues: N/A
  • Average time to close pull requests: N/A
  • Issue authors: 0
  • Pull request authors: 1
  • Average comments per issue: 0
  • Average comments per pull request: 0.0
  • Merged pull requests: 0
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
  • ahmad-alqabandi (2)
Top Labels
Issue Labels
Pull Request Labels

Packages

  • Total packages: 1
  • Total downloads:
    • cran 117 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 1
  • Total maintainers: 1
cran.r-project.org: stors

Step Optimised Rejection Sampling

  • Versions: 1
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 117 Last month
Rankings
Dependent packages count: 27.0%
Dependent repos count: 33.3%
Average: 49.1%
Downloads: 87.0%
Last synced: 9 months ago

Dependencies

DESCRIPTION cran
  • R >= 3.60 depends
  • digest * imports
  • microbenchmark * imports
  • ggplot2 * suggests
  • knitr * suggests
  • rmarkdown * suggests
  • testthat >= 3.0.0 suggests