Example #1
0
	def __init__(self, n, source, target, bias, opts=None):
		MapSeeker.__init__(self, opts)
		shape = bias.shape
		if not isinstance(bias, Sparse):
			bias = Sparse(bias)
			bias.squeeze()
		self.bias = bias
		self._params = (n, source, target)
		self._space = Sparse(None, shape)
		self.prep(n, source, target)
Example #2
0
class SparseNavMSC(MapSeeker):
	def __init__(self, n, source, target, bias, opts=None):
		MapSeeker.__init__(self, opts)
		shape = bias.shape
		if not isinstance(bias, Sparse):
			bias = Sparse(bias)
			bias.squeeze()
		self.bias = bias
		self._params = (n, source, target)
		self._space = Sparse(None, shape)
		self.prep(n, source, target)
	
	def space(self):
		return self._space.clone()
		
	
	def prep(self, n, source, target):
		ss = self.space()
		if not hasattr(source[0], '__getitem__'):
			source = [source]
		for pt in source:
			ss[pt[:2]]=pt[2]
		self.source=ss
		ts = self.space()
		if not hasattr(target[0], '__getitem__'):
			target = [target]
		for pt in target:
			ts[pt[:2]]=pt[2]
		self.layers=[]
		self.iter=0
		for i in range(n):
			self.layers.append({'source':None, 'target':None, 'gain':ones(self.nMaps(i)),  'dead':zeros(self.nMaps(i))})
		self.layers[-1]['target']=ts
	
	def applyBias(self, layer, source):
		return source*self.bias	
	
	def getTrajectory(self):
		path = self.bestPath()
		s = self.source.clone()
		pts = [maxPt(s)]
		for i, p in enumerate(path):
			s = self.doMap(i, p, True, s)
			pts.append(maxPt(s))
		return array(pts)
Example #3
0
def test_append():
    s = Sparse(test_list1)
    assert len(s.array) == len(test_list1)
    s.append(test_list2)
    assert len(s.array) == len(test_list1) + len(test_list2)
    assert s.array == test_list1 + test_list2