Math::...otstrap(3pm)

πŸ“¦
version 0.22 Β· 2 versions
  • 0.22 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.22 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ Math::...otstrap πŸ’–

okay bestie, welcome to Math::Random::OO::Bootstrap β€” it's a Perl module, it lives in the User Contributed Perl Documentation section (man page Math::...otstrap(3pm), iykyk), and it does exactly one thing but does it flawlessly: it generates random numbers by bootstrap resampling from a non-parametric distribution. no cap. πŸ’…


🌸 NAME 🌸

Math::Random::OO::Bootstrap β€” generate random numbers with bootstrap resampling from a non-parametric distribution. literally that's the whole vibe. πŸŽ€


πŸ¦‹ VERSION πŸ¦‹

version 0.22 ✨


πŸ’œ SYNOPSIS πŸ’œ

  use Math::Random::OO::Bootstrap;
  @sample = qw( 2 3 3 4 4 5 5 6 6 7 );
  $prng = Math::Random::OO::Bootstrap->new(@sample);
  $prng->seed(42);
  $prng->next() # draws randomly from the sample

see how cute that is?? you hand it a lil pile of observations, you seed it, and it just hands you back random picks from the pile. main character energy fr fr. 🌈


πŸŽ€ DESCRIPTION πŸŽ€

so this is a subclass of Math::Random::OO, and what it does is generate random numbers with bootstrap resampling β€” that's resampling with replacement, bestie, meaning you can pull the same value over and over β€” from a given set of observations.

and the way each item in the sample array gets drawn? equal probability. every single one. no favourites, no rigging, no drama. πŸ‘‘


πŸ’… METHODS πŸ’…

🌟 new

  $prng = Math::Random::OO::Bootstrap->new(@sample);
  $prng = Math::Random::OO::Bootstrap->new(\@sample);

new takes either a list or a reference to an array holding a set of observations, and returns you a brand new Math::Random::OO::Bootstrap object. 🫢

and here's the thoughtful part: if you hand it a reference, the object makes an internal copy of the array β€” so if you go and mutate your original array afterwards, nothing chaotic happens. it's giving "I made a backup, you're welcome." 😌

⚠️ important!! if the sample you want is an array of array references, you gotta wrap that list in an anonymous array reference, or it gets ambiguous and things go wrong. listen:
  @sample = ( [ 1, 2, 3], [2, 3, 4] );

  # Correct way
  $prng = Math::Random::OO::Bootstrap->new( [ @sample ] );

  # Incorrect -- will only use [1, 2, 3] as the desired sample
  $prng = Math::Random::OO::Bootstrap->new( @sample );

see that?? the "incorrect" one only uses [1, 2, 3] as the desired sample. so do the correct one. do it. πŸ’€

and also: calling new with no arguments is an error. don't do that. πŸ™ˆ


🌟 seed

  $rv = $prng->seed( @seeds );

this method seeds the random number generator. 🌱

at the moment, only the first seed value matters β€” the rest are just kinda there, vibing. and it should be a positive integer. that's it, that's the tea. πŸ“


🌟 next

  $rnd = $prng->next();

this method returns the next random number from the random number generator by resampling with replacement from the provided data. 🎲

it does not take any parameters. zero. none. it just shows up and delivers. iconic behaviour honestly. ✨


πŸ‘‘ AUTHOR πŸ‘‘

David Golden <dagolden@cpan.org> πŸ’–


This software is Copyright (c) 2013 by David Golden.

This is free software, licensed under:

  The Apache License, Version 2.0, January 2004

okay that's the whole page bestie!! πŸ¦‹ this was perl v5.36.0, dated 2022-12-12, from the Math::...otstrap(3pm) man page β€” mwah, go forth and resample responsibly, ily, periodt. πŸ’–βœ¨πŸŽ€