Giter Club home page Giter Club logo

rho-mu's Introduction

ρμ - Java library of Randomization enHancements and Other Math Utilities

ρμ - Java library of Randomization enHancements and Other Math Utilities

Copyright (C) 2017-2024 Vincent A. Cicirello.

Website: https://rho-mu.cicirello.org/

API documentation: https://rho-mu.cicirello.org/api/

Publications About the Library DOI
Packages and Releases Maven Central GitHub release (latest by date)
Build Status build docs CodeQL
JaCoCo Test Coverage coverage branches coverage
Security Snyk security score Snyk Known Vulnerabilities
DOI DOI
Other Information GitHub style
Support GitHub Sponsors Liberapay Ko-Fi

How to Cite

If you use this library in your research, please cite the following paper:

Cicirello, V. A., (2022). ρμ: A Java library of randomization enhancements and other math utilities. Journal of Open Source Software, 7(76), 4663, https://doi.org/10.21105/joss.04663.

Overview

ρμ is a Java library of Randomization enHancements and Other Math Utilities (rho mu). It includes implementations of various algorithms for efficiently randomly sampling combinations of indexes into arrays and other sequential structures. It also includes efficient implementations of random number generation from distributions other than uniform, such as Gaussian, Cauchy, etc. Additionally, it includes implementations of other math functions that are either needed by the randomization utilities, or which are needed by some of our other projects.

Much of the core randomization enhancements is in a pair of utility classes: RandomIndexer and RandomVariates. Beginning with v2.0.0, the ρμ library was revised to utilize Java 17's hierarchy of random number generator interfaces (i.e., RandomGenerator and its subinterfaces). Specifically, ρμ now provides a class EnhancedRandomGenerator that wraps an instance of RandomGenerator while also implementing RandomGenerator, enabling adding the enhanced randomization features to any of Java 17's many random number generators, while also serving as a drop-in replacement. Additionally, ρμ provides a hierarchy of such wrapper classes, corresponding to Java 17's hierarchy of random number generator interfaces.

Some of the randomization enhancements include:

  • Faster generation of random int values subject to a bound or bound and origin.
  • Faster generation of random int values within an IntStream subject to a bound and origin.
  • Faster generation of Gaussian distributed random doubles.
  • Additional distributions available beyond what is supported by the Java API's RandomGenerator classes, such as Binomial and Cauchy random vaiables.
  • Ultrafast, but biased, nextBiasedInt methods that sacrifices uniformity for speed by excluding the rejection sampling necessary to ensure uniformity, as well as a biasedInts methods for generating streams of such integers.
  • Methods for generating random pairs of integers without replacement, and random triples of integers without replacement.
  • Methods for generating random samples of k integers without replacement from a range of integers.
  • Methods to generate streams of numbers from distributions other than uniform, such as streams of random numbers from binomial distributions, Cauchy distributions, exponential distributions, and Gaussian distributions.

The ρμ library is a dependency of some of our other projects, including JavaPermutationTools and Chips-n-Salsa.

Table of Contents

The rest of this README is organized as follows:

UML Class Diagram

This class diagram summarizes the public classes of ρμ in relation to Java 17's hierarchy of RandomGenerator interfaces. Note that for brevity in the diagram, methods are omitted. Each class and interface in the diagram is a clickable link to the javadoc page that documents it either within the documentation of ρμ for the classes of the ρμ library, or within the Java 17 API documentation for Java's RandomGenerator interfaces.

classDiagram
  class Statistics
  class MatrixOps
  class JacobiDiagonalization
  class MathFunctions
  class RandomGenerator
  <<interface>> RandomGenerator
  class StreamableGenerator
  <<interface>> StreamableGenerator
  RandomGenerator <|-- StreamableGenerator
  class SplittableGenerator
  <<interface>> SplittableGenerator
  StreamableGenerator <|-- SplittableGenerator
  class JumpableGenerator
  <<interface>> JumpableGenerator
  StreamableGenerator <|-- JumpableGenerator
  class LeapableGenerator
  <<interface>> LeapableGenerator
  JumpableGenerator <|-- LeapableGenerator
  class ArbitrarilyJumpableGenerator
  <<interface>> ArbitrarilyJumpableGenerator
  LeapableGenerator <|-- ArbitrarilyJumpableGenerator
  class EnhancedRandomGenerator
  RandomGenerator <|.. EnhancedRandomGenerator
  class RandomSampler
  RandomSampler <.. EnhancedRandomGenerator
  class RandomIndexer
  RandomIndexer <.. EnhancedRandomGenerator
  RandomIndexer <.. RandomSampler
  RandomSampler <.. RandomIndexer
  class RandomVariates
  RandomVariates <.. EnhancedRandomGenerator
  RandomVariates <.. RandomSampler
  EnhancedRandomGenerator : -RandomGenerator generator
  class ZigguratGaussian
  ZigguratGaussian <.. RandomVariates
  class EnhancedStreamableGenerator
  EnhancedRandomGenerator <|-- EnhancedStreamableGenerator
  StreamableGenerator <|.. EnhancedStreamableGenerator
  EnhancedStreamableGenerator : -StreamableGenerator generator
  class EnhancedSplittableGenerator
  EnhancedStreamableGenerator <|-- EnhancedSplittableGenerator
  SplittableGenerator <|.. EnhancedSplittableGenerator
  EnhancedSplittableGenerator : -SplittableGenerator generator
  class EnhancedJumpableGenerator
  EnhancedStreamableGenerator <|-- EnhancedJumpableGenerator
  JumpableGenerator <|.. EnhancedJumpableGenerator
  EnhancedJumpableGenerator : -JumpableGenerator generator
  class EnhancedLeapableGenerator
  EnhancedJumpableGenerator <|-- EnhancedLeapableGenerator
  LeapableGenerator <|.. EnhancedLeapableGenerator
  EnhancedLeapableGenerator : -LeapableGenerator generator
  class EnhancedArbitrarilyJumpableGenerator
  EnhancedLeapableGenerator <|-- EnhancedArbitrarilyJumpableGenerator
  ArbitrarilyJumpableGenerator <|.. EnhancedArbitrarilyJumpableGenerator
  EnhancedArbitrarilyJumpableGenerator : -ArbitrarilyJumpableGenerator generator
  link RandomIndexer "https://rho-mu.cicirello.org/api/org.cicirello.rho_mu/org/cicirello/math/rand/RandomIndexer.html"
  link RandomVariates "https://rho-mu.cicirello.org/api/org.cicirello.rho_mu/org/cicirello/math/rand/RandomVariates.html"
  link RandomSampler "https://rho-mu.cicirello.org/api/org.cicirello.rho_mu/org/cicirello/math/rand/RandomSampler.html"
  link EnhancedRandomGenerator "https://rho-mu.cicirello.org/api/org.cicirello.rho_mu/org/cicirello/math/rand/EnhancedRandomGenerator.html"
  link EnhancedStreamableGenerator "https://rho-mu.cicirello.org/api/org.cicirello.rho_mu/org/cicirello/math/rand/EnhancedStreamableGenerator.html"
  link EnhancedSplittableGenerator "https://rho-mu.cicirello.org/api/org.cicirello.rho_mu/org/cicirello/math/rand/EnhancedSplittableGenerator.html"
  link EnhancedJumpableGenerator "https://rho-mu.cicirello.org/api/org.cicirello.rho_mu/org/cicirello/math/rand/EnhancedJumpableGenerator.html"
  link EnhancedLeapableGenerator "https://rho-mu.cicirello.org/api/org.cicirello.rho_mu/org/cicirello/math/rand/EnhancedLeapableGenerator.html"
  link EnhancedArbitrarilyJumpableGenerator "https://rho-mu.cicirello.org/api/org.cicirello.rho_mu/org/cicirello/math/rand/EnhancedArbitrarilyJumpableGenerator.html"
  link RandomGenerator "https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/random/RandomGenerator.html"
  link StreamableGenerator "https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/random/RandomGenerator.StreamableGenerator.html"
  link SplittableGenerator "https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/random/RandomGenerator.SplittableGenerator.html"
  link JumpableGenerator "https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/random/RandomGenerator.JumpableGenerator.html"
  link LeapableGenerator "https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/random/RandomGenerator.LeapableGenerator.html"
  link ArbitrarilyJumpableGenerator "https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/random/RandomGenerator.ArbitrarilyJumpableGenerator.html"
  link ZigguratGaussian "https://rho-mu.cicirello.org/api/org.cicirello.rho_mu/org/cicirello/math/rand/ZigguratGaussian.html"
  link MathFunctions "https://rho-mu.cicirello.org/api/org.cicirello.rho_mu/org/cicirello/math/MathFunctions.html"
  link Statistics "https://rho-mu.cicirello.org/api/org.cicirello.rho_mu/org/cicirello/math/stats/Statistics.html"
  link MatrixOps "https://rho-mu.cicirello.org/api/org.cicirello.rho_mu/org/cicirello/math/la/MatrixOps.html"
  link JacobiDiagonalization "https://rho-mu.cicirello.org/api/org.cicirello.rho_mu/org/cicirello/math/la/JacobiDiagonalization.html"

