Skip to content

Numo::Random provides random number generation with several distributions for Numo::NArray.

License

Notifications You must be signed in to change notification settings

yoshoku/numo-random

This branch is up to date with main.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

3a9d51a · Jan 1, 2025

History

79 Commits
Dec 28, 2024
Oct 16, 2022
Jan 1, 2025
Nov 27, 2022
Nov 20, 2022
Oct 16, 2022
Oct 16, 2022
Jan 2, 2023
Nov 27, 2022
Oct 16, 2022
Oct 23, 2022
Oct 22, 2022
Nov 12, 2022
Nov 5, 2022
Oct 16, 2022
Oct 24, 2022
Oct 22, 2022

Repository files navigation

Numo::Random

Build Status Gem Version License Documentation

Numo::Random provides random number generation with several distributions for Numo::NArray.

Installation

Add this line to your application's Gemfile:

gem 'numo-random'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install numo-random

Usage

An example of generating random numbers according to the standard normal distribution:

require 'numo/narray'
require 'numo/gnuplot'

require 'numo/random'

# Creating random number generator.
rng = Numo::Random::Generator.new(seed: 42)

# Generating random numbers with a normal distribution.
x = rng.normal(shape: [5000, 2], loc: 0.0, scale: 1.0)

# Plotting the generated result.
Numo.gnuplot do
  set(terminal: 'png')
  set(output: 'normal2d.png')
  plot(x[true, 0], x[true, 1])
end

normal2d.png

An example of generating random numbers according to the Poisson distribution:

require 'numo/narray'
require 'numo/gnuplot'

require 'numo/random'

# Creating random number generator.
rng = Numo::Random::Generator.new(seed: 9)

# Generating random numbers with Poisson distribution.
x = rng.poisson(shape: 10000, mean: 12)

# Plotting the generated result.
h = x.bincount

Numo.gnuplot do
  set(terminal: 'png')
  set(output: 'poisson2d.png')
  plot(h, with: 'boxes')
end

poisson2d.png

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/yoshoku/numo-random. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the Apache-2.0 License.