Example #1
0
 def test_push(self, shape):
     vals = []
     rs = RunningStat(shape)
     for _ in range(5):
         val = t.randn(shape, dtype=t.float64)
         rs.push(val)
         vals.append(val)
         m = t.mean(t.stack(vals), dim=0)
         assert t.allclose(rs.mean, m)
         v = (t.square(m) if (len(vals) == 1) else t.var(
             t.stack(vals), dim=0, unbiased=True))
         assert t.allclose(rs.var, v)
Example #2
0
 def test_update(self, shape):
     rs1 = RunningStat(shape)
     rs2 = RunningStat(shape)
     rs = RunningStat(shape)
     for _ in range(5):
         val = t.randn(shape, dtype=t.float64)
         rs1.push(val)
         rs.push(val)
     for _ in range(9):
         val = t.randn(shape, dtype=t.float64)
         rs2.push(val)
         rs.push(val)
     rs1.update(rs2)
     assert t.allclose(rs.mean, rs1.mean)
     assert t.allclose(rs.std, rs1.std)