示例#1
0
def hist_compare_best(game,name='dense',num_games=100):

    wins_list = []
    losses_list = []
    draws_list = []
    best_wins = 0
    best_net = 0
    for net_no in range(1,11):
        if best_net == 0:
            player2 = Nets.Dense()                                                             # dense or conv
        else:
            player2 = Nets.Dense()                                                             # dense or conv
            player2.load_state_dict(torch.load(name+'/'+name+str(int(best_net))+'.pth'))       # dense or conv
            player2.eval()
        player1 = Nets.Dense()                                                                 # dense or conv
        player1.load_state_dict(torch.load(name+'/'+name+str(int(net_no))+'.pth'))             # dense or conv
        player1.eval()
        print('Pitting',net_no-1,'and',net_no)
        wins,draws,losses = pit_against_network(player1,player2,game,num_games)
        print('wins:',wins)
        print('draws:',draws)
        print('losses:',losses)
        if(wins>=best_wins):
            best_wins = wins
            best_net = net_no
        print('Best Net:',best_net)
        wins_list.append(wins)
        draws_list.append(draws)
        losses_list.append(losses)
    
    plt.plot(wins_list,color='green')
    plt.plot(losses_list,color='red',alpha=0.3)
    plt.savefig('BestHistComp'+name+'.png')
示例#2
0
import numpy as np
import torch

import Nets
from eval import pit_against_network, pit_human, hist_compare
from Connect4Game import Connect4Game

if __name__ == '__main__':

    # initialize networks
    net = Nets.Dense()
    net.load_state_dict(torch.load('dense/dense9.pth'))
    net.eval()
    aux_net = Nets.Dense()

    # initialize game
    game = Connect4Game()

    wins, draws, losses = pit_against_network(net, aux_net, game, 100)

    print('Wins:', wins)
    print('Losses:', losses)
    print('Draws:', draws)

    #pit_human(net,game)
    #hist_compare(game,name='dense',num_games=100)