예제 #1
0
파일: cc.py 프로젝트: nikhilYadala/blurt
 def __init__(self, code=standard_cc):
     self.nu = code[0]
     self.g0 = util.rev(code[1], self.nu)
     self.g1 = util.rev(code[2], self.nu)
     self.output_map_1      = np.uint8(1 & (util.mul(self.g0, np.arange(1<<self.nu)) >> (self.nu-1)))
     self.output_map_2      = np.uint8(1 & (util.mul(self.g1, np.arange(1<<self.nu)) >> (self.nu-1)))
     self.states            = np.arange(1<<self.nu)
     self.state_inv_map     = ((np.arange(1<<self.nu) << 1) & ((1<<self.nu)-1))[:,np.newaxis] + np.array([0,1])[np.newaxis,:]
     self.state_inv_map_tag = np.tile(np.arange(1<<self.nu)[:,np.newaxis] >> (self.nu-1), (1,2))
     self.output_map_1_soft = self.output_map_1.astype(int)[np.newaxis,:] * 2 - 1
     self.output_map_2_soft = self.output_map_2.astype(int)[np.newaxis,:] * 2 - 1
예제 #2
0
파일: map.py 프로젝트: librarian/dclord
	def onMotion(self, evt):
		old_offset = self.offset_pos
		#fix for windows focus policy ( after treeCtrl grabs focus it wont let it back )
		self.SetFocus()
		if not self.moving:
			return
		
		#if not self.moving_proved:
		#	self.pushMotionEvent(evt)
		#	return

		curPos = evt.GetPosition()
		dx,dy = util.div(util.sub(self.prevPos, curPos), float(self.cell_size))
		
		if dx != 0 or dy != 0:
			x,y=self.offset_pos
			x+=dx
			y+=dy
			self.offset_pos=(x,y)
			#self.Refresh()
			self.prevPos = curPos
		
		self.shift(util.mul(util.sub(old_offset, self.offset_pos), self.cell_size))
		#self.update()
		self.Refresh()
		self.Update()
예제 #3
0
    def adadelta(allparams,
                 nat_stepsize,
                 num_epochs,
                 seq_len,
                 num_seqs=None,
                 rho=0.95,
                 epsilon=1e-6,
                 num_samples=1,
                 permute=True):
        natparams, params = allparams[:1], allparams[1:]
        sum_gsq = zeros_like(params)  # accumulated sq. grads
        sum_usq = zeros_like(params)  # accumulated sq. updates
        accumulate = lambda a, b: add(scale(rho, a), scale(1 - rho, b))

        for epoch in xrange(num_epochs):
            vals = []
            batches, num_batches = split_into_batches(data, seq_len, num_seqs)
            for y in batches:
                val, grad = scale(
                    1. / num_datapoints,
                    val_and_grad(y, num_batches, num_samples, *allparams))
                natgrad, grad = grad[:1], grad[1:]
                sum_gsq = accumulate(sum_gsq, square(grad))
                diag_scaling = div(sqrt(add_scalar(epsilon, sum_usq)),
                                   sqrt(add_scalar(epsilon, sum_gsq)))
                update = mul(diag_scaling, grad)
                sum_usq = accumulate(sum_usq, square(update))

                natparams = add(natparams, scale(nat_stepsize, natgrad))
                params = add(params, update)
                allparams = concat(natparams, params)
                vals.append(val)

                if callback: callback(epoch, vals, natgrad, allparams)
        return allparams
예제 #4
0
    def __init__(self, algo):
        self.env = gym.make('CartPole-v1')
        #self.env = gym.wrappers.Monitor(self.env, "videos", force=True)

        self.input_size = mul(self.env.observation_space.shape)
        self.num_actions = self.env.action_space.n
        print "num_inputs: {}\nnum_actions: {}".format(self.input_size, self.num_actions)

        self.gamma = 0.9
        self.algo = algo(self.input_size, self.num_actions, self.gamma)

        self.run()
예제 #5
0
파일: map.py 프로젝트: librarian/dclord
	def onScroll(self, evt):

		pos = evt.GetPosition()
		logicPos = util.div(pos, float(self.cell_size))

		diff = 1 if evt.GetWheelRotation()>0 else -1
		self.cell_size += diff
		if self.cell_size < 1:
			self.cell_size = 1
		elif self.cell_size > 40:
			self.cell_size = 40

		self.calcScreenSize()
		
		#make sure mouse is pointing on the centre  of the scroll area ( just move the pos so that this _is_ the center )
		newScreenPos = util.mul(logicPos, self.cell_size)
		newScreenDiff = util.sub(newScreenPos, pos)
		newLogicDiff = util.div(newScreenDiff, self.cell_size)
		self.offset_pos = util.add(self.offset_pos, newLogicDiff)

		self.update()
예제 #6
0
 def gainControl(self, LMS, LMS_white, D):
     LMS_white_t = (100/LMS_white - 1) * D + 1
     LMS_c = ut.mul(v=LMS_white_t, img=LMS)
     return LMS_c
예제 #7
0
def plcp_bits(rate, octets):
    plcp_rate = util.rev(rate.encoding, 4)
    plcp = plcp_rate | (octets << 5)
    parity = (util.mul(plcp, 0x1FFFF) >> 16) & 1
    plcp |= parity << 17
    return util.shiftout(np.array([plcp]), 18)