patgen

package
v1.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 3, 2022 License: BSD-3-Clause Imports: 14 Imported by: 57

README

Docs: GoDoc

Package patgen contains functions that generate patterns, typically based on various constrained-forms of random patterns, e.g., permuted binary random patterns.

Pattern Generator

Pattern generator is capable of flexibly making patterns for models. To configure your own patterns, follow these four steps:

  1. make your vocabulary as a pool name -- tensor map;
  2. use your vocabulary to initialize a big pattern (e.g., TrainAB), in which you later use to store input & output patterns;
  3. mix different pools in the vocabulary into one pattern (e.g., A+B+context-->input pattern), which is stored in the big pattern;
  4. repeat 3) for the output pattern.

Example code could be found in ConfigPats() in hip bench.

Documentation

Overview

Package patgen contains functions that generate patterns, typically based on various constrained-forms of random patterns

Index

Constants

This section is empty.

Variables

View Source
var MinDiffPrintIters = false

MinDiffPrintIters set this to true to see the iteration stats for PermutedBinaryMinDiff -- for large, long-running cases.

Functions

func AddVocabClone added in v1.0.1

func AddVocabClone(mp Vocab, name string, copyFrom string) (*etensor.Float32, error)

AddVocabClone clones an existing pool in the vocabulary to make a new one.

func AddVocabDrift added in v1.0.1

func AddVocabDrift(mp Vocab, name string, rows int, pctDrift float32, copyFrom string, copyRow int) (*etensor.Float32, error)

AddVocabDrift adds a row-by-row drifting pool to the vocabulary, starting from the given row in existing vocabulary item (which becomes starting row in this one -- drift starts in second row). The current row patterns are generated by taking the previous row pattern and flipping pctDrift percent of active bits (min of 1 bit).

func AddVocabEmpty added in v1.0.1

func AddVocabEmpty(mp Vocab, name string, rows, poolY, poolX int) (*etensor.Float32, error)

AddVocabEmpty adds an empty pool to the vocabulary. This can be used to make test cases with missing pools.

func AddVocabPermutedBinary added in v1.0.1

func AddVocabPermutedBinary(mp Vocab, name string, rows, poolY, poolX int, pctAct, minPctDiff float32) (*etensor.Float32, error)

AddVocabPermutedBinary adds a permuted binary pool to the vocabulary. This is a good source of random patterns with no systematic similarity. pctAct = proportion (0-1) bits turned on for a pool. minPctDiff = proportion of pctAct (0-1) for minimum difference between patterns -- e.g., .5 = each pattern must have half of its bits different from each other. This constraint can be hard to meet depending on the number of rows, amount of activity, and minPctDiff level -- an error will be returned and printed if it cannot be satisfied in a reasonable amount of time.

func AddVocabRepeat added in v1.0.1

func AddVocabRepeat(mp Vocab, name string, rows int, copyFrom string, copyRow int) (*etensor.Float32, error)

AddVocabRepeat adds a repeated pool to the vocabulary, copying from given row in existing vocabulary item .

func FlipBits added in v1.0.1

func FlipBits(tsr etensor.Tensor, nOff, nOn int, onVal, offVal float64)

FlipBits turns nOff bits that are currently On to Off and nOn bits that are currently Off to On, using permuted lists.

func FlipBitsRows added in v1.0.1

func FlipBitsRows(tsr etensor.Tensor, nOff, nOn int, onVal, offVal float64)

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 InitPats added in v1.0.1

func InitPats(dt *etable.Table, name, desc, inputName, outputName string, listSize, ySize, xSize, poolY, poolX int)

InitPats initiates patterns to be used in MixPats

func MixPats added in v1.0.1

func MixPats(dt *etable.Table, mp Vocab, colName string, poolSource []string) error

MixPats mixes patterns using first listSize rows in the vocabulary map poolSource order: left right, bottom up

func MixPatsN added in v1.1.5

func MixPatsN(dt *etable.Table, mp Vocab, colName string, poolSource []string, targRow, vocabStart, vocabN int) error

MixPatsN mixes patterns using specified startVocab and vocabN numbers of vocabulary patterns, inserting starting at specified targRow in table. poolSource order: left right, bottom up

func NFmPct added in v1.0.1

func NFmPct(pct float32, n int) int

NFmPct returns the number of bits for given pct (proportion 0-1), relative to total n. uses math.Round.

func NOnInTensor added in v1.0.1

func NOnInTensor(trow *etensor.Float32) int

NOnInTensor returns the number of bits active in given tensor

func PctActInTensor added in v1.0.1

func PctActInTensor(trow *etensor.Float32) float32

PctActInTensor returns the percent activity in given tensor (NOn / size)

func PermutedBinary

func PermutedBinary(tsr etensor.Tensor, nOn int, onVal, offVal float64)

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 added in v1.0.1

func PermutedBinaryMinDiff(tsr *etensor.Float32, nOn int, onVal, offVal float32, minDiff int) error

PermutedBinaryMinDiff treats the tensor as a column of rows as in a etable.Table and sets each row to contain nOn onVal values and the remainder are offVal values, using a permuted order of tensor elements (i.e., randomly shuffled or permuted). This version 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 a reasonable number of iterations, then an error is returned.

func PermutedBinaryRows

func PermutedBinaryRows(tsr etensor.Tensor, nOn int, onVal, offVal float64)

PermutedBinaryRows treats the tensor as a column of rows as in a etable.Table and sets each row 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 ReshapeCpp added in v1.0.0

func ReshapeCpp(dt *etable.Table)

ReshapeCpp fixes C++ emergent table shape which is reversed from Go. it switches the dimension order in the given table, for all columns that are float 2D or 4D columns -- assumes these are layer patterns and names dimensions accordingly.

func ReshapeCppFile added in v1.0.0

func ReshapeCppFile(dt *etable.Table, fname, fixnm string)

ReshapeCppFile fixes C++ emergent table shape which is reversed from Go. It loads file from fname and saves to fixnm

func RowVsPrevDist32 added in v1.0.1

func RowVsPrevDist32(tsr *etensor.Float32, row int, fun metric.Func32) (min, max float32)

RowVsPrevDist32 returns the minimum and maximum distance between the given row in tensor and all previous rows. Row must be >= 1 and < total rows. (outer-most dimension is row, as in columns of etable.Table).

func Shuffle added in v1.0.1

func Shuffle(dt *etable.Table, rows []int, colNames []string, colIndependent bool)

Shuffle shuffles rows in specified columns in the table independently

func VocabConcat added in v1.0.1

func VocabConcat(mp Vocab, newPool string, frmPools []string) error

VocabConcat contatenates several pools in the vocabulary and store it into newPool (could be one of the previous pools).

func VocabShuffle added in v1.0.1

func VocabShuffle(mp Vocab, shufflePools []string)

VocabShuffle shuffles a pool in the vocabulary on its first dimension (row).

func VocabSlice added in v1.0.1

func VocabSlice(mp Vocab, frmPool string, newPools []string, sliceOffs []int) error

VocabSlice slices a pool in the vocabulary into new ones. SliceOffs is the cutoff points in the original pool, should have one more element than newPools.

Types

type Vocab added in v1.0.1

type Vocab map[string]*etensor.Float32

Vocab is a map of named tensors that contain patterns used for creating larger patterns by mixing together.

func (Vocab) ByNameTry added in v1.0.1

func (vc Vocab) ByNameTry(name string) (*etensor.Float32, error)

ByNameTry looks for vocabulary item of given name, and returns (and logs) error message if not found

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL