Пример #1
0
 def getAll(self):
     import plugins
     ''' gets all of the plugins '''
     rPath =  plugins.__dict__['__path__'][0]
     ## it should turn out something like
     ## shovel.sys.http.download => [plugins]/sys/http.py[function:download]
     for loadable in locate('*.py', rPath):
         pyElement = loadable.split('/')[-1:]
         ## i only want the end element
         if pyElement[0] != '__init__.py':
             cwd = os.getcwd()
             diff = pathDifference(cwd.split('/'), loadable.split('/'))
             diffList = ['shovel']
             ## so our list is only ['shovel'] currently
             for k in diff[1:-1]:                
                 diffList.append(k)
                 ## now append all of the elements in the path
                 ## list should be something like ['shovel','path','path']
                 
                 
             diffList.append(diff[-1:][0].split('.')[0])
             ## now append the last bit, stripped of the .py
             ## should be somethg like ['shovel','path','path','file']
             useString = '.'.join(diffList)
             ## concat it so
             ## 'shovel.path.path.file'
             debug(useString, DEBUG)
             ## print useString
             self.config.putFeature(useString)
Пример #2
0
def mkdirIfAbsent(*args):
    ''' Create a directory if its not there '''
    for dirName in args:
        debug("ensuring that dir exists: %s" % dirName,DEBUG)
        if not os.path.exists(dirName):
            debug("creating dir: %s" % dirName,DEBUG)
            os.makedirs(dirName)
Пример #3
0
    def test_convolution2d_plotting(self):
        image_path = self.get_image( 'Vd-Orig.png')
        image = plt.imread(image_path)
        shape = image.shape
        print("shape {}".format(shape))

        img_node = node.VarNode('x')
        x_image = self.rgb2gray(image * 20)
        print(x_image.shape)
        plt.imshow(x_image)
        plt.show()
        debug("Now showing ..")
        var_map = {'x': x_image}
        x_shape = (image.shape[0], image.shape[1])
        conv_node = conv.Convolution2D(img_node, x_shape)
        img_node.forward(var_map)
        final_image = conv_node.value()
        plt.imshow(final_image)
        plt.show()
        edge_kernel = np.array([[-1, -1, -1], [-1, 8, -1], [-1, -1, -1]])
        img_node = node.VarNode('x')
        conv_node = conv.Convolution2D(img_node, x_shape, kernel=edge_kernel)
        img_node.forward(var_map)
        edge_img = conv_node.value()
        plt.imshow(edge_img)
        plt.show()
Пример #4
0
Файл: stun.py Проект: AKJ/sage
def stun(line, time, backrefs):
	if core.is_paused():
		return

	if player.stunned is False:
		player.stun_ticks = 0
	core.enable_trigger('cures_stun', 'cures')
	core.enable_trigger('cures_unconciousness', 'cures')
	core.enable_trigger('ai_stun_check', 'anti-illusion')
	player.stunned = True
	player.stun_ticks += 1
	player.stun_time = time
	if player.stun_ticks < 3:
		if core.aeon_mode == False:
			core.write('touch stun')
	core.debug("stunned")
	# should probably add more balance resets here
	if player.focus_balance == .5:
		player.focus_balance = 1
	if player.herb_balance == .5:
		player.herb_balance = 1
	if player.salve_balance == .5:
		player.salve_balance = 1
	if player.hmsip_balance == .5:
		player.hmsip_balance = 1
	player.waiting_for_aeon = 0
Пример #5
0
 def test_cross_entropy(self):
     predicted = np.array([[1, 3, -1, 0], [0, 9, 1, 3.]]).T
     target = np.array([[0, 1, 0, 0], [0, 0, 0, 1]]).T
     predicted_node = node.VarNode('predicted')
     target_node = node.VarNode('target')
     softmax = Softmax(predicted_node)
     cross_entropy = CrossEntropy(softmax, target_node)
     var_map = {'predicted': predicted, 'target': target}
     predicted_node.forward(var_map)
     target_node.forward(var_map)
     loss = cross_entropy.value()
     debug("loss = {}".format(loss))
     expected_loss = 6.188115770824936
     self.assertAlmostEqual(expected_loss, loss)
     cross_entropy.backward(1.0, self, var_map)
     x_grad = predicted_node.total_incoming_gradient()
     debug("x_grad = np.{}".format(repr(x_grad)))
     # Note that this grad is  1/8 the size reported by pytorch
     # because pytorch does not average out during softmax for CrossEntropy
     # whereas I use softmax node
     expected_grad = np.array([[1.40571517e-02, 1.53810418e-05],
                               [-2.11309174e-02, 1.24633872e-01],
                               [1.90242861e-03, 4.18100064e-05],
                               [5.17133712e-03, -1.24691064e-01]])
     np.testing.assert_array_almost_equal(expected_grad, x_grad)
Пример #6
0
Файл: stun.py Проект: AKJ/sage
def unstun(line, time, backrefs):
	player.stunned = False
	player.stun_ticks = 0
	core.disable_trigger('cures_stun', 'cures')
	core.disable_trigger('cures_unconciousness', 'cures')
	core.disable_trigger('ai_stun_check', 'anti-illusion')
	core.debug("unstunned")
