math::quasirandom(n)
β¨ math::quasirandom(n) β¨
okay bestie, so this is a page from the Tcl Math Library manual, and it's literally about quasi-random points for integration and Monte Carlo type methods π like, no cap, it's giving "math but make it cover the whole space evenly."
πΈ SYNOPSIS πΈ
package require Tcl 8.6 9
package require TclOO
package require math::quasirandom 1.1
::math::quasirandom::qrpoint create NAME DIM ?ARGS?
gen next
gen set-start index
gen set-evaluations number
gen integral func minmax args
π¦ DESCRIPTION π¦
so picture this: in so many applications, pseudo-random numbers and pseudo-random points in a (limited) sample space are doing the absolute most. Like, any type of Monte Carlo simulation? Yeah, they're there. Pseudo-random numbers, however, can be too random, and the consequence is kinda tragic β you need a huge number of data points just to reduce the error or the fluctuation in the results down to the value you actually want π
enter quasi-random numbers: the alternative we've all been waiting for. Instead of "completely" arbitrary points, you generate points that are diverse enough to cover the entire sample space in a more or less uniform way. And as a consequence? Convergence to the limit can be much faster when such quasi-random numbers are well-chosen. slay.
This package defines a class "qrpoint" that creates a command to generate quasi-random points in 1, 2 or more dimensions. The command can either generate separate points, so that they can be used in a user-defined algorithm, or use these points to calculate integrals of functions defined over 1, 2 or more dimensions. It also holds several other common algorithms. (NOTE: these are not implemented yet π)
One particular characteristic of the generators is that there are no tuning parameters involved, which makes the use particularly simple. iconic behaviour, honestly.
π COMMANDS π
A quasi-random point generator is created using the qrpoint class:
::math::quasirandom::qrpoint create NAME DIM ?ARGS?β this command takes the following arguments:- string
NAMEβ the name of the command to be created (alternatively: the new subcommand will generate a unique name). - integer/string
DIMβ the number of dimensions, or one of:"circle","disk","sphere"or"ball". - strings
ARGSβ zero or more key-value pairs. The supported options are:-start indexβ the index for the next point to be generated (default:1).-evaluations numberβ the number of evaluations to be used by default (default:100).
- string
The points that are returned lie in the hyperblock [0,1[^n (n = the number of dimensions) or on the unit circle, within the unit disk, on the unit sphere or within the unit ball. β¨
Each generator supports the following subcommands:
gen nextβ return the coordinates of the next quasi-random point.gen set-start indexβ reset the index for the next quasi-random point. This is useful to control which list of points is returned. Returns the new or the current value, if no value is given.gen set-evaluations numberβ reset the default number of evaluations in compound algorithms. Note that the actual number is the smallest 4-fold larger or equal to the given number. (The 4-fold plays a role in the detailed integration routine.)gen integral func minmax argsβ calculate the integral of the given function over the block (or the circle, sphere etc.)- string
funcβ the name of the function to be integrated. - list
minmaxβ list of pairs of minimum and maximum coordinates. This can be used to map the quasi-random coordinates to the desired hyper-block.
- string
If the space is a circle, disk etc. then this argument should be a single value, the radius. The circle, disk, etc. is centred at the origin. If this is not what is required, then a coordinate transformation should be made within the function.
- strings
argsβ zero or more key-value pairs. The following options are supported:-evaluations numberβ the number of evaluations to be used. If not specified, use the default of the generator object.
π TODO π
- Implement other algorithms and variants
- Implement more unit tests.
- Comparison to pseudo-random numbers for integration.
π REFERENCES π
Various algorithms exist for generating quasi-random numbers. The generators created in this package are based on: http://extremelearning.com.au/unreasonable-effectiveness-of-quasirandom-sequences/
π KEYWORDS π
mathematics, quasi-random
β CATEGORY β
Mathematics
and that's the whole vibe check, bestie π«Ά this lil masterpiece comes to you from tcllib, version 1.1, and it lives its best life as the manual page math::quasirandom(n). go integrate something gorgeous πβ¨
π¦ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 Β· TCL
- fedora 44: tcllib 2.0-4.fc44 Β· TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms