def test_identity(): ''' Identity sets are just ranges of numbers. ''' iset = IdentitySet(10) eq_(iset[5], 5) eq_(iset.index(2), 2) eq_(len(iset), 10) assert iset == RecyclingSet(10, range(10)) iset = pickle.loads(pickle.dumps(iset)) eq_(iset[5], 5) eq_(iset.index(2), 2) eq_(len(iset), 10) assert iset == RecyclingSet(10, range(10))
def test_recycle2(): r = RecyclingSet(5) for item in ('one', 'two', 'three', 'four', 'five', 'six'): r.add(item) r.add('two') assert r[0] == 'six' assert r[1] == 'two' r.add('seven') assert r[1] == 'two' assert r[2] == 'seven'
def test_pickle(): ''' Test that RecyclingSets can be pickled. ''' s = RecyclingSet(10, ['dog','cat','banana']) import cPickle as pickle s2 = pickle.loads(pickle.dumps(s)) eq_(s, s2) eq_(s2[0], 'dog') eq_(s2.index('cat'), 1)
def __init__(self, host, port, channel, nconcepts, k=2): QThread.__init__(self) self.stomp = Client(host, port) self.channel = channel self.array = np.zeros((nconcepts, k)) self.k = k self.nconcepts = nconcepts self.labels = RecyclingSet(nconcepts) self.labels.listen_for_drops(self.on_drop) self.exiting = False
def test_delete_and_pickle(): ''' Deleting an element doesn't affect the remaining elements' indices. ''' s = RecyclingSet(10, ['dog','cat','banana']) del s[1] eq_(s[1], None) eq_(s.index('banana'), 2) # Pickling doesn't change things. s2 = pickle.loads(pickle.dumps(s)) eq_(s, s2) eq_(s2[1], None) eq_(s2.index('banana'), 2) assert None not in s2 assert None not in s2
def __init__(self, k, ev=None, i=0, bootstrap=20, amnesia=3.0, remembrance=100000.0, vector_size=10000, auto_baseline=True): """Construct a CCIPCA computation with k initial eigenvectors ev at iteration i, using simple averaging until the iteration given by bootstrap, afterward using CCIPCA given amnesic parameter amnesia, rememberance parameter remembrance, and a weight vector and subspace criteria for simultaneous vector presentation""" if ev is not None: self._v = ev else: self._v = np.zeros((k, vector_size)) self._k = k self._amnesia = amnesia self._iteration = i self._bootstrap = bootstrap self._remembrance = remembrance self._vector_size = vector_size self._labels = RecyclingSet(self._vector_size) self._labels.listen_for_drops(self.forget_column) self._auto_baseline = auto_baseline
def test_duplicates(): r = RecyclingSet(5) for i in xrange(10): r.add('two') assert len(r) == 1
def test_recycle(): r = RecyclingSet(5) for item in ('one', 'two', 'three', 'four', 'five', 'six'): r.add(item) assert r[0] == 'six' assert 'one' not in r
def test_reprOfEmpty(): ''' repr() of an empty OrderedSet should not fail. ''' repr(RecyclingSet(10))