示例#1
0
// NewStrategy creates a basic strategy.
func NewStrategy(inputs, outputs uint, guide Guide, minLevel, maxLevel uint,
	absoluteError, relativeError, scoreError float64) *Strategy {

	return &Strategy{
		ni: inputs,
		no: outputs,

		guide: guide,

		lmin: minLevel,
		lmax: maxLevel,
		εs:   scoreError,

		active:    internal.NewActive(inputs),
		threshold: internal.NewThreshold(outputs, absoluteError, relativeError),
		hash:      internal.NewHash(inputs),
		unique:    internal.NewUnique(inputs),

		lndexer: make(map[string]uint),
		indexer: make(map[string]uint),
	}
}
示例#2
0
// Validate checks if an index set is admissible and contains no repetitions.
func Validate(indices []uint64, ni uint, parent grid.Parenter) bool {
	nn := uint(len(indices)) / ni

	hash := ainternal.NewHash(ni)
	mapping := make(map[string]bool)
	for i := uint(0); i < nn; i++ {
		key := hash.Key(indices[i*ni : (i+1)*ni])
		if _, ok := mapping[key]; ok {
			return false
		}
		mapping[key] = true
	}

	for i := uint(0); i < nn; i++ {
		root, found := true, false
		index := indices[i*ni : (i+1)*ni]
		for j := uint(0); !found && j < ni; j++ {
			level := rinternal.LEVEL_MASK & index[j]
			if level == 0 {
				continue
			} else {
				root = false
			}

			order := index[j] >> rinternal.LEVEL_SIZE
			plevel, porder := parent.Parent(level, order)

			index[j] = porder<<rinternal.LEVEL_SIZE | plevel
			_, found = mapping[hash.Key(index)]
			index[j] = order<<rinternal.LEVEL_SIZE | level
		}
		if !found && !root {
			return false
		}
	}

	return true
}