Пример #7
0
def clean_queues(type, defence):
	if type == 'action':
		_truncate_queue(defence, action_queue)
	elif type == 'immediate':
		_truncate_queue(defence, immediate_queue)
	elif type == 'free':
		_truncate_queue(defence, free_queue)
	elif type == 'herb':
		if defence != 'deaf':
			_truncate_queue(defence, herb_queue)
	elif type == 'salve':
		_truncate_queue(defence, salve_queue)
	elif type == 'asip':
		_truncate_queue(defence, asip_queue)
	elif type == 'balance':
		_truncate_queue(defence, balance_queue)
	elif type == 'equilibrium':
		_truncate_queue(defence, equilibrium_queue)
	elif type == 'hmsip':
		_truncate_queue(defence, hmsip_queue)
	elif type == 'smoke':
		_truncate_queue(defence, smoke_queue)
		if defence == 'rebounding':
			player.rebounding_pending = False
			core.disable_trigger('failure_rebounding', 'failures')

	core.debug("ondef " + defence)
Пример #8
0
def herb_balance(line, time, backrefs):
	if time - player.herb_lastate <= 1.3 and player.ate_offbal == False:
		core.debug("Herb balance restored too soon! Illusion?")
		return
	player.herb_balance = 1
	player.ate_offbal = False
	core.disable_trigger('herb_balance', 'balances')
Пример #9
0
    def backward(self, downstream_grad, downstream_node, var_map):
        r"""
        This implements some of the common processing needed for backprop to work properly.
        :param downstream_grad:   gradient coming from downstream. This should be the
        gradient flowing upstream from this node. you can also get to it through the
        downstream_node.total_incoming_gradient() method but this API is still quite fluid
        so not sure what is the best approach
        :param downstream_node: downstream node that invoked backward
        :param var_map:
        :return:
        """
        calling_node_name = downstream_node.simple_name()
        if type(downstream_grad).__module__ == np.__name__:
            grad_shape = downstream_grad.shape
        else:
            grad_shape = "(float)"
        if is_debug_on():
            _value = self.value()
            debug("Backprop@{} from:{} downstream grad shape:{}".format(self.simple_name(),
                                                                                        calling_node_name,
                                                                                        grad_shape
                                                                                        ))
            debug("Downstream grad received:")
            debug(repr(downstream_grad))
            debug("Value:")
            debug(repr(_value))

        should_continue = self._process_backprop(downstream_grad)
        if not should_continue:
            return
        self._collect_grads()
        self._do_backprop(downstream_grad, downstream_node, var_map)
Пример #10
0
    def test_softmax(self):
        r"""
        See TestActivations.Softmax.ipynb for corresponding pytorch calculations
        :return:
        """
        x = np.array([[1, 3, -1, 0], [0, 9, 1, 3]]).T
        x_node = node.VarNode('x')

        softmax = Softmax(x_node)
        target = np.zeros(x.shape)
        target_node = node.VarNode('target')
        var_map = {'x': x, 'target': target}
        l2loss = L2DistanceSquaredNorm(softmax, target_node)
        x_node.forward(var_map)
        target_node.forward(var_map)

        expected_value = np.array([[1.12457214e-01, 1.23048334e-04],
                                   [8.30952661e-01, 9.97070980e-01],
                                   [1.52194289e-02, 3.34480051e-04],
                                   [4.13706969e-02, 2.47149186e-03]])
        value = softmax.value()
        np.testing.assert_almost_equal(expected_value, value)
        loss_value = l2loss.value()
        debug("Loss = {}".format(loss_value))
        l2loss.backward(1.0, self, var_map)
        x_grad = x_node.total_incoming_gradient()

        expected_grad = np.array([[-0.01666096, -0.00003058],
                                  [0.02615019, 0.00072642],
                                  [-0.00262479, -0.0000831],
                                  [-0.00686445, -0.00061274]])

        debug("x_grad = np.{}".format(repr(x_grad)))
        np.testing.assert_almost_equal(expected_grad, x_grad)
