func (pc *Ring) EncodeImpl(pat *[]float32, val float32, n int) {
	if len(*pat) != n {
		*pat = make([]float32, n)
	}
	if pc.Clip {
		val = mat32.Clamp(val, pc.Min, pc.Max)
	}
	rng := pc.Max - pc.Min
	gnrm := 1 / (rng * pc.Sigma)
	incr := rng / float32(n-1)
	for i := 0; i < n; i++ {
		trg := pc.Min + incr*float32(i)
		act := float32(0)
		switch pc.Code {
		case GaussBump:
			dist := gnrm * (trg - val)
			act = mat32.Exp(-(dist * dist))
		case Localist:
			dist := mat32.Abs(trg - val)
			if dist > incr {
				act = 0
			} else {
				act = 1.0 - (dist / incr)
			}
		}
		(*pat)[i] = act
	}
}
EncodeImpl generates a pattern of activation of given size to encode given value.
n must be 2 or more.
pat slice will be constructed if len != n
package popcode
import (
	"github.com/goki/mat32"
)
type Ring struct {
	OneD
	LowVec  []float32 `view:"-" desc:"low-end encoding vector"`
	HighVec []float32 `view:"-" desc:"high-end encoding vector"`
}
func (pc *Ring) AllocVecs(n int) {
	if cap(pc.LowVec) < n {
		pc.LowVec = make([]float32, n)
		pc.HighVec = make([]float32, n)
	}
	pc.LowVec = pc.LowVec[:n]
	pc.HighVec = pc.HighVec[:n]
}
func (pc *Ring) Encode(pat *[]float32, val float32, n int) {
	pc.Clip = false  
	if len(*pat) != n {
		*pat = make([]float32, n)
	}
	pc.AllocVecs(n)
	rng := pc.Max - pc.Min
	sr := pc.Sigma * rng
	if mat32.Abs(pc.Max-val) < sr {  
		pc.EncodeImpl(&pc.LowVec, pc.Min+(val-pc.Max), n)  
		pc.EncodeImpl(&pc.HighVec, val, n)
	} else if mat32.Abs(val-pc.Min) < sr {  
		pc.EncodeImpl(&pc.LowVec, val, n)                   
		pc.EncodeImpl(&pc.HighVec, pc.Max+(val-pc.Min), n)  
	} else {
		pc.EncodeImpl(pat, val, n)
		return
	}
	for i := 0; i < n; i++ {
		(*pat)[i] = pc.LowVec[i] + pc.HighVec[i]
	}
}