Example #1
0
def evaluate(model, dataset, emap, tmap, min_dur=0, raw=False):
    """ Evaluate the model on the embeddings corresponding to emap and tmap.
    The code assumes that tmap only has single-session test models.
    For the multi-session enrollment models, we simply create single-session trials
    and then average the resulting scores. 
    """
    if len(tmap.mappings.keys()) > 1 or list(tmap.mappings.keys())[0] != 1:
        raise Exception("Scoring not implemented for multi-session test maps.")

    data = dataset.get_data()
    durs = dataset.get_durs()
    ids = dataset.get_ids()
    model.eval()

    with torch.no_grad():

        # We assume that emap and tmap were created using the ids in the dataset, but
        # we double check just in case.
        if np.any(ids != tmap.sample_ids) or np.any(ids != emap.sample_ids):
            raise Exception(
                "The dataset is not sorted the same way as the columns in emap or tmap. Make sure emap and tmap are created using the sample_ids in the dataset object you use in evaluation."
            )

        tidx = tmap.mappings[1]['map'][0]
        tids = tmap.model_ids
        scores = []
        eids = []
        for k in emap.mappings.keys():
            emapk = emap.mappings[k]['map']
            eidsk = emap.mappings[k]['model_ids']
            eids += eidsk
            scoresk = torch.zeros(len(eidsk), len(tids))
            for i in np.arange(k):
                eidx = emapk[i]
                scoreski = model.score(data[eidx],
                                       data[tidx],
                                       durs[eidx],
                                       durs[tidx],
                                       raw=raw)
                scoreski[durs[eidx] < min_dur, :] = 0
                scoreski[:, durs[tidx] < min_dur] = 0
                scoresk += scoreski
            scoresk /= k
            scores.append(scoresk)

        scores = torch.cat(scores, 0)
        # Make sure that the enrollment ids are sorted as in the emap, else, other stuff might break.
        # If there are no bugs this check should always pass.
        if np.any(eids != emap.model_ids):
            raise Exception(
                "Something is wrong, model_ids in emap do not coincide with the model ids after scoring"
            )

    return scr.Scores(eids, tids, scores)
Example #2
0
    def __init__(self):
        # Consts
        self._PLAYGROUND_WIDTH = 10  # PLGR - short for playground
        self._PLAYGROUND_HEIGHT = 20
        self._MARGIN = 20
        self._SCALE = 30  # px
        self._WIDTH = self._SCALE * self._PLAYGROUND_WIDTH * 2 + 2 * self._MARGIN  # *2, bo pole na wynik, menu
        self._HEIGHT = self._SCALE * self._PLAYGROUND_HEIGHT + 2 * self._MARGIN
        self._FPS = 30

        self._RUNNING = True
        self._PAUSED = False
        self._SWAPPED = False
        self._SCORES = False

        self._MOVE_SIDE_TIME = time()
        self._MOVE_DOWN_TIME = time()
        self._MOVE_SIDE_SPEED = 0
        self._MOVE_DOWN_SPEED = 0.4
        self._HIDE_REFALL = 0

        self._SCORE = 0
        self._LEVEL = 1

        # initialization
        pygame.init()                                                       # Pygame
        self.musicplayer = ms.Music()                                       # Music
        self.screen = pygame.display.set_mode((self._WIDTH, self._HEIGHT))  # Screen
        self.clock = pygame.time.Clock()                                    # clock
        pygame.display.set_caption(
            "Tetris - Adrian Janakiewicz (C) 2017 _FPS: {:.2f}".format(self.clock.get_fps()))  # Window caption

        self.playground = pg.Playground(self.screen, self._PLAYGROUND_WIDTH,
                                        self._PLAYGROUND_HEIGHT, self._SCALE, self._MARGIN)

        self.utility_window = ud.UtilityWindow(self.screen, self._PLAYGROUND_WIDTH,
                                               self._PLAYGROUND_HEIGHT, self._SCALE, self._MARGIN)

        self.scores_screen = sc.Scores(self.screen, self._WIDTH, self._HEIGHT)

        self.falling = bl.Tetromino(-5, 3)
        self.next_piece = bl.Tetromino(2, 13)
        self.utility_window.next_piece = self.next_piece
