本文整理汇总了Golang中github.com/zacg/testify/assert.Equal函数的典型用法代码示例。如果您正苦于以下问题:Golang Equal函数的具体用法?Golang Equal怎么用?Golang Equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Equal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestUpdateDutyCycleHelper
func TestUpdateDutyCycleHelper(t *testing.T) {
dc := []float64{1000.0, 1000.0, 1000.0, 1000.0, 1000.0}
period := 1000
newvals := make([]int, 5)
actual := updateDutyCyclesHelper(dc, newvals, period)
expected := []float64{999, 999, 999, 999, 999}
assert.Equal(t, expected, actual)
utils.FillSliceInt(newvals, 1000)
actual = updateDutyCyclesHelper(dc, newvals, period)
assert.Equal(t, dc, actual)
newvals = []int{2000, 4000, 5000, 6000, 7000}
expected = []float64{1001, 1003, 1004, 1005, 1006}
actual = updateDutyCyclesHelper(dc, newvals, period)
assert.Equal(t, expected, actual)
dc = []float64{1000, 800, 600, 400, 2000}
utils.FillSliceInt(newvals, 0)
period = 2
actual = updateDutyCyclesHelper(dc, newvals, period)
expected = []float64{500, 400, 300, 200, 1000}
assert.Equal(t, expected, actual)
}
示例2: TestUpdatePermanencesForColumn
func TestUpdatePermanencesForColumn(t *testing.T) {
sp := SpatialPooler{}
sp.InputDimensions = []int{5}
sp.ColumnDimensions = []int{5}
sp.numColumns = 5
sp.numInputs = 5
sp.SynPermConnected = 0.1
sp.SynPermTrimThreshold = 0.05
sp.connectedCounts = make([]int, sp.numColumns)
elms := make(map[int]float64, 25)
sp.permanences = matrix.MakeSparseMatrix(elms, sp.numColumns, sp.numInputs)
sp.potentialPools = NewDenseBinaryMatrix(sp.numColumns, sp.numInputs)
sp.connectedSynapses = NewDenseBinaryMatrix(sp.numColumns, sp.numInputs)
sp.SynPermMax = 1
sp.SynPermMin = 0
permanences := [][]float64{
{-0.10, 0.500, 0.400, 0.010, 0.020},
{0.300, 0.010, 0.020, 0.120, 0.090},
{0.070, 0.050, 1.030, 0.190, 0.060},
{0.180, 0.090, 0.110, 0.010, 0.030},
{0.200, 0.101, 0.050, -0.09, 1.100}}
/*
These are the 'true permanences' reflected in trueConnectedSynapses
truePermanences = SparseMatrix(
[[0.000, 0.500, 0.400, 0.000, 0.000],
Clip - - Trim Trim
[0.300, 0.000, 0.000, 0.120, 0.090],
- Trim Trim - -
[0.070, 0.050, 1.000, 0.190, 0.060],
- - Clip - -
[0.180, 0.090, 0.110, 0.000, 0.000],
- - - Trim Trim
[0.200, 0.101, 0.050, 0.000, 1.000]])
- - - Clip Clip
*/
trueConnectedSynapses := utils.Make2DBool([][]int{{0, 1, 1, 0, 0},
{1, 0, 0, 1, 0},
{0, 0, 1, 1, 0},
{1, 0, 1, 0, 0},
{1, 1, 0, 0, 1}})
trueConnectedCounts := []int{2, 2, 2, 2, 3}
for i := 0; i < sp.numColumns; i++ {
sp.updatePermanencesForColumn(permanences[i], i, true)
assert.Equal(t, trueConnectedSynapses[i], sp.connectedSynapses.GetDenseRow(i))
}
assert.Equal(t, trueConnectedCounts, sp.connectedCounts)
}
示例3: phase2
func phase2(t *testing.T, bt *boostTest) {
y := make([]bool, bt.sp.numColumns)
// Do 9 training batch through the input patterns
for i := 0; i < 9; i++ {
for idx, input := range bt.x {
utils.FillSliceBool(y, false)
bt.sp.Compute(input, true, y, bt.sp.InhibitColumns)
for j, winner := range y {
if winner {
bt.winningIteration[j] = bt.sp.IterationLearnNum
}
}
bt.lastSDR[idx] = y
}
}
// The boost factor for all columns should be at 1.
assert.Equal(t, bt.sp.numColumns, utils.CountFloat64(bt.sp.boostFactors, 1), "Boost factors are not all 1")
// Roughly half of the columns should have never been active.
winners := utils.CountInt(bt.winningIteration, 0)
assert.True(t, winners >= int(0.4*float64(bt.sp.numColumns)), "More than 60% of the columns have been active")
// All the never-active columns should have duty cycle of 0
activeSum := 0.0
for idx, val := range bt.sp.activeDutyCycles {
if bt.winningIteration[idx] == 0 {
activeSum += val
}
}
assert.Equal(t, 0, activeSum, "Inactive columns have positive duty cycle.")
dutyAvg := 0.0
dutyCount := 0
for _, val := range bt.sp.activeDutyCycles {
if val > 0 {
dutyAvg += val
dutyCount++
}
}
// The average at-least-once-active columns should have duty cycle >= 0.15
// and <= 0.25
dutyAvg = dutyAvg / float64(dutyCount)
assert.True(t, dutyAvg >= 0.15, "Average on-columns duty cycle is too low.")
assert.True(t, dutyAvg <= 0.30, "Average on-columns duty cycle is too high.")
verifySDRProps(t, bt)
}
示例4: TestUpdateMinDutyCyclesGlobal
func TestUpdateMinDutyCyclesGlobal(t *testing.T) {
sp := SpatialPooler{}
sp.MinPctActiveDutyCycles = 0.02
sp.MinPctOverlapDutyCycles = 0.01
sp.numColumns = 5
sp.overlapDutyCycles = []float64{0.06, 1, 3, 6, 0.5}
sp.activeDutyCycles = []float64{0.6, 0.07, 0.5, 0.4, 0.3}
sp.minOverlapDutyCycles = make([]float64, sp.numColumns)
sp.minActiveDutyCycles = make([]float64, sp.numColumns)
sp.updateMinDutyCyclesGlobal()
trueMinActiveDutyCycles := utils.MakeSliceFloat64(sp.numColumns, 0.02*0.6)
trueMinOverlapDutyCycles := utils.MakeSliceFloat64(sp.numColumns, 0.01*6)
assert.Equal(t, 5, len(sp.minActiveDutyCycles))
assert.Equal(t, 5, len(sp.minOverlapDutyCycles))
for i := 0; i < sp.numColumns; i++ {
assert.AlmostEqualFloat(t, trueMinActiveDutyCycles[i], sp.minActiveDutyCycles[i])
assert.AlmostEqualFloat(t, trueMinOverlapDutyCycles[i], sp.minOverlapDutyCycles[i])
}
sp.MinPctOverlapDutyCycles = 0.015
sp.MinPctActiveDutyCycles = 0.03
sp.numColumns = 5
sp.overlapDutyCycles = []float64{0.86, 2.4, 0.03, 1.6, 1.5}
sp.activeDutyCycles = []float64{0.16, 0.007, 0.15, 0.54, 0.13}
sp.updateMinDutyCyclesGlobal()
trueMinOverlapDutyCycles = utils.MakeSliceFloat64(sp.numColumns, 0.015*2.4)
for i := 0; i < sp.numColumns; i++ {
assert.AlmostEqualFloat(t, trueMinOverlapDutyCycles[i], sp.minOverlapDutyCycles[i])
}
sp.MinPctOverlapDutyCycles = 0.015
sp.MinPctActiveDutyCycles = 0.03
sp.numColumns = 5
sp.overlapDutyCycles = utils.MakeSliceFloat64(sp.numColumns, 0)
sp.activeDutyCycles = utils.MakeSliceFloat64(sp.numColumns, 0)
sp.updateMinDutyCyclesGlobal()
trueMinActiveDutyCycles = utils.MakeSliceFloat64(sp.numColumns, 0)
trueMinOverlapDutyCycles = utils.MakeSliceFloat64(sp.numColumns, 0)
assert.Equal(t, 5, len(sp.minActiveDutyCycles))
assert.Equal(t, 5, len(sp.minOverlapDutyCycles))
for i := 0; i < sp.numColumns; i++ {
assert.AlmostEqualFloat(t, trueMinActiveDutyCycles[i], sp.minActiveDutyCycles[i])
assert.AlmostEqualFloat(t, trueMinOverlapDutyCycles[i], sp.minOverlapDutyCycles[i])
}
}
示例5: TestUpdateSynapsePermanence
func TestUpdateSynapsePermanence(t *testing.T) {
c := NewTemporalMemoryConnections(1000, 32, []int{64, 64})
c.CreateSegment(0)
c.CreateSynapse(0, 483, 0.1284)
c.UpdateSynapsePermanence(0, 0.2496)
assert.Equal(t, 0.2496, c.DataForSynapse(0).Permanence)
}
示例6: TestInhibitColumnsGlobal
func TestInhibitColumnsGlobal(t *testing.T) {
sp := SpatialPooler{}
density := 0.3
sp.numColumns = 10
overlaps := []float64{1, 2, 1, 4, 8, 3, 12, 5, 4, 1}
active := sp.inhibitColumnsGlobal(overlaps, density)
trueActive := []int{4, 6, 7}
assert.Equal(t, trueActive, active)
density = 0.5
overlaps = []float64{0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
active = sp.inhibitColumnsGlobal(overlaps, density)
trueActive = []int{5, 6, 7, 8, 9}
assert.Equal(t, trueActive, active)
}
示例7: TestAvgConnectedSpanForColumn2D
func TestAvgConnectedSpanForColumn2D(t *testing.T) {
sp := SpatialPooler{}
sp.InputDimensions = []int{8}
sp.numInputs = 8
sp.numColumns = 9
sp.ColumnDimensions = []int{9}
ints := [][]int{{0, 1, 0, 1, 0, 1, 0, 1},
{0, 0, 0, 1, 0, 0, 0, 1},
{0, 0, 0, 0, 0, 0, 1, 0},
{0, 0, 1, 0, 0, 0, 1, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 1, 1, 0, 0, 0, 0, 0},
{0, 0, 1, 1, 1, 0, 0, 0},
{0, 0, 1, 0, 1, 0, 0, 0},
{1, 1, 1, 1, 1, 1, 1, 1}}
sp.connectedSynapses = NewDenseBinaryMatrixFromInts(ints)
trueAvgConnectedSpan := []int{7, 5, 1, 5, 0, 2, 3, 3, 8}
for i := 0; i < sp.numColumns; i++ {
connectedSpan := sp.avgConnectedSpanForColumnND(i)
assert.Equal(t, trueAvgConnectedSpan[i], connectedSpan)
}
}
示例8: TestParseXmlNodesWithCdataAndComment
func TestParseXmlNodesWithCdataAndComment(t *testing.T) {
var actuals []string = make([]string, 10)
var actualsPos int = 0
emitter := func(ed *contentBuffer.EmitterData) bool {
actuals[actualsPos] = ed.Content
actualsPos++
return false
}
reader := bytes.NewReader([]byte("<helloA><!-- test<>--<><--><helloB><helloC><![CDATA[Hello<! World!]]></helloC><helloC>C2</helloC></helloB></helloA>"))
saxReader := newTestSaxReader(emitter)
tm := tagMatcher.NewTagMatcher("helloA/helloB/helloC")
err := saxReader.Read(reader, &tm)
assert.Nil(t, err)
assert.Equal(t, actuals[0], "<helloC><![CDATA[Hello<! World!]]></helloC>")
assert.Equal(t, actuals[1], "<helloC>C2</helloC>")
}
示例9: TestParseXmlNodesConstrainedBuffer
func TestParseXmlNodesConstrainedBuffer(t *testing.T) {
var actuals []string = make([]string, 10)
var actualsPos int = 0
emitter := func(ed *contentBuffer.EmitterData) bool {
actuals[actualsPos] = ed.Content
actualsPos++
return false
}
reader := bytes.NewReader([]byte("<helloA><helloB><helloC>C1</helloC><helloC>C2</helloC></helloB></helloA>"))
saxReader := newTestSaxReader(emitter)
saxReader.ReaderBufferSize = 1
tm := tagMatcher.NewTagMatcher("helloA/helloB/helloC")
err := saxReader.Read(reader, &tm)
assert.Nil(t, err)
assert.Equal(t, actuals[0], "<helloC>C1</helloC>")
assert.Equal(t, actuals[1], "<helloC>C2</helloC>")
}
示例10: TestUpdateInhibitionRadius
func TestUpdateInhibitionRadius(t *testing.T) {
sp := SpatialPooler{}
// Test global inhibition case
sp.GlobalInhibition = true
sp.ColumnDimensions = []int{57, 31, 2}
sp.numColumns = 3
sp.updateInhibitionRadius(sp.avgConnectedSpanForColumnND, sp.avgColumnsPerInput)
expected := 57
assert.Equal(t, expected, sp.inhibitionRadius)
sp.GlobalInhibition = false
avgConnectedSpan := 3.0
avgColPerInput := 4.0
var avgConnectedSpanMock = func(i int) float64 {
return avgConnectedSpan
}
var avgColPerInputMock = func() float64 {
return avgColPerInput
}
trueInhibitionRadius := 6
//((3 * 4) - 1) / 2 => round up
sp.updateInhibitionRadius(avgConnectedSpanMock, avgColPerInputMock)
assert.Equal(t, trueInhibitionRadius, sp.inhibitionRadius)
//Test clipping at 1.false
sp.GlobalInhibition = false
trueInhibitionRadius = 1
avgConnectedSpan = 0.5
avgColPerInput = 1.2
sp.updateInhibitionRadius(avgConnectedSpanMock, avgColPerInputMock)
assert.Equal(t, trueInhibitionRadius, sp.inhibitionRadius)
// //Test rounding up
sp.GlobalInhibition = false
avgConnectedSpan = 2.4
avgColPerInput = 2
trueInhibitionRadius = 2
// ((2 * 2.4) - 1) / 2.false => round up
sp.updateInhibitionRadius(avgConnectedSpanMock, avgColPerInputMock)
assert.Equal(t, trueInhibitionRadius, sp.inhibitionRadius)
}
示例11: basicComputeLoop
func basicComputeLoop(t *testing.T, spParams SpParams) {
/*
Feed in some vectors and retrieve outputs. Ensure the right number of
columns win, that we always get binary outputs, and that nothing crashes.
*/
sp := NewSpatialPooler(spParams)
// Create a set of input vectors as well as various numpy vectors we will
// need to retrieve data from the SP
numRecords := 100
inputMatrix := make([][]bool, numRecords)
for i := range inputMatrix {
inputMatrix[i] = make([]bool, sp.numInputs)
for j := range inputMatrix[i] {
inputMatrix[i][j] = rand.Float64() > 0.8
}
}
// With learning off and no prior training we should get no winners
y := make([]bool, sp.numColumns)
for _, input := range inputMatrix {
utils.FillSliceBool(y, false)
sp.Compute(input, false, y, sp.InhibitColumns)
assert.Equal(t, 0, utils.CountTrue(y))
}
// With learning on we should get the requested number of winners
for _, input := range inputMatrix {
utils.FillSliceBool(y, false)
sp.Compute(input, true, y, sp.InhibitColumns)
assert.Equal(t, sp.NumActiveColumnsPerInhArea, utils.CountTrue(y))
}
// With learning off and some prior training we should get the requested
// number of winners
for _, input := range inputMatrix {
utils.FillSliceBool(y, false)
sp.Compute(input, false, y, sp.InhibitColumns)
assert.Equal(t, sp.NumActiveColumnsPerInhArea, utils.CountTrue(y))
}
}
示例12: phase1
func phase1(t *testing.T, bt *boostTest) {
y := make([]bool, bt.sp.numColumns)
// Do one training batch through the input patterns
for idx, input := range bt.x {
utils.FillSliceBool(y, false)
bt.sp.Compute(input, true, y, bt.sp.InhibitColumns)
for j, winner := range y {
if winner {
bt.winningIteration[j] = bt.sp.IterationLearnNum
}
}
bt.lastSDR[idx] = y
}
//The boost factor for all columns should be at 1.
assert.Equal(t, bt.sp.numColumns, utils.CountFloat64(bt.sp.boostFactors, 1), "Boost factors are not all 1")
//At least half of the columns should have never been active.
winners := utils.CountInt(bt.winningIteration, 0)
assert.True(t, winners >= bt.sp.numColumns/2, "More than half of the columns have been active")
//All the never-active columns should have duty cycle of 0
//All the at-least-once-active columns should have duty cycle >= 0.2
activeSum := 0.0
for idx, val := range bt.sp.activeDutyCycles {
if bt.winningIteration[idx] == 0 {
//assert.Equal(t, expected, actual, ...)
activeSum += val
}
}
assert.Equal(t, 0, activeSum, "Inactive columns have positive duty cycle.")
winningMin := 100000.0
for idx, val := range bt.sp.activeDutyCycles {
if bt.winningIteration[idx] > 0 {
if val < winningMin {
winningMin = val
}
}
}
assert.True(t, winningMin >= 0.2, "Active columns have duty cycle that is too low.")
verifySDRProps(t, bt)
}
示例13: TestLearnPredict
func TestLearnPredict(t *testing.T) {
tps := NewTemporalPoolerParams()
tps.Verbosity = 0
tps.NumberOfCols = 50
tps.CellsPerColumn = 2
tps.ActivationThreshold = 8
tps.MinThreshold = 10
tps.InitialPerm = 0.5
tps.ConnectedPerm = 0.5
tps.NewSynapseCount = 10
tps.PermanenceDec = 0.0
tps.PermanenceInc = 0.1
tps.GlobalDecay = 0
tps.BurnIn = 1
tps.PamLength = 10
//tps.DoPooling = true
tps.CollectStats = true
tp := NewTemporalPooler(*tps)
inputs := make([][]bool, 5)
// inputs[0] = GenerateRandSequence(80, 50)
// inputs[1] = GenerateRandSequence(80, 50)
// inputs[2] = GenerateRandSequence(80, 50)
inputs[0] = boolRange(0, 9, 50)
inputs[1] = boolRange(10, 19, 50)
inputs[2] = boolRange(20, 29, 50)
inputs[3] = boolRange(30, 39, 50)
inputs[4] = boolRange(40, 49, 50)
//Learn 5 sequences above
for i := 0; i < 10; i++ {
for p := 0; p < 5; p++ {
tp.Compute(inputs[p], true, false)
}
tp.Reset()
}
//Predict sequences
for i := 0; i < 4; i++ {
tp.Compute(inputs[i], false, true)
p := tp.DynamicState.InfPredictedState.Entries()
fmt.Println(p)
assert.Equal(t, 10, len(p))
for _, val := range p {
next := i + 1
if next > 4 {
next = 4
}
assert.True(t, inputs[next][val.Row])
}
}
}
示例14: TestUpdateBoostFactors
func TestUpdateBoostFactors(t *testing.T) {
sp := SpatialPooler{}
sp.MaxBoost = 10.0
sp.numColumns = 6
sp.minActiveDutyCycles = make([]float64, sp.numColumns)
for i, _ := range sp.minActiveDutyCycles {
sp.minActiveDutyCycles[i] = -0.0000001
}
sp.activeDutyCycles = []float64{0.1, 0.3, 0.02, 0.04, 0.7, 0.12}
sp.boostFactors = make([]float64, sp.numColumns)
trueBoostFactors := []float64{1, 1, 1, 1, 1, 1}
sp.updateBoostFactors()
for i, _ := range sp.boostFactors {
assert.Equal(t, trueBoostFactors[i], sp.boostFactors[i])
}
sp.MaxBoost = 10.0
sp.numColumns = 6
sp.minActiveDutyCycles = []float64{0.1, 0.3, 0.02, 0.04, 0.7, 0.12}
sp.activeDutyCycles = []float64{0.1, 0.3, 0.02, 0.04, 0.7, 0.12}
trueBoostFactors = []float64{1, 1, 1, 1, 1, 1}
sp.updateBoostFactors()
for i, _ := range sp.boostFactors {
diff := math.Abs(trueBoostFactors[i] - sp.boostFactors[i])
assert.True(t, diff <= 0.0000001)
}
sp.MaxBoost = 10.0
sp.numColumns = 6
sp.minActiveDutyCycles = []float64{0.1, 0.2, 0.02, 0.03, 0.7, 0.12}
sp.activeDutyCycles = []float64{0.01, 0.02, 0.002, 0.003, 0.07, 0.012}
trueBoostFactors = []float64{9.1, 9.1, 9.1, 9.1, 9.1, 9.1}
sp.updateBoostFactors()
for i, _ := range sp.boostFactors {
diff := math.Abs(trueBoostFactors[i] - sp.boostFactors[i])
assert.True(t, diff <= 0.0000001)
}
sp.MaxBoost = 10.0
sp.numColumns = 6
sp.minActiveDutyCycles = []float64{0.1, 0.2, 0.02, 0.03, 0.7, 0.12}
sp.activeDutyCycles = make([]float64, sp.numColumns)
trueBoostFactors = utils.MakeSliceFloat64(6, sp.MaxBoost)
sp.updateBoostFactors()
for i, _ := range sp.boostFactors {
diff := math.Abs(trueBoostFactors[i] - sp.boostFactors[i])
assert.True(t, diff <= 0.0000001)
}
}
示例15: TestParseXmlOneNodeOneAttributeSingle
func TestParseXmlOneNodeOneAttributeSingle(t *testing.T) {
res := ""
emitter := func(ed *contentBuffer.EmitterData) bool {
res = ed.Content
return false
}
reader := bytes.NewReader([]byte("<hello id='123'>test</hello>"))
saxReader := newTestSaxReader(emitter)
tm := tagMatcher.NewTagMatcher("hello?id=123")
err := saxReader.Read(reader, &tm)
assert.Nil(t, err)
assert.Equal(t, res, "<hello id='123'>test</hello>")
}