Java Requirements

We currently support Java 17+. Our development process utilizes OpenJDK 17, and all jar files released via Maven Central, GitHub Packages, and GitHub Releases are built with a Java 17 target. See the following table for a mapping between library version and minimum supported Java version.

version Java requirements
2.w.x to 3.y.z Java 17+
1.x.y Java 11+

Versioning Scheme

ρμ uses Semantic Versioning with version numbers of the form: MAJOR.MINOR.PATCH, where differences in MAJOR correspond to incompatible API changes, differences in MINOR correspond to introduction of backwards compatible new functionality, and PATCH corresponds to backwards compatible bug fixes.

Building the Library (with Maven)

The ρμ library is built using Maven. The root of the repository contains a Maven pom.xml. To build the library, execute mvn package at the root of the repository, which will compile all classes, run all tests, run javadoc, and generate jar files of the library, the sources, and the javadocs. The file names make this distinction explicit. All build outputs will then be found in the directory target.

To include generation of a code coverage report during the build, execute mvn package -Pcoverage at the root of the repository to enable a Maven profile that executes JaCoCo during the test phase.

To run all static analysis tools (i.e., SpotBugs, Find Security Bugs, refactor-first), execute mvn package -Panalysis to enable a Maven profile that executes the various static analysis tools that we are using. The SpotBugs html report will be found in the target directory, or you can use the SpotBugs GUI with: mvn spotbugs:gui -Panalysis. The refactor-first report will be found in the target/site directory.

To run all of the above: mvn package -P "analysis,coverage".

Examples

The examples directory contains source code of a few example programs demonstrating how to use various features of the library. The source code of the examples is commented with explanations where appropriate.

Some of our other projects make extensive use of this library. You may consult the source code of JavaPermutationTools and/or Chips-n-Salsa for additional real code examples. For example Chips-n-Salsa is a library of parallel and adaptive stochastic local search algorithms, and as such requires extensive use of random number generation.

Java Modules

This library provides a Java module, org.cicirello.rho_mu. To use in your project, add the following to your module-info.java:

module your.module.name.here {
	requires org.cicirello.rho_mu;
}

Importing from Package Repositories

Prebuilt artifacts are regularly published to Maven Central and GitHub Packages. In most cases, you'll want to use Maven Central. Releases are published to GitHub Packages mainly as a fall-back in the unlikely scenario that Maven Central is unavailable.

Importing the Library from Maven Central

Add this to the dependencies section of your pom.xml, replacing the version number with the version that you want to use.

<dependency>
  <groupId>org.cicirello</groupId>
  <artifactId>rho-mu</artifactId>
  <version>3.0.0</version>
</dependency>

Importing the Library from GitHub Packages

If you'd prefer to import from GitHub Packages, rather than Maven Central, then: (1) add the dependency as indicated in previous section above, and (2) add the following to the repositories section of your pom.xml:

<repository>
  <id>github</id>
  <name>GitHub cicirello Apache Maven Packages</name>
  <url>https://maven.pkg.github.com/cicirello/rho-mu</url>
</repository>

Note that GitHub Packages requires authenticating to GitHub. Thus, it is likely less convenient than importing from Maven Central. We mainly provide this option as a backup source of artifacts.

Downloading Jar Files

If you don't use a dependency manager that supports importing from Maven Central, or if you simply prefer to download manually, prebuilt jars are also attached to each GitHub Release.

License

The ρμ library is licensed under the GNU General Public License 3.0.

Contribute

If you would like to contribute to ρμ in any way, such as reporting bugs, suggesting new functionality, or code contributions such as bug fixes or implementations of new functionality, then start by reading the contribution guidelines. This project has adopted the Contributor Covenant Code of Conduct.

rho-mu's People

Contributors

cicirello avatar dependabot[bot] avatar

Stargazers

 avatar

Watchers

 avatar  avatar

rho-mu's Issues

Configure JitPack builds as alternate source of artifacts

Summary

Library currently released via Maven Central and GitHub Packages. Configure builds for JitPack to provide a backup source of artifacts. This will also provide a convenient approach to snapshot builds since JitPack will build the default branch on demand.

Update UML diagram in API docs on website

Summary

The README already has an updated UML diagram as a mermaid diagram. But the diagram on the website in the javadocs doesn't include the new RandomSampler class. Update this.

Remove deprecated sampling methods of RandomIndexer class

Summary

In #121, it is proposed that the sampling methods of RandomIndexer are moved to a new class, and that the existing methods are deprecated in the planned release of 2.5.0. This issue concerns the future removal of those deprecated methods. They should be removed in version 3.0.0. This will be a BREAKING CHANGE. This is part of #119.