Example #3
0
def main():
    '''interface for user. will prompt user for options 1-5. Exits upon option 5. Will
    re-ask user if repsonse invalid'''
    scoresObj = scores.Scores()
    menu(scoresObj)
Example #4
0
challengeDir = "challenges"
sys.path.append(challengeDir)
DEBUG = 1

#CONFIGZ
#http://docs.python.org/library/socketserver.html

HOST, PORT = '', 1337

#
#
#	Code::Phun Network challonge.
#
#

scores = scores.Scores()


def load(chl):
    """ Dynamically loading modules. Returns the module loaded"""

    if os.path.isdir(chl): return load("%s.%s" % ((chl, chl)))

    byteCodeFile = challenge.Challenge.challengeDir + "/" + chl + ".pyc"
    if (os.path.exists(byteCodeFile)):
        print("python bytecode exists. Deleting it ")
        try:
            os.remove(byteCodeFile)
        except:
            print(
                "Could not delete file. please delete manually for a refreshed challenge"
Example #5
0
def main():
    global count, ID

    score = scores.Scores()

    my_camp = camp.Camp()

    while True:
        new_snake = snake.Snake()
        i = new_snake.get_orientation()
        s = new_snake.get_snake(my_camp.set_position(i))
        if my_camp.add_snake_camp(s):
            list_snakes.append(s)
            count += 1
        if count == mode:
            break
    count = 0

    player_one = player.Player()
    my_camp.create_camp(0)

    if mode == EASY: my_mode = EASY_MODE
    elif mode == NORMAL: my_mode = NORMAL_MODE
    elif mode == HARD: my_mode = HARD_MODE

    # Rode enquanto os erros do player forem menores que 20 e os acertos menores que 25
    while True:

        if player_one.get_total_errors() < my_mode:

            # player_one.hit() retorna um False ou um número(True). Se False ele sair do while
            to_return = player_one.guess()
            if to_return:
                my_camp.create_camp(to_return)
                player_one.errors = my_camp.get_errors()

                if my_camp.error == 1:
                    score.guess_hit()
                elif my_camp.error == 0:
                    score.guess_error()

                print('-' * WIDTH)
                print('\tPontuação: [ {} ]'.format(score.get_total()), end=' ')
                player_one.get_info()

                thread.start_new_thread(hits_player, (to_return, ))
                # hits_player(to_return)

                count += 1
                # Se o player alcançar 25 acertos ele é declarado vencedor
                if player_one.get_hits() == my_camp.get_total_positions():
                    print(FRAME[2])
                    time.sleep(2)
                    score.winner()
                    print('\tSua pontuação foi [ {} ]\n'.format(
                        score.get_total()))

                    # Salvar dados
                    db.saveData(ID, score.get_total(), count,
                                player_one.get_hits(), mode, today)
                    db.closeConnection()

                    print('As posições das cobras eram essas:\n')
                    for i in range(len(list_snakes)):
                        print('Cobra {0} : {1} -> Acertos: {2}\n'.format(
                            i + 1, list_snakes[i], list_snakes_hits[i]))
                    break

            else:
                break
        else:
            print(FRAME[1])
            time.sleep(2)
            score.loser()
            print('\tSua pontuação foi [ {} ]\n'.format(score.get_total()))

            # Salvar dados
            db.saveData(ID, score.get_total(), count, player_one.get_hits(),
                        mode, today)
            db.closeConnection()

            print('As posições das cobras eram essas:\n')
            for i in range(len(list_snakes)):
                print('Cobra {0} : {1} -> Acertos: {2}\n'.format(
                    i + 1, list_snakes[i], list_snakes_hits[i]))
            break
Example #6
0
import scores

score = scores.Scores()

# score.guess_hit()
# score.guess_hit()
# score.guess_hit()
# score.guess_hit()

print(score.get_total())

score.guess_error()
score.guess_error()
score.guess_error()
score.guess_error()
score.guess_error()

print(score.get_total())

score.guess_hit()
score.guess_hit()

print(score.get_total())

score.guess_error()
score.guess_error()

print(score.get_total())

# score.guess_hit()
# score.guess_hit()