def test_write_adder(self, qty=1000): for i in range(qty): a = Hardlocation() b = Bitstring() a.write(b) self.assertEqual([ b.bitsign(i) for i in xrange(sdm.get_dimension()) ], a.adder) a.write(b) self.assertEqual([ 2*b.bitsign(i) for i in xrange(sdm.get_dimension()) ], a.adder)
def sample_radius(rounds=1, verbose=0): if verbose > 0: print 'Initializing SDM' sdm.initialize() dimension = sdm.get_dimension() v = [] for i in xrange(rounds): if verbose > 0: print 'Round #%d' % (i+1) addr = Bitstring() dist = sdm.distance(addr) if verbose > 0: print ' Processing results' w = [0]*(dimension+1) for d in dist: w[d] += 1 u = [0]*(dimension+1) for d, n in enumerate(w): for j in range(d, dimension+1): u[j] += n v.append(u) sdm.free() return v
def test_mean_distance(self, qty=10): #sdm.initialize() for i in range(qty): a = Bitstring() arr = array(sdm.distance(a)) value = abs(arr.mean()-sdm.get_dimension()/2.)/arr.std() self.assertTrue(value <= 1.5)
def sample_radius(rounds=1, verbose=0): if verbose > 0: print 'Initializing SDM' sdm.initialize() dimension = sdm.get_dimension() v = [] for i in xrange(rounds): if verbose > 0: print 'Round #%d' % (i + 1) addr = Bitstring() dist = sdm.distance(addr) if verbose > 0: print ' Processing results' w = [0] * (dimension + 1) for d in dist: w[d] += 1 u = [0] * (dimension + 1) for d, n in enumerate(w): for j in range(d, dimension + 1): u[j] += n v.append(u) sdm.free() return v
def test_random_swap(self, qty=1000): for i in range(qty): a = Bitstring() b = a.copy() self.assertEqual(a.distance_to(b), 0) dist = random.randint(0, sdm.get_dimension()) b.bitrandomswap(dist) self.assertEqual(a.distance_to(b), dist)
def sample(): print 'Initializing SDM' sdm.initialize() dimension = sdm.get_dimension() addr = Bitstring() dist = sdm.distance(addr) sdm.free() return dist
def test_bitset(self): dim = sdm.get_dimension() a = Bitstring(zero=True) for i in range(dim): a.bitset(i) s = str(a) s1 = sum([ 1 for x in s[:dim-i-1] if x == '0' ]) s2 = sum([ 1 for x in s[-i-1:] if x == '1' ]) self.assertEqual(s1+s2, dim)
def test_uniform_distribution(qty=10000): n = sdm.get_dimension() v = [0]*n for i in xrange(qty): a = Bitstring() for j in range(n): v[j] += a.bitsign(j) import pylab pylab.hist(v, bins=15) return v
def test_uniform_distribution(qty=10000): n = sdm.get_dimension() v = [0] * n for i in xrange(qty): a = Bitstring() for j in range(n): v[j] += a.bitsign(j) import pylab pylab.hist(v, bins=15) return v
def table_7_1(): n = sdm.get_dimension() a = Bitstring() v = [] for i in range(550): b = a.copy() b.bitrandomswap(i) v.append([ i, sdm.thread_radius_count_intersect(a, b) ]) print i sys.stdout.flush() return v
def table_7_1(): n = sdm.get_dimension() a = Bitstring() v = [] for i in range(550): b = a.copy() b.bitrandomswap(i) v.append([i, sdm.thread_radius_count_intersect(a, b)]) print i sys.stdout.flush() return v
def scan_for_distances(numwrites=1): import time, cPickle; #Configure execution numwrites_string = '_x_at_x_'+str(numwrites)+'_writes' sdm.initialize() v = sdm.Bitstring() for i in range(numwrites): sdm.thread_write(v,v) for i in range (1000,2000,1000): print 'Registering '+str(i)+' new items in SDM' #add 1000 itens to memory mem_write_x_at_x(1000) print 'Computing the distances to these items' a = sdm_utils.critical_distance2(0, sdm.get_dimension(), 1, v, iterated_reading=6, read=sdm.thread_read_cubed,debug=0) #save new distance values in a picklename = 'N=256_iter_read=2_'+str(i)+'saved items'+numwrites_string+'_DrK_cubed.cPickle' cPickle.dump(a, open (picklename, 'wb')) print 'saved '+picklename sdm.free()
def chart_sample_radius(rounds=1, verbose=0): import pylab data = sample_radius(rounds=rounds, verbose=verbose) #for i in range(sdm.get_dimension()+1): # data[-1][i] += 100000 dist = range(sdm.get_dimension()+1) args = [] kwargs = { 'linewidth': 1.0 } for v in data: args.extend([ dist, v, 'k-' ]) pylab.plot(*args, **kwargs) pylab.xlabel('distance') pylab.ylabel('qty of hardlocations') pylab.title('Qty of hardlocations around random address') pylab.grid(True) pylab.show() arr = array(zip(*data)) stat = [ (i, m, v) for i, (m, v) in enumerate(zip(arr.mean(axis=1), arr.std(axis=1))) ] return data, stat
def chart_sample_radius(rounds=1, verbose=0): import pylab data = sample_radius(rounds=rounds, verbose=verbose) #for i in range(sdm.get_dimension()+1): # data[-1][i] += 100000 dist = range(sdm.get_dimension() + 1) args = [] kwargs = {'linewidth': 1.0} for v in data: args.extend([dist, v, 'k-']) pylab.plot(*args, **kwargs) pylab.xlabel('distance') pylab.ylabel('qty of hardlocations') pylab.title('Qty of hardlocations around random address') pylab.grid(True) pylab.show() arr = array(zip(*data)) stat = [(i, m, v) for i, (m, v) in enumerate(zip(arr.mean(axis=1), arr.std(axis=1)))] return data, stat