Seeded constructors for EnhancedSplittableGenerator, EnhancedStreamableGenerator, EnhancedRandomGenerator

Summary

Add constructors with seed to EnhancedSplittableGenerator, EnhancedStreamableGenerator, EnhancedRandomGenerator classes. When seeded constructor used, wrap a SplittableRandom object since that class is considered legacy by the JDK and thus will supposedly stick around long term, and it is also the fastest of the only two options currently available that allow the seed to be specified. Note at the present time it is not feasible to provide seeded constructors for the other subclasses of EnhancedRandomGenerator.

Refactor to utilize org.cicirello.core 2.4.0

Summary

Refactor the classes of package org.cicirello.math.rand to use the new functionality of org.cicirello.core v2.4.0 (e.g., ArrayFiller and ArrayMinimumLengthEnforcer). This will require adding a dependency on org.cicirello.core 2.4.0.

Wrapper class of RandomGenerator.JumpableGenerator

Summary

Add a class to wrap objects of RandomGenerator.JumpableGenerator to add the enhanced functionality of EnhancedRandomGenerator. The new class should be a subclass of the wrapper of RandomGenerator.StreamableGenerator (see #44).

Remove old "since" tags in javadoc comments

Summary
RandomIndexer originated in another project and has "since" tags that are not relevant, mentioning versions of a different project. Remove these and check other classes for this.

Wrapper class for RandomGenerator interface

Create a wrapper class for objects implementing RandomGenerator with that wrapper likewise implementing RandomGenerator. Use methods of rho mu's RandomIndexer and RandomVariates classes where appropriate, and delegate remaining functionality to wrapped object. Add all functionality of RandomIndexer and RandomVariates.

Result will be a drop in replacement for existing Java random number classes but with rho mu's enhancements.

Fix Sonatype Lift configuration

Summary

The configuration file for Sonatype Lift includes an unnecessary exclusion for the source code of the test cases. The default exclusions should cover that.

Wrapper of RandomGenerator.LeapableGenerator

Summary

Add a class to wrap objects of RandomGenerator.LeapableGenerator to add the enhanced functionality of EnhancedRandomGenerator. The new class should be a subclass of the wrapper of RandomGenerator.JumpableGenerator (see #47).

Extract sampling methods from RandomIndexer to separate class

Summary

The RandomIndexer class currently has a very high weighted method count. Although the various sampling methods (e.g., sample, sampleReservoir, samplePool, sampleInsertion, etc) are somewhat related to the rest of the functionality offered by this class, those methods are a bit different in purpose than the rest. This issue requests the following:

  1. Extract all of the sample methods for generating random samples without replacement to a new class perhaps named RandomSampler.
  2. Temporarily keep the existing methods in RandomIndexer, but delegate the work to the proposed RandomSampler class.
  3. Deprecate the existing methods in RandomIndexer, rather than removing (for now).
  4. All uses of the existing methods from other parts of the library should be switched to the methods of the proposed new class.

This will also help work toward achieving #119.

Use Java 17 RandomGenerator interface to consolidate duplicate code

Java 17 introduced a RandomGenerator interface that all random number generators implement. Use this to remove redundancy (currently, there are 2 versions of most methods, one that expects a Random and one a SplittableRandom). For each such case, replace with single method that expects a RandomGenerator).

Added benefit is that doing so enables supporting all of the new random number generators introduced in Java 17.

This will be a breaking change requiring bumping major version number.

Migrate rho mu to Java 17

Summary
Java 17 introduced a RandomGenerator interface, as well as expanded support for a variety of pseudorandom number generators. Upgrade minimum supported Java version to Java 17 to get access to the new features. This includes:

  • migrating local build to Java 17
  • updating maven pom.xml
  • testing existing codebase against Java 17
  • updating GitHub Actions workflows to Java 17

Document source article of insertion sampling algorithm

Summary

The details of the Insertion Sampling algorithm implemented by the sampleInsertion method of RandomIndexer and EnhancedRandomGenerator are described in an article about to appear in the journal Applied Sciences, article titled "Cycle Mutation: Evolving Permutations via Cycle Induction." Reference this article in the javadoc comments of those methods.

Additionally, the composite sampling approach of the sample method of those same classes is a composite of three algorithms, including the above. Check the comments to see if they need editing.

Wrapper class of RandomGenerator.SplittableGenerator

Summary

Add a class to wrap objects of RandomGenerator.SplittableGenerator to add the enhanced functionality of EnhancedRandomGenerator. The new class should be a subclass of the wrapper of RandomGenerator.StreamableGenerator (see #44).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.