예제 #1
0
    def decode_sen_no(self, s):
        self.current_list_cl = self.data.crowdlabs[s]
        sentence = self.data.sentences[s]

        ml_states = self.decode(util.get_obs(
            sentence), include_crowd_obs=True)

        return ml_states
예제 #2
0
def run_test(test, h):
    cnt = 0
    correct = 0
    for s in test:
        x = util.get_obs(s)
        g = util.get_lab(s)
        p = h.decode(x)
        for i, j in zip(g, p):
            cnt += 1
            if i == j:
                correct += 1

    print correct * 1.0 / cnt
예제 #3
0
 def mls(self):
     """
     compute the most likely states seq for all sentences
     :return:
     """
     self.res = []
     for s, sentence in enumerate(self.data.sentences):
         if len(sentence) > 0:
             self.current_list_cl = self.data.crowdlabs[s]
             ml_states = self.decode(util.get_obs(
                 sentence), include_crowd_obs=True)
             self.res.append(ml_states)
         else:
             self.res.append([])
}

freqs = {
    _CONCEDER: [1, 1, 1, 1, 1, 1, 1],
    _HARDHEADED: [1, 1, 1, 1, 1, 1, 1],
    _TFT: [1, 1, 1, 1, 1, 1, 1],
    _RANDOM: [1, 1, 1, 1, 1, 1, 1]
}
fileNames = os.listdir(training_folder)
testFileName = ""

for name in fileNames:
    strategy_names = name.split('.')[0].split('_')
    strat1 = u.get_strat_name(strategy_names[0])
    strat2 = u.get_strat_name(strategy_names[1])
    obs = u.get_obs(name)

    for i in range(len(obs)):
        a1 = obs[i][0]
        a2 = obs[i][1]

        a1 = u.movetype_to_number(a1)
        a2 = u.movetype_to_number(a2)
        freqs[strat1][a1] += 1

        freqs[strat2][a2] += 1
print("Concede-selfish-fortune-unfortune-nice-silent-unchange")
for k in freqs.keys():
    freqs[k] = u.normalize(freqs[k])

for k in freqs.keys():
예제 #5
0
 def decode_all(self, sentences):
     self.res = []
     for s in sentences:
         mls = self.decode(util.get_obs(s))
         self.res.append(mls)
예제 #6
0
def get_tag_hc(hc, sen):
    return hc.decode(util.get_obs(sen))
예제 #7
0
for name in fileNames:
    # reset the frequencies count, except for the tit-for-tat strategy
    freqs[_CONCEDER] = [0, 0, 0, 0, 0, 0, 0]
    freqs[_HARDHEADED] = [0, 0, 0, 0, 0, 0, 0]
    freqs[_RANDOM] = [0, 0, 0, 0, 0, 0, 0]

    # store the previous evidence probabilities matrix
    old_prob = prob

    # extrapolate the strategy IDs from the file name
    strategy_names = name.split('.')[0].split('_')
    strat1 = u.get_strat_name(strategy_names[0])
    strat2 = u.get_strat_name(strategy_names[1])

    # define the observations vector. It would contain couple of moves: [agent1_move, agent2_move]
    obs = u.get_obs(folderPath + name)

    # extrapolate the moves of agent1 and store them
    o1 = []
    for o in obs:
        o1.append(o[0])
    observations[strat1].append(o1)

    # extrapolate the moves of agent2 and store them
    o2 = []
    for o in obs:
        o2.append(o[1])
    observations[strat2].append(o2)

    # count how many moves of each type the agents did
    for i in range(len(obs)):