bertini.random

bertini.random.complex_bounded_modulus() → bertini._pybertini.multiprec.complex_mp :

Make a random complex number of bounded modulus (box-uniform in [-1,1]x[-1,1], magnitude at most sqrt(2), away from 0 – the Bertini coefficient draw), in the current default precision

bertini.random.complex_in_minus_one_to_one() → bertini._pybertini.multiprec.complex_mp :

Make a random complex number uniformly distributed in [-1,1]x[-1,1], in the current default precision

bertini.random.complex_unit() → bertini._pybertini.multiprec.complex_mp :

Make a random complex number of magnitude 1, in the current default precision

bertini.random.conjugate_orthonormal_matrix((int)rows, (int)cols[, (bool)real=False]) → numpy.ndarray :

A rows x cols random conjugate-orthonormal matrix (its rows orthonormal – QR-factored from a square matrix of units, then truncated; perfectly conditioned), at the current default precision. real=True yields a real orthogonal matrix (entries with zero imaginary part). Returns a complex_mp matrix.

bertini.random.derive_solve_seed() → int :

Capture the session stream’s current position as an effective per-solve seed: one draw off the current stream (advancing it), nonzero, 32-bit portable. bertini.solve uses this when no explicit seed is given, so a recorded run’s seed reproduces that run standalone – deterministic from the session master when one was set, random for a never-seeded session.

bertini.random.get_random_seed() → int :

Return the global RNG seed in effect. If none has been set, draws one from entropy on the first call and keeps it.

bertini.random.random_complex(symbolic=False)[source]

A random complex number of bounded modulus, at the current default precision.

Modulus pulled toward 1 (away from 0 and infinity) – the Bertini genericity draw. Reproducible via set_random_seed().

Parameters:

symbolic (bool, default False) – When False (default) return a numeric multiprec.complex_mp value. When True return a constant function-tree node (a Complex leaf) ready to drop straight into an expression. bertini.symbolics.random_complex is the always-symbolic shortcut.

Notes

The node carries exactly the digits drawn, i.e. the current default precision – set bertini.default_precision(1000) first for a 1000-digit constant. For a precision-independent exact random constant use bertini.symbolics.Rational.rand instead.

bertini.random.random_real(symbolic=False)[source]

A random real number of bounded modulus, at the current default precision.

Box-uniform in [-1, 1] and pulled away from 0 – the Bertini genericity draw. Reproducible via set_random_seed().

Parameters:

symbolic (bool, default False) – When False (default) return a numeric multiprec.real_mp value. When True return a constant function-tree node (a real Complex leaf, imaginary part 0) ready to drop straight into an expression – the spelling to reach for when you want a random coefficient rather than a random value. bertini.symbolics.random_real is the always-symbolic shortcut.

Notes

The node carries exactly the digits drawn, i.e. the current default precision – set bertini.default_precision(1000) first for a 1000-digit constant. (A random float can be no more precise than its draw; for a precision-independent exact random constant use bertini.symbolics.Rational.rand_real instead.)

bertini.random.random_vector(size, real=False, symbolic=False)[source]

A random length-size vector of bounded-modulus numbers, at the current default precision.

The natural random projection / linear-functional coefficient vector (generic and seed-reproducible, unlike the quantized orthonormal random_matrix()).

Parameters:
  • size (int) – The length of the vector.

  • real (bool, default False) – When True the entries are real (real_mp); otherwise complex (complex_mp).

  • symbolic (bool, default False) – When True return a numpy object array of constant coefficient nodes (via bertini.coefficients()) rather than numeric multiprecision values – each entry a Complex leaf.

Notes

As for random_real(), a symbolic entry carries the current default precision’s worth of digits; set bertini.default_precision first if you need more.

bertini.random.real_as_complex() → bertini._pybertini.multiprec.complex_mp :

Make a random real number in [-1,1], as a complex number with imaginary part 0, in the current default precision

bertini.random.real_bounded_modulus() → bertini._pybertini.multiprec.complex_mp :

Make a random real number of bounded modulus (box-uniform in [-1,1]), as a complex number with imaginary part 0, in the current default precision

bertini.random.real_unit() → bertini._pybertini.multiprec.complex_mp :

Make a random real number of unit modulus (i.e. +1 or -1), as a complex number with imaginary part 0, in the current default precision

bertini.random.set_random_seed([(object)seed=None]) → int :

Set the global RNG seed, and return it. Every non-negative integer is a seed, 0 included, as in numpy and Python’s random; set_random_seed() or set_random_seed(None) draws one from entropy, and the returned value reproduces the run. Call before constructing any homotopy or solver to get reproducible results. (In a classic Bertini input file, randomseed: 0 instead means draw from entropy, as in Bertini 1.)

bertini.random.random_matrix(rows, cols, real=False, units=False, orthonormal=True, symbolic=False)[source]

A rows x cols random matrix, at the current default precision.

The building block for a random linear form / projection / slice / patch – they are all just linear functions, and “what you use them for is up to you.” Returns a numpy array of arbitrary-precision values (bertini.multiprec.Complex); pass symbolic=True to instead get coefficient nodes ready to drop straight into function-tree expressions.

Parameters:
  • rows (int) – The shape of the matrix.

  • cols (int) – The shape of the matrix.

  • real (bool, default False) – When True the entries are real (zero imaginary part); otherwise complex.

  • units (bool, default False) – When True (and not orthonormal) each entry has modulus 1 (a real unit is +/-1); otherwise each entry is drawn with bounded modulus (box-uniform in [-1,1] per component).

  • orthonormal (bool, default True) – When True the rows are conjugate-orthonormal (QR-factored from a square matrix of units, then truncated – perfectly conditioned). real=True gives a real orthogonal matrix. orthonormal takes precedence over units (orthonormal rows are already normalized).

  • symbolic (bool, default False) – When True, return a numpy object array of coefficient nodes (via bertini.coefficients()); otherwise numeric multiprec.complex_mp.

Notes

Reproducible via bertini.random.set_random_seed(). A projection is just a linear functional with zero constant term, so its gradient row is exactly random_matrix(1, n).

For a generic real direction (e.g. a real projection), prefer bertini.random_vector() with real=True: a real orthonormal matrix is QR-factored from a matrix of real units (+/-1), so its entries are quantized (a real random_matrix(3, 1) has entries +/-1/sqrt(3)) and look seed-independent – fine for conditioning, but not a generic direction. random_vector draws continuous bounded-modulus reals instead (generic and seed-reproducible).