Documentation
¶
Overview ¶
Package patterns contains functions that generate patterns, typically based on various constrained-forms of random patterns.
Index ¶
- Variables
- func FlipBits(tsr tensor.Values, nOff, nOn int, onVal, offVal float64)
- func FlipBitsRows(tsr tensor.Values, nOff, nOn int, onVal, offVal float64)
- func Mix(dest tensor.Values, rows int, srcs ...tensor.Values) error
- func NFromPct(pct float64, n int) int
- func NOnInTensor(trow tensor.Values) int
- func NameRows(tsr tensor.Values, prefix string, nzeros int)
- func NewRand(seed int64)
- func PctActInTensor(trow tensor.Values) float32
- func PermutedBinary(tsr tensor.Values, nOn int, onVal, offVal float64)
- func PermutedBinaryMinDiff(tsr tensor.Values, nOn int, onVal, offVal float64, minDiff int) error
- func PermutedBinaryRows(tsr tensor.Values, nOn int, onVal, offVal float64)
- func ReplicateRows(dest, src tensor.Values, nCopies int)
- func RestoreSeed()
- func SetRandSeed(seed int64)
- func Shuffle(src tensor.Values) *tensor.Rows
- func SplitRows(dir *tensorfs.Node, src tensor.Values, names []string, rows ...int) error
Constants ¶
This section is empty.
Variables ¶
var ( // RandSource is a random source to use for all random numbers used in patterns. // By default it just uses the standard Go math/rand source. // If initialized, e.g., by calling NewRand(seed), then a separate stream of // random numbers will be generated for all calls, and the seed is saved as // RandSeed. It can be reinstated by calling RestoreSeed. // Can also set RandSource to another existing randx.Rand source to use it. RandSource = &randx.SysRand{} // Random seed last set by NewRand or SetRandSeed. RandSeed int64 )
var MinDiffPrintIterations = false
MinDiffPrintIterations set this to true to see the iteration stats for PermutedBinaryMinDiff -- for large, long-running cases.
Functions ¶
func FlipBits ¶
FlipBits turns nOff bits that are currently On to Off and nOn bits that are currently Off to On, using permuted lists.
func FlipBitsRows ¶
FlipBitsRows turns nOff bits that are currently On to Off and nOn bits that are currently Off to On, using permuted lists. Iterates over the outer-most tensor dimension as rows.
func Mix ¶
Mix mixes patterns from different tensors into a combined set of patterns, over the outermost row dimension (i.e., each source is a list of patterns over rows). The source tensors must have the same cell size, and the existing shape of the destination will be used if compatible, otherwise reshaped with linear list of sub-tensors. Each source list wraps around if shorter than the total number of rows specified.
func NFromPct ¶
NFromPct returns the number of bits for given pct (proportion 0-1), relative to total n: just int(math.Round(pct * n))
func NOnInTensor ¶
NOnInTensor returns the number of bits active in given tensor
func NewRand ¶
func NewRand(seed int64)
NewRand sets RandSource to a new separate random number stream using given seed, which is saved as RandSeed -- see RestoreSeed.
func PctActInTensor ¶
PctActInTensor returns the percent activity in given tensor (NOn / size)
func PermutedBinary ¶
PermutedBinary sets the given tensor to contain nOn onVal values and the remainder are offVal values, using a permuted order of tensor elements (i.e., randomly shuffled or permuted).
func PermutedBinaryMinDiff ¶
PermutedBinaryMinDiff uses the tensor.RowMajor view of a tensor as a column of rows as in a [table.Table], setting each row to contain nOn onVal values, with the remainder being offVal values, using a permuted order of tensor elements (i.e., randomly shuffled or permuted). This version (see also PermutedBinaryRows) ensures that all patterns have at least a given minimum distance from each other, expressed using minDiff = number of bits that must be different (can't be > nOn). If the mindiff constraint cannot be met within 100 iterations, an error is returned and automatically logged.
func PermutedBinaryRows ¶
PermutedBinaryRows uses the tensor.RowMajor view of a tensor as a column of rows as in a [table.Table], setting each row to contain nOn onVal values with the remainder being offVal values, using a permuted order of tensor elements (i.e., randomly shuffled or permuted). See also PermutedBinaryMinDiff.
func ReplicateRows ¶
ReplicateRows adds nCopies rows of the source tensor pattern into the destination tensor. The destination shape is set to ensure it can contain the results, preserving any existing rows of data.
func RestoreSeed ¶
func RestoreSeed()
RestoreSeed restores the random seed last used -- random number sequence will repeat what was generated from that point onward.
func SetRandSeed ¶
func SetRandSeed(seed int64)
SetRandSeed sets existing random number stream to use given random seed, starting from the next call. Saves the seed in RandSeed -- see RestoreSeed.
func Shuffle ¶
Shuffle returns a tensor.Rows view of the given source tensor with the outer row-wise dimension randomly shuffled (permuted).
Types ¶
This section is empty.