Esempio n. 1
0
 def testCompute(self):
     """ Check that there are no errors in call to compute. """
     inputs = SDR(100).randomize(.05)
     active = SDR(100)
     sp = SP(inputs.dimensions, active.dimensions, stimulusThreshold=1)
     sp.compute(inputs, True, active)
     assert (active.getSum() > 0)
Esempio n. 2
0
 def testNan(self):
     gc = GridCellEncoder(size=200,
                          sparsity=.25,
                          periods=[6, 8.5, 12, 17, 24],
                          seed=42)
     zero = SDR(gc.dimensions)
     zero.randomize(.25)
     gc.encode([3, float('nan')], zero)
     assert (zero.getSum() == 0)
Esempio n. 3
0
 def testNaNs(self):
     p = ScalarEncoderParameters()
     p.size       = 100
     p.activeBits =  10
     p.minimum    =   0
     p.maximum    = 100
     enc = ScalarEncoder(p)
     sdr = SDR( 100 )
     enc.encode( float("nan"), sdr )
     assert( sdr.getSum() == 0 )
Esempio n. 4
0
  def calculateRawAnomaly(activeCols, predictiveCols ):
    """

    :param activeColSDR: SDR with active columns
    :param predictiveColsSDR: SDR with predictive columns, means columns where some of the cells are predictive
    :return: Raw anomaly score in range <0.0, 1.0>
    """
    if activeCols.dimensions != predictiveCols.dimensions:
      raise ValueError("activeColumns must have same dimension as predictiveCellsSDR!")

    if activeCols.getSum() != 0:
      intersect = SDR(activeCols.dimensions)

      intersect.intersection(activeCols, predictiveCols)
      rawAnomaly = (activeCols.getSum() - intersect.getSum()) / activeCols.getSum()

      if rawAnomaly<0 or rawAnomaly>1.0:
        raise ValueError("rawAnomaly out of bounds! <0.0, 1.0>")
    else:
      rawAnomaly = 0

    return rawAnomaly
Esempio n. 5
0
    def testSetSDR(self):
        A = SDR((103, ))
        B = SDR((103, ))
        A.sparse = [66]
        B.setSDR(A)
        assert (B.dense[66] == 1)
        assert (B.getSum() == 1)
        B.dense[77] = 1
        B.dense = B.dense
        A.setSDR(B)
        assert (set(A.sparse) == set((66, 77)))

        # Test wrong dimensions assigned
        C = SDR((2, 4, 5, 1, 1, 1, 1, 3))
        C.randomize(.5)
        try:
            A.setSDR(C)
        except RuntimeError:
            pass
        else:
            self.fail()
        # Check return value.
        D = A.setSDR(B)
        assert (D is A)
Esempio n. 6
0
 def testMirroring(self):
     A = SDR(100)
     A.randomize(.05)
     Ax10 = SDR(100 * 10)
     Ax10.concatenate([A] * 10)
     assert (Ax10.getSum() == 100 * 10 * .05)
Esempio n. 7
0
 def testGetSum(self):
     A = SDR((103, ))
     assert (A.getSum() == 0)
     A.dense = np.ones(A.size)
     assert (A.getSum() == 103)