Example #1
0
// NewChecker4In creates a BlockChecker which feeds a
// block a few input sequences whose input vectors contain
// four values each.
func NewChecker4In(b rnn.Block, l sgd.Learner) *BlockChecker {
	testVars := []*autofunc.Variable{
		{Vector: []float64{0.098591, -0.595453, -0.751214, 0.266051}},
		{Vector: []float64{0.988517, 0.107284, -0.331529, 0.028565}},
		{Vector: []float64{-0.150604, 0.889039, 0.120916, 0.240999}},
		{Vector: []float64{0.961058, 0.878608, 0.052284, -0.635746}},
	}
	testSeqs := [][]*autofunc.Variable{
		{testVars[0], testVars[2]},
		{testVars[1]},
		{testVars[2], testVars[1], testVars[3]},
	}
	testRV := autofunc.RVector{
		testVars[0]: []float64{0.62524, -0.52979, 0.33020, 0.54462},
		testVars[1]: []float64{0.13498, 0.12607, 0.35989, 0.23255},
		testVars[2]: []float64{0.85996, 0.68435, -0.68506, 0.96907},
		testVars[3]: []float64{-0.79095, -0.33867, 0.86759, -0.16159},
	}
	for _, v := range l.Parameters() {
		testVars = append(testVars, v)
		testRV[v] = make(linalg.Vector, len(v.Vector))
		for i := range v.Vector {
			testRV[v][i] = rand.NormFloat64()
		}
	}
	return &BlockChecker{
		B:     b,
		Input: testSeqs,
		Vars:  testVars,
		RV:    testRV,
	}
}
Example #2
0
func randBaselineTestSeqs(l sgd.Learner, inSize int) ([][]*autofunc.Variable, autofunc.RVector) {
	var seqs [][]*autofunc.Variable

	// Empty sequences will help test for certain edge cases.
	seqs = append(seqs, nil)

	rv := autofunc.RVector{}
	for i := 0; i < BaselineSeqCount; i++ {
		count := rand.Intn(BaselineSeqMaxLen-BaselineSeqMinLen) + BaselineSeqMinLen
		seq := make([]*autofunc.Variable, count)
		for j := range seq {
			seq[j] = &autofunc.Variable{
				Vector: make(linalg.Vector, inSize),
			}
			for k := range seq[j].Vector {
				seq[j].Vector[k] = rand.NormFloat64()
			}
			rv[seq[j]] = make(linalg.Vector, inSize)
			for k := range rv[seq[j]] {
				rv[seq[j]][k] = rand.NormFloat64()
			}
		}
		seqs = append(seqs, seq)
	}

	// Empty sequences will help test for certain edge cases.
	seqs = append(seqs, nil)

	for _, param := range l.Parameters() {
		rv[param] = make(linalg.Vector, len(param.Vector))
		for i := range rv[param] {
			rv[param][i] = rand.NormFloat64()
		}
	}

	return seqs, rv
}