Пример #11
0
	def pkgconfig(self,Name):
		p = subprocess.Popen("/usr/bin/env pkg-config",shell=True,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
		while p.stdout.readline():
			if p.stdout.readline() != "Must specify package names on the command line":
				debug("pkg-config not found!", ERROR)
			else:
				debug("pkg-config found!", INFO)
Пример #12
0
def database_setvalue(key,keyto,name):
	#no try
	debug("数据库更新: "+"UPDATE userdata SET "+ key +" = "+str(keyto)+" where NAME = '"+ name+"'")
	conn = sqlite3.connect(dbname)
	retstr = conn.execute("UPDATE userdata SET "+ key +" = "+str(keyto)+" where NAME = '"+ name+"'")
	conn.commit()
	conn.close()
Пример #13
0
 def test_rnn_var_node(self):
     x = np.array([[1, 2, 1], [-1, 0, -.5]]).T
     x = x.reshape((3, 1, 2))
     x0_var = rnn.RnnVarNode(0, x)
     x1_var = rnn.RnnVarNode(1, x)
     np.testing.assert_equal(x0_var.value(), x[:, :, 0])
     np.testing.assert_equal(x1_var.value(), x[:, :, 1])
     debug("[SimpleRnnCellTests.test_rnn_var_node()] x0_var.value() = np.{}".format(repr(x0_var.value())))
Пример #14
0
def herbs_container_single(line, time, backrefs):
	herb = backrefs[1]
	if herb in herbs.rift_name_conversion.keys():
		herb = herbs.rift_name_conversion[herb]
		herbs.herbs[herb].inv -= 1
		if herbs.herbs[herb].inv < 0:
			core.debug("inventory fault: got negative inventory count")
			herbs.herbs[herb].inv = 0
Пример #15
0
 def runBlock(self, block):
     """ run the block of code """
     debug(self._os[0], DEBUG)
     for gen in self.gen.featureBlock(self.dirtY):
         if gen["os"] == self._os[0]:
             if gen["block"] == block and gen["fb"][0] == "use":
                 feature = self.config.getFeature(gen["fb"][1])
                 self.featureDebug(feature, gen["fb"][1])
Пример #16
0
def GetTables():
	dbtables = []
	s = database_query("select name from sqlite_master where type = 'table' order by name;")
	for table in s:
		if table[0].find('malf')<0:
			dbtables.append(table[0])
	debug("GetTables Return---->"+str(dbtables),3)
	return  dbtables
Пример #17
0
 def setUp(self):
     x = np.array([[1, 2, -1, 4], [2, -1, 3, 1], [4, 9, -4, 5]])
     debug("x = np.{}".format(repr(x)))
     self.x_node = node.VarNode('x')
     self.var_map = {'x': x}
     self.max_pool_node = conv.MaxPool2D(self.x_node,
                                         pool_size=(2, 2),
                                         name="maxpool")
     debug("x = np.{}".format(repr(x)))
Пример #18
0
def GetMessageLine(strrawmsg):
	p = re.compile('text="(.*?)"')
	s = " ".join(p.findall(strrawmsg))
	try:
		mhint = s.find(":")
		s = s[mhint+2:]
	except:
		pass
	debug("GetMessageLine---->"+s,3)
	return s
Пример #19
0
def pipe_fill_skullcap(line, time, backrefs):
	player.waiting_for_aeon = 0
	player.skullcap_puffs = 10
	herbs.skullcap.inv -= 1
	player.pipe_reloading = ''
	free_queue.remove_by_name('reload_skullcap')
	core.disable_trigger('skullcap', 'pipes')
	core.disable_trigger('pipe_full', 'pipes')
	core.disable_trigger('pipes_paralysis_nofill', 'pipes')
	core.debug("filled skullcap pipe")
Пример #20
0
def herbs_inb(line, time, backrefs):
	num = int(backrefs[0])
	herb = backrefs[1]

	if herb in herbs.rift_name_conversion.keys():
		herb = herbs.rift_name_conversion[herb]
		herbs.herbs[herb].inv -= num
		if herbs.herbs[herb].inv < 0:
			core.debug("inventory fault: got negative inventory count")
			herbs.herbs[herb].inv = 0
Пример #21
0
def pipe_fill_elm(line, time, backrefs):
	player.waiting_for_aeon = 0
	player.elm_puffs = 10
	herbs.elm.inv -= 1
	player.pipe_reloading = ''
	free_queue.remove_by_name('reload_elm')
	core.disable_trigger('elm', 'pipes')
	core.disable_trigger('pipe_full', 'pipes')
	core.disable_trigger('pipes_paralysis_nofill', 'pipes')
	core.debug("filled elm pipe")
Пример #22
0
def pipe_fill_valerian(line, time, backrefs):
	player.waiting_for_aeon = 0
	player.valerian_puffs = 10
	herbs.valerian.inv -= 1
	player.pipe_reloading = ''
	free_queue.remove_by_name('reload_valerian')
	core.disable_trigger('valerian', 'pipes')
	core.disable_trigger('pipe_full', 'pipes')
	core.disable_trigger('pipes_paralysis_nofill', 'pipes')
	core.debug("filled valerian pipe")
Пример #23
0
 def test_backprop(self):
     self.forward()
     value = self.max_pool_node.value()
     debug("value = np.{}".format(repr(value)))
     ones = np.ones_like(value)
     self.max_pool_node.backward(ones, self, self.var_map)
     grad_from_maxpool = self.x_node.total_incoming_gradient()
     debug("grad_from_maxpool = np.{}".format(repr(grad_from_maxpool)))
     expected_grad = np.array([[0, 1, 0, 1], [0, 0, 1, 0], [0, 2, 0, 1]])
     np.testing.assert_almost_equal(expected_grad, grad_from_maxpool)
Пример #24
0
 def _copyDirs(self):
     copyDirs = [
         'bin', 'usr/bin'
     ]
     for dir in copyDirs:
         rPath  = file.buildPath('/',dir)
         chPath = file.buildPath(self.baseDir,dir)
         ## if os.path.exists(chPath):
         ##     os.remove(chPath)
         
         debug('%s --> %s' % (rPath,chPath), DEBUG)
         shutil.copytree(rPath,chPath)
Пример #25
0
def database_query(query_str):
	try:
		conn = sqlite3.connect(dbname)
		retstr = conn.execute(query_str).fetchall()
	except Exception as err:
		debug("***database_query error: " +str(err)+", 使用代替方式",1)
		filename = str(random.randint(0,99999999))
		shutil.copyfile(dbname,tempdir+"\\"+filename)
		connnew = sqlite3.connect(tempdir+"\\"+filename)
		retstr = connnew.execute(query_str).fetchall()
		connnew.close()
		os.remove(tempdir+"\\"+filename)
	return retstr
 def test_rnn_layer(self):
     x = np.array([[1, 2, 1], [-1, 0, -.5]]).T
     x = x.reshape((3, 1, 2))
     input_node = n.VarNode('x')
     var_map = {'x': x}
     rnn_layer = rnn.SimpleRnnLayer(input_node, 4, 2)
     input_node.forward(var_map)
     y = rnn_layer.value()
     dely = y * .1
     rnn_layer.backward(dely, self, var_map)
     x_grad = input_node.total_incoming_gradient()
     debug("[SimpleRnnCellTests.test_rnn_layer()] x_grad = np.{}".format(
         repr(x_grad)))
Пример #27
0
def text_reply(msg):
    #itchat.send('%s: %s' % (msg['Type'], msg['Text']), msg['FromUserName'])
    try:
        userinfo = itchat.update_friend(msg['FromUserName'])
        usernick = userinfo['NickName']
        debug("收到消息!来源:" + usernick + " 内容:" + msg['Text'])
    except Exception as e:
        debug("回复消息:解析用户错误!错误原因:" + str(e) + ",msg = " + str(msg))
    if core.settings.get_value('TIEBA_SHIDA_UPDATEING_STATE') == False:
        core.game.core_input(usernick, int(time.time()), msg['Text'],
                             msg['FromUserName'])
    else:
        itchat.send_msg('贴吧更新正在进行中,请稍后访问本公众号!', msg['FromUserName'])
Пример #28
0
def flash_userdata(player_id):
    allinfo = core.userinfo.database_getall(player_id)
    if player_id in userdata:
        if allinfo == []:
            debug("******Database damage in flash_userdata," + player_id)
            return
        else:
            get_userdata(player_id, allinfo)
    else:
        if allinfo == []:
            core.userinfo.database_newuser(player_id)
            allinfo = core.userinfo.database_getall(player_id)
            get_userdata(player_id, allinfo)
        else:
            get_userdata(player_id, allinfo)
Пример #29
0
def RealTimeGetMSG(dbtables,lastmsg):
	newlastmsg = {}
	for table in dbtables:
		msg = GetNewestPrivateChat(table,MAX_CHATCOUNT_IN_INTERVAL)
		newlastmsg[table] = str(msg[0][0])+"--"+str(msg[0][1])+"--"+str(msg[0][2])
		for (rettime,rettalker,retmsg) in msg:
			
			if (lastmsg[table]==str(rettime)+"--"+rettalker+"--"+retmsg)or(lastmsg[table]==""):
				break #considering orderd by time, if encounter equals, the messages after are old.
			if retmsg.find("你悄悄地对")<0: # avoid the response interrupting 
				debug(str(rettime)+"###"+str(rettalker)+"###"+str(GetMessageLine(retmsg)),2)
				
				core.game.core_input(rettalker,rettime,str(GetMessageLine(retmsg)))
				
	return newlastmsg
Пример #30
0
    def workRunner(self, block, work):
        debug("block: " + block + " work: " + work)
        # [gen for gen in self.gen.featureBlock(self.dirtY) if gen['']]
        for gen in self.gen.featureBlock(self.dirtY):
            if gen["fb"][0] == "use" and gen["block"] == block and gen["os"] == self._os[0] and gen["subblock"] == work:

                feature = self.config.getFeature(gen["fb"][1])
                if feature:
                    self.config.putPackage(work, gen["feature"])
                    lst = [gen["os"], gen["block"], gen["subblock"]]
                    features = yamlReduce(self.dirtY, lst)[0][gen["feature"]]
                    self.features.RunFeature(gen["fb"][1], gen["subblock"], features)

                else:
                    debug("Not loaded: " + gen["fb"][1], ERROR)
Пример #31
0
 def test_sigmoid_node(self):
     x_node = node.VarNode('x')
     x = (np.array([[1, -1, 2]])).T
     var_map = {'x': x}
     sigmoid = SigmoidNode(x_node)
     x_node.forward(var_map)
     value = sigmoid.value()
     expected_value = 1 / (1 + np.exp(-x))
     np.testing.assert_array_almost_equal(expected_value, value)
     debug(value)
     sigmoid.backward(np.ones_like(value), self, var_map)
     grad = x_node.total_incoming_gradient()
     expected_grad = expected_value * (1 - expected_value)
     debug(grad)
     np.testing.assert_array_almost_equal(expected_grad / expected_grad.size, grad)
Пример #32
0
    def backprop(self, incoming_gradient, **kwargs):
        n = self.input.shape[0]
        del_s = np.zeros((n, n))
        for i in range(n):
            for j in range(n):
                if i==j:
                    del_s[i,j] = self.output[i,0]-self.output[i,0]**2
                else:
                    del_s[i,j] = -self.output[i,0]*self.output[j,0]
        debug("[Softmax.backprop()] incoming_gradient = np.{}".format(repr(incoming_gradient)))
        debug("[Softmax.backprop()] del_s = np.{}".format(repr(del_s)))

        self.outgoing_grad = del_s*incoming_gradient

        return self.outgoing_grad
Пример #33
0
    def _do_backprop(self, downstream_grad, downstream_node, var_map):
        r"""

        :param downstream_grad: should be ignored.
        :param downstream_node: should be ignored
        :param var_map:
        :return:
        """
        if self.prev_rnn_node is None:
            h0 = self.hidden_state_in
        else:
            h0 = self.prev_rnn_node._hidden_state_out()

        x = self.x_node.value()
        xh = np.concatenate((x, h0))
        incoming_y_grad, incoming_h_grad = self.total_incoming_gradient()
        if incoming_y_grad is None:
            if is_debug_on():
                debug("[RnnCell._do_backprop()] null incoming_y_grad ")
            incoming_y_grad = np.zeros((self.output_shape[0], 1))
        if incoming_h_grad is None:
            if is_debug_on():
                debug("[RnnCell._do_backprop()] Null incoming_h_grad = np.{}")
            incoming_h_grad = np.zeros((self.hidden_shape[0], 1))

        w_grad = incoming_y_grad @ xh.T
        u_grad = incoming_h_grad @ xh.T
        wb_grad = np.sum(incoming_y_grad, axis=1).reshape((-1, 1))
        ub_grad = np.sum(incoming_h_grad, axis=1).reshape((-1, 1))
        x_dim = x.shape[0]
        w = self.W.value()
        u = self.U.value()
        x_grad_from_y = w[:, 0:x_dim].T @ incoming_y_grad
        x_grad_from_h = u[:, 0:x_dim].T @ incoming_h_grad
        h_grad_from_y = w[:, x_dim:].T @ incoming_y_grad
        h_grad_from_h = u[:, x_dim:].T @ incoming_h_grad
        x_total_grad = (x_grad_from_h + x_grad_from_y)
        h_total_grad = (h_grad_from_h + h_grad_from_y)

        self.W.add_gradient(w_grad, self)
        self.Wb.add_gradient(wb_grad, self)
        self.U.add_gradient(u_grad, self)
        self.Ub.add_gradient(ub_grad, self)

        self.x_node.backward(x_total_grad, self, var_map)
        if not (self.prev_rnn_node is None):
            self.prev_rnn_node.backward((None, h_total_grad), self, var_map)
Пример #34
0
def APP_TuLing(player_id, msg):
    if msg == '退出':
        PlayerState[player_id] = 1
        response(1, player_id, 'from state 6')
    else:
        apiUrl = 'http://www.tuling123.com/openapi/api'
        data = {
            'key': TULINGKEY,  # 如果这个Tuling Key不能用,那就换一个
            'info': msg,  # 这是我们发出去的消息
            'userid': 'wechat-robot-' + str(player_id),  # 这里你想改什么都可以
        }
        try:
            r = requests.post(apiUrl, data=data).json()
            sendstr(player_id, r.get('Text'))
        except Exception as e:
            debug("图灵机器人出错,错误原因:" + str(e))
            sendstr(player_id, "群宝在打盹儿= =过会儿再来呗~~~")
Пример #35
0
	def patch(self, Name):
		Config = self.Config.GetConfig(Name)
		self.Config.CreateOutYaml(Name)
		Folder = self.Config.FindInPackage("extract",Name)
		PatchDir = ExtractNameFromTar(Folder['file'])
		CWD = os.getcwd()
		os.chdir("tmp/downloads/" + PatchDir)
		for File in Config["file"]:
			#IntelliPatcher(Files)
			PatchLevel =  File.split('@')
			pLevel = PatchLevel[1].split(':')[1]
			pFile  = PatchLevel[0]
			Patch = subprocess.Popen('patch -p%d < %s' % (int(pLevel),CWD+"/"+pFile), shell=True, stdout=None, stderr=None)
			Patch.wait()
			if Patch.returncode > 0:
				debug("Patch didn't return 0!",WARNING)
		os.chdir(CWD)
Пример #36
0
    def run(self, _all=False):
        """ this is the main runner for the yaml parser """
        ## Run all of the blocks
        if _all:
            for cmds in self.commands:
                debug(cmds, DEBUG)
                self.runBlock(cmds)
                self.depRunner(cmds)

        ## If value hasnt changed, raise ParseError
        if not _all:
            raise ParseError
        ## Otherwise run specified block
        else:
            # debug(_all, DEBUG)
            self.runBlock(_all)
            self.depRunner(_all)
Пример #37
0
    def test_2_debug(self):
        self.mock.StubOutWithMock(inspect, 'currentframe')
        inspect.currentframe(0).AndReturn('')  

        self.mock.StubOutWithMock(inspect, 'getouterframes')
        inspect.getouterframes('').AndReturn('')

        #configurator = self.mock.CreateMockAnything()
        #configurator.getGlobal('debug').AndReturn(3)
        #self.mock.StubOutWithMock(core.debug, '_dPrint')
        #debug._dPrint('').AndReturn('')

        self.mock.ReplayAll()

        debug('debug test', DEBUG)

        #self.assertStdoutEquals('')
        self.mock.VerifyAll()
Пример #38
0
def def_list_disable(line, time, backrefs):
	# TODO: compare this to our keepup list and correct!
	core.disable_trigger_group('def_list')
	# Flush player defences except channels
	for defence in player.defences:
		if defence not in ('earth', 'air', 'water', 'fire', 'spirit'):
			player.defences[defence] = 0

	for defence in player.pre_def:
		try:
			type = defences.defup_actions[defence][0]
			defences.clean_queues(type, defence)
		except KeyError:
			pass
		player.defences[defence] = 1
		core.debug("deflist added defence " + defence)

	player.pre_def = []
Пример #39
0
	def GET(self, request, artist_id):
		db = musicdb.model.db.DB()
		artists = self.get_related(db, artist_id)
		for artist in artists:
			if not artist.AliasID: # dan zal het wel een groep zijn, leden ophalen
				artist['Members'] = [a.ArtistID for a in db.artist.get_group_members(artist.ArtistID)]
			else:
				artist['Members'] = []
		graph = dict(
			(a.ArtistID, ([a.AliasID] if a.AliasID else []) + a.Members)
			for a in artists)
		node_text = dict((a.ArtistID, a.Name) for a in artists)
		core.debug(request, repr(graph)+'\n')
		core.debug(request, repr(node_text)+'\n')
		return webob.Response(
			body=musicdb.view.graph.draw_graph(graph, node_text, directed=False),
			content_type='image/png',
			cache_control='no-store, no-cache')			
 def test_batch(self):
     sx = sl.SoftmaxCrossEntropy()
     debug("-------------  Batch with 2 samples -----------------")
     predicted = np.array([[1, 3, -1, 0], [0, 9, 1, 3.]]).T.reshape(4, 2)
     debug("[SoftmaxTestCase.test_batch()] predicted = np.{}".format(
         repr(predicted)))
     target = np.array([[0, 1, 0, 0], [0, 0, 0, 1]]).T.reshape(4, 2)
     loss = sx.forward(predicted, target)
     debug("[SoftmaxTestCase.test_forward()] Loss = {}".format(repr(loss)))
     grad = sx.backward(1.0)
     debug("[SoftmaxTestCase.test_forward()] grad = np.{}".format(
         repr(grad.T)))
Пример #41
0
 def __init__(self, data_dir):
     self.all_letters = string.ascii_letters + " .,;'"
     self.n_letters = len(self.all_letters)
     self.data_dir = data_dir
     self.file_list = u.get_file_list(self.data_dir, u.ext_filter(".txt"))
     self.category_files = {}
     self.categories_list = []
     self.data = {}
     self.total_names = 0
     for file_name in self.file_list:
         language = os.path.splitext(os.path.basename(file_name))[0]
         self.category_files[language] = file_name
         lines = self.read_lines(file_name)
         self.data[language] = lines
         self.total_names += len(lines)
         self.categories_list.append(language)
     self.n_categories = len(self.category_files)
     debug("[NameDS.__init__()] self.total_names = {}".format(
         self.total_names))
Пример #42
0
    def __init__(self, name=None, is_trainable=False):
        global compute_node_list
        idx = len(compute_node_list)
        compute_node_list.append(self)

        if name:
            self.name = name + "-" + str(idx)
        else:
            self.name = self.__class__.__name__ + str(idx)
        debug("Created Node named:{}".format(self.name))
        self.upstream_nodes = {}
        self.downstream_nodes = {}
        self.grad_from_downstream = []
        self.fwd_count = 0
        self.back_count = 0
        self.node_value = None
        self._total_incoming_grad_value = None
        self.is_trainable = is_trainable
        self.optimization_storage = {}
Пример #43
0
    def depRunner(self, block):
        """ resolves the dependencies """
        lst = [
            gen["subblock"]
            for gen in self.gen.featureBlock(self.dirtY)
            if gen["block"] == block and gen["os"] == self._os[0]
        ]

        for gen in self.gen.featureBlock(self.dirtY):
            if gen["os"] == self._os[0]:
                if gen["block"] == block or block == True:
                    if gen["fb"][0].lower() == "dependencies":
                        for deps in gen["fb"][1]:
                            debug("[" + gen["subblock"] + "] depends on: " + deps, INFO)
                            self.deps.depGenAdd(gen["subblock"], deps)
                    else:
                        self.deps.depGenAdd(gen["subblock"])

        depList = self.deps.dependencyGenRun()
        for revDep in depList[0]:
            self.workRunner(block, revDep)
Пример #44
0
    def tar(self, Name, filename=None):
        Tar = {}
        Config = self.Config.GetConfig(Name)
        debug(Config, DEBUG)
        File = Config["file"]

        if filename:
            File = Filename

        self.Config.CreateOutYaml(Name)
        if not os.path.exists("tmp/downloads/"+ExtractNameFromTar(File)):
            print "[tar] Extracting: " + File
            if os.path.exists("tmp/downloads/"+File):
                End = File.split(".")
                if End[-1] == "bz2":
                    tar = tarfile.open(name="tmp/downloads/" + File,mode='r:bz2')
                    try:
                        extract = tar.extractall(path="tmp/downloads/",members=None)
                    except EOFError,e:
                        print "The file appears to be corrupt, run with",
                        print "--clean and then retry building"
                        debug(e, ERROR)
                        sys.exit(0)
                if End[-1] == "gz":
                    tar = tarfile.open(name="tmp/downloads/" + File,mode='r:gz')
                    try:
                        extract = tar.extractall(path="tmp/downloads/",members=None)
                    except EOFError,e:
                        print "The file appears to be corrupt, run with",
                        print "--clean and then retry building"
                        debug(e, ERROR)
                        sys.exit(0)
Пример #45
0
    def forward(self, var_map: ComputeContext):
        if self.prev_rnn_node is None:
            h0 = self.hidden_state_in
        else:
            h0 = self.prev_rnn_node._hidden_state_out()

        x = self.x_node.value()
        xh = np.concatenate((x, h0))

        w = self.W.value()
        wb = self.Wb.value()
        u = self.U.value()
        ub = self.Ub.value()

        y = w @ xh + wb
        h = u @ xh + ub

        self.node_value = y, h
        self.hidden_state_out = h

        if is_debug_on():
            debug("[{}] RnnCell.forward() y=np.{}".format(
                self.simple_name(), repr(y)))
            debug("[{}] RnnCell.forward() h=np.{}".format(
                self.simple_name(), repr(h)))
            debug("[{}] RnnCell.forward() x=np.{}".format(
                self.simple_name(), repr(x)))

        self._forward_downstream(var_map)
Пример #46
0
def bcure(cure):
	now = time.time()

	core.debug("registering blackout cure " + cure)

	player.waiting_for_aeon = 0

	if player.fire_focus and player.focus_balance == .5:
		core.debug("fired focus in blackout")
		player.fire_focus = False
		player.focus_balance = 0
		player.actions['focus'] = True
		core.enable_trigger('focus_balance', 'balances')

	ate = False
	for herb in player.blackout_ate:
		if player.blackout_ate[herb] == True:
			ate = True
			ate_herb = herb
			core.debug("Ate " + ate_herb + " in blackout")
			player.blackout_ate[herb] = False

	if ate:
		player.herb_balance = 0
		player.herb_lastate = now
		player.ate[ate_herb] = True
		herbs.herbs[ate_herb].inv -= 1

	cures.cure(cure)
Пример #47
0
def output(string):
	global conc_curing, next_cure
	if core.retardation_mode:
		next_cure = string
		if rr_auto == False:
			return

	player.waiting_for_aeon = .5

	if player.afflictions['amnesia'] or player.afflictions['concussion']:
		core.write(string)
		core.write(string)
		#core.write(string)
	else:
		core.write(string)

	if player.afflictions['concussion']:
		conc_curing = string
	else:
		conc_curing = False

	core.debug("Aeon Event: Firing " + string)
Пример #48
0
 def test_delete(self):
     x = np.random.rand(5,4)
     debug("[TestingPythonDelete.test_delete()]  x= np.{}".format(repr(x)))
     c = Container(3,x)
     debug("[TestingPythonDelete.test_delete()] c = np.{}".format(repr(c)))
     del c 
     time.sleep(1) 
     debug("[TestingPythonDelete.test_delete()] x = np.{}".format(repr(x)))
Пример #49
0
def affliction_event():
	global temporary_priorities, temps_focus, preempt_cures

	core.disable_trigger_group('venoms')
	cures.disable_restro_break_triggers()

	real = True
	if len(cures.pre_afflictions) > 0:
		for aff in cures.pre_afflictions:
			if cures.ai['reflection_strike']:
				if aff in ('roped', 'impale'):
					real = False

			if cures.lifevision:
				real = False
				core.debug("lifevision nulled out affliction " + aff)

			# stupidity failures
			if aff == 'stupidity' and player.afflictions['stupidity'] is True:
				player.waiting_for_aeon = 0

			# sleep resetting
			if aff == 'sleep':
				player.waiting_for_aeon = 0

			if real:
				cures.escalate_breaks(aff)
				player.afflictions[aff] = True

		cures.pre_afflictions = []
		cures.ai['reflection_strike'] = False

	if core.retardation_mode:
		dynamic_retardation_priorities()
	else:
		dynamic_priorities()

	load_queue()
Пример #50
0
 def test_batch_norm(self):
     x = np.array([[1, 2, 3], [3, 4, 1]])
     x_node = node.VarNode('x')
     bnorm = reg.BatchNormalization(x_node)
     x_node.forward({'x': x})
     norm_value = bnorm.value()
     debug("normalized value = np.{}".format(repr(norm_value)))
     bnorm.backward(np.ones_like(norm_value), self, {'x': x})
     grad_at_x = x_node.total_incoming_gradient()
     debug("grad_at_x = np.{}".format(repr(grad_at_x)))
     debug(
         "[BatchNormalizationTest.test_something()] bnorm.gamma_grad = np.{}"
         .format(repr(bnorm.gamma_grad)))
     debug(
         "[BatchNormalizationTest.test_something()] bnorm.beta_grad = np.{}"
         .format(repr(bnorm.beta_grad)))
Пример #51
0
    def forward(self, compute_context: ComputeContext):
        x = self.input_node.value()
        if not self.weights_initialized:
            self.input_dim = x.shape[0]
            compute_context.initialize_layer(self)

        if is_debug_on():
            debug("[{}] DenseLayer.forward() W=np.{}".format(self.simple_name(), repr(self.w)))
            debug("[{}] DenseLayer.forward() b=np.{}".format(self.simple_name(), repr(self.b)))
            debug("[{}] DenseLayer.forward() x=np.{}".format(self.simple_name(), repr(x)))
        self.node_value = self.w @ x + self.b
        self._forward_downstream(compute_context)
Пример #52
0
 def InitUpdateTieba(self):
     debug("初始化贴吧十大 启动", 2)
     todayymd = time.strftime("%y-%m-%d")
     if not os.path.exists(todayymd + "_2"):
         debug("未检测到今日十大")
         core.jx3tieba.tiebatop_update("剑网三", todayymd)
         time.sleep(1)
     else:
         debug("检测到今日十大,直接使用已生成文件")
     if core.settings.TIEBA_UPDATE_FORCE == 1:
         debug("十大强制更新开关 打开,开始更新十大")
         core.jx3tieba.tiebatop_update("剑网三", todayymd)
         time.sleep(1)
     f = open(todayymd + "_2", 'rU', encoding='utf-8')
     tmplist = []
     for i in range(0, 10):
         tmplist.append(f.readline().strip("\n"))
     core.settings.set_value('TIEBA_SHIDA', tmplist)
     core.settings.set_value('TIEBA_SHIDA_UPDATE', todayymd)
     core.settings.set_value('TIEBA_UPDATE_TO', todayymd)
Пример #53
0
    def test_forward(self):
        input_x_node = n.VarNode('x')

        rnn_cell = rnn.RnnCell(input_x_node, None, self.w_param, self.wb_param,
                               self.u_param, self.ub_param, self.h)
        input_x_node.forward(self.var_map)
        y, h = rnn_cell.value()
        debug("[SimpleRnnCellTests.test_forward()] y = np.{}".format(repr(y)))
        debug("[SimpleRnnCellTests.test_forward()] h = np.{}".format(repr(h)))
        dely, delh = y * .1, h * .1
        rnn_cell.backward((dely, delh), self, self.var_map)
        grad_x = input_x_node.total_incoming_gradient()
        debug("[SimpleRnnCellTests.test_forward()] grad_x = np.{}".format(repr(grad_x)))
Пример #54
0
    def init_readskills(self):
        debug("readskills组件初始化")
        try:
            f = open(core.settings.APP_skill_filename, encoding='utf-8')
            skilllist = f.readlines()
            f.close()
            core.settings.set_value("APP_SKILL_SKILLLIST", skilllist)

            if not os.path.exists(core.settings.APP_skill_savedir):
                os.mkdir(core.settings.APP_skill_savedir)
        except Exception as e:
            debug("readskills组件初始化失败,原因:" + str(e), '错误')
            return
        debug("readskills组件初始化成功!")
Пример #55
0
 def test_logit_cross_entropy(self):
     logits = np.array([[2, 1, 4, -1], [3, 2, 1, -9]])
     target_values = np.array([2, 0])
     one_hot_target = to_one_hot(target_values, logits.shape[1] - 1)
     debug(" [SimpleActivationTests.test_logit_cross_entropy()] one_hot_target = np.{}".format(repr(one_hot_target)))
     pred_node = node.VarNode('yp')
     target_node = node.VarNode('yt')
     var_map = {'yp': logits.T, 'yt': one_hot_target}
     lx = LogitsCrossEntropy(pred_node, target_node)
     pred_node.forward(var_map)
     target_node.forward(var_map)
     value = lx.value()
     expected = 0.2915627072172198
     debug(" [SimpleActivationTests.test_logit_cross_entropy()] value = {}".format(repr(value)))
     self.assertAlmostEqual(expected, value)
     lx.backward(1.0, self, var_map)
     grad = pred_node.total_incoming_gradient()
     debug(" [LogitCrossEntropyTests.test_logit_cross_entropy()] grad = np.{}".format(repr(grad)))
     expected_grad = np.array([[5.67748097e-02, -1.67380882e-01],
                               [2.08862853e-02, 1.22363735e-01],
                               [-8.04877463e-02, 4.50151026e-02],
                               [2.82665133e-03, 2.04368250e-06]])
     debug(" [LogitCrossEntropyTests.test_logit_cross_entropy()] expected_grad = np.{}".format(repr(expected_grad)))
     np.testing.assert_array_almost_equal(expected_grad, grad)
Пример #56
0
 def runner(self, recipeName, *arguments):
     ''' runner, arguments: recipeLocation '''
     debug(arguments, DEBUG)
     try:
         module = sys.modules['recipes.' + recipeName]
     except KeyError:
         __import__('recipes.' + recipeName)
         module = sys.modules['recipes.' + recipeName]
         
     ## if the recipe has requirements
     if 'requires' in module.__dict__ and isinstance(module.__dict__['requires'], list):
         for reqs in  module.__dict__['requires']:
             if self.config.getFeature(reqs):
                 debug('feature %s available' % (reqs), DEBUG)
             else:
                 debug('feature %s unavailable' % (reqs), DEBUG)
                 print 'plugin %s not available, exiting gracefully...' %  (reqs)
                 sys.exit(-1)
     
     ## run the run function, run()    
     for function in module.__dict__:
         if function == self.runFunction:
             self.run(module, arguments)
Пример #57
0
def chdir(dir):
    ''' Wrapper for os.chdir so that it emits debugging code '''
    debug("Changing to directory: " + dir, DEBUG)
    os.chdir(dir)
Пример #58
0
	def GET(self, request, artist_id):
		db = musicdb.model.db.DB()
		related = self.get_related(db, artist_id)
		core.debug(request, `related`+'\n')
		return webob.Response(body=musicdb.view.artist.artist_list(related))
Пример #59
0
    def run(self):
        ''' runs all of the blocks of yaml code '''
        block = {}

        for blck, a in reversed(self.dyaml.items()):
            for subblock, b in a.items():
                if isinstance(b, dict):
                    for feature, value in b.items():
                        if 'recipe' not in feature:
                            try:
                                block[subblock].append({feature:value})
                            except KeyError:
                                block[subblock] = []
                                block[subblock].append({feature:value})

                else:
                    if 'recipe' not in subblock:
                        try:
                            block[blck].append({subblock:b})
                        except KeyError:
                            block[blck] = []
                            block[blck].append({subblock:b})



        for gen in yGen(self.dyaml):
            if isinstance(gen['keys'], dict):         
                if 'recipe' in gen['keys']:
                    try:
                        debug(block[gen['subblock']], DEBUG)
                        if block.has_key(gen['subblock']):
                            self.recipe.runner(gen['keys']['recipe'], block[gen['subblock']])
                        if block.has_key(gen['block']):
                            self.recipe.runner(gen['keys']['recipe'], block[gen['block']])
                            
                    except KeyError:
                        self.recipe.runner(gen['keys']['recipe'])

            elif isinstance(gen['keys'], bool):
                pass
            elif '->' in gen['keys']:
                thenCount = 1
                thenList = gen['keys'].split('->')
                then = []
                for thenItr in thenList:
                    if not thenCount % 2:
                        if thenItr[:1] == ' ':
                            thenItr = thenItr[1:]
                    else:
                        if thenItr[:-1] == ' ':
                            thenItr = thenItr[-1:]
                            
                    then.append(thenItr)
                    thenCount = thenCount + 1  
                    
                for recipe in then:
                    try:
                        if block.has_key(gen['subblock']):
                            self.recipe.runner(gen['keys'], block[gen['subblock']])
                        if block.has_key(gen['block']):
                            self.recipe.runner(gen['keys'], block[gen['block']])
                        
                    except Exception, E:
                        print E
                        debug(E, ERROR)
                        debug('%s failed so any dependants will not run' % (recipe), ERROR)
                        sys.exit(-1)
 def __debugSignal(self, *args):
     """ Receives debug signal """
     debug(str(args))