def main(): print "Entity Linking System in Web Tables with Multiple Linked Knowledge Bases" print "Version 2.1" print "Copyright @2017/3/1 Shengjia Yan. All Rights Reserved." # mark() # preprocess() # candidate_generation() entity_disambiguation() result()
def QLearning(num_episodes, e, gamma, lr, Q, GenerateAction1): for epi in range(0, num_episodes): i = 0 done = False reward = 0 action1 = {} action2 = {} Grade1, Grade2, player1, player2 = Grade() [level1, rank1] = Grade1 # if level1 > 1: # action111 = (1, 1, 1, 1, 1) # if level1 == 1: # action111 = (1, 0, 0) [level, rank] = GradetheAgent() winnerp = judge(Grade1, Grade2) action = (0, 1, 2, 3) ##################### #taolu if GenerateAction1 == 1: action111 = genact1(level1, rank1) if GenerateAction1 == 2: action111 = genact2(level1, rank1) if GenerateAction1 == 3: action111 = genact3(level1, rank1) #action1[0] = random.choice(action) action1[0] = action111[0] pot = 30 R = 0 delta = 10 if action1[0] == 0 or action1[0] == 3: done = True action2[0] = 0 #reward = result(action1, action2, winnerp) if action1[0] == 1: pot = 10 delta = 10 if action1[0] == 2: pot = 20 delta = 20 state = state2[pot][R][delta][level][rank] while not done: if action1[i] == 0 or action1[i] == 3: reward = result(action1, action2, winnerp) Q[state][0] = Q[state][0] + lr * reward Q[state][1] = Q[state][1] + lr * reward Q[state][2] = Q[state][2] + lr * reward Q[state][3] = Q[state][3] + lr * reward break if action1[i] == 1 or action1[i] == 2: a = random.random() if a < 1 - 4 / 3 * e: action2[i] = np.argmax(Q[state]) else: action2[i] = random.choice(action) #action1[i+1] = random.choice(action) action1[i + 1] = action111[i + 1] QA = np.zeros(4) #if (action2[i] == 0 or action2[i] == 3) or R == 4: if (action2[i] == 0 or action2[i] == 3) or R == 2: reward = result(action1, action2, winnerp) Q[state][action2[i]] = Q[state][action2[i]] + lr * reward break if action2[i] == 1: if action1[i + 1] == 1: pot = pot + 2 * delta if action1[i + 1] == 2: pot = pot + 3 * delta delta = 2 * delta if action2[i] == 2: if action1[i + 1] == 1: pot = pot + 4 * delta delta = 2 * delta if action1[i + 1] == 2: pot = pot + 6 * delta delta = 4 * delta statep = state2[pot][R][delta][level][rank] for actionp in range(0, 4): QA[actionp] = Q[statep][actionp] Q[state][action2[i]] = Q[state][action2[i]] + lr * ( reward + gamma * max(QA) - Q[state][action2[i]]) state = statep R = R + 1 i = i + 1 # if epi > 999900: # print(action2) return Q
# print('cards of Player1:') # print(player1) [level, rank] = Grade2 winnerp = judge(Grade1, Grade2) action = (0, 1, 2, 3) action1 = {} action2 = {} pot = 20 delta = 10 #for R in range(0, 5): for R in range(0, 3): action1[R] = random.randint(0, 3) if action1[R] == 0 or action1[R] == 3: action2[R] = 0 reward = result(action1, action2, winnerp) break if action1[R] == 1: pot = pot + delta state = state2[pot][R][delta][level][rank] action2[R] = np.argmax(Q[state]) if action2[R] == 1: pot = pot + delta if action2[R] == 2: pot = pot + 2 * delta delta = 2 * delta if action1[R] == 2: pot = pot + 2 * delta delta = 2 * delta state = state2[pot][R][delta][level][rank]
from result import * import pickle for depth in [2,3,4]: for branches in [11]: r=result(s,branches,depth) p=r.finalResult print depth,branches,p[0],p[1][0],p[1][1],p[1][2],p[1][3] del p del r gc.collect()
from result import * import pickle for depth in [2, 3, 4]: for branches in [11]: r = result(s, branches, depth) p = r.finalResult print depth, branches, p[0], p[1][0], p[1][1], p[1][2], p[1][3] del p del r gc.collect()
hheaders1 = ['alumno'] hheaders1.extend(list(np.unique(vr._get_('videos','observer._id_')))) vheaders1 = ['segundos'] times2 = vr.timesFor('weekdays') hheaders2 = ['dia'] hheaders2.extend(list(np.unique(vr._get_('videos','weekday()')))) vheaders2 = ['segundos'] times3 = vr.timesFor('blocks') hheaders3 = ['bloque'] hheaders3.extend(list(np.unique(vr._get_('videos','block')))) vheaders3 = ['segundos'] times4 = vr.timesFor('subjects') hheaders4 = ['materia'] hheaders4.extend(list(np.unique(vr._get_('videos','subject')))) vheaders4 = ['segundos'] times5 = vr.timesFor('observers','subjects') hheaders5 = ['alumno\\materia'] hheaders5.extend(list(np.unique(vr._get_('videos','subject')))) vheaders5 = list(np.unique(vr._get_('videos','observer._id_'))) hheaders = [hheaders1,hheaders2,hheaders3,hheaders4,hheaders5] vheaders = [vheaders1,vheaders2,vheaders3,vheaders4,vheaders5] times = [times1,times2,times3,times4,times5] res = result('tiempos de grabacion', hheaders, vheaders, times) res.toExcel('tiempos